Skip to content

Commit

Permalink
feat: add numbers to the seed phrases and update style (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranroneill authored Aug 23, 2024
1 parent 86747b5 commit 670f287
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
49 changes: 41 additions & 8 deletions src/extension/components/SeedPhraseDisplay/SeedPhraseDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,61 @@
import { Code, Grid, GridItem } from '@chakra-ui/react';
import React, { FC } from 'react';
import { Grid, GridItem, HStack, Text } from '@chakra-ui/react';
import React, { type FC } from 'react';

// constants
import { DEFAULT_GAP } from '@extension/constants';

// hooks
import useDefaultTextColor from '@extension/hooks/useDefaultTextColor';
import useTextBackgroundColor from '@extension/hooks/useTextBackgroundColor';

// types
import type { IProps } from './types';

const SeedPhraseDisplay: FC<IProps> = ({ seedPhrase }) => {
const SeedPhraseDisplay: FC<IProps> = ({ _context, seedPhrase }) => {
// hooks
const defaultTextColor = useDefaultTextColor();
const textBackgroundColor = useTextBackgroundColor();

return (
<Grid gap={2} templateColumns="repeat(3, 1fr)" w="full">
<Grid gap={DEFAULT_GAP / 3} templateColumns="repeat(3, 1fr)" w="full">
{seedPhrase.split(' ').map((value, index, array) => {
const node = (
<HStack
alignItems="center"
backgroundColor={textBackgroundColor}
borderRadius="full"
px={DEFAULT_GAP / 3}
py={1}
spacing={DEFAULT_GAP / 3}
w="full"
>
{/*numbering*/}
<Text as="b" color={defaultTextColor} fontSize="xs">
{index + 1}
</Text>

{/*word*/}
<Text color={defaultTextColor} fontSize="sm">
{value}
</Text>
</HStack>
);

if (index >= array.length - 1) {
return (
<GridItem
colEnd={2}
colStart={2}
key={`seed-phrase-display-item-${index}`}
key={`${_context}-seed-phrase-display-item-${index}`}
>
<Code w="full">{value}</Code>
{node}
</GridItem>
);
}

return (
<GridItem key={`seed-phrase-display-item-${index}`}>
<Code w="full">{value}</Code>
<GridItem key={`${_context}-seed-phrase-display-item-${index}`}>
{node}
</GridItem>
);
})}
Expand Down
1 change: 1 addition & 0 deletions src/extension/components/SeedPhraseDisplay/types/IProps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
interface IProps {
_context: string;
seedPhrase: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const CreateNewAccountPage: FC<IAddAccountPageProps> = ({
const [name, setName] = useState<string | null>(null);
const [nameError, setNameError] = useState<string | null>(null);
// misc
const _context = 'create-new-account-page';
const seedPhrase = convertPrivateKeyToSeedPhrase({
logger,
privateKey: keyPair.privateKey,
Expand Down Expand Up @@ -172,7 +173,10 @@ const CreateNewAccountPage: FC<IAddAccountPageProps> = ({
</Text>

{/*seed phrase*/}
<SeedPhraseDisplay seedPhrase={seedPhrase} />
<SeedPhraseDisplay
_context={_context}
seedPhrase={seedPhrase}
/>
</VStack>

{/*copy seed phrase button*/}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const ViewSeedPhrasePage: FC = () => {
null
);
const [value, setValue] = useState<IAccountAndSeedPhraseValue | null>(null);
// misc
const _context = 'view-seed-phrase--page';
// handlers
const handleAccountSelect = async (account: IAccountWithExtendedProps) => {
setValue(
Expand Down Expand Up @@ -227,7 +229,10 @@ const ViewSeedPhrasePage: FC = () => {
{!value ? (
<SeedPhraseDisplaySkeleton />
) : (
<SeedPhraseDisplay seedPhrase={value.seedPhrase} />
<SeedPhraseDisplay
_context={_context}
seedPhrase={value.seedPhrase}
/>
)}
</VStack>

Expand Down

0 comments on commit 670f287

Please sign in to comment.