-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathWallets.tsx
More file actions
125 lines (115 loc) · 4.64 KB
/
Wallets.tsx
File metadata and controls
125 lines (115 loc) · 4.64 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
import { formatAddress, useOpenConnectModal, useWallets } from '@0xsequence/connect'
import { cardVariants, cn, Text, Divider, IconButton, CheckmarkIcon, CloseIcon, Spinner } from '@0xsequence/design-system'
import { useState } from 'react'
import { CopyButton } from '../../components/CopyButton'
import { MediaIconWrapper } from '../../components/IconWrappers'
import { ListCardSelect } from '../../components/ListCard/ListCardSelect'
import { WalletAccountGradient } from '../../components/WalletAccountGradient'
export const SettingsWallets = () => {
const { wallets, disconnectWallet } = useWallets()
const { setOpenConnectModal } = useOpenConnectModal()
const [disconnectConfirm, setDisconnectConfirm] = useState<string | null>(null)
const [isUnlinking, setIsUnlinking] = useState<boolean>(false)
const onClickAddWallet = () => {
setOpenConnectModal(true)
}
const DisconnectButton = ({ label, onClick }: { label: string; onClick: () => void }) => {
return (
<div
className={cn(cardVariants({ clickable: true }), 'flex flex-row justify-between items-center rounded-full h-9')}
onClick={onClick}
>
<Text color="primary" fontWeight="bold" variant="normal">
{label}
</Text>
</div>
)
}
const confrimDisconnectAll = () => {
setDisconnectConfirm('All')
}
const confirmDisconnect = (address: string) => {
setDisconnectConfirm(address)
}
const handleDisconnect = async () => {
setIsUnlinking(true)
if (disconnectConfirm === 'All') {
wallets.forEach(async wallet => await disconnectWallet(wallet.address))
} else {
await disconnectWallet(disconnectConfirm || '')
}
setDisconnectConfirm(null)
setIsUnlinking(false)
}
return (
<div className="flex flex-col justify-between" style={{ height: '100%' }}>
<div className="flex flex-col px-4 pb-4 gap-2" style={{ paddingBottom: 'calc(77px + 1px + 16px)' }}>
{wallets.length > 1 && (
<ListCardSelect
key="all"
type="custom"
disabled
rightChildren={
isUnlinking ? (
<Spinner />
) : disconnectConfirm === 'All' ? (
<div className="flex gap-3">
<IconButton size="xs" variant="danger" icon={CheckmarkIcon} onClick={() => handleDisconnect()} />
<IconButton size="xs" variant="glass" icon={CloseIcon} onClick={() => setDisconnectConfirm(null)} />
</div>
) : (
<DisconnectButton label="Disconnect All" onClick={() => confrimDisconnectAll()} />
)
}
>
<MediaIconWrapper iconList={wallets.map(wallet => wallet.address)} size="sm" isAccount />
<Text color="primary" fontWeight="medium" variant="normal">
All
</Text>
</ListCardSelect>
)}
{wallets.map(wallet => (
<ListCardSelect
key={wallet.address}
type="custom"
disabled
rightChildren={
isUnlinking && disconnectConfirm === wallet.address ? (
<Spinner />
) : disconnectConfirm === wallet.address ? (
<div className="flex gap-3">
<IconButton size="xs" variant="danger" icon={CheckmarkIcon} onClick={() => handleDisconnect()} />
<IconButton size="xs" variant="glass" icon={CloseIcon} onClick={() => setDisconnectConfirm(null)} />
</div>
) : (
<DisconnectButton label="Disconnect" onClick={() => confirmDisconnect(wallet.address)} />
)
}
>
<WalletAccountGradient accountAddress={wallet.address} size={'small'} />
<Text className="flex flex-row gap-1 items-center" color="primary" fontWeight="medium" variant="normal">
{formatAddress(wallet.address)}
<CopyButton text={wallet.address} buttonVariant="icon" />
</Text>
</ListCardSelect>
))}
</div>
<div className="bg-background-primary" style={{ position: 'absolute', bottom: 0, width: '100%' }}>
<Divider className="my-0" />
<div className="rounded-none m-4">
<div
className={cn(
cardVariants({ clickable: true }),
'flex justify-center items-center bg-gradient-primary rounded-full gap-2 p-3'
)}
onClick={() => onClickAddWallet()}
>
<Text color="primary" fontWeight="bold" variant="normal">
+ Add new Wallet
</Text>
</div>
</div>
</div>
</div>
)
}