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
2 changes: 2 additions & 0 deletions packages/maskbook/src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions packages/maskbook/src/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "コレクションデータのソース",
Expand Down
2 changes: 2 additions & 0 deletions packages/maskbook/src/_locales/ko/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "수집품 데이터 소스",
Expand Down
2 changes: 2 additions & 0 deletions packages/maskbook/src/_locales/zh/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "收藏品資料來源",
Expand Down
13 changes: 4 additions & 9 deletions packages/maskbook/src/plugins/Wallet/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
30 changes: 26 additions & 4 deletions packages/maskbook/src/web3/UI/EthereumChainBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -87,6 +93,22 @@ export function EthereumChainBoundary(props: EthereumChainBoundaryProps) {

if (isMatched || isValid) return <>{props.children}</>

if (!account)
return (
<Box display="flex" flexDirection="column" alignItems="center" sx={{ paddingTop: 1, paddingBottom: 1 }}>
<Typography color="textPrimary">
<span>{t('plugin_wallet_connect_wallet_tip')}</span>
</Typography>
<ActionButton
variant="contained"
size="small"
sx={{ marginTop: 1.5 }}
onClick={openSelectProviderDialog}>
{t('plugin_wallet_connect_wallet')}
</ActionButton>
</Box>
)

if (!isAllowed)
return (
<Box display="flex" flexDirection="column" alignItems="center" sx={{ paddingTop: 1, paddingBottom: 1 }}>
Expand Down