|
1 | 1 | import Services from '#services' |
2 | 2 | import { Trans } from '@lingui/react/macro' |
3 | 3 | import { Icons } from '@masknet/icons' |
4 | | -import { DashboardRoutes, ECKeyIdentifier, NetworkPluginID, PopupRoutes, type Wallet } from '@masknet/shared-base' |
| 4 | +import { |
| 5 | + DashboardRoutes, |
| 6 | + ECKeyIdentifier, |
| 7 | + NetworkPluginID, |
| 8 | + PopupRoutes, |
| 9 | + PrivyEnvGuard, |
| 10 | + type Wallet, |
| 11 | +} from '@masknet/shared-base' |
5 | 12 | import { ActionButton, makeStyles } from '@masknet/theme' |
6 | 13 | import { useChainContext, useNetworks, useWallet, useWallets, useWeb3State } from '@masknet/web3-hooks-base' |
7 | 14 | import { EVMWeb3, PRIVY_SUPPORTED_CHAINS } from '@masknet/web3-providers' |
@@ -41,117 +48,119 @@ const useStyles = makeStyles()((theme) => ({ |
41 | 48 | }, |
42 | 49 | })) |
43 | 50 |
|
44 | | -const SwitchWallet = memo(function SwitchWallet() { |
45 | | - const { classes, theme } = useStyles() |
46 | | - const navigate = useNavigate() |
47 | | - const { closeModal } = useActionModal() |
48 | | - const wallet = useWallet() |
49 | | - const wallets = useWallets() |
50 | | - const { wallets: privyWallets } = usePrivyWallets() |
51 | | - const { chainId } = useChainContext<NetworkPluginID.PLUGIN_EVM>() |
| 51 | +const SwitchWallet = memo( |
| 52 | + PrivyEnvGuard(function SwitchWallet() { |
| 53 | + const { classes, theme } = useStyles() |
| 54 | + const navigate = useNavigate() |
| 55 | + const { closeModal } = useActionModal() |
| 56 | + const wallet = useWallet() |
| 57 | + const wallets = useWallets() |
| 58 | + const { wallets: privyWallets } = usePrivyWallets() |
| 59 | + const { chainId } = useChainContext<NetworkPluginID.PLUGIN_EVM>() |
52 | 60 |
|
53 | | - const handleImport = useCallback(async () => { |
54 | | - await browser.tabs.create({ |
55 | | - active: true, |
56 | | - url: browser.runtime.getURL('/dashboard.html#' + DashboardRoutes.RecoveryMaskWallet), |
57 | | - }) |
58 | | - }, []) |
| 61 | + const handleImport = useCallback(async () => { |
| 62 | + await browser.tabs.create({ |
| 63 | + active: true, |
| 64 | + url: browser.runtime.getURL('/dashboard.html#' + DashboardRoutes.RecoveryMaskWallet), |
| 65 | + }) |
| 66 | + }, []) |
59 | 67 |
|
60 | | - const { Network } = useWeb3State(NetworkPluginID.PLUGIN_EVM) |
61 | | - const networks = useNetworks(NetworkPluginID.PLUGIN_EVM) |
62 | | - const handleSelect = useCallback( |
63 | | - async (wallet: Wallet) => { |
64 | | - const address = wallet.address |
65 | | - const isPrivyWallet = privyWallets.some((x) => isSameAddress(x.address, address)) |
66 | | - await EVMWeb3.connect({ |
67 | | - account: address, |
68 | | - chainId: isPrivyWallet && !PRIVY_SUPPORTED_CHAINS.includes(chainId) ? ChainId.Mainnet : chainId, |
69 | | - providerType: ProviderType.MaskWallet, |
| 68 | + const { Network } = useWeb3State(NetworkPluginID.PLUGIN_EVM) |
| 69 | + const networks = useNetworks(NetworkPluginID.PLUGIN_EVM) |
| 70 | + const handleSelect = useCallback( |
| 71 | + async (wallet: Wallet) => { |
| 72 | + const address = wallet.address |
| 73 | + const isPrivyWallet = privyWallets.some((x) => isSameAddress(x.address, address)) |
| 74 | + await EVMWeb3.connect({ |
| 75 | + account: address, |
| 76 | + chainId: isPrivyWallet && !PRIVY_SUPPORTED_CHAINS.includes(chainId) ? ChainId.Mainnet : chainId, |
| 77 | + providerType: ProviderType.MaskWallet, |
70 | 78 |
|
71 | | - identifier: ECKeyIdentifier.from(wallet.identifier).unwrapOr(undefined), |
72 | | - }) |
73 | | - closeModal() |
74 | | - }, |
75 | | - [chainId, closeModal, Network, networks], |
76 | | - ) |
| 79 | + identifier: ECKeyIdentifier.from(wallet.identifier).unwrapOr(undefined), |
| 80 | + }) |
| 81 | + closeModal() |
| 82 | + }, |
| 83 | + [chainId, closeModal, Network, networks], |
| 84 | + ) |
77 | 85 |
|
78 | | - const handleClickSettings = useCallback(async () => { |
79 | | - navigate(PopupRoutes.WalletSettings) |
80 | | - }, []) |
| 86 | + const handleClickSettings = useCallback(async () => { |
| 87 | + navigate(PopupRoutes.WalletSettings) |
| 88 | + }, []) |
81 | 89 |
|
82 | | - const handleLock = useCallback(async () => { |
83 | | - await Services.Wallet.lockWallet() |
84 | | - navigate(PopupRoutes.Wallet) |
85 | | - }, []) |
| 90 | + const handleLock = useCallback(async () => { |
| 91 | + await Services.Wallet.lockWallet() |
| 92 | + navigate(PopupRoutes.Wallet) |
| 93 | + }, []) |
86 | 94 |
|
87 | | - const action = ( |
88 | | - <Box className={classes.modalAction}> |
89 | | - <ActionButton |
90 | | - className={classes.actionButton} |
91 | | - fullWidth |
92 | | - size="small" |
93 | | - variant="outlined" |
94 | | - onClick={() => { |
95 | | - navigate(PopupRoutes.CreateWallet) |
96 | | - }}> |
97 | | - <Icons.Wallet size={20} color={theme.palette.maskColor.second} /> |
98 | | - <Typography className={classes.actionLabel} component="span"> |
99 | | - <Trans>Add Wallet</Trans> |
100 | | - </Typography> |
101 | | - </ActionButton> |
102 | | - <ActionButton |
103 | | - className={classes.actionButton} |
104 | | - fullWidth |
105 | | - size="small" |
106 | | - variant="outlined" |
107 | | - onClick={handleImport}> |
108 | | - <Icons.Download2 size={20} color={theme.palette.maskColor.second} /> |
109 | | - <Typography className={classes.actionLabel} component="span"> |
110 | | - <Trans>Import Wallet</Trans> |
111 | | - </Typography> |
112 | | - </ActionButton> |
113 | | - <ActionButton |
114 | | - className={classes.actionButton} |
115 | | - fullWidth |
116 | | - size="small" |
117 | | - variant="outlined" |
118 | | - onClick={handleLock}> |
119 | | - <Icons.Lock size={20} color={theme.palette.maskColor.second} /> |
120 | | - <Typography className={classes.actionLabel} component="span"> |
121 | | - <Trans>Lock Wallet</Trans> |
122 | | - </Typography> |
123 | | - </ActionButton> |
124 | | - <ActionButton |
125 | | - className={classes.actionButton} |
126 | | - fullWidth |
127 | | - size="small" |
128 | | - variant="outlined" |
129 | | - onClick={handleClickSettings}> |
130 | | - <Icons.WalletSetting size={20} color={theme.palette.maskColor.second} /> |
131 | | - <Typography className={classes.actionLabel} component="span"> |
132 | | - <Trans>Wallet Settings</Trans> |
133 | | - </Typography> |
134 | | - </ActionButton> |
135 | | - </Box> |
136 | | - ) |
| 95 | + const action = ( |
| 96 | + <Box className={classes.modalAction}> |
| 97 | + <ActionButton |
| 98 | + className={classes.actionButton} |
| 99 | + fullWidth |
| 100 | + size="small" |
| 101 | + variant="outlined" |
| 102 | + onClick={() => { |
| 103 | + navigate(PopupRoutes.CreateWallet) |
| 104 | + }}> |
| 105 | + <Icons.Wallet size={20} color={theme.palette.maskColor.second} /> |
| 106 | + <Typography className={classes.actionLabel} component="span"> |
| 107 | + <Trans>Add Wallet</Trans> |
| 108 | + </Typography> |
| 109 | + </ActionButton> |
| 110 | + <ActionButton |
| 111 | + className={classes.actionButton} |
| 112 | + fullWidth |
| 113 | + size="small" |
| 114 | + variant="outlined" |
| 115 | + onClick={handleImport}> |
| 116 | + <Icons.Download2 size={20} color={theme.palette.maskColor.second} /> |
| 117 | + <Typography className={classes.actionLabel} component="span"> |
| 118 | + <Trans>Import Wallet</Trans> |
| 119 | + </Typography> |
| 120 | + </ActionButton> |
| 121 | + <ActionButton |
| 122 | + className={classes.actionButton} |
| 123 | + fullWidth |
| 124 | + size="small" |
| 125 | + variant="outlined" |
| 126 | + onClick={handleLock}> |
| 127 | + <Icons.Lock size={20} color={theme.palette.maskColor.second} /> |
| 128 | + <Typography className={classes.actionLabel} component="span"> |
| 129 | + <Trans>Lock Wallet</Trans> |
| 130 | + </Typography> |
| 131 | + </ActionButton> |
| 132 | + <ActionButton |
| 133 | + className={classes.actionButton} |
| 134 | + fullWidth |
| 135 | + size="small" |
| 136 | + variant="outlined" |
| 137 | + onClick={handleClickSettings}> |
| 138 | + <Icons.WalletSetting size={20} color={theme.palette.maskColor.second} /> |
| 139 | + <Typography className={classes.actionLabel} component="span"> |
| 140 | + <Trans>Wallet Settings</Trans> |
| 141 | + </Typography> |
| 142 | + </ActionButton> |
| 143 | + </Box> |
| 144 | + ) |
137 | 145 |
|
138 | | - return ( |
139 | | - <ActionModal header={<Trans>Wallet Account</Trans>} action={action}> |
140 | | - <div className={classes.content}> |
141 | | - <List dense className={classes.list}> |
142 | | - {wallets.map((item) => ( |
143 | | - <WalletItem |
144 | | - key={item.address} |
145 | | - wallet={item} |
146 | | - onSelect={handleSelect} |
147 | | - isSelected={isSameAddress(item.address, wallet?.address)} |
148 | | - className={classes.walletItem} |
149 | | - /> |
150 | | - ))} |
151 | | - </List> |
152 | | - </div> |
153 | | - </ActionModal> |
154 | | - ) |
155 | | -}) |
| 146 | + return ( |
| 147 | + <ActionModal header={<Trans>Wallet Account</Trans>} action={action}> |
| 148 | + <div className={classes.content}> |
| 149 | + <List dense className={classes.list}> |
| 150 | + {wallets.map((item) => ( |
| 151 | + <WalletItem |
| 152 | + key={item.address} |
| 153 | + wallet={item} |
| 154 | + onSelect={handleSelect} |
| 155 | + isSelected={isSameAddress(item.address, wallet?.address)} |
| 156 | + className={classes.walletItem} |
| 157 | + /> |
| 158 | + ))} |
| 159 | + </List> |
| 160 | + </div> |
| 161 | + </ActionModal> |
| 162 | + ) |
| 163 | + }), |
| 164 | +) |
156 | 165 |
|
157 | 166 | export default SwitchWallet |
0 commit comments