Skip to content

Commit 9fb4888

Browse files
committed
feat: add QR code modal and copy functionality to FundingDescription
1 parent 2e749d0 commit 9fb4888

1 file changed

Lines changed: 79 additions & 16 deletions

File tree

frontend/components/ui/FundingDescription.tsx

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
import { Button, Flex, message, Modal, Typography } from 'antd';
1+
import {
2+
Button,
3+
Flex,
4+
message,
5+
Modal,
6+
ModalProps,
7+
QRCode,
8+
Typography,
9+
} from 'antd';
210
import Image from 'next/image';
311
import { useCallback, useState } from 'react';
4-
import { TbCopy, TbWallet } from 'react-icons/tb';
12+
import { TbCopy, TbQrcode, TbWallet } from 'react-icons/tb';
513
import styled from 'styled-components';
614

715
import { InfoTooltip } from '@/components/ui';
816
import { COLOR } from '@/constants';
917
import { useMasterWalletContext } from '@/hooks';
18+
import { Address } from '@/types';
1019
import { copyToClipboard } from '@/utils';
1120

1221
const { Title, Text, Paragraph } = Typography;
@@ -18,15 +27,10 @@ const FundingDescriptionContainer = styled(Flex)`
1827
margin-top: 32px;
1928
`;
2029

21-
const MODAL_STYLE = {
22-
content: {
23-
padding: 24,
24-
borderRadius: 24,
25-
},
26-
mask: {
27-
backgroundColor: 'rgba(0, 0, 0, 0)',
28-
},
29-
};
30+
const MODAL_STYLE: ModalProps['styles'] = {
31+
content: { padding: 24, borderRadius: 24 },
32+
mask: { backgroundColor: 'rgba(0, 0, 0, 0)' },
33+
} as const;
3034

3135
type ChainConfirmationMessageModalProps = {
3236
chainName: string;
@@ -69,6 +73,58 @@ const ChainConfirmationMessageModal = ({
6973
);
7074
};
7175

76+
type ScanQrCodeProps = { chainName: string; address: Address };
77+
const ScanQrCode = ({ chainName, address }: ScanQrCodeProps) => {
78+
const [isModalOpen, setIsModalOpen] = useState(false);
79+
80+
const handleCopyAddress = useCallback(() => {
81+
copyToClipboard(address).then(() => message.success('Address copied!'));
82+
}, [address]);
83+
84+
return (
85+
<>
86+
<Button
87+
onClick={() => setIsModalOpen(true)}
88+
size="small"
89+
icon={<TbQrcode />}
90+
>
91+
Show QR Code
92+
</Button>
93+
94+
<Modal
95+
open={isModalOpen}
96+
onCancel={() => setIsModalOpen(false)}
97+
title="Scan QR Code"
98+
footer={null}
99+
centered
100+
width={440}
101+
styles={MODAL_STYLE}
102+
>
103+
<Flex vertical gap={32} align="center" className="mt-32">
104+
<QRCode value={address} />
105+
<Flex vertical gap={24} align="center">
106+
<Flex vertical gap={8} align="center">
107+
<Title className="text-lg" style={{ margin: 0 }}>
108+
Pearl - {chainName} Address
109+
</Title>
110+
<Text className="text-neutral-secondary text-center">
111+
Use this address to send funds from your external wallet on
112+
Gnosis Chain.
113+
</Text>
114+
</Flex>
115+
<Text className="text-neutral-secondary text-center">
116+
{address}
117+
</Text>
118+
<Button onClick={handleCopyAddress} icon={<TbCopy />}>
119+
Copy Address
120+
</Button>
121+
</Flex>
122+
</Flex>
123+
</Modal>
124+
</>
125+
);
126+
};
127+
72128
const ExternalWalletTooltip = () => (
73129
<InfoTooltip placement="top" iconColor={COLOR.BLACK}>
74130
<Paragraph className="text-sm m-0">
@@ -77,14 +133,20 @@ const ExternalWalletTooltip = () => (
77133
</InfoTooltip>
78134
);
79135

136+
type FundingDescriptionProps = Pick<
137+
ChainConfirmationMessageModalProps,
138+
'chainName' | 'chainImage' | 'isMainnet'
139+
>;
140+
141+
/**
142+
* Displays the funding details including chain info, external wallet info,
143+
* and Pearl Wallet address with copy functionality.
144+
*/
80145
export const FundingDescription = ({
81146
chainName,
82147
chainImage,
83148
isMainnet = false,
84-
}: Pick<
85-
ChainConfirmationMessageModalProps,
86-
'chainName' | 'chainImage' | 'isMainnet'
87-
>) => {
149+
}: FundingDescriptionProps) => {
88150
const { masterEoa } = useMasterWalletContext();
89151
const address = masterEoa?.address;
90152
const [
@@ -136,10 +198,11 @@ export const FundingDescription = ({
136198
onClose={() => setIsChainConfirmationMessageModalOpen(false)}
137199
/>
138200
)}
139-
<Flex style={{ marginTop: -8 }}>
201+
<Flex gap={8} style={{ marginTop: -8 }}>
140202
<Button size="small" icon={<TbCopy />} onClick={handleCopyAddress}>
141203
Copy
142204
</Button>
205+
{address && <ScanQrCode chainName={chainName} address={address} />}
143206
</Flex>
144207
</FundingDescriptionContainer>
145208
);

0 commit comments

Comments
 (0)