-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
013b870
commit 51370df
Showing
10 changed files
with
210 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 122 additions & 47 deletions
169
apps/desktop/src/components/Onboarding/showSeedphrase/ShowSeedphrase.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,134 @@ | ||
import { Button, Flex, Heading, SimpleGrid, Text, VStack } from "@chakra-ui/react"; | ||
import { | ||
Button, | ||
Flex, | ||
Heading, | ||
Popover, | ||
PopoverArrow, | ||
PopoverBody, | ||
PopoverContent, | ||
PopoverTrigger, | ||
SimpleGrid, | ||
Text, | ||
VStack, | ||
useDisclosure, | ||
} from "@chakra-ui/react"; | ||
import { useState } from "react"; | ||
|
||
import { KeyIcon } from "../../../assets/icons"; | ||
import { EyeIcon, EyeSlashIcon, FileCopyIcon, KeyIcon } from "../../../assets/icons"; | ||
import colors from "../../../style/colors"; | ||
import { ModalContentWrapper } from "../ModalContentWrapper"; | ||
import { type OnboardingStep, type ShowSeedphraseStep } from "../OnboardingStep"; | ||
|
||
const COPY_TIMEOUT = 30_000; | ||
const COPIED_POPUP_DURATION = 2000; | ||
|
||
export const ShowSeedphrase = ({ | ||
goToStep, | ||
account, | ||
}: { | ||
goToStep: (step: OnboardingStep) => void; | ||
account: ShowSeedphraseStep["account"]; | ||
}) => ( | ||
<ModalContentWrapper | ||
icon={<KeyIcon width="24px" height="24px" />} | ||
subtitle="Please record the following 24 words in sequence in order to restore it in the future." | ||
title="Record Seed Phrase" | ||
> | ||
<VStack> | ||
<SimpleGrid columns={3} spacing={2}> | ||
{account.mnemonic.split(" ").map((item, index) => ( | ||
<Flex | ||
key={index} | ||
width="126px" | ||
padding="6px" | ||
border="1px dashed" | ||
borderColor={colors.gray[500]} | ||
borderRadius="4px" | ||
> | ||
<Heading | ||
width="18px" | ||
marginRight="10px" | ||
paddingTop="2px" | ||
color={colors.gray[450]} | ||
textAlign="right" | ||
size="sm" | ||
}) => { | ||
const [isHidden, setIsHidden] = useState(false); | ||
const { | ||
isOpen: isPopoverOpen, | ||
onOpen: setIsPopoverOpen, | ||
onClose: setIsPopoverClose, | ||
} = useDisclosure(); | ||
|
||
const handleCopy = () => { | ||
// window.electronAPI.clipboardWriteText(account.mnemonic); | ||
setIsPopoverOpen(); | ||
|
||
setTimeout(() => { | ||
setIsPopoverClose(); | ||
}, COPIED_POPUP_DURATION); | ||
|
||
setTimeout(() => { | ||
window.electronAPI.clipboardClear(); | ||
}, COPY_TIMEOUT); | ||
}; | ||
|
||
return ( | ||
<ModalContentWrapper | ||
icon={<KeyIcon width="24px" height="24px" />} | ||
subtitle="Please record the following 24 words in sequence in order to restore it in the future." | ||
title="Record Seed Phrase" | ||
> | ||
<VStack> | ||
<SimpleGrid userSelect="none" columns={3} spacing={2}> | ||
{account.mnemonic.split(" ").map((item, index) => ( | ||
<Flex | ||
key={index} | ||
width="126px" | ||
padding="6px" | ||
border="1px dashed" | ||
borderColor={colors.gray[500]} | ||
borderRadius="4px" | ||
> | ||
{index + 1} | ||
</Heading> | ||
<Text data-testid={`mnemonic-word-${index}`} size="sm"> | ||
{item} | ||
</Text> | ||
</Flex> | ||
))} | ||
</SimpleGrid> | ||
<Button | ||
width="100%" | ||
marginTop="20px" | ||
onClick={_ => { | ||
goToStep({ type: "verifySeedphrase", account }); | ||
}} | ||
size="lg" | ||
> | ||
OK, I've recorded it | ||
</Button> | ||
</VStack> | ||
</ModalContentWrapper> | ||
); | ||
<Heading | ||
width="18px" | ||
marginRight="10px" | ||
paddingTop="2px" | ||
color={colors.gray[450]} | ||
textAlign="right" | ||
size="sm" | ||
> | ||
{index + 1} | ||
</Heading> | ||
<Text | ||
sx={{ | ||
WebkitTextSecurity: isHidden ? "disc" : "none", | ||
}} | ||
data-testid={`mnemonic-word-${index}`} | ||
size="sm" | ||
> | ||
{isHidden ? "********" : item} | ||
</Text> | ||
</Flex> | ||
))} | ||
</SimpleGrid> | ||
<Flex justifyContent="space-between" gap="16px" width="100%" marginTop="20px"> | ||
<Button | ||
width="100%" | ||
leftIcon={isHidden ? <EyeSlashIcon /> : <EyeIcon />} | ||
onClick={() => setIsHidden(!isHidden)} | ||
variant="outline" | ||
> | ||
{isHidden ? "Show" : "Hide"} seed phrase | ||
</Button> | ||
<Popover autoFocus={false} closeOnBlur={false} isOpen={isPopoverOpen}> | ||
<PopoverTrigger> | ||
<Button | ||
width="100%" | ||
leftIcon={<FileCopyIcon stroke={colors.gray[450]} />} | ||
onClick={handleCopy} | ||
variant="outline" | ||
> | ||
Copy to clipboard | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent maxWidth="max-content" background="white"> | ||
<PopoverArrow background="white !important" /> | ||
<PopoverBody padding="8px 12px"> | ||
<Text color="black" fontWeight="medium" size="sm"> | ||
Copied! | ||
</Text> | ||
</PopoverBody> | ||
</PopoverContent> | ||
</Popover> | ||
</Flex> | ||
<Button | ||
width="100%" | ||
marginTop="8px" | ||
onClick={_ => { | ||
goToStep({ type: "verifySeedphrase", account }); | ||
}} | ||
size="lg" | ||
> | ||
OK, I've recorded it | ||
</Button> | ||
</VStack> | ||
</ModalContentWrapper> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export {}; | ||
|
||
declare global { | ||
interface Window { | ||
electronAPI: { | ||
clipboardWriteText: (text: string) => void; | ||
clipboardClear: () => void; | ||
onDeeplink: (callback: (url: string) => void) => void; | ||
onAppUpdateDownloaded: (callback: () => void) => void; | ||
installAppUpdateAndQuit: () => void; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.