-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust WalletConnect URI implementation
- Loading branch information
Showing
11 changed files
with
247 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { IconButton } from '@chakra-ui/react' | ||
import CopyIcon from './Icons/CopyIcon' | ||
import { ComponentProps, useRef, useState } from 'react' | ||
import { CheckIcon } from '@chakra-ui/icons' | ||
|
||
type CopyButtonProps = { | ||
text: string | ||
} & Partial<ComponentProps<typeof IconButton>> | ||
|
||
export default function CopyButton({ text, ...props }: CopyButtonProps) { | ||
const size = '1.75rem' | ||
const checkSize = '1.15rem' | ||
|
||
const [showCheck, setShowCheck] = useState(false) | ||
const checkTimeoutRef = useRef<NodeJS.Timeout | null>(null) | ||
const icon = showCheck ? ( | ||
<CheckIcon boxSize={checkSize} /> | ||
) : ( | ||
<CopyIcon boxSize={size} /> | ||
) | ||
|
||
function onClick() { | ||
navigator.clipboard.writeText(text) | ||
setShowCheck(true) | ||
if (checkTimeoutRef.current) { | ||
clearTimeout(checkTimeoutRef.current) | ||
} | ||
checkTimeoutRef.current = setTimeout(() => { | ||
setShowCheck(false) | ||
}, 1000) | ||
} | ||
|
||
return ( | ||
<IconButton | ||
variant={'ghost'} | ||
size={'sm'} | ||
isRound={true} | ||
borderRadius={'full'} | ||
aria-label={'Copy'} | ||
minW={0} | ||
boxSize={size} | ||
icon={icon} | ||
onClick={onClick} | ||
{...props} | ||
></IconButton> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { createIcon } from '@chakra-ui/react' | ||
|
||
export default createIcon({ | ||
displayName: 'CopyIcon', | ||
viewBox: '0 0 28 28', | ||
path: [ | ||
<path | ||
id="Rectangle 7 (Stroke)" | ||
fillRule="evenodd" | ||
clipRule="evenodd" | ||
d="M14 3.5H20C22.4853 3.5 24.5 5.51472 24.5 8V14C24.5 16.4853 22.4853 18.5 20 18.5H14C11.5147 18.5 9.5 16.4853 9.5 14V8C9.5 5.51472 11.5147 3.5 14 3.5ZM14 6C12.8954 6 12 6.89543 12 8V14C12 15.1046 12.8954 16 14 16H20C21.1046 16 22 15.1046 22 14V8C22 6.89543 21.1046 6 20 6H14Z" | ||
fill="black" | ||
fillOpacity="0.6" | ||
/>, | ||
<path | ||
id="Subtract" | ||
d="M8 9.5C5.51472 9.5 3.5 11.5147 3.5 14V20C3.5 22.4853 5.51472 24.5 8 24.5H14C16.4853 24.5 18.5 22.4853 18.5 20H16C16 21.1046 15.1046 22 14 22H8C6.89543 22 6 21.1046 6 20V14C6 12.8954 6.89543 12 8 12V9.5Z" | ||
fill="black" | ||
fillOpacity="0.6" | ||
/>, | ||
], | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,59 @@ | ||
import { Box, Stack, Text } from '@chakra-ui/react' | ||
import QRCode from 'react-qr-code' | ||
import { Box, Flex, Stack, Text } from '@chakra-ui/react' | ||
import { Wallet } from '../../data/wallets' | ||
import { useConfig } from '../../contexts/ConfigContext' | ||
import QRCode from '../QRCode' | ||
import CopyButton from '../CopyButton' | ||
import HybridButton from '../HybridButton' | ||
|
||
interface ScanConnectProps { | ||
wallet: Wallet | ||
onGetWallet: () => void | ||
} | ||
|
||
export default function ScanConnect({ wallet }: ScanConnectProps) { | ||
const { walletConnectUri } = useConfig() | ||
export default function ScanConnect({ wallet, onGetWallet }: ScanConnectProps) { | ||
const { | ||
walletconnect: { uri }, | ||
} = useConfig() | ||
return ( | ||
<Stack flexGrow={1} alignItems="center" spacing={8} padding={4}> | ||
<Text color="gray" fontWeight="bold" maxW="2xs" textAlign="center"> | ||
Scan in the {wallet.name} app to connect | ||
</Text> | ||
<Stack | ||
flexGrow={1} | ||
alignItems="center" | ||
spacing={2} | ||
px={5} | ||
pb={5} | ||
justifyContent="space-evenly" | ||
> | ||
<Flex justifyContent="space-between" width="100%" alignItems="center"> | ||
<Text textStyle="body2">Scan in the {wallet.name} app to connect</Text> | ||
<CopyButton text={uri} /> | ||
</Flex> | ||
|
||
<Box | ||
padding={4} | ||
bg="white" | ||
borderRadius="xl" | ||
shadow="md" | ||
padding={3} | ||
borderRadius="0.75rem" | ||
border="1px" | ||
borderColor="gray.200" | ||
> | ||
<QRCode level="M" value={walletConnectUri} size={300} /> | ||
<QRCode value={uri} size="20rem" image={wallet.icon} imageSize="5rem" /> | ||
</Box> | ||
|
||
<Flex width="100%" justifyContent="space-between" alignItems="center"> | ||
<Text textStyle="body2">Don't have {wallet.name}?</Text> | ||
<HybridButton | ||
variant="secondary" | ||
size="sm" | ||
ml="auto" | ||
alignSelf="center" | ||
borderRadius="full" | ||
{...(!wallet.installLink | ||
? { href: wallet.website } | ||
: { | ||
onClick: onGetWallet, | ||
})} | ||
> | ||
Get | ||
</HybridButton> | ||
</Flex> | ||
</Stack> | ||
) | ||
} |
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.