1
- import React , { useCallback } from 'react' ;
1
+ import React , { useCallback , useMemo } from 'react' ;
2
2
import { ADDRESS_CARD_QR_CODE_SIZE , AddressCard , HandleAddressCard } from '@lace/core' ;
3
3
import { useTheme } from '@providers/ThemeProvider' ;
4
4
import { useWalletStore } from '@src/stores' ;
@@ -11,20 +11,36 @@ import { useGetHandles } from '@hooks/useGetHandles';
11
11
import { getAssetImageUrl } from '@src/utils/get-asset-image-url' ;
12
12
import { useAnalyticsContext } from '@providers' ;
13
13
import { PostHogAction } from '@providers/AnalyticsProvider/analyticsTracker' ;
14
+ import { Button , Flex } from '@input-output-hk/lace-ui-toolkit' ;
15
+ import { PlusOutlined } from '@ant-design/icons' ;
16
+ import { isUsedAddress } from '@src/utils/is-used-addresses' ;
17
+ import { useNextUnusedAddress } from '@hooks' ;
18
+
19
+ const useAdvancedReceived = process . env . USE_ADVANCED_RECEIVED === 'true' ;
14
20
15
21
const useWalletInformation = ( ) =>
16
22
useWalletStore ( ( state ) => ( {
17
23
name : state ?. walletInfo ?. name ,
18
- address : state ?. walletInfo ?. addresses [ 0 ] . address
24
+ addresses : state ?. walletInfo ?. addresses
19
25
} ) ) ;
20
26
27
+ const useTransactionHistory = ( ) =>
28
+ useWalletStore ( ( state ) => ( {
29
+ transactionHistory : state ?. walletState ?. transactions . history
30
+ } ) ) ;
31
+
32
+ const addressCopiedTranslation = 'core.infoWallet.addressCopied' ;
33
+
21
34
export const QRInfoWalletDrawer = ( ) : React . ReactElement => {
22
35
const analytics = useAnalyticsContext ( ) ;
23
36
const { t } = useTranslation ( ) ;
24
37
const { theme } = useTheme ( ) ;
25
- const { name, address } = useWalletInformation ( ) ;
38
+ const { name, addresses } = useWalletInformation ( ) ;
39
+
40
+ const { transactionHistory } = useTransactionHistory ( ) ;
26
41
const [ , closeDrawer ] = useDrawer ( ) ;
27
42
const handles = useGetHandles ( ) ;
43
+ const nextUnusedAddress = useNextUnusedAddress ( ) ;
28
44
29
45
useKeyboardShortcut ( [ 'Escape' ] , ( ) => closeDrawer ( ) ) ;
30
46
@@ -36,24 +52,61 @@ export const QRInfoWalletDrawer = (): React.ReactElement => {
36
52
analytics . sendEventToPostHog ( PostHogAction . ReceiveCopyAddressIconClick ) ;
37
53
} ;
38
54
55
+ const usedAddresses = useMemo (
56
+ ( ) => addresses ?. filter ( ( addr ) => isUsedAddress ( addr . address , transactionHistory ) ) ,
57
+ [ addresses , transactionHistory ]
58
+ ) ;
59
+
60
+ const getQRCodeOpts = useCallback ( ( ) => getQRCodeOptions ( theme , ADDRESS_CARD_QR_CODE_SIZE ) , [ theme ] ) ;
61
+
39
62
return (
40
- < div className = { styles . infoContainer } >
41
- < AddressCard
42
- name = { name }
43
- address = { address ?. toString ( ) }
44
- getQRCodeOptions = { useCallback ( ( ) => getQRCodeOptions ( theme , ADDRESS_CARD_QR_CODE_SIZE ) , [ theme ] ) }
45
- copiedMessage = { t ( 'core.infoWallet.addressCopied' ) }
46
- onCopyClick = { handleCopyAddress }
47
- />
48
- { handles ?. map ( ( { nftMetadata, image } ) => (
49
- < HandleAddressCard
50
- key = { nftMetadata . name }
51
- name = { nftMetadata . name }
52
- image = { getAssetImageUrl ( image || nftMetadata . image ) }
53
- copiedMessage = { t ( 'core.infoWallet.handleCopied' ) }
54
- onCopyClick = { handleCopyAdaHandle }
55
- />
56
- ) ) }
57
- </ div >
63
+ < Flex flexDirection = "column" justifyContent = "space-between" alignItems = "center" >
64
+ < div className = { styles . infoContainer } >
65
+ { ! useAdvancedReceived ? (
66
+ < AddressCard
67
+ name = { name }
68
+ address = { addresses ?. [ 0 ] . address }
69
+ getQRCodeOptions = { getQRCodeOpts }
70
+ copiedMessage = { t ( addressCopiedTranslation ) }
71
+ onCopyClick = { handleCopyAddress }
72
+ />
73
+ ) : (
74
+ < >
75
+ { usedAddresses ?. map ( ( addr , i ) => (
76
+ < AddressCard
77
+ key = { addr . accountIndex }
78
+ name = { i === 0 ? name : `Index ${ i } ` }
79
+ address = { addr . address }
80
+ getQRCodeOptions = { getQRCodeOpts }
81
+ copiedMessage = { t ( addressCopiedTranslation ) }
82
+ onCopyClick = { handleCopyAddress }
83
+ />
84
+ ) ) }
85
+ { nextUnusedAddress && (
86
+ < AddressCard
87
+ name = { 'Next Unused Address' }
88
+ address = { nextUnusedAddress }
89
+ getQRCodeOptions = { getQRCodeOpts }
90
+ copiedMessage = { t ( addressCopiedTranslation ) }
91
+ onCopyClick = { handleCopyAddress }
92
+ />
93
+ ) }
94
+ </ >
95
+ ) }
96
+ { handles ?. map ( ( { nftMetadata, image } ) => (
97
+ < HandleAddressCard
98
+ key = { nftMetadata . name }
99
+ name = { nftMetadata . name }
100
+ image = { getAssetImageUrl ( image || nftMetadata . image ) }
101
+ copiedMessage = { t ( 'core.infoWallet.handleCopied' ) }
102
+ onCopyClick = { handleCopyAdaHandle }
103
+ />
104
+ ) ) }
105
+ </ div >
106
+ { /* TODO: onClick to generate visible unused address, translation */ }
107
+ { useAdvancedReceived && (
108
+ < Button . Secondary icon = { < PlusOutlined /> } onClick = { ( ) => void 0 } label = "Create new address" />
109
+ ) }
110
+ </ Flex >
58
111
) ;
59
112
} ;
0 commit comments