From 9353d652e973d318fad2d7d9e0dd52f86f6d1f8c Mon Sep 17 00:00:00 2001 From: billy Date: Fri, 11 Mar 2022 14:41:45 +0800 Subject: [PATCH 1/2] fix: fix disconnect --- .../components/DisconnectProfileDialog/index.tsx | 1 + .../src/pages/Personas/components/PersonaCard/Row.tsx | 4 ++-- .../src/pages/Personas/components/PersonaLine/index.tsx | 9 ++++----- .../src/pages/Personas/hooks/useOperateBindingProof.ts | 4 ++-- .../src/pages/Personas/hooks/usePersonaContext.ts | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/dashboard/src/pages/Personas/components/DisconnectProfileDialog/index.tsx b/packages/dashboard/src/pages/Personas/components/DisconnectProfileDialog/index.tsx index 895750ea549a..e0dcd18c3551 100644 --- a/packages/dashboard/src/pages/Personas/components/DisconnectProfileDialog/index.tsx +++ b/packages/dashboard/src/pages/Personas/components/DisconnectProfileDialog/index.tsx @@ -99,6 +99,7 @@ export const DisconnectProfileDialog = ({ variant="contained" onClick={() => { onDisconnect(profileIdentifier) + setCurrentStep(steps.selection) onClose() }}> {t.confirm()} diff --git a/packages/dashboard/src/pages/Personas/components/PersonaCard/Row.tsx b/packages/dashboard/src/pages/Personas/components/PersonaCard/Row.tsx index 6a8bfb8fa683..62459bbf4d72 100644 --- a/packages/dashboard/src/pages/Personas/components/PersonaCard/Row.tsx +++ b/packages/dashboard/src/pages/Personas/components/PersonaCard/Row.tsx @@ -68,7 +68,7 @@ export const PersonaRowCard = memo(() => { connectPersona, disconnectPersona, renamePersona, - operateBound, + deleteBound, definedSocialNetworks, verification, } = PersonaContext.useContainer() @@ -83,7 +83,7 @@ export const PersonaRowCard = memo(() => { profiles={currentPersona.linkedProfiles} onConnect={connectPersona} onDisconnect={disconnectPersona} - onDeleteBound={operateBound} + onDeleteBound={deleteBound} onRename={renamePersona} definedSocialNetworks={definedSocialNetworks} /> diff --git a/packages/dashboard/src/pages/Personas/components/PersonaLine/index.tsx b/packages/dashboard/src/pages/Personas/components/PersonaLine/index.tsx index 308cdfe5c00b..a1fe533898d8 100644 --- a/packages/dashboard/src/pages/Personas/components/PersonaLine/index.tsx +++ b/packages/dashboard/src/pages/Personas/components/PersonaLine/index.tsx @@ -101,7 +101,7 @@ export const ConnectedPersonaLine = memo( const handleUserIdClick = async (network: string, userId: string) => { await openProfilePage(network, userId) } - const handleProofIconClick = async (e: MouseEvent, proof: any, profile: any) => { + const handleProofIconClick = (e: MouseEvent, proof: any, profile: any) => { e.stopPropagation() if (!proof || !proof.is_valid) { onConnect() @@ -112,12 +112,11 @@ export const ConnectedPersonaLine = memo( const isProved = verification?.proofs.find((x) => { return x.platform === 'twitter' && x.identity === profile.userId.toLowerCase() }) - - if (!isProved || !onDeleteBound) { - onDisconnect(profile) - } else { + if (isProved && onDeleteBound) { onDeleteBound(profile) + return } + onDisconnect(profile) } const userIdBox = (profile: any) => { const proofSupport = ['twitter.com'].includes(profile.network) diff --git a/packages/dashboard/src/pages/Personas/hooks/useOperateBindingProof.ts b/packages/dashboard/src/pages/Personas/hooks/useOperateBindingProof.ts index 9789559471c6..25bda7a11f38 100644 --- a/packages/dashboard/src/pages/Personas/hooks/useOperateBindingProof.ts +++ b/packages/dashboard/src/pages/Personas/hooks/useOperateBindingProof.ts @@ -3,7 +3,7 @@ import { bindProof, createPersonaPayload } from '@masknet/web3-providers' import { useAsyncFn } from 'react-use' import { Services } from '../../../API' -export function useOperateBound() { +export function useDeleteBound() { return useAsyncFn(async (identifier: ECKeyIdentifier, profile, network, action) => { const persona_ = await Services.Identity.queryPersona(identifier) const username = profile.userId.toLowerCase() @@ -21,6 +21,6 @@ export function useOperateBound() { await bindProof(persona_.publicHexKey, action, platform, username, { signature: signature, }) - await Services.Identity.detachProfile(profile) + Services.Identity.detachProfile(profile) }) } diff --git a/packages/dashboard/src/pages/Personas/hooks/usePersonaContext.ts b/packages/dashboard/src/pages/Personas/hooks/usePersonaContext.ts index 8694fb2117c9..b3154d7e458d 100644 --- a/packages/dashboard/src/pages/Personas/hooks/usePersonaContext.ts +++ b/packages/dashboard/src/pages/Personas/hooks/usePersonaContext.ts @@ -7,7 +7,7 @@ import { useCreatePersona } from './useCreatePersona' import { queryExistedBindingByPersona } from '@masknet/web3-providers' import { useAsync, useAsyncRetry } from 'react-use' import type { ECKeyIdentifier } from '@masknet/shared-base' -import { useOperateBound } from './useOperateBindingProof' +import { useDeleteBound } from './useOperateBindingProof' function usePersonaContext() { const currentPersonaIdentifier = useCurrentPersonaIdentifier() @@ -28,7 +28,7 @@ function usePersonaContext() { const [, openProfilePage] = useOpenProfilePage() const [, disconnectPersona] = useDisconnectSocialNetwork() const [, createPersona] = useCreatePersona() - const [, operateBound] = useOperateBound() + const [, deleteBound] = useDeleteBound() const renamePersona = Services.Identity.renamePersona const changeCurrentPersona = useCallback(Services.Settings.setCurrentPersonaIdentifier, []) @@ -38,7 +38,7 @@ function usePersonaContext() { createPersona, renamePersona, changeCurrentPersona, - operateBound, + deleteBound, currentPersona, definedSocialNetworks, personas, From 4a92a64fae6fdfcb6f4ac1770567f824c7fb2c31 Mon Sep 17 00:00:00 2001 From: billy Date: Fri, 11 Mar 2022 14:51:33 +0800 Subject: [PATCH 2/2] fix: types --- .../Personas/components/PersonaLine/index.tsx | 10 ++++------ packages/shared-base/src/NextID/type.ts | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/dashboard/src/pages/Personas/components/PersonaLine/index.tsx b/packages/dashboard/src/pages/Personas/components/PersonaLine/index.tsx index a1fe533898d8..405515bafc09 100644 --- a/packages/dashboard/src/pages/Personas/components/PersonaLine/index.tsx +++ b/packages/dashboard/src/pages/Personas/components/PersonaLine/index.tsx @@ -3,7 +3,7 @@ import { Box, Button, Link, Stack, Typography } from '@mui/material' import { getMaskColor, MaskColorVar, makeStyles } from '@masknet/theme' import { useDashboardI18N } from '../../../../locales' import { DisconnectProfileDialog } from '../DisconnectProfileDialog' -import type { NextIDPersonaBindings, PersonaIdentifier, ProfileIdentifier } from '@masknet/shared-base' +import type { NextIDPersonaBindings, PersonaIdentifier, ProfileIdentifier, BindingProof } from '@masknet/shared-base' import { SOCIAL_MEDIA_ICON_MAPPING } from '@masknet/shared' import { PersonaContext } from '../../hooks/usePersonaContext' import { NextIdPersonaWarningIcon, NextIdPersonaVerifiedIcon } from '@masknet/icons' @@ -101,7 +101,7 @@ export const ConnectedPersonaLine = memo( const handleUserIdClick = async (network: string, userId: string) => { await openProfilePage(network, userId) } - const handleProofIconClick = (e: MouseEvent, proof: any, profile: any) => { + const handleProofIconClick = (e: MouseEvent, proof: BindingProof | undefined) => { e.stopPropagation() if (!proof || !proof.is_valid) { onConnect() @@ -118,7 +118,7 @@ export const ConnectedPersonaLine = memo( } onDisconnect(profile) } - const userIdBox = (profile: any) => { + const userIdBox = (profile: ProfileIdentifier) => { const proofSupport = ['twitter.com'].includes(profile.network) const proof = verification?.proofs.find((x) => { return x.platform === 'twitter' && x.identity === profile.userId.toLowerCase() @@ -126,9 +126,7 @@ export const ConnectedPersonaLine = memo( return (
@{profile.userId}
-
handleProofIconClick(e, proof, profile)}> +
handleProofIconClick(e, proof)}> {!proofSupport ? null : proof?.is_valid ? ( ) : ( diff --git a/packages/shared-base/src/NextID/type.ts b/packages/shared-base/src/NextID/type.ts index 35886def5132..90e920bd141b 100644 --- a/packages/shared-base/src/NextID/type.ts +++ b/packages/shared-base/src/NextID/type.ts @@ -23,14 +23,16 @@ export interface Binding { export interface NextIDPersonaBindings { persona: string - proofs: { - platform: NextIDPlatform - identity: string - created_at: string - invalid_reason: string - latest_checked_at: string - is_valid: boolean - }[] + proofs: BindingProof[] +} + +export interface BindingProof { + platform: NextIDPlatform + identity: string + created_at: string + invalid_reason: string + latest_checked_at: string + is_valid: boolean } export interface NextIDBindings {