-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathShareAddressQR.tsx
More file actions
153 lines (144 loc) · 4.58 KB
/
ShareAddressQR.tsx
File metadata and controls
153 lines (144 loc) · 4.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import React, { useCallback, useRef } from 'react';
import { useSelector } from 'react-redux';
import { AccountGroupId } from '@metamask/account-api';
import BottomSheet, {
BottomSheetRef,
} from '../../../../../component-library/components/BottomSheets/BottomSheet';
import { strings } from '../../../../../../locales/i18n';
import {
ParamListBase,
RouteProp,
useNavigation,
useRoute,
} from '@react-navigation/native';
import {
Box,
BoxFlexDirection,
BoxAlignItems,
Button,
ButtonVariant,
ButtonSize,
HeaderStandard,
TextVariant,
TextColor,
FontWeight,
Text,
} from '@metamask/design-system-react-native';
import { useTailwind } from '@metamask/design-system-twrnc-preset';
import QRAccountDisplay from '../../../QRAccountDisplay';
import QRCode from 'react-native-qrcode-svg';
import useBlockExplorer from '../../../../hooks/useBlockExplorer';
import { getNetworkImageSource } from '../../../../../util/networks';
import { ShareAddressQRIds } from './ShareAddressQR.testIds';
import { selectAccountGroupById } from '../../../../../selectors/multichainAccounts/accountTreeController';
import { RootState } from '../../../../../reducers';
export interface ShareAddressQRParams {
address: string;
networkName: string;
chainId: string;
groupId: AccountGroupId;
}
interface RootNavigationParamList extends ParamListBase {
ShareAddressQR: ShareAddressQRParams;
}
type ShareAddressQRRouteProp = RouteProp<
RootNavigationParamList,
'ShareAddressQR'
>;
export const ShareAddressQR = () => {
const sheetRef = useRef<BottomSheetRef>(null);
const tw = useTailwind();
const route = useRoute<ShareAddressQRRouteProp>();
const { address, networkName, chainId, groupId } = route.params;
const accountGroup = useSelector((state: RootState) =>
selectAccountGroupById(state, groupId),
);
const accountGroupName = accountGroup?.metadata.name;
const navigation = useNavigation();
const { toBlockExplorer, getBlockExplorerName } = useBlockExplorer(chainId);
const networkImageSource = getNetworkImageSource({ chainId });
const handleOnBack = useCallback(() => {
navigation.goBack();
}, [navigation]);
const handleViewOnBlockExplorer = useCallback(() => {
toBlockExplorer(address);
}, [address, toBlockExplorer]);
return (
<BottomSheet ref={sheetRef}>
<HeaderStandard
title={`${accountGroupName} / ${networkName}`}
onClose={handleOnBack}
closeButtonProps={{ testID: ShareAddressQRIds.GO_BACK }}
/>
<Box
flexDirection={BoxFlexDirection.Column}
alignItems={BoxAlignItems.Center}
twClassName="px-4 py-6"
>
<Box twClassName="p-6 border border-muted rounded-2xl bg-white">
<QRCode
value={address}
size={200}
logo={networkImageSource}
logoSize={32}
logoBorderRadius={8}
/>
</Box>
<Box twClassName="mt-6 mb-4">
<QRAccountDisplay
accountAddress={address}
analyticsLocation="qr-code"
chainId={chainId}
label={strings('multichain_accounts.share_address_qr.title', {
networkName,
})}
description={
<Text
variant={TextVariant.BodyMd}
color={TextColor.TextAlternative}
style={tw.style('px-4 text-center')}
>
{strings(
'multichain_accounts.share_address_qr.description_prefix',
)}{' '}
<Text
variant={TextVariant.BodyMd}
color={TextColor.TextDefault}
>
{networkName}
</Text>
.
</Text>
}
labelProps={{
variant: TextVariant.BodyLg,
fontWeight: FontWeight.Medium,
}}
descriptionProps={{
variant: TextVariant.BodyMd,
color: TextColor.TextAlternative,
}}
/>
</Box>
</Box>
<Box twClassName="px-4 pb-4">
<Button
variant={ButtonVariant.Secondary}
size={ButtonSize.Lg}
isFullWidth
onPress={handleViewOnBlockExplorer}
testID={ShareAddressQRIds.SHARE_ADDRESS_QR_COPY_BUTTON}
style={tw.style('mt-1 self-center')}
>
{strings(
'multichain_accounts.share_address.view_on_explorer_button',
{
explorer: getBlockExplorerName(),
},
)}
</Button>
</Box>
</BottomSheet>
);
};
export default ShareAddressQR;