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
1 change: 0 additions & 1 deletion packages/icons/utils/ssr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions packages/mask/src/components/DataSource/useNextID.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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) => {

@UncleBill UncleBill Jun 6, 2022

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.

Instead of userId , identity may be a more appropriate term, since it could be address of a wallet.

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
}
Expand Down
115 changes: 54 additions & 61 deletions packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 (
<Component
identity={identity}
personaList={personaList?.map((x) => 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)
Expand All @@ -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 (
<Component
identity={identity}
personaList={personaList?.map((x) => 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)
Expand All @@ -169,7 +162,7 @@ export function ProfileTabContent(props: ProfileTabContentProps) {
</Typography>
)}
</div>
<div className={classes.content}>{content}</div>
<div className={classes.content}>{component}</div>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
26 changes: 14 additions & 12 deletions packages/mask/src/extension/popups/pages/Wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})) ?? ''
}
Expand Down
22 changes: 9 additions & 13 deletions packages/mask/src/plugins/NextID/components/NextIdPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Button variant="contained" onClick={personaConnectStatus.action}>
Expand All @@ -82,25 +81,22 @@ export function NextIdPage({ personaList }: NextIdPageProps) {
if (!visitingPersonaIdentifier?.identifier) return
return Services.Identity.queryPersonaByProfile(visitingPersonaIdentifier.identifier)
}, [visitingPersonaIdentifier, personaConnectStatus.hasPersona])
const publicKeyAsHex = currentPersona?.identifier.publicKeyAsHex

const { value: isAccountVerified, loading: loadingVerifyInfo } = useAsync(async () => {
if (!currentPersona?.identifier.publicKeyAsHex) return
if (!publicKeyAsHex) return
if (!visitingPersonaIdentifier.identifier) return
return NextIDProof.queryIsBound(
currentPersona.identifier.publicKeyAsHex,
platform,
visitingPersonaIdentifier.identifier.userId,
)
}, [isOwn, currentPersona, visitingPersonaIdentifier, isVerified])
return NextIDProof.queryIsBound(publicKeyAsHex, platform, visitingPersonaIdentifier.identifier.userId)
}, [publicKeyAsHex, visitingPersonaIdentifier, isVerified])

const {
value: bindings,
loading,
loading: loadingBindings,
retry: retryQueryBinding,
} = useAsyncRetry(async () => {
if (!currentPersona?.identifier.publicKeyAsHex) return
return NextIDProof.queryExistedBindingByPersona(currentPersona.identifier.publicKeyAsHex)
}, [currentPersona, isOwn])
if (!publicKeyAsHex) return
return NextIDProof.queryExistedBindingByPersona(publicKeyAsHex)
}, [publicKeyAsHex])

const onVerify = async () => {
reset()
Expand All @@ -122,7 +118,7 @@ export function NextIdPage({ personaList }: NextIdPageProps) {
)
}

if (loading || loadingPersona || loadingVerifyInfo) {
if (loadingBindings || loadingPersona || loadingVerifyInfo) {
return (
<>
{Array.from({ length: 2 })
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/src/plugins/Pets/SNSAdaptor/PetSetDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function PetSetDialog({ configNFTs, onClose }: PetSetDialogProps) {
}
try {
await PluginPetRPC.setUserAddress(user)
const signature = await connection?.signMessage(user.userId, 'personaSign', { account: user.address })
const signature = await connection?.signMessage(user.userId, 'personalSign', { account: user.address })
if (signature && connection) {
await saveCustomEssayToRSS(user.address, meta, signature, connection)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/src/plugins/Pets/Services/rss3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function saveCustomEssayToRSS(
) {
if (!address) return
const rss = RSS3.createRSS3(address, async (message: string) => {
return connection.signMessage(message, 'personaSign', { account: address })
return connection.signMessage(message, 'personalSign', { account: address })
})
await RSS3.setFileData<EssayRSSNode>(rss, address, '_pet', { address, signature, essay })
return essay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default function RedPacketDialog(props: RedPacketDialogProps) {
if (!connection) return
payload.password = await connection.signMessage(
Web3Utils.sha3(payload.sender.message) ?? '',
'personaSign',
'personalSign',
{ account },
)
payload.password = payload.password!.slice(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ interface ContractListItemProps {
function ContractListItem(props: ContractListItemProps) {
const { onSubmit, contract } = props
const { classes } = useStyles()
console.log({ contract })
return (
<div style={{ position: 'relative' }}>
<ListItem className={classes.listItem} onClick={() => onSubmit(contract)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function SelectProviderDialog(props: SelectProviderDialogProps) {

const onProviderIconClicked = useCallback(
async (network: Web3Helper.NetworkDescriptorAll, provider: Web3Helper.ProviderDescriptorAll) => {
if (!(await Provider?.isReady(provider.type))) {
if (!Provider?.isReady(provider.type)) {
const downloadLink = Others?.providerResolver.providerDownloadLink(provider.type)
if (downloadLink) openWindow(downloadLink)
return
Expand Down
Loading