Skip to content

Commit 6de7442

Browse files
authored
fix: mf-6637 popup disconnect wallet (#12135)
1 parent 1fcecd0 commit 6de7442

File tree

4 files changed

+70
-57
lines changed

4 files changed

+70
-57
lines changed

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

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
import Services from '#services'
2+
import { Trans } from '@lingui/react/macro'
13
import { Icons } from '@masknet/icons'
24
import { ConfirmDialog, FormattedAddress, ImageIcon, PersonaContext, ProgressiveText } from '@masknet/shared'
3-
import { MaskMessages, NetworkPluginID, NextIDAction, PopupModalRoutes, SignType } from '@masknet/shared-base'
5+
import {
6+
MaskMessages,
7+
NetworkPluginID,
8+
NextIDAction,
9+
PopupModalRoutes,
10+
SignType,
11+
type BindingProof,
12+
type PersonaInformation,
13+
} from '@masknet/shared-base'
414
import { makeStyles, usePopupCustomSnackbar } from '@masknet/theme'
515
import { useChainContext, useNetworkDescriptor, useWallets, useWeb3State } from '@masknet/web3-hooks-base'
616
import { EVMExplorerResolver, NextIDProof } from '@masknet/web3-providers'
@@ -9,11 +19,8 @@ import { ChainId, formatDomainName, formatEthereumAddress } from '@masknet/web3-
919
import { Box, Link, Typography, useTheme } from '@mui/material'
1020
import { useQueries } from '@tanstack/react-query'
1121
import { memo, useCallback } from 'react'
12-
import Services from '#services'
13-
import type { ConnectedWalletInfo } from '../../pages/Personas/type.js'
14-
import { useModalNavigate } from '../ActionModal/index.js'
1522
import { useVerifiedWallets } from '../../hooks/index.js'
16-
import { Trans } from '@lingui/react/macro'
23+
import { useModalNavigate } from '../ActionModal/index.js'
1724

1825
const useStyles = makeStyles()((theme) => ({
1926
walletList: {
@@ -85,9 +92,9 @@ export const ConnectedWallet = memo(function ConnectedWallet() {
8592
const wallets = useVerifiedWallets(proofs)
8693

8794
const queries = useQueries({
88-
queries: wallets.map((wallet, index) => ({
95+
queries: wallets.map((wallet) => ({
8996
enabled: !!NameService,
90-
queryKey: ['persona-connected-wallet', wallet.identity, index],
97+
queryKey: ['persona-connected-wallet', wallet.identity],
9198
queryFn: async () => {
9299
const domain = await NameService?.reverse?.(wallet.identity)
93100
if (domain) return domain
@@ -100,51 +107,46 @@ export const ConnectedWallet = memo(function ConnectedWallet() {
100107
// TODO: remove this after next dot id support multiple chain
101108
const networkDescriptor = useNetworkDescriptor(NetworkPluginID.PLUGIN_EVM, ChainId.Mainnet)
102109

103-
const handleConfirmRelease = useCallback(
104-
async (wallet?: ConnectedWalletInfo) => {
105-
try {
106-
if (!currentPersona?.identifier.publicKeyAsHex || !wallet) return
110+
const handleConfirmDisconnect = useCallback(async (wallet: BindingProof, persona: PersonaInformation) => {
111+
try {
112+
const result = await NextIDProof.createPersonaPayload(
113+
persona.identifier.publicKeyAsHex,
114+
NextIDAction.Delete,
115+
wallet.identity,
116+
wallet.platform,
117+
)
107118

108-
const result = await NextIDProof.createPersonaPayload(
109-
currentPersona.identifier.publicKeyAsHex,
110-
NextIDAction.Delete,
111-
wallet.identity,
112-
wallet.platform,
113-
)
114-
115-
if (!result) return
119+
if (!result) return
116120

117-
const signature = await Services.Identity.signWithPersona(
118-
SignType.Message,
119-
result.signPayload,
120-
currentPersona.identifier,
121-
location.origin,
122-
true,
123-
)
121+
const signature = await Services.Identity.signWithPersona(
122+
SignType.Message,
123+
result.signPayload,
124+
persona.identifier,
125+
location.origin,
126+
true,
127+
)
124128

125-
if (!signature) return
129+
if (!signature) return
126130

127-
await NextIDProof.bindProof(
128-
result.uuid,
129-
currentPersona.identifier.publicKeyAsHex,
130-
NextIDAction.Delete,
131-
wallet.platform,
132-
wallet.identity,
133-
result.createdAt,
134-
{ signature },
135-
)
131+
await NextIDProof.bindProof(
132+
result.uuid,
133+
persona.identifier.publicKeyAsHex,
134+
NextIDAction.Delete,
135+
wallet.platform,
136+
wallet.identity,
137+
result.createdAt,
138+
{ signature },
139+
)
136140

137-
// Broadcast updates.
138-
MaskMessages.events.ownProofChanged.sendToAll()
139-
showSnackbar(<Trans>Wallet disconnected</Trans>)
140-
} catch {
141-
showSnackbar(<Trans>Failed to disconnect wallet</Trans>, {
142-
variant: 'error',
143-
})
144-
}
145-
},
146-
[currentPersona],
147-
)
141+
// Broadcast updates.
142+
MaskMessages.events.ownProofChanged.sendToAll()
143+
showSnackbar(<Trans>Wallet disconnected</Trans>)
144+
} catch {
145+
showSnackbar(<Trans>Failed to disconnect wallet</Trans>, {
146+
variant: 'error',
147+
})
148+
}
149+
}, [])
148150

149151
return (
150152
<Box className={classes.walletList}>
@@ -201,7 +203,7 @@ export const ConnectedWallet = memo(function ConnectedWallet() {
201203
</Trans>
202204
),
203205
})
204-
if (confirmed) return handleConfirmRelease(wallet)
206+
if (confirmed) return handleConfirmDisconnect(wallet, currentPersona)
205207
}}
206208
/>
207209
</Box>

packages/mask/popups/pages/Personas/Home/UI.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import { Trans } from '@lingui/react/macro'
12
import { Icons } from '@masknet/icons'
23
import { PopupHomeTabType, useParamTab } from '@masknet/shared'
3-
import { PopupModalRoutes, PopupRoutes, type EnhanceableSite, type ProfileAccount } from '@masknet/shared-base'
4+
import {
5+
PopupModalRoutes,
6+
PopupRoutes,
7+
type BindingProof,
8+
type EnhanceableSite,
9+
type ProfileAccount,
10+
} from '@masknet/shared-base'
411
import { MaskTabList, makeStyles } from '@masknet/theme'
512
import { TabContext, TabPanel } from '@mui/lab'
613
import { Box, Tab, Typography, useTheme } from '@mui/material'
@@ -12,8 +19,6 @@ import { PersonaPublicKey } from '../../../components/PersonaPublicKey/index.js'
1219
import { SelectProvider } from '../../../components/SelectProvider/index.js'
1320
import { SocialAccounts } from '../../../components/SocialAccounts/index.js'
1421
import { useModalNavigate } from '../../../components/index.js'
15-
import type { ConnectedWalletInfo } from '../type.js'
16-
import { Trans } from '@lingui/react/macro'
1722

1823
const useStyles = makeStyles()((theme) => ({
1924
container: {
@@ -171,7 +176,7 @@ interface PersonaHomeUIProps {
171176
networks: EnhanceableSite[]
172177
onConnect: (networkIdentifier: EnhanceableSite) => void
173178
onAccountClick: (account: ProfileAccount) => void
174-
bindingWallets?: ConnectedWalletInfo[]
179+
bindingWallets?: BindingProof[]
175180
hasPaymentPassword?: boolean
176181
}
177182

packages/mask/popups/pages/Personas/type.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/shared/src/hooks/usePersonaProofs.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import { useQuery } from '@tanstack/react-query'
33
import { NextIDProof } from '@masknet/web3-providers'
44
import { EMPTY_LIST, type BindingProof, MaskMessages, Sniffings } from '@masknet/shared-base'
55
import type { UseQueryResult } from '@tanstack/react-query'
6+
import { queryClient } from '@masknet/shared-base-ui'
7+
8+
function clearPersonaProofsCache(publicKey?: string) {
9+
const queryKey = ['@@next-id', 'bindings-by-persona']
10+
if (publicKey) queryKey.push(publicKey)
11+
12+
queryClient.removeQueries({
13+
queryKey,
14+
})
15+
}
616

717
export function usePersonaProofs(publicKey?: string): UseQueryResult<BindingProof[]> {
818
const result = useQuery({
@@ -24,6 +34,7 @@ export function usePersonaProofs(publicKey?: string): UseQueryResult<BindingProo
2434
if (publicKey) {
2535
await NextIDProof.clearPersonaQueryCache(publicKey)
2636
}
37+
clearPersonaProofsCache(publicKey)
2738
refetch()
2839
})
2940
}, [publicKey])

0 commit comments

Comments
 (0)