diff --git a/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx
index 36fd0399b416..29e85eb3b1ae 100644
--- a/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx
+++ b/packages/mask/src/extension/popups/pages/Wallet/VerifyWallet/index.tsx
@@ -1,16 +1,17 @@
+import { memo, useState } from 'react'
+import { useLocation } from 'react-use'
+import { useNavigate } from 'react-router-dom'
import { NextIDAction, NextIDPayload, NextIDPlatform, PopupRoutes } from '@masknet/shared-base'
import { makeStyles } from '@masknet/theme'
import { NextIDProof } from '@masknet/web3-providers'
-import { memo, useState } from 'react'
+import { ChainId, isSameAddress, NetworkType, ProviderType } from '@masknet/web3-shared-evm'
+import type { Web3Plugin } from '@masknet/plugin-infra/src/web3-types'
import { SignSteps, Steps } from '../../../../../components/shared/VerifyWallet/Steps'
import Services from '../../../../service'
import { PersonaContext } from '../../Personas/hooks/usePersonaContext'
import { useTitle } from '../../../hook/useTitle'
import { useI18N } from '../../../../../utils'
import { useQueryIsBound } from '../../../hook/useQueryIsBound'
-import { useNavigate } from 'react-router-dom'
-import { useLocation } from 'react-use'
-import { isSameAddress } from '@masknet/web3-shared-evm'
const useStyles = makeStyles()((theme) => ({
container: {
@@ -32,7 +33,7 @@ const VerifyWallet = memo(() => {
const navigate = useNavigate()
useTitle(t('popups_add_wallet'))
const location = useLocation()
- const wallet = location.state.usr
+ const wallet: Web3Plugin.ConnectionResult
= location.state.usr
const bounds = useQueryIsBound(wallet.account)
if (bounds && bounds.length > 0 && !isBound) {
@@ -72,7 +73,10 @@ const VerifyWallet = memo(() => {
const walletSign = async () => {
if (!payload) throw new Error('payload error')
try {
- const walletSig = await Services.Ethereum.personalSign(payload.signPayload, wallet.account)
+ const walletSig = await Services.Ethereum.personalSign(payload.signPayload, wallet.account, '', {
+ chainId: wallet.chainId,
+ providerType: wallet.providerType,
+ })
if (!walletSig) throw new Error('Wallet sign failed')
await NextIDProof.bindProof(
payload.uuid,
diff --git a/packages/mask/src/plugins/Wallet/SNSAdaptor/ConnectWalletDialog/index.tsx b/packages/mask/src/plugins/Wallet/SNSAdaptor/ConnectWalletDialog/index.tsx
index a8d61e61bad3..87277ebce9fe 100644
--- a/packages/mask/src/plugins/Wallet/SNSAdaptor/ConnectWalletDialog/index.tsx
+++ b/packages/mask/src/plugins/Wallet/SNSAdaptor/ConnectWalletDialog/index.tsx
@@ -1,5 +1,8 @@
import { useCallback, useState } from 'react'
import { useAsyncRetry } from 'react-use'
+import urlcat from 'urlcat'
+import { useNavigate } from 'react-router-dom'
+import { first } from 'lodash-unified'
import { DialogContent } from '@mui/material'
import { makeStyles, useStylesExtends } from '@masknet/theme'
import { safeUnreachable, delay } from '@dimensiondev/kit'
@@ -12,11 +15,13 @@ import {
resolveNetworkName,
resolveProviderName,
} from '@masknet/web3-shared-evm'
+import { isPopupPage, PopupRoutes } from '@masknet/shared-base'
import { useRemoteControlledDialog } from '@masknet/shared-base-ui'
import { InjectedDialog } from '@masknet/shared'
import { WalletMessages } from '../../messages'
import { ConnectionProgress } from './ConnectionProgress'
import Services from '../../../../extension/service'
+import { useSelectAccount } from '../../hooks/useSelectAccount'
const useStyles = makeStyles()((theme) => ({
content: {
@@ -29,6 +34,9 @@ export interface ConnectWalletDialogProps {}
export function ConnectWalletDialog(props: ConnectWalletDialogProps) {
const classes = useStylesExtends(useStyles(), props)
+ const navigate = useNavigate()
+ const [onSelectAccountPrepare] = useSelectAccount()
+
const [providerType, setProviderType] = useState()
const [networkType, setNetworkType] = useState()
@@ -68,7 +76,26 @@ export function ConnectWalletDialog(props: ConnectWalletDialogProps) {
switch (providerType) {
case ProviderType.MaskWallet:
- ;({ account, chainId } = await Services.Ethereum.connectMaskWallet(networkType))
+ if (isPopupPage()) {
+ ;({ account, chainId } = await new Promise<{
+ account: string
+ chainId: ChainId
+ }>(async (resolve) => {
+ onSelectAccountPrepare(async (accounts, chainId) => {
+ resolve({
+ chainId,
+ account: first(accounts) ?? '',
+ })
+ })
+ navigate(
+ urlcat(PopupRoutes.SelectWallet, {
+ popup: true,
+ }),
+ )
+ }))
+ } else {
+ ;({ account, chainId } = await Services.Ethereum.connectMaskWallet(expectedChainId))
+ }
break
case ProviderType.MetaMask:
;({ account, chainId } = await Services.Ethereum.connectMetaMask())
@@ -141,7 +168,7 @@ export function ConnectWalletDialog(props: ConnectWalletDialogProps) {
networkType,
providerType,
}
- }, [networkType, providerType])
+ }, [networkType, providerType, onSelectAccountPrepare])
const connection = useAsyncRetry(async () => {
if (!open) return true
@@ -156,6 +183,9 @@ export function ConnectWalletDialog(props: ConnectWalletDialogProps) {
if (!providerType) return null
+ // The connection state is transferring between pages when we connect Mask Wallet on the popup page
+ if (isPopupPage() && providerType === ProviderType.MaskWallet) return null
+
return (
diff --git a/packages/mask/src/plugins/Wallet/SNSAdaptor/WalletConnectQRCodeDialog/index.tsx b/packages/mask/src/plugins/Wallet/SNSAdaptor/WalletConnectQRCodeDialog/index.tsx
index 7de9b3a09cc9..bec9a9ba05e9 100644
--- a/packages/mask/src/plugins/Wallet/SNSAdaptor/WalletConnectQRCodeDialog/index.tsx
+++ b/packages/mask/src/plugins/Wallet/SNSAdaptor/WalletConnectQRCodeDialog/index.tsx
@@ -1,4 +1,5 @@
import { useState } from 'react'
+import { useAsync } from 'react-use'
import { Button, DialogActions, DialogContent } from '@mui/material'
import { makeStyles } from '@masknet/theme'
import { useRemoteControlledDialog } from '@masknet/shared-base-ui'
@@ -35,6 +36,12 @@ export const WalletConnectQRCodeDialog: React.FC = () => {
)
// #endregion
+ useAsync(async () => {
+ if (!open) return
+ await Services.Ethereum.connectWalletConnect()
+ closeDialog()
+ }, [open])
+
let mode: QRCodeDialogProps['mode'] = 'qrcode'
if (process.env.architecture === 'app' && process.env.engine === 'firefox') {
mode = 'firefox'
diff --git a/packages/mask/src/plugins/Wallet/hooks/useSelectAccount.ts b/packages/mask/src/plugins/Wallet/hooks/useSelectAccount.ts
new file mode 100644
index 000000000000..96ae005e274b
--- /dev/null
+++ b/packages/mask/src/plugins/Wallet/hooks/useSelectAccount.ts
@@ -0,0 +1,25 @@
+import { useCallback } from 'react'
+import type { ChainId } from '@masknet/web3-shared-evm'
+
+interface SelectAccountCallback {
+ (accounts: string[], chainId: ChainId): Promise
+}
+
+let globalCallback: SelectAccountCallback | undefined
+
+export function useSelectAccount() {
+ const onSelectAccountPrepare = useCallback((callback: SelectAccountCallback) => {
+ if (callback) {
+ globalCallback = callback
+ }
+ }, [])
+
+ const onSelectAccount = useCallback((accounts: string[], chainId: ChainId) => {
+ if (globalCallback) {
+ globalCallback(accounts, chainId)
+ globalCallback = undefined
+ }
+ }, [])
+
+ return [onSelectAccountPrepare, onSelectAccount] as const
+}
diff --git a/packages/mask/src/social-network/defaults/inject/PageInspector.tsx b/packages/mask/src/social-network/defaults/inject/PageInspector.tsx
index 415e765425c3..24c2691d74e8 100644
--- a/packages/mask/src/social-network/defaults/inject/PageInspector.tsx
+++ b/packages/mask/src/social-network/defaults/inject/PageInspector.tsx
@@ -1,9 +1,12 @@
import { memo } from 'react'
+import { HashRouter } from 'react-router-dom'
import { makeStyles } from '@masknet/theme'
import { PageInspector, PageInspectorProps } from '../../../components/InjectedComponents/PageInspector'
import { createReactRootShadowed } from '../../../utils/shadow-root/renderInShadowRoot'
import { Flags } from '../../../../shared'
+export interface InjectPageInspectorDefaultConfig {}
+
export function injectPageInspectorDefault(
config: InjectPageInspectorDefaultConfig = {},
additionalPropsToPageInspector: (classes: Record) => Partial = () => ({}),
@@ -20,8 +23,10 @@ export function injectPageInspectorDefault(
.appendChild(document.createElement('div'))
.attachShadow({ mode: Flags.using_ShadowDOM_attach_mode })
- createReactRootShadowed(dom, { signal, key: 'page-inspector' }).render()
+ createReactRootShadowed(dom, { signal, key: 'page-inspector' }).render(
+
+
+ ,
+ )
}
}
-
-interface InjectPageInspectorDefaultConfig {}