Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update enforce netork function signature #240

Merged
merged 1 commit into from
Dec 11, 2023
Merged
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
9 changes: 5 additions & 4 deletions src/core/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,20 @@ async function _networkSwitch(

export async function enforceNetwork(
chainId: bigint,
walletClient: WalletClient,
walletClient: any,
switchNetwork: (chainId: number | undefined) => Promise<Chain | undefined>,
skaleNetwork: SkaleNetwork,
chainName: string
): Promise<bigint> {
const currentChainId = await walletClient.getChainId()
const _walletClient = walletClient as WalletClient
const currentChainId = await _walletClient.getChainId()
log(
`Current chainId: ${currentChainId}, required chainId: ${chainId}, required network: ${chainName} `
)
if (currentChainId !== Number(chainId)) {
log(`Switching network to ${chainId}...`)
if (chainId !== 1n && chainId !== 5n) {
await walletClient.addChain({ chain: constructWagmiChain(skaleNetwork, chainName) })
await _walletClient.addChain({ chain: constructWagmiChain(skaleNetwork, chainName) })
}
try {
// tmp fix for coinbase wallet
Expand All @@ -169,7 +170,7 @@ export async function enforceNetwork(
await sleep(DEFAULT_SLEEP)
_networkSwitch(chainId, currentChainId, switchNetwork)
}
await waitForNetworkChange(walletClient, currentChainId, chainId)
await waitForNetworkChange(_walletClient, currentChainId, chainId)
log(`Network switched to ${chainId}...`)
}
return chainId
Expand Down
Loading