1+ import Services from '#services'
2+ import { Trans } from '@lingui/react/macro'
13import { Icons } from '@masknet/icons'
24import { 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'
414import { makeStyles , usePopupCustomSnackbar } from '@masknet/theme'
515import { useChainContext , useNetworkDescriptor , useWallets , useWeb3State } from '@masknet/web3-hooks-base'
616import { EVMExplorerResolver , NextIDProof } from '@masknet/web3-providers'
@@ -9,11 +19,8 @@ import { ChainId, formatDomainName, formatEthereumAddress } from '@masknet/web3-
919import { Box , Link , Typography , useTheme } from '@mui/material'
1020import { useQueries } from '@tanstack/react-query'
1121import { 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'
1522import { useVerifiedWallets } from '../../hooks/index.js'
16- import { Trans } from '@lingui/react/macro '
23+ import { useModalNavigate } from '../ActionModal/index.js '
1724
1825const 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 >
0 commit comments