diff --git a/packages/maskbook/src/_locales/en/messages.json b/packages/maskbook/src/_locales/en/messages.json index 3e892213efa7..d2738ddb8f4b 100644 --- a/packages/maskbook/src/_locales/en/messages.json +++ b/packages/maskbook/src/_locales/en/messages.json @@ -365,6 +365,8 @@ "plugin_wallet_switch_network": "Swtich to {{network}}", "plugin_wallet_switch_network_under_going": "Switching to {{network}}…", "plugin_wallet_not_availabe_on": "Not available on {{network}}.", + "plugin_wallet_connect_wallet": "Connect Wallet", + "plugin_wallet_connect_wallet_tip": "No wallet found.", "plugin_wallet_settings_portfolio_data_source_primary": "Portfolio Data Source", "plugin_wallet_settings_portfolio_data_source_secondary": "Select the source of portfolio data.", "plugin_wallet_settings_collectible_data_source_primary": "Collectible Data Source", diff --git a/packages/maskbook/src/_locales/ja/messages.json b/packages/maskbook/src/_locales/ja/messages.json index eed9f3f852e3..2e03d5d3ddf1 100644 --- a/packages/maskbook/src/_locales/ja/messages.json +++ b/packages/maskbook/src/_locales/ja/messages.json @@ -365,6 +365,8 @@ "plugin_wallet_switch_network": "", "plugin_wallet_switch_network_under_going": "", "plugin_wallet_not_availabe_on": "", + "plugin_wallet_connect_wallet": "", + "plugin_wallet_connect_wallet_tip": "", "plugin_wallet_settings_portfolio_data_source_primary": "ポートフォリオデータのソーズ", "plugin_wallet_settings_portfolio_data_source_secondary": "ポートフォリオデータのソースを選択", "plugin_wallet_settings_collectible_data_source_primary": "コレクションデータのソース", diff --git a/packages/maskbook/src/_locales/ko/messages.json b/packages/maskbook/src/_locales/ko/messages.json index 46397d4f14a8..7ac2e6674e99 100644 --- a/packages/maskbook/src/_locales/ko/messages.json +++ b/packages/maskbook/src/_locales/ko/messages.json @@ -365,6 +365,8 @@ "plugin_wallet_switch_network": "", "plugin_wallet_switch_network_under_going": "", "plugin_wallet_not_availabe_on": "", + "plugin_wallet_connect_wallet": "", + "plugin_wallet_connect_wallet_tip": "", "plugin_wallet_settings_portfolio_data_source_primary": "포트폴리오 데이터 소스", "plugin_wallet_settings_portfolio_data_source_secondary": "포트폴리오 데이터 소스 선택", "plugin_wallet_settings_collectible_data_source_primary": "수집품 데이터 소스", diff --git a/packages/maskbook/src/_locales/zh/messages.json b/packages/maskbook/src/_locales/zh/messages.json index 75446ec6b43f..16e8566d5b42 100644 --- a/packages/maskbook/src/_locales/zh/messages.json +++ b/packages/maskbook/src/_locales/zh/messages.json @@ -365,6 +365,8 @@ "plugin_wallet_switch_network": "", "plugin_wallet_switch_network_under_going": "", "plugin_wallet_not_availabe_on": "", + "plugin_wallet_connect_wallet": "", + "plugin_wallet_connect_wallet_tip": "", "plugin_wallet_settings_portfolio_data_source_primary": "投資組合資料來源", "plugin_wallet_settings_portfolio_data_source_secondary": "選擇投資組合資料來源。", "plugin_wallet_settings_collectible_data_source_primary": "收藏品資料來源", diff --git a/packages/maskbook/src/plugins/Wallet/services/account.ts b/packages/maskbook/src/plugins/Wallet/services/account.ts index e5b9bb4c42d1..91687d08c2b7 100644 --- a/packages/maskbook/src/plugins/Wallet/services/account.ts +++ b/packages/maskbook/src/plugins/Wallet/services/account.ts @@ -51,14 +51,9 @@ export async function resetAccount( providerType?: ProviderType } = {}, ) { - const { - account = '', - chainId = ChainId.Mainnet, - networkType = NetworkType.Ethereum, - providerType = ProviderType.Maskbook, - } = options + const { account = '', chainId, networkType, providerType } = options currentAccountSettings.value = account - currentChainIdSettings.value = chainId - currentNetworkSettings.value = networkType - currentProviderSettings.value = providerType + if (chainId) currentChainIdSettings.value = chainId + if (networkType) currentNetworkSettings.value = networkType + if (providerType) currentProviderSettings.value = providerType } diff --git a/packages/maskbook/src/web3/UI/EthereumChainBoundary.tsx b/packages/maskbook/src/web3/UI/EthereumChainBoundary.tsx index ba65ef0d1d13..08da6ad6e24b 100644 --- a/packages/maskbook/src/web3/UI/EthereumChainBoundary.tsx +++ b/packages/maskbook/src/web3/UI/EthereumChainBoundary.tsx @@ -10,14 +10,15 @@ import { ProviderType, resolveNetworkName, useAccount, + useAllowTestnet, useChainId, } from '@masknet/web3-shared' -import { useValueRef, delay } from '@masknet/shared' -import { ActionButtonPromise } from '../../extension/options-page/DashboardComponents/ActionButton' +import { useValueRef, delay, useRemoteControlledDialog } from '@masknet/shared' +import ActionButton, { ActionButtonPromise } from '../../extension/options-page/DashboardComponents/ActionButton' import { currentProviderSettings } from '../../plugins/Wallet/settings' import Services from '../../extension/service' import { useI18N } from '../../utils' -import { WalletRPC } from '../../plugins/Wallet/messages' +import { WalletMessages, WalletRPC } from '../../plugins/Wallet/messages' export interface EthereumChainBoundaryProps { chainId: ChainId @@ -29,6 +30,7 @@ export function EthereumChainBoundary(props: EthereumChainBoundaryProps) { const { t } = useI18N() const account = useAccount() const chainId = useChainId() + const allowTestnet = useAllowTestnet() const providerType = useValueRef(currentProviderSettings) const expectedChainId = props.chainId @@ -37,7 +39,7 @@ export function EthereumChainBoundary(props: EthereumChainBoundaryProps) { const actualNetwork = getChainName(actualChainId) // if false then it will not guide the user to switch the network - const isAllowed = isChainIdValid(expectedChainId) && !!account + const isAllowed = isChainIdValid(expectedChainId, allowTestnet) && !!account const onSwitch = useCallback(async () => { // a short time loading makes the user fells better @@ -79,6 +81,10 @@ export function EthereumChainBoundary(props: EthereumChainBoundaryProps) { } }, [account, isAllowed, providerType, expectedChainId]) + const { openDialog: openSelectProviderDialog } = useRemoteControlledDialog( + WalletMessages.events.selectProviderDialogUpdated, + ) + // is the actual chain id matched with the expected one? const isMatched = actualChainId === expectedChainId @@ -87,6 +93,22 @@ export function EthereumChainBoundary(props: EthereumChainBoundaryProps) { if (isMatched || isValid) return <>{props.children} + if (!account) + return ( + + + {t('plugin_wallet_connect_wallet_tip')} + + + {t('plugin_wallet_connect_wallet')} + + + ) + if (!isAllowed) return (