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
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Suspense, useMemo } from 'react'
import { Plugin, usePostInfoDetails } from '@masknet/plugin-infra'
import { extractTextFromTypedMessage, parseURL } from '@masknet/shared'
import { ChainId } from '@masknet/web3-shared'
import { SnackbarContent } from '@material-ui/core'
import { base } from '../base'
import MaskbookPluginWrapper from '../../MaskbookPluginWrapper'
import { DepositDialog } from '../UI/DepositDialog'
import { URL_PATTERN } from '../constants'
import { PoolTogetherView } from '../UI/PoolTogetherView'
import { EthereumChainBoundary } from '../../../web3/UI/EthereumChainBoundary'

const isPoolTogetherUrl = (url: string) => URL_PATTERN.test(url)

Expand Down Expand Up @@ -44,7 +46,11 @@ function Renderer(props: React.PropsWithChildren<{ url: string }>) {
return (
<MaskbookPluginWrapper pluginName="PoolTogether">
<Suspense fallback={<SnackbarContent message="Mask is loading this plugin..." />}>
<PoolTogetherView />
<EthereumChainBoundary
chainId={ChainId.Mainnet}
isValidChainId={(chainId) => [ChainId.Mainnet, ChainId.Matic].includes(chainId)}>
Comment thread
guanbinrui marked this conversation as resolved.
<PoolTogetherView />
</EthereumChainBoundary>
</Suspense>
</MaskbookPluginWrapper>
)
Expand Down
14 changes: 10 additions & 4 deletions packages/maskbook/src/web3/UI/EthereumChainBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { WalletRPC } from '../../plugins/Wallet/messages'
export interface EthereumChainBoundaryProps {
chainId: ChainId
children?: React.ReactNode
isValidChainId?: (actualChainId: ChainId, expectedChainId: ChainId) => boolean
}

export function EthereumChainBoundary(props: EthereumChainBoundaryProps) {
Expand All @@ -31,8 +32,8 @@ export function EthereumChainBoundary(props: EthereumChainBoundaryProps) {

const expectedChainId = props.chainId
const expectedNetwork = getChainName(expectedChainId)
const acutalChainId = chainId
const actualNetwork = getChainName(acutalChainId)
const actualChainId = chainId
const actualNetwork = getChainName(actualChainId)

// if false then it will not guide the user to switch the network
const isAllowed = isChainIdValid(expectedChainId) && !!account
Expand Down Expand Up @@ -62,8 +63,13 @@ export function EthereumChainBoundary(props: EthereumChainBoundaryProps) {
else await Services.Ethereum.addEthereumChain(chainDetailedCAIP, account)
}, [account, isAllowed, providerType, expectedChainId])

// matched
if (acutalChainId === expectedChainId) return <>{props.children}</>
// is the actual chain id matched with the expected one?
const isMatched = actualChainId === expectedChainId

// is the actual chain id a valid one even if it does not match with the expected one?
const isValid = props?.isValidChainId?.(actualChainId, expectedChainId) ?? false

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

if (!isAllowed)
return (
Expand Down