diff --git a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx index 6196f805e0f4..63bf85fd115b 100644 --- a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx +++ b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx @@ -59,9 +59,15 @@ export function ProfileTabContent(props: ProfileTabContentProps) { 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 displayPlugins = useMemo(() => { + return availablePlugins + .flatMap((x) => x.ProfileTabs?.map((y) => ({ ...y, pluginID: x.ID })) ?? EMPTY_LIST) + .filter((z) => z.Utils?.shouldDisplay?.(identity, socialAddressList) ?? true) + }, [ + identity.identifier?.userId, + availablePlugins.map((x) => x.ID).join(), + socialAddressList.map((x) => x.address).join(), + ]) const tabs = displayPlugins .sort((a, z) => { diff --git a/packages/mask/src/plugins/Wallet/services/send.ts b/packages/mask/src/plugins/Wallet/services/send.ts index 89d971d474b3..c8f64c6ec55f 100644 --- a/packages/mask/src/plugins/Wallet/services/send.ts +++ b/packages/mask/src/plugins/Wallet/services/send.ts @@ -124,11 +124,10 @@ export async function send( options?: Options, ) { const provider = await createProvider(options?.chainId) - + const computedPayload = getPayloadConfig(payload) switch (payload.method) { case EthereumMethodType.ETH_SEND_TRANSACTION: case EthereumMethodType.MASK_REPLACE_TRANSACTION: - const computedPayload = getPayloadConfig(payload) if (!computedPayload?.from || !computedPayload.to || !options?.chainId) return const rawTransaction = await WalletRPC.signTransaction(computedPayload.from as string, { @@ -145,6 +144,32 @@ export async function send( }, callback, ) + case EthereumMethodType.ETH_SIGN_TYPED_DATA: + const [address, dataToSign] = payload.params as [string, string] + const signed = await WalletRPC.signTypedData(address, dataToSign) + try { + callback(null, { + jsonrpc: '2.0', + id: payload.id as number, + result: signed, + }) + } catch (error) { + callback(getError(error, null, 'Failed to sign message.')) + } + break + case EthereumMethodType.PERSONAL_SIGN: + const [data, account] = payload.params as [string, string] + const personalSigned = await WalletRPC.signPersonalMessage(data, account) + try { + callback(null, { + jsonrpc: '2.0', + id: payload.id as number, + result: personalSigned, + }) + } catch (error) { + callback(getError(error, null, 'Failed to sign message.')) + } + break default: return provider.send(payload, callback) } diff --git a/packages/plugins/Debugger/src/SNSAdaptor/components/TabContent.tsx b/packages/plugins/Debugger/src/SNSAdaptor/components/TabContent.tsx index 5db93092794c..28bbd778491f 100644 --- a/packages/plugins/Debugger/src/SNSAdaptor/components/TabContent.tsx +++ b/packages/plugins/Debugger/src/SNSAdaptor/components/TabContent.tsx @@ -1,7 +1,16 @@ -import { useAccount, useBalance, useBlockNumber, useWeb3Connection, useWeb3State } from '@masknet/plugin-infra/web3' +import { + useAccount, + useBalance, + useBlockNumber, + useChainId, + useCurrentWeb3NetworkPluginID, + useWeb3Connection, + useWeb3State, + Web3Helper, +} from '@masknet/plugin-infra/web3' import { makeStyles } from '@masknet/theme' -import type { NetworkPluginID, SocialAddress, SocialIdentity } from '@masknet/web3-shared-base' -import { useTokenConstants } from '@masknet/web3-shared-evm' +import { NetworkPluginID, SocialAddress, SocialIdentity } from '@masknet/web3-shared-base' +import { ChainId, useTokenConstants } from '@masknet/web3-shared-evm' import { Button, List, ListItem, ListItemText, Table, TableBody, TableCell, TableRow, Typography } from '@mui/material' import { useCallback } from 'react' @@ -66,11 +75,13 @@ export function TabContent({ identity, socialAddressList }: TabContentProps) { } const { NATIVE_TOKEN_ADDRESS } = useTokenConstants() - const { Others } = useWeb3State() + const pluginID = useCurrentWeb3NetworkPluginID() + const { Others } = useWeb3State<'all'>() + const connection = useWeb3Connection<'all'>() const account = useAccount() + const chainId = useChainId() const { value: balance = '0' } = useBalance() const { value: blockNumber = 0 } = useBlockNumber() - const connection = useWeb3Connection() const onTransferCallback = useCallback(() => { if (!NATIVE_TOKEN_ADDRESS) return return connection.transferFungibleToken( @@ -80,11 +91,67 @@ export function TabContent({ identity, socialAddressList }: TabContentProps) { ) }, [connection]) - const onPersonaSign = useCallback(async () => { - const signed = await connection.signMessage('hello world', 'personalSign') - console.log(signed) - window.alert(`Signed: ${signed}`) - }, [connection]) + const onSignMessage = useCallback( + async (type?: string) => { + const message = 'Hello World' + const typedData = JSON.stringify({ + domain: { + chainId: chainId.toString(), + name: 'Ether Mail', + verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC', + version: '1', + }, + message: { + contents: 'Hello, Bob!', + from: { + name: 'Cow', + wallets: [ + '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826', + '0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF', + ], + }, + to: [ + { + name: 'Bob', + wallets: [ + '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB', + '0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57', + '0xB0B0b0b0b0b0B000000000000000000000000000', + ], + }, + ], + }, + primaryType: 'Mail', + types: { + Group: [ + { name: 'name', type: 'string' }, + { name: 'members', type: 'Person[]' }, + ], + Mail: [ + { name: 'from', type: 'Person' }, + { name: 'to', type: 'Person[]' }, + { name: 'contents', type: 'string' }, + ], + Person: [ + { name: 'name', type: 'string' }, + { name: 'wallets', type: 'address[]' }, + ], + }, + }) + const signed = await connection.signMessage(type === 'typedDataSign' ? typedData : message, type) + window.alert(`Signed: ${signed}`) + }, + [chainId, connection], + ) + + const onSwitchChain = useCallback( + async (chainId: Web3Helper.ChainIdAll) => { + return connection?.switchChain?.({ + chainId, + }) + }, + [connection], + ) return (
@@ -92,7 +159,19 @@ export function TabContent({ identity, socialAddressList }: TabContentProps) { - Balance of {Others?.formatAddress(account, 4)} + + Account + + + + {Others?.formatAddress(account, 4)} + + + + + + Balance + {balance} @@ -100,7 +179,9 @@ export function TabContent({ identity, socialAddressList }: TabContentProps) { - Block Number + + Block Number + {blockNumber} @@ -108,7 +189,9 @@ export function TabContent({ identity, socialAddressList }: TabContentProps) { - Native Token Transfer + + Native Token Transfer + - Identity + + Sign Typed Data + + + + + + + + + + Switch Chain + + + + + + + + + + Profile Data + {renderIdentity()} - Social Address List + + Found Address Names + {renderAddressNames()} diff --git a/packages/plugins/Debugger/src/SNSAdaptor/index.tsx b/packages/plugins/Debugger/src/SNSAdaptor/index.tsx index f3cf3b70610c..2e9218c6fdb0 100644 --- a/packages/plugins/Debugger/src/SNSAdaptor/index.tsx +++ b/packages/plugins/Debugger/src/SNSAdaptor/index.tsx @@ -16,9 +16,6 @@ const sns: Plugin.SNSAdaptor.Definition = { TabContent, }, Utils: { - filter(x) { - return x.type !== SocialAddressType.ENS - }, sorter(a, z) { if (a.type === SocialAddressType.ADDRESS) return 1 if (z.type === SocialAddressType.ADDRESS) return -1 diff --git a/packages/plugins/EVM/src/state/Connection/connection.ts b/packages/plugins/EVM/src/state/Connection/connection.ts index a67ace10b623..4de08c802c18 100644 --- a/packages/plugins/EVM/src/state/Connection/connection.ts +++ b/packages/plugins/EVM/src/state/Connection/connection.ts @@ -281,7 +281,9 @@ class Connection implements EVM_Connection { async switchChain(options?: EVM_Web3ConnectionOptions): Promise { await Providers[options?.providerType ?? this.providerType].switchChain(options?.chainId) } - getNativeTokenBalance(options?: EVM_Web3ConnectionOptions): Promise { + async getNativeTokenBalance(options?: EVM_Web3ConnectionOptions): Promise { + const account = options?.account ?? this.account + if (!account) return '0' return this.getBalance(options?.account ?? this.account, options) } async getFungibleTokenBalance(address: string, options?: EVM_Web3ConnectionOptions): Promise { diff --git a/packages/plugins/EVM/src/state/Connection/providers/MetaMask.ts b/packages/plugins/EVM/src/state/Connection/providers/MetaMask.ts index f44d3b47acea..508aff6fa762 100644 --- a/packages/plugins/EVM/src/state/Connection/providers/MetaMask.ts +++ b/packages/plugins/EVM/src/state/Connection/providers/MetaMask.ts @@ -20,6 +20,11 @@ export class MetaMaskProvider extends BaseInjectedProvider implements EVM_Provid return super.readyPromise } + override onDisconnect() { + // MetaMask will emit disconnect after switching chain id + // since then, override to stop listening to the disconnect event with MetaMask + } + override async disconnect(): Promise { // do nothing } diff --git a/packages/plugins/EVM/src/state/IdentityService.ts b/packages/plugins/EVM/src/state/IdentityService.ts index 088b89c9e66f..844afc00a536 100644 --- a/packages/plugins/EVM/src/state/IdentityService.ts +++ b/packages/plugins/EVM/src/state/IdentityService.ts @@ -67,7 +67,7 @@ export class IdentityService extends IdentityServiceState { const addressENS = getSettledAddress(allSettled[0]) const addressRSS3 = getSettledAddress(allSettled[1]) - const addressGUN = getSettledAddress(allSettled[2]) + const addressKV = getSettledAddress(allSettled[2]) return [ isValidSocialAddress(address) @@ -94,12 +94,12 @@ export class IdentityService extends IdentityServiceState { address: addressRSS3, } : null, - isValidSocialAddress(addressGUN) + isValidSocialAddress(addressKV) ? { networkSupporterPluginID: NetworkPluginID.PLUGIN_EVM, - type: SocialAddressType.GUN, - label: addressGUN, - address: addressGUN, + type: SocialAddressType.KV, + label: addressKV, + address: addressKV, } : null, ].filter(Boolean) as Array> diff --git a/packages/shared/src/UI/components/AddressViewer/index.tsx b/packages/shared/src/UI/components/AddressViewer/index.tsx index 026db8689996..93d23cbbd628 100644 --- a/packages/shared/src/UI/components/AddressViewer/index.tsx +++ b/packages/shared/src/UI/components/AddressViewer/index.tsx @@ -44,6 +44,7 @@ export function AddressViewer({ identityAddress }: AddressViewerProps) { [SocialAddressType.UNS]: t.address_viewer_address_name_uns(), [SocialAddressType.DNS]: t.address_viewer_address_name_dns(), [SocialAddressType.RSS3]: t.address_viewer_address_name_rns(), + [SocialAddressType.KV]: t.address_viewer_address_name_address(), [SocialAddressType.GUN]: t.address_viewer_address_name_address(), [SocialAddressType.NEXT_ID]: t.address_viewer_address_name_address(), [SocialAddressType.THE_GRAPH]: t.address_viewer_address_name_address(), diff --git a/packages/web3-shared/base/src/specs/index.ts b/packages/web3-shared/base/src/specs/index.ts index 1eabca5f1253..840559ac9d73 100644 --- a/packages/web3-shared/base/src/specs/index.ts +++ b/packages/web3-shared/base/src/specs/index.ts @@ -91,6 +91,7 @@ export enum SocialAddressType { UNS = 'UNS', DNS = 'DNS', RSS3 = 'RSS3', + KV = 'KV', GUN = 'GUN', THE_GRAPH = 'THE_GRAPH', TWITTER_BLUE = 'TWITTER_BLUE',