From 8b6fe7027e968a5cd0558dbbcfcd43bb7d4bf5fd Mon Sep 17 00:00:00 2001 From: lelenei Date: Wed, 15 Jun 2022 18:26:49 +0800 Subject: [PATCH 1/4] fix: get account at timeline --- packages/mask/src/web3/UI/ChainBoundary.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/mask/src/web3/UI/ChainBoundary.tsx b/packages/mask/src/web3/UI/ChainBoundary.tsx index 6135eeb03b8a..353129fa1708 100644 --- a/packages/mask/src/web3/UI/ChainBoundary.tsx +++ b/packages/mask/src/web3/UI/ChainBoundary.tsx @@ -75,11 +75,12 @@ export function ChainBoundary(props: ChainBoundaryPro const actualChainId = useChainId(actualPluginID) const actualProviderType = useProviderType(actualPluginID) const actualChainName = actualOthers?.chainResolver.chainName(actualChainId) + const account = useAccount(actualPluginID) const { Others: expectedOthers } = useWeb3State(expectedPluginID) const expectedConnection = useWeb3Connection(expectedPluginID) const expectedAllowTestnet = useAllowTestnet(expectedPluginID) - const expectedAccount = useAccount(expectedPluginID) + const expectedChainName = expectedOthers?.chainResolver.chainName(expectedChainId) const expectedNetworkDescriptor = useNetworkDescriptor(NetworkPluginID.PLUGIN_EVM, expectedChainId) const expectedChainAllowed = expectedOthers?.chainResolver.isValid(expectedChainId, expectedAllowTestnet) @@ -151,7 +152,7 @@ export function ChainBoundary(props: ChainBoundaryPro ) } - if (!expectedAccount) + if (!account) return renderBox( <> {!props.hiddenConnectButton ? ( From defab018f4116b3f98d6b7265c378319826fc1ca Mon Sep 17 00:00:00 2001 From: lelenei Date: Wed, 15 Jun 2022 18:59:02 +0800 Subject: [PATCH 2/4] fix: revert code --- packages/mask/src/web3/UI/ChainBoundary.tsx | 51 +++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/packages/mask/src/web3/UI/ChainBoundary.tsx b/packages/mask/src/web3/UI/ChainBoundary.tsx index 353129fa1708..eebdfc3effc7 100644 --- a/packages/mask/src/web3/UI/ChainBoundary.tsx +++ b/packages/mask/src/web3/UI/ChainBoundary.tsx @@ -24,6 +24,7 @@ import { WalletMessages } from '../../plugins/Wallet/messages' import { WalletIcon } from '@masknet/shared' import { PluginWalletConnectIcon } from '@masknet/icons' import { NetworkPluginID } from '@masknet/web3-shared-base' +import { useActivatedPlugin } from '@masknet/plugin-infra/dom' const useStyles = makeStyles()((theme) => ({ action: { @@ -71,6 +72,8 @@ export function ChainBoundary(props: ChainBoundaryPro const classes = useStylesExtends(useStyles(), props) const actualPluginID = useCurrentWeb3NetworkPluginID() + const plugin = useActivatedPlugin(actualPluginID, 'any') + const { Others: actualOthers } = useWeb3State(actualPluginID) const actualChainId = useChainId(actualPluginID) const actualProviderType = useProviderType(actualPluginID) @@ -172,6 +175,54 @@ export function ChainBoundary(props: ChainBoundaryPro if (isMatched) return <>{props.children} + if (actualPluginID !== expectedPluginID) { + return renderBox( + <> + {!noSwitchNetworkTip ? ( + + + {t('plugin_wallet_not_available_on', { + network: plugin?.name?.fallback ?? 'Unknown Plugin', + })} + + + ) : null} + {expectedChainAllowed ? ( + + } + sx={props.ActionButtonPromiseProps?.sx} + style={{ borderRadius: 10 }} + init={ + + {t('plugin_wallet_connect_network', { + network: 'EVM', + })} + + } + waiting={t('plugin_wallet_connect_network_under_going', { + network: 'EVM', + })} + complete={t('plugin_wallet_connect_network', { + network: 'EVM', + })} + failed={t('retry')} + executor={onSwitchChain} + completeOnClick={onSwitchChain} + failedOnClick="use executor" + {...props.ActionButtonPromiseProps} + /> + ) : null} + , + ) + } + return renderBox( <> {!noSwitchNetworkTip ? ( From 108147b97a9d794d97ca13a152a15f2a5a290464 Mon Sep 17 00:00:00 2001 From: lelenei Date: Wed, 15 Jun 2022 21:11:37 +0800 Subject: [PATCH 3/4] fix: css style --- packages/mask/src/web3/UI/ChainBoundary.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/mask/src/web3/UI/ChainBoundary.tsx b/packages/mask/src/web3/UI/ChainBoundary.tsx index eebdfc3effc7..e0286452bf9b 100644 --- a/packages/mask/src/web3/UI/ChainBoundary.tsx +++ b/packages/mask/src/web3/UI/ChainBoundary.tsx @@ -101,6 +101,11 @@ export function ChainBoundary(props: ChainBoundaryPro if (!expectedChainAllowed) return + if (isPluginIDMatched || actualProviderType === ProviderType.MaskWallet) { + await expectedConnection.connect({ chainId: expectedChainId }) + return + } + if (!isPluginIDMatched || actualProviderType === ProviderType.WalletConnect) { openSelectProviderDialog() return @@ -216,7 +221,7 @@ export function ChainBoundary(props: ChainBoundaryPro executor={onSwitchChain} completeOnClick={onSwitchChain} failedOnClick="use executor" - {...props.ActionButtonPromiseProps} + {...buttonProps} /> ) : null} , From e55ac11f633da5965f99c9c27209349d131a6bf7 Mon Sep 17 00:00:00 2001 From: lelenei Date: Wed, 15 Jun 2022 21:15:44 +0800 Subject: [PATCH 4/4] fix: remove unused code --- packages/mask/src/web3/UI/ChainBoundary.tsx | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/mask/src/web3/UI/ChainBoundary.tsx b/packages/mask/src/web3/UI/ChainBoundary.tsx index e0286452bf9b..b2c63246abb6 100644 --- a/packages/mask/src/web3/UI/ChainBoundary.tsx +++ b/packages/mask/src/web3/UI/ChainBoundary.tsx @@ -101,11 +101,6 @@ export function ChainBoundary(props: ChainBoundaryPro if (!expectedChainAllowed) return - if (isPluginIDMatched || actualProviderType === ProviderType.MaskWallet) { - await expectedConnection.connect({ chainId: expectedChainId }) - return - } - if (!isPluginIDMatched || actualProviderType === ProviderType.WalletConnect) { openSelectProviderDialog() return