Skip to content

Commit

Permalink
Merge pull request #240 from skalenetwork/add-send-tx-func
Browse files Browse the repository at this point in the history
Update enforce netork function signature
  • Loading branch information
dmytrotkk authored Dec 11, 2023
2 parents 61f2f53 + 4e47f41 commit 0b3b88a
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit 0b3b88a

Please sign in to comment.