Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions packages/mask/src/components/DataSource/useNextID.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAsync, useAsyncRetry } from 'react-use'
import { useAsyncRetry } from 'react-use'
import type { NextIDPlatform } from '@masknet/shared-base'
import Services from '../../extension/service'
import { useMemo, useState } from 'react'
Expand All @@ -13,15 +13,16 @@ import { useValueRef } from '@masknet/shared'
import { queryExistedBindingByPersona, queryExistedBindingByPlatform, queryIsBound } from '@masknet/web3-providers'

export const usePersonaBoundPlatform = (personaPublicKey: string) => {
useAsyncRetry(() => {
return useAsyncRetry(() => {
return queryExistedBindingByPersona(personaPublicKey)
}, [personaPublicKey])
}

let isOpenedVerifyDialog = false
let isOpenedFromButton = false

export const useNextIDBoundByPlatform = (platform: NextIDPlatform, identity: string) => {
useAsyncRetry(() => {
return useAsyncRetry(() => {
return queryExistedBindingByPlatform(platform, identity)
}, [platform, identity])
}
Expand All @@ -45,15 +46,18 @@ export function useNextIDConnectStatus() {
lastState.username || (lastRecognized.identifier.isUnknown ? '' : lastRecognized.identifier.userId),
)

const { value: isVerified = false } = useAsync(async () => {
const { value: isVerified = false, retry } = useAsyncRetry(async () => {
if (lastState.status === SetupGuideStep.FindUsername) return true
if (isOpenedVerifyDialog) return true
if (!enableNextID || !username || !personaConnectStatus.connected) return true

const currentPersona = await Services.Settings.getCurrentPersona()
if (!currentPersona?.publicHexKey) return true

if (dismissVerifyNextID[ui.networkIdentifier].value[`${username}_${currentPersona.identifier.toText()}`])
if (
dismissVerifyNextID[ui.networkIdentifier].value[`${username}_${currentPersona.identifier.toText()}`] &&
!isOpenedFromButton
)
return true

const platform = ui.configuration.nextIDConfig?.platform as NextIDPlatform | undefined
Expand All @@ -68,8 +72,16 @@ export function useNextIDConnectStatus() {
})

isOpenedVerifyDialog = true
isOpenedFromButton = false
return false
}, [username, enableNextID, lastStateRef.value])
}, [username, enableNextID, lastStateRef.value, isOpenedVerifyDialog])

return isVerified
return {
isVerified,
reset: () => {
isOpenedVerifyDialog = false
isOpenedFromButton = true
retry()
},
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DashboardRoutes, ProfileIdentifier } from '@masknet/shared-base'
import stringify from 'json-stable-stringify'
import { useMemo } from 'react'
import type { Persona } from '../../database'
import Services from '../../extension/service'
import { currentSetupGuideStatus } from '../../settings/settings'
import { activatedSocialNetworkUI } from '../../social-network'
Expand All @@ -27,13 +28,13 @@ export function usePersonaConnectStatus() {
return useMemo(() => {
const id = new ProfileIdentifier(activatedSocialNetworkUI.networkIdentifier, lastRecognized.identifier.userId)
let connected = false
let currentConnectedPersona: Persona | undefined
personas.forEach((p) => {
p.identifier
if (p.linkedProfiles.get(id)) {
connected = true
}
if (!p.linkedProfiles.get(id)) return
connected = true
currentConnectedPersona = p
})
const action = !personas.length ? createPersona : !connected ? connectPersona : null
return { connected, action, hasPersona: !!personas.length }
return { connected, action, hasPersona: !!personas.length, currentConnectedPersona }
}, [personas, lastRecognized, activatedSocialNetworkUI])
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { useEffect, useMemo, useState } from 'react'
import { useUpdateEffect } from 'react-use'
import { first } from 'lodash-unified'
import type { NextIDPlatform } from '@masknet/shared-base'
import { Box, CircularProgress } from '@mui/material'
import { makeStyles, useStylesExtends } from '@masknet/theme'
import { useAddressNames } from '@masknet/web3-shared-evm'
import { createInjectHooksRenderer, useActivatedPluginsSNSAdaptor, Plugin, PluginId } from '@masknet/plugin-infra'
import { PageTab } from '../InjectedComponents/PageTab'
import { useLocationChange } from '../../utils/hooks/useLocationChange'
import { MaskMessages, useI18N } from '../../utils'
import { useCurrentVisitingIdentity } from '../DataSource/useActivatedUI'
import { useCurrentVisitingIdentity, useLastRecognizedIdentity } from '../DataSource/useActivatedUI'
import { useNextIDBoundByPlatform } from '../DataSource/useNextID'
import { usePersonaConnectStatus } from '../DataSource/usePersonaConnectStatus'
import { activatedSocialNetworkUI } from '../../social-network'

function getTabContent(tabId: string) {
return createInjectHooksRenderer(useActivatedPluginsSNSAdaptor.visibility.useAnyMode, (x) => {
Expand Down Expand Up @@ -39,8 +43,18 @@ export function ProfileTabContent(props: ProfileTabContentProps) {
const [hidden, setHidden] = useState(true)
const [selectedTab, setSelectedTab] = useState<Plugin.SNSAdaptor.ProfileTab | undefined>()

const currentIdentity = useLastRecognizedIdentity()
const identity = useCurrentVisitingIdentity()
const { currentConnectedPersona } = usePersonaConnectStatus()
const platform = activatedSocialNetworkUI.configuration.nextIDConfig?.platform as NextIDPlatform
const { value: addressNames = [], loading: loadingAddressNames } = useAddressNames(identity)
const { value: personaList = [], loading: loadingPersonaList } = useNextIDBoundByPlatform(
platform as NextIDPlatform,
identity.identifier.userId,
)
const currentAccountNotConnectPersona =
currentIdentity.identifier.userId === identity.identifier.userId &&
personaList.findIndex((persona) => persona?.persona === currentConnectedPersona?.publicHexKey) === -1

const tabs = useActivatedPluginsSNSAdaptor('any')
.flatMap((x) => x.ProfileTabs?.map((y) => ({ ...y, pluginID: x.ID })) ?? [])
Expand Down Expand Up @@ -81,12 +95,15 @@ export function ProfileTabContent(props: ProfileTabContentProps) {
}, [identity])

const ContentComponent = useMemo(() => {
return getTabContent(selectedTabComputed?.ID ?? '')
const tab = currentAccountNotConnectPersona

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use interface ProfileTab.Utils.shouldDisplay to control it.

? tabs?.find((tab) => tab?.pluginID === PluginId.NextID)?.ID
: selectedTabComputed?.ID
return getTabContent(tab ?? '')
}, [selectedTabComputed, identity.identifier])

if (hidden) return null

if (loadingAddressNames)
if (loadingAddressNames || loadingPersonaList)
return (
<div className={classes.root}>
<Box
Expand All @@ -105,7 +122,11 @@ export function ProfileTabContent(props: ProfileTabContentProps) {
<PageTab tabs={tabs} selectedTab={selectedTabComputed} onChange={setSelectedTab} />
</div>
<div className={classes.content}>
<ContentComponent addressNames={addressNames} identity={identity} />
<ContentComponent
addressNames={addressNames}
identity={identity}
personaList={personaList?.map((persona) => persona.persona)}
/>
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export interface ToolboxHintProps {
}
export function ToolboxHintUnstyled(props: ToolboxHintProps) {
const { t } = useI18N()
const isNextIDVerified = useNextIDConnectStatus()
const { isVerified: isNextIDVerified } = useNextIDConnectStatus()
const {
ListItemButton = MuiListItemButton,
ListItemText = MuiListItemText,
Expand Down
3 changes: 2 additions & 1 deletion packages/mask/src/plugins/NextID/SNSAdaptor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { NextIdPage } from '../components/NextIdPage'
import { RootContext } from '../contexts'
import { TipButton, TipTaskManager } from '../components/tip'
import { Flags } from '../../../../shared'
import { EMPTY_LIST } from '@masknet/web3-shared-evm'

const sns: Plugin.SNSAdaptor.Definition = {
...base,
Expand All @@ -15,7 +16,7 @@ const sns: Plugin.SNSAdaptor.Definition = {
label: 'Wallet',
priority: 10,
UI: {
TabContent: NextIdPage,
TabContent: ({ personaList = EMPTY_LIST }) => <NextIdPage personaList={personaList} />,
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/src/plugins/NextID/components/BindDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useAsyncRetry } from 'react-use'
import Services from '../../../extension/service'
import { isSameAddress } from '@masknet/web3-shared-evm'
import type { Persona } from '../../../database'
import type { Binding } from '../types'
import type { Binding } from '@masknet/shared-base'
import { BindPanelUI } from './BindPanelUI'
import { useAccount } from '@masknet/plugin-infra'
import { useCustomSnackbar } from '@masknet/theme'
Expand Down
6 changes: 3 additions & 3 deletions packages/mask/src/plugins/NextID/components/BindingItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChainId, formatEthereumAddress } from '@masknet/web3-shared-evm'
import { Box, Link, Stack, Typography } from '@mui/material'
import { memo } from 'react'
import { Platform } from '../types'
import { NextIDPlatform } from '@masknet/shared-base'
import { DeleteIcon } from '@masknet/icons'
import { makeStyles } from '@masknet/theme'
import { CopyIconButton } from './CopyIconButton'
Expand Down Expand Up @@ -42,7 +42,7 @@ const useStyles = makeStyles()((theme) => ({
},
}))
interface Item {
platform: Platform
platform: NextIDPlatform
Comment thread
Randolph314 marked this conversation as resolved.
identity: string
enableAction: boolean
onUnBind(address: string): void
Expand All @@ -54,7 +54,7 @@ export const BindingItem = memo<Item>(({ platform, identity, enableAction, onUnB
const { classes } = useStyles()
const networkDescriptor = useNetworkDescriptor(ChainId.Mainnet, NetworkPluginID.PLUGIN_EVM)

if (platform === Platform.ethereum) {
if (platform === NextIDPlatform.Ethereum) {
return (
<Stack
direction="row"
Expand Down
Loading