Skip to content

Commit a4d6fd7

Browse files
committed
fix(wallet): reset to mask wallet on cancel and support embedded select view
1 parent bb01a2b commit a4d6fd7

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

packages/mask/popups/components/ConnectedWallet/index.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import {
1212
type PersonaInformation,
1313
} from '@masknet/shared-base'
1414
import { makeStyles, usePopupCustomSnackbar } from '@masknet/theme'
15-
import { useChainContext, useNetworkDescriptor, useWallets, useWeb3State } from '@masknet/web3-hooks-base'
15+
import { useChainContext, useWallets, useWeb3State } from '@masknet/web3-hooks-base'
1616
import { EVMExplorerResolver, NextIDProof } from '@masknet/web3-providers'
1717
import { isSameAddress, resolveNextIDPlatformWalletName } from '@masknet/web3-shared-base'
18-
import { ChainId, formatDomainName, formatEthereumAddress } from '@masknet/web3-shared-evm'
18+
import { formatDomainName, formatEthereumAddress } from '@masknet/web3-shared-evm'
1919
import { Box, Link, Typography, useTheme } from '@mui/material'
2020
import { useQueries } from '@tanstack/react-query'
2121
import { memo, useCallback } from 'react'
@@ -105,9 +105,6 @@ export const ConnectedWallet = memo(function ConnectedWallet() {
105105
})),
106106
})
107107

108-
// TODO: remove this after next dot id support multiple chain
109-
const networkDescriptor = useNetworkDescriptor(NetworkPluginID.PLUGIN_EVM, ChainId.Mainnet)
110-
111108
const handleConfirmDisconnect = useCallback(async (wallet: BindingProof, persona: PersonaInformation) => {
112109
try {
113110
const result = await NextIDProof.createPersonaPayload(

packages/mask/popups/pages/Personas/ConnectWallet/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
useChainContext,
1616
useNetworkContext,
1717
usePrivyWallet,
18-
useProviderDescriptor,
1918
useReverseAddress,
2019
useWallets,
2120
} from '@masknet/web3-hooks-base'
@@ -107,7 +106,6 @@ export const Component = memo(function ConnectWalletPage() {
107106
const { providerType, chainId, account } = useChainContext<NetworkPluginID.PLUGIN_EVM>()
108107
const wallets = useWallets()
109108

110-
const providerDescriptor = useProviderDescriptor(pluginID, providerType)
111109
const { data: domain } = useReverseAddress(pluginID, account)
112110
const { currentPersona } = PersonaContext.useContainer()
113111

@@ -217,11 +215,14 @@ export const Component = memo(function ConnectWalletPage() {
217215
navigate(-1)
218216
return
219217
}
218+
// reset to MaskWallet after cancellation
219+
const maskAccount = wallets.some((x) => isSameAddress(x.address, account)) ? account : wallets[0].address
220220
await EVMWeb3.connect({
221221
providerType: ProviderType.MaskWallet,
222+
account: maskAccount,
222223
})
223224
await Services.Helper.removePopupWindow()
224-
}, [signResult])
225+
}, [signResult, wallets, account, navigate, providerType])
225226

226227
const handleChooseAnotherWallet = useCallback(() => {
227228
modalNavigate(PopupModalRoutes.SelectProvider)

packages/mask/popups/pages/Wallet/SelectWallet/index.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ import { Trans, useLingui } from '@lingui/react/macro'
33
import { PersonaContext } from '@masknet/shared'
44
import { EMPTY_LIST, NetworkPluginID, PopupRoutes } from '@masknet/shared-base'
55
import { ActionButton, makeStyles } from '@masknet/theme'
6-
import { useChainContext, useChainIdValid, useNetworks, useWallets, useWeb3State } from '@masknet/web3-hooks-base'
6+
import { useChainContext, useChainIdValid, useWallets, useWeb3State } from '@masknet/web3-hooks-base'
77
import { EVMWeb3 } from '@masknet/web3-providers'
88
import { isSameAddress } from '@masknet/web3-shared-base'
99
import { ProviderType, type ChainId } from '@masknet/web3-shared-evm'
10-
import { Box, Button, Typography } from '@mui/material'
10+
import { Box, Button, Typography, type BoxProps } from '@mui/material'
1111
import { first } from 'lodash-es'
1212
import { memo, useCallback, useMemo, useState } from 'react'
1313
import { useNavigate, useSearchParams } from 'react-router-dom'
1414
import { useAsync } from 'react-use'
1515
import urlcat from 'urlcat'
16-
import { BottomController } from '../../../components/BottomController/index.js'
1716
import { WalletItem } from '../../../components/WalletItem/index.js'
1817
import { useTitle, useVerifiedWallets } from '../../../hooks/index.js'
1918
import { ProfilePhotoType } from '../type.js'
@@ -32,9 +31,20 @@ const useStyles = makeStyles()((theme) => ({
3231
justifyContent: 'center',
3332
alignItems: 'center',
3433
},
34+
actions: {
35+
background: theme.palette.maskColor.secondaryBottom,
36+
padding: theme.spacing(2),
37+
boxShadow: theme.palette.maskColor.bottomBg,
38+
backdropFilter: 'blur(8px)',
39+
display: 'flex',
40+
columnGap: theme.spacing(2),
41+
},
3542
}))
3643

37-
export const Component = memo(function SelectWallet() {
44+
interface SelectWalletProps extends BoxProps {
45+
embed?: boolean
46+
}
47+
export const Component = memo(function SelectWallet({ embed, ...props }: SelectWalletProps) {
3848
const { t } = useLingui()
3949
const { classes, cx } = useStyles()
4050
const navigate = useNavigate()
@@ -53,7 +63,6 @@ export const Component = memo(function SelectWallet() {
5363
chainId: chainIdSearched ? (Number.parseInt(chainIdSearched, 10) as ChainId) : undefined,
5464
})
5565

56-
const networks = useNetworks(NetworkPluginID.PLUGIN_EVM)
5766
const chainIdValid = useChainIdValid(NetworkPluginID.PLUGIN_EVM, chainId)
5867

5968
const { value: localWallets = EMPTY_LIST } = useAsync(async () => Services.Wallet.getWallets(), [])
@@ -83,13 +92,15 @@ export const Component = memo(function SelectWallet() {
8392
}, [isVerifyWalletFlow])
8493

8594
const handleConfirm = useCallback(async () => {
86-
if (isVerifyWalletFlow || isSettingNFTAvatarFlow) {
95+
if (isVerifyWalletFlow || isSettingNFTAvatarFlow || embed) {
8796
await EVMWeb3.connect({
8897
account: selected,
8998
chainId,
9099
providerType: ProviderType.MaskWallet,
91100
})
92101

102+
if (embed) return
103+
93104
navigate(
94105
isSettingNFTAvatarFlow ?
95106
urlcat(PopupRoutes.PersonaAvatarSetting, { tab: ProfilePhotoType.NFT })
@@ -112,22 +123,22 @@ export const Component = memo(function SelectWallet() {
112123
}
113124

114125
return Services.Helper.removePopupWindow()
115-
}, [source, isVerifyWalletFlow, selected, chainId, wallets, isSettingNFTAvatarFlow, networks, Network])
126+
}, [source, isVerifyWalletFlow, selected, chainId, wallets, isSettingNFTAvatarFlow, Network, embed])
116127

117128
useTitle(t`Select Wallet`)
118129

119130
if (!chainIdValid)
120131
return (
121-
<Box className={classes.placeholder}>
132+
<Box {...props} className={cx(classes.placeholder, props.className)}>
122133
<Typography>
123134
<Trans>Unsupported network type</Trans>
124135
</Typography>
125136
</Box>
126137
)
127138

128139
return (
129-
<Box overflow="auto" data-hide-scrollbar>
130-
<Box pt={1} pb={9} px={2} display="flex" flexDirection="column" rowGap="6px">
140+
<Box overflow="auto" display="flex" flexGrow={1} flexDirection="column" data-hide-scrollbar {...props}>
141+
<Box pt={1} pb={9} px={2} display="flex" flexGrow={1} minHeight={0} flexDirection="column" rowGap="6px">
131142
{wallets.map((item) => {
132143
const disabled =
133144
isVerifyWalletFlow && bindingWallets?.some((x) => isSameAddress(x.identity, item.address))
@@ -146,14 +157,14 @@ export const Component = memo(function SelectWallet() {
146157
)
147158
})}
148159
</Box>
149-
<BottomController>
160+
<div className={classes.actions}>
150161
<Button variant="outlined" fullWidth onClick={handleCancel}>
151162
<Trans>Cancel</Trans>
152163
</Button>
153164
<ActionButton fullWidth onClick={handleConfirm}>
154165
<Trans>Confirm</Trans>
155166
</ActionButton>
156-
</BottomController>
167+
</div>
157168
</Box>
158169
)
159170
})

packages/mask/popups/pages/Wallet/components/WalletAssets/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ export const Component = memo(function WalletAssets() {
103103
[chainId, navigate],
104104
)
105105

106-
return wallet ? <WalletAssetsUI onAddToken={handleAdd} /> : <SelectWallet />
106+
return wallet ?
107+
<WalletAssetsUI onAddToken={handleAdd} />
108+
: <Box pb="72px" display="flex" flexGrow={1} minHeight={0}>
109+
<SelectWallet flexGrow={1} embed />
110+
</Box>
107111
})
108112

109113
interface WalletAssetsUIProps {

packages/shared-base/src/types/Wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface Wallet {
2929
storedKeyInfo?: api.IStoredKeyInfo
3030
/** record created at */
3131
createdAt: Date
32-
/** an abstract wallet has a owner */
32+
/** only abstract wallet has owner */
3333
owner?: string
3434
/** record updated at */
3535
updatedAt: Date

0 commit comments

Comments
 (0)