From ce3fc962d67dad1da897d1cebaaea4b15eea2830 Mon Sep 17 00:00:00 2001 From: hueso Date: Thu, 18 Jul 2024 19:23:09 -0300 Subject: [PATCH] fix chain detection --- src/blockchain/addresses.ts | 2 +- src/blockchain/wallet.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/blockchain/addresses.ts b/src/blockchain/addresses.ts index ef486b5..661b267 100644 --- a/src/blockchain/addresses.ts +++ b/src/blockchain/addresses.ts @@ -48,7 +48,7 @@ const network2Chain: { [key: string]: string } = { }; const isPossibleNetwork = (networkChain: string): boolean => { - if (Object.keys(possibleChains).includes(networkChain)) { + if (Object.keys(possibleChains).includes(networkChain.toString())) { return true; } return false; diff --git a/src/blockchain/wallet.ts b/src/blockchain/wallet.ts index d29afb9..7a9fdb4 100644 --- a/src/blockchain/wallet.ts +++ b/src/blockchain/wallet.ts @@ -1,7 +1,7 @@ import { useEtherStore } from "@/store/ether"; import { getContract, getProvider } from "./provider"; -import { getTokenAddress, possibleChains } from "./addresses"; +import { getTokenAddress, possibleChains, isPossibleNetwork } from "./addresses"; import mockToken from "@/utils/smart_contract_files/MockToken.json"; @@ -21,6 +21,10 @@ const updateWalletStatus = async (): Promise => { const signer = provider.getSigner(); const { chainId } = await provider.getNetwork(); + if(!isPossibleNetwork(chainId.toString())){ + window.alert("Invalid chain!:"+chainId); + return; + } etherStore.setNetworkName(possibleChains[chainId]); const mockTokenContract = new ethers.Contract(