Skip to content

Commit cc748ed

Browse files
authored
Merge pull request #290 from node-real/feat/binance-web3-wallet-extension-support
feat(qrcode): add copy link button to QR code view
2 parents d3e4806 + f8b2ee0 commit cc748ed

4 files changed

Lines changed: 76 additions & 11 deletions

File tree

.changeset/empty-kangaroos-move.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@node-real/walletkit': patch
3+
---
4+
5+
add copy link button to QR code view

packages/walletkit/src/core/modals/ConnectModal/TemplateQRCodeView/index.tsx

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
import { useEffect } from 'react';
12
import { Link } from '@/core/base/components/Link';
23
import { ModalBody } from '@/core/base/components/Modal/ModalBody';
34
import { ModalFooter } from '@/core/base/components/Modal/ModalFooter';
45
import { ModalHeader } from '@/core/base/components/Modal/ModalHeader';
56
import { ForwardIcon } from '@/core/base/icons/ForwardIcon';
7+
import { CopyIcon } from '@/core/base/icons/CopyIcon';
8+
import { SuccessIcon } from '@/core/base/icons/SuccessIcon';
69
import { cx } from '@/core/base/utils/css';
710
import { CustomQRCode } from '@/core/components/CustomQRCode';
11+
import { useClipboard } from '@/core/base/hooks/useClipboard';
812
import { useWalletLogos } from '@/core/hooks/useWalletLogos';
913
import { useWalletKit } from '@/core/providers/WalletKitProvider/context';
10-
import { clsContainer, clsOfficialButton } from './styles.css';
14+
import { clsContainer, clsOfficialButton, clsCopyButton, clsFooter } from './styles.css';
1115
import { useAutoCloseConnectModal } from '@/core/hooks/useAutoCloseConnectModal';
1216
import { BaseWallet } from '@/core/configs/types';
1317

@@ -25,9 +29,18 @@ export function TemplateQRCodeView(props: TemplateQRCodeViewProps) {
2529

2630
const { options } = useWalletKit();
2731
const logos = useWalletLogos(wallet?.logos);
32+
const { onCopy, hasCopied, setValue } = useClipboard(qrCodeUri ?? '');
33+
34+
useEffect(() => {
35+
if (qrCodeUri) {
36+
setValue(qrCodeUri);
37+
}
38+
}, [qrCodeUri, setValue]);
2839

2940
useAutoCloseConnectModal(isConnected, address);
3041

42+
const showFooter = !!qrCodeUri || (isWalletConnect && !options?.hideOfficialWalletConnectCTA);
43+
3144
return (
3245
<>
3346
<ModalHeader>Scan with your phone</ModalHeader>
@@ -36,15 +49,32 @@ export function TemplateQRCodeView(props: TemplateQRCodeViewProps) {
3649
<CustomQRCode value={qrCodeUri} logo={logos.default} />
3750
</ModalBody>
3851

39-
{isWalletConnect && !options?.hideOfficialWalletConnectCTA && (
40-
<ModalFooter>
41-
<Link
42-
className={cx('wk-official-wc-button', clsOfficialButton)}
43-
onClick={onClickOpenWcModal}
44-
>
45-
Open the official WalletConnect modal
46-
<ForwardIcon />
47-
</Link>
52+
{showFooter && (
53+
<ModalFooter className={clsFooter}>
54+
{!!qrCodeUri && (
55+
<button className={cx('wk-copy-link-button', clsCopyButton)} onClick={onCopy}>
56+
{hasCopied ? (
57+
<>
58+
<SuccessIcon width={16} height={16} />
59+
Copied
60+
</>
61+
) : (
62+
<>
63+
<CopyIcon width={16} height={16} />
64+
Copy Link
65+
</>
66+
)}
67+
</button>
68+
)}
69+
{isWalletConnect && !options?.hideOfficialWalletConnectCTA && (
70+
<Link
71+
className={cx('wk-official-wc-button', clsOfficialButton)}
72+
onClick={onClickOpenWcModal}
73+
>
74+
Open the official WalletConnect modal
75+
<ForwardIcon />
76+
</Link>
77+
)}
4878
</ModalFooter>
4979
)}
5080
</>

packages/walletkit/src/core/modals/ConnectModal/TemplateQRCodeView/styles.css.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
import { style } from '@vanilla-extract/css';
2+
import { cssVar } from '@/core/base/utils/css';
3+
import { hover } from '@/core/base/vanilla/index.css';
4+
5+
export const clsFooter = style({
6+
flexDirection: 'column',
7+
alignItems: 'center',
8+
gap: 12,
9+
});
210

311
export const clsContainer = style({
412
alignItems: 'center',
@@ -14,3 +22,25 @@ export const clsOfficialButton = style({
1422
gap: 4,
1523
cursor: 'pointer',
1624
});
25+
26+
export const clsCopyButton = style({
27+
display: 'inline-flex',
28+
alignItems: 'center',
29+
justifyContent: 'center',
30+
gap: 6,
31+
height: 36,
32+
padding: '0 12px',
33+
fontSize: 14,
34+
fontWeight: 400,
35+
lineHeight: '20px',
36+
cursor: 'pointer',
37+
border: '1px solid',
38+
borderRadius: cssVar('common', 'radii'),
39+
borderColor: cssVar('border'),
40+
background: 'transparent',
41+
color: cssVar('text'),
42+
'@media': hover({
43+
background: cssVar('border'),
44+
color: cssVar('text'),
45+
}),
46+
});

website/src/pages/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ npm i @node-real/walletkit@^2 wagmi@^2 viem@^2 @tanstack/react-query@^5
1616

1717
| wallet | mainnet | testnet |
1818
| ---------------- | ------- | ------- |
19-
| binanceWallet() || |
19+
| binanceWallet() || |
2020
| bitgetWallet() |||
2121
| coinbaseWallet() |||
2222
| metaMask() |||

0 commit comments

Comments
 (0)