diff --git a/packages/mask/src/components/DataSource/useNextID.ts b/packages/mask/src/components/DataSource/useNextID.ts index ce13a265d284..ec4d4b522b7c 100644 --- a/packages/mask/src/components/DataSource/useNextID.ts +++ b/packages/mask/src/components/DataSource/useNextID.ts @@ -67,7 +67,7 @@ export function useNextIDConnectStatus() { if (lastState.status === SetupGuideStep.FindUsername) return NextIDVerificationStatus.WaitingLocalConnect // Whether it has been opened in a lifecycle - if (isOpenedVerifyDialog) return NextIDVerificationStatus.HideVerifyDialog + if (isOpenedVerifyDialog && !isOpenedFromButton) return NextIDVerificationStatus.HideVerifyDialog // Whether current platform support next id if (!enableNextID || !username || !personaConnectStatus.connected) @@ -98,6 +98,9 @@ export function useNextIDConnectStatus() { const isBound = await queryIsBound(currentConnectedPersona.publicHexKey, platform, username) if (isBound) return NextIDVerificationStatus.Verified + if (isOpenedFromButton) { + verifyPersona(personaConnectStatus.currentConnectedPersona?.identifier)() + } isOpenedVerifyDialog = true isOpenedFromButton = false return NextIDVerificationStatus.WaitingVerify diff --git a/packages/mask/src/plugins/NextID/components/BindDialog.tsx b/packages/mask/src/plugins/NextID/components/BindDialog.tsx index 7498c317d199..525e608bc341 100644 --- a/packages/mask/src/plugins/NextID/components/BindDialog.tsx +++ b/packages/mask/src/plugins/NextID/components/BindDialog.tsx @@ -17,12 +17,12 @@ import { bindProof } from '@masknet/web3-providers' interface BindDialogProps { open: boolean onClose(): void - onBind(): void + onBound(): void persona: Persona bounds: Binding[] } -export const BindDialog = memo(({ open, onClose, persona, onBind, bounds }) => { +export const BindDialog = memo(({ open, onClose, persona, onBound, bounds }) => { const account = useAccount() const t = useI18N() const { showSnackbar } = useCustomSnackbar() @@ -53,7 +53,7 @@ export const BindDialog = memo(({ open, onClose, persona, onBin message: t.notify_wallet_sign_request_success(), }) await delay(2000) - onBind() + onBound() onClose() } catch { showSnackbar(t.notify_wallet_sign_request_title(), { diff --git a/packages/mask/src/plugins/NextID/components/NextIdPage.tsx b/packages/mask/src/plugins/NextID/components/NextIdPage.tsx index 0f5abb4adf98..12a63395ffb9 100644 --- a/packages/mask/src/plugins/NextID/components/NextIdPage.tsx +++ b/packages/mask/src/plugins/NextID/components/NextIdPage.tsx @@ -3,7 +3,7 @@ import { makeStyles } from '@masknet/theme' import { queryExistedBindingByPersona, queryIsBound } from '@masknet/web3-providers' import { Box, Button, Skeleton, Stack, Typography } from '@mui/material' import { useMemo, useState } from 'react' -import { useAsync, useAsyncRetry, useCounter } from 'react-use' +import { useAsync, useAsyncRetry } from 'react-use' import { useCurrentVisitingIdentity, useLastRecognizedIdentity } from '../../../components/DataSource/useActivatedUI' import { useNextIDConnectStatus } from '../../../components/DataSource/useNextID' import { usePersonaConnectStatus } from '../../../components/DataSource/usePersonaConnectStatus' @@ -58,11 +58,10 @@ export function NextIdPage({ personaList }: NextIDPageProps) { const currentProfileIdentifier = useLastRecognizedIdentity() const visitingPersonaIdentifier = useCurrentVisitingIdentity() const personaConnectStatus = usePersonaConnectStatus() - const { reset, isVerified } = useNextIDConnectStatus() + const { reset, isVerified, action } = useNextIDConnectStatus() const [openBindDialog, toggleBindDialog] = useState(false) const [unbindAddress, setUnBindAddress] = useState() - const [count, { inc }] = useCounter(0) const platform = activatedSocialNetworkUI.configuration.nextIDConfig?.platform as NextIDPlatform const isOwn = currentProfileIdentifier.identifier.toText() === visitingPersonaIdentifier.identifier.toText() @@ -87,10 +86,14 @@ export function NextIdPage({ personaList }: NextIDPageProps) { return queryIsBound(currentPersona.publicHexKey, platform, visitingPersonaIdentifier.identifier.userId) }, [isOwn, currentPersona, visitingPersonaIdentifier, isVerified]) - const { value: bindings, loading } = useAsync(async () => { + const { + value: bindings, + loading, + retry: retryQueryBinding, + } = useAsyncRetry(async () => { if (!currentPersona) return return queryExistedBindingByPersona(currentPersona.publicHexKey!) - }, [currentPersona, isOwn, count]) + }, [currentPersona, isOwn]) const onVerify = async () => { reset() @@ -168,7 +171,7 @@ export function NextIdPage({ personaList }: NextIDPageProps) { onClose={() => toggleBindDialog(false)} persona={currentPersona} bounds={bindings?.proofs ?? []} - onBind={() => inc(1)} + onBound={retryQueryBinding} /> )} {unbindAddress && currentPersona && isOwn && ( @@ -176,7 +179,7 @@ export function NextIdPage({ personaList }: NextIDPageProps) { unbindAddress={unbindAddress} onClose={() => setUnBindAddress(undefined)} persona={currentPersona} - onUnBind={() => inc(1)} + onUnBound={retryQueryBinding} bounds={bindings?.proofs ?? []} /> )} @@ -218,7 +221,7 @@ export function NextIdPage({ personaList }: NextIDPageProps) { onClose={() => toggleBindDialog(false)} persona={currentPersona} bounds={bindings?.proofs ?? []} - onBind={() => inc(1)} + onBound={retryQueryBinding} /> )} diff --git a/packages/mask/src/plugins/NextID/components/UnbindDialog.tsx b/packages/mask/src/plugins/NextID/components/UnbindDialog.tsx index 486b62129df0..16f8b9a498d9 100644 --- a/packages/mask/src/plugins/NextID/components/UnbindDialog.tsx +++ b/packages/mask/src/plugins/NextID/components/UnbindDialog.tsx @@ -1,4 +1,4 @@ -import { memo, useState } from 'react' +import { memo, useCallback, useState } from 'react' import { useI18N } from '../locales' import { useAsyncRetry } from 'react-use' import { isSameAddress, useAccount } from '@masknet/web3-shared-evm' @@ -17,12 +17,12 @@ import { bindProof } from '@masknet/web3-providers' interface VerifyWalletDialogProps { unbindAddress: string persona: Persona - onUnBind(): void + onUnBound(): void onClose(): void bounds: Binding[] } -export const UnbindDialog = memo(({ unbindAddress, onClose, persona, onUnBind, bounds }) => { +export const UnbindDialog = memo(({ unbindAddress, onClose, persona, onUnBound, bounds }) => { const account = useAccount() const t = useI18N() @@ -57,7 +57,7 @@ export const UnbindDialog = memo(({ unbindAddress, onCl message: t.notify_wallet_sign_request_success(), }) await delay(2000) - onUnBind() + onUnBound() onClose() } catch { showSnackbar(t.notify_wallet_sign_request_title(), { @@ -67,9 +67,11 @@ export const UnbindDialog = memo(({ unbindAddress, onCl } }, [walletSignState.value, personaSignState.value, unbindAddress]) + const handleConfirm = useCallback(() => setSecondDialog(true), []) + return ( <> - setSecondDialog(true)} onClose={onClose} /> +