diff --git a/packages/icons/utils/ssr.tsx b/packages/icons/utils/ssr.tsx index 873fe49f36c0..5cbd96ef0acd 100644 --- a/packages/icons/utils/ssr.tsx +++ b/packages/icons/utils/ssr.tsx @@ -31,7 +31,6 @@ svg { // This file will output to ./dist/utils/ so target actually points to ../build.html const target = resolve(fileURLToPath(import.meta.url), '../../../build.html') -console.log(target) writeFileSync(target, render()) function render() { // @ts-ignore esm emit bug diff --git a/packages/mask/src/components/DataSource/useNextID.ts b/packages/mask/src/components/DataSource/useNextID.ts index 039da241104d..8cfb9cb81e85 100644 --- a/packages/mask/src/components/DataSource/useNextID.ts +++ b/packages/mask/src/components/DataSource/useNextID.ts @@ -1,5 +1,5 @@ import { useAsyncRetry } from 'react-use' -import type { NextIDPlatform, PersonaIdentifier } from '@masknet/shared-base' +import { EMPTY_LIST, NextIDPlatform, PersonaIdentifier } from '@masknet/shared-base' import { useEffect, useMemo, useState } from 'react' import { activatedSocialNetworkUI } from '../../social-network' import { usePersonaConnectStatus } from './usePersonaConnectStatus' @@ -31,11 +31,11 @@ const verifyPersona = (personaIdentifier?: PersonaIdentifier, username?: string) }) } -export const useNextIDBoundByPlatform = (platform?: NextIDPlatform, identity?: string) => { - const res = useAsyncRetry(() => { - if (!platform || !identity) return Promise.resolve([]) - return NextIDProof.queryExistedBindingByPlatform(platform, identity) - }, [platform, identity]) +export const useNextIDBoundByPlatform = (platform?: NextIDPlatform, userId?: string) => { + const res = useAsyncRetry(async () => { + if (!platform || !userId) return EMPTY_LIST + return NextIDProof.queryExistedBindingByPlatform(platform, userId) + }, [platform, userId]) useEffect(() => MaskMessages.events.ownProofChanged.on(res.retry), [res.retry]) return res } diff --git a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx index 4f7f3a6f7fb6..6196f805e0f4 100644 --- a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx +++ b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx @@ -20,8 +20,6 @@ import { useCurrentVisitingIdentity, useLastRecognizedIdentity } from '../DataSo import { useNextIDBoundByPlatform } from '../DataSource/useNextID' import { usePersonaConnectStatus } from '../DataSource/usePersonaConnectStatus' -const platform = activatedSocialNetworkUI.configuration.nextIDConfig?.platform as NextIDPlatform | undefined - function getTabContent(tabId?: string) { return createInjectHooksRenderer(useActivatedPluginsSNSAdaptor.visibility.useAnyMode, (x) => { const tab = x.ProfileTabs?.find((x) => x.ID === tabId) @@ -55,51 +53,68 @@ export function ProfileTabContent(props: ProfileTabContentProps) { const { value: socialAddressList = EMPTY_LIST, loading: loadingSocialAddressList } = useSocialAddressListAll(identity) const { value: personaList = EMPTY_LIST, loading: loadingPersonaList } = useNextIDBoundByPlatform( - platform, + activatedSocialNetworkUI.configuration.nextIDConfig?.platform as NextIDPlatform | undefined, identity.identifier?.userId, ) + const activatedPlugins = useActivatedPluginsSNSAdaptor('any') + const availablePlugins = useAvailablePlugins(activatedPlugins) + const displayPlugins = availablePlugins + .flatMap((x) => x.ProfileTabs?.map((y) => ({ ...y, pluginID: x.ID })) ?? EMPTY_LIST) + .filter((z) => z.Utils?.shouldDisplay?.(identity, socialAddressList) ?? true) + + const tabs = displayPlugins + .sort((a, z) => { + // order those tabs from next id first + if (a.pluginID === PluginId.NextID) return -1 + if (z.pluginID === PluginId.NextID) return 1 + + // order those tabs from collectible first + if (a.pluginID === PluginId.Collectible) return -1 + if (z.pluginID === PluginId.Collectible) return 1 + + // place those tabs from debugger last + if (a.pluginID === PluginId.Debugger) return 1 + if (z.pluginID === PluginId.Debugger) return -1 + + // place those tabs from dao before the last + if (a.pluginID === PluginId.DAO) return 1 + if (z.pluginID === PluginId.DAO) return -1 + + return a.priority - z.priority + }) + .map((x) => ({ + id: x.ID, + label: typeof x.label === 'string' ? x.label : translate(x.pluginID, x.label), + })) + const currentAccountNotConnectPersona = currentIdentity.identifier === identity.identifier && personaList.findIndex((persona) => persona?.persona === currentConnectedPersona?.identifier.publicKeyAsHex) === -1 + const selectedTabId = selectedTab ?? first(tabs)?.id + const componentTabId = + isTwitter(activatedSocialNetworkUI) && currentAccountNotConnectPersona + ? displayPlugins?.find((tab) => tab?.pluginID === PluginId.NextID)?.ID + : selectedTabId - const activatedPlugins = useActivatedPluginsSNSAdaptor('any') - const availablePlugins = useAvailablePlugins(activatedPlugins) - const displayPlugins = useMemo(() => { - return availablePlugins - .flatMap((x) => x.ProfileTabs?.map((y) => ({ ...y, pluginID: x.ID })) ?? []) - .filter((z) => z.Utils?.shouldDisplay?.(identity, socialAddressList) ?? true) - }, [availablePlugins]) - - const tabs = useMemo(() => { - return displayPlugins - .sort((a, z) => { - // order those tabs from next id first - if (a.pluginID === PluginId.NextID) return -1 - if (z.pluginID === PluginId.NextID) return 1 - - // order those tabs from collectible first - if (a.pluginID === PluginId.Collectible) return -1 - if (z.pluginID === PluginId.Collectible) return 1 - - // place those tabs from debugger last - if (a.pluginID === PluginId.Debugger) return 1 - if (z.pluginID === PluginId.Debugger) return -1 - - // place those tabs from dao before the last - if (a.pluginID === PluginId.DAO) return 1 - if (z.pluginID === PluginId.DAO) return -1 - - return a.priority - z.priority - }) - .map((x) => ({ - id: x.ID, - label: typeof x.label === 'string' ? x.label : translate(x.pluginID, x.label), - })) - }, [displayPlugins, translate]) + const component = useMemo(() => { + const Component = getTabContent(componentTabId) + const Utils = displayPlugins.find((x) => x.ID === selectedTabId)?.Utils - const selectedTabId = selectedTab ?? first(tabs)?.id + return ( + x.persona)} + socialAddressList={socialAddressList.filter((x) => Utils?.filter?.(x) ?? true).sort(Utils?.sorter)} + /> + ) + }, [ + componentTabId, + displayPlugins.map((x) => x.ID).join(), + personaList.join(), + socialAddressList.map((x) => x.address).join(), + ]) useLocationChange(() => { setSelectedTab(undefined) @@ -121,28 +136,6 @@ export function ProfileTabContent(props: ProfileTabContentProps) { }) }, [identity.identifier?.userId]) - const content = useMemo(() => { - const Component = getTabContent( - isTwitter(activatedSocialNetworkUI) && currentAccountNotConnectPersona - ? displayPlugins?.find((tab) => tab?.pluginID === PluginId.NextID)?.ID - : selectedTabId, - ) - const Utils = displayPlugins.find((x) => x.ID === selectedTabId)?.Utils - - return ( - x.persona)} - socialAddressList={socialAddressList.filter((x) => Utils?.filter?.(x) ?? true).sort(Utils?.sorter)} - /> - ) - }, [ - selectedTabId, - displayPlugins.map((x) => x.ID).join(), - identity.identifier?.userId, - currentAccountNotConnectPersona, - ]) - if (hidden) return null if (!identity.identifier?.userId || loadingSocialAddressList || loadingPersonaList) @@ -169,7 +162,7 @@ export function ProfileTabContent(props: ProfileTabContentProps) { )} -
{content}
+
{component}
) } diff --git a/packages/mask/src/extension/popups/pages/Personas/VerifyWallet/index.tsx b/packages/mask/src/extension/popups/pages/Personas/VerifyWallet/index.tsx index 2f142aa1523d..e377550fdbac 100644 --- a/packages/mask/src/extension/popups/pages/Personas/VerifyWallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Personas/VerifyWallet/index.tsx @@ -105,7 +105,7 @@ const VerifyWallet = memo(() => { const [{ value: walletSignState }, walletSign] = useAsyncFn(async () => { if (!payload || !currentPersona?.identifier.publicKeyAsHex) return false try { - const walletSignature = await connection?.signMessage(payload.signPayload, 'personaSign', { + const walletSignature = await connection?.signMessage(payload.signPayload, 'personalSign', { chainId: wallet.chainId, account: wallet.account, providerType: wallet.providerType, diff --git a/packages/mask/src/extension/popups/pages/Wallet/SignRequest/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/SignRequest/index.tsx index c7da1f333ef0..71c8abf4b361 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/SignRequest/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/SignRequest/index.tsx @@ -95,25 +95,29 @@ const SignRequest = memo(() => { const { data, address } = useMemo(() => { if ( - (value?.payload?.method === EthereumMethodType.ETH_SIGN || - value?.payload?.method === EthereumMethodType.ETH_SIGN_TYPED_DATA) && - value.computedPayload?.data + value?.payload.method === EthereumMethodType.ETH_SIGN || + value?.payload.method === EthereumMethodType.ETH_SIGN_TYPED_DATA ) { - let message = value.computedPayload?.data - try { - message = toUtf8(value.computedPayload?.data) - } catch (error) { - console.log(error) + return { + address: value.payload.params?.[0], + data: toUtf8(value.payload.params?.[1] ?? ''), + } + } catch { + return { + address: value.payload.params?.[0], + data: value.payload.params?.[1], + } } + } else if (value?.payload.method === EthereumMethodType.PERSONAL_SIGN) return { - address: value.computedPayload.to, - data: message, + address: value.payload.params?.[1], + data: value.payload.params?.[0], } - } + return { - address: '', data: '', + address: '', } }, [value]) diff --git a/packages/mask/src/extension/popups/pages/Wallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/index.tsx index 33b31c567d11..f24b67593077 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/index.tsx @@ -57,7 +57,21 @@ export default function Wallet() { return const payload = await WalletRPC.topUnconfirmedRequest() if (!payload) return + + if (payload) { + switch (payload.method) { + case EthereumMethodType.ETH_SIGN: + case EthereumMethodType.ETH_SIGN_TYPED_DATA: + case EthereumMethodType.PERSONAL_SIGN: + navigate(PopupRoutes.WalletSignRequest, { replace: true }) + break + default: + break + } + } + const computedPayload = getPayloadConfig(payload) + if (!computedPayload) return const formatterTransaction = await TransactionFormatter?.formatTransaction(chainId, computedPayload) @@ -70,18 +84,6 @@ export default function Wallet() { ) { navigate(PopupRoutes.ContractInteraction, { replace: true }) } - - if (computedPayload) { - switch (payload.method) { - case EthereumMethodType.ETH_SIGN: - case EthereumMethodType.ETH_SIGN_TYPED_DATA: - case EthereumMethodType.PERSONAL_SIGN: - navigate(PopupRoutes.WalletSignRequest, { replace: true }) - break - default: - break - } - } }, [location.search, location.pathname, chainId]) useEffect(() => { diff --git a/packages/mask/src/plugins/ITO/SNSAdaptor/CompositionDialog.tsx b/packages/mask/src/plugins/ITO/SNSAdaptor/CompositionDialog.tsx index c0073c603506..4cf3ddb35610 100644 --- a/packages/mask/src/plugins/ITO/SNSAdaptor/CompositionDialog.tsx +++ b/packages/mask/src/plugins/ITO/SNSAdaptor/CompositionDialog.tsx @@ -151,7 +151,7 @@ export function CompositionDialog(props: CompositionDialogProps) { if (!payload.password) { const [, title] = payload.message.split(MSG_DELIMITER) payload.password = - (await connection?.signMessage(Web3Utils.sha3(title) ?? '', 'personaSign', { + (await connection?.signMessage(Web3Utils.sha3(title) ?? '', 'personalSign', { account, })) ?? '' } diff --git a/packages/mask/src/plugins/NextID/components/NextIdPage.tsx b/packages/mask/src/plugins/NextID/components/NextIdPage.tsx index 106fbdff3e75..14aeb9c327b7 100644 --- a/packages/mask/src/plugins/NextID/components/NextIdPage.tsx +++ b/packages/mask/src/plugins/NextID/components/NextIdPage.tsx @@ -69,7 +69,6 @@ export function NextIdPage({ personaList }: NextIdPageProps) { const personaActionButton = useMemo(() => { if (!personaConnectStatus.action) return null - const button = personaConnectStatus.hasPersona ? t.connect_persona() : t.create_persona() return (