diff --git a/src/App.tsx b/src/App.tsx index 26a1942..a156b08 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -23,6 +23,7 @@ import { IAssetData } from "./helpers/types"; import Banner from "./components/Banner"; import AccountAssets from "./components/AccountAssets"; import { eip712 } from "./helpers/eip712"; +import {getChainData} from "./helpers/utilities" const SLayout = styled.div` position: relative; @@ -193,6 +194,11 @@ class App extends React.Component { } const { chainId, accounts } = payload.params[0]; + if (getChainData(chainId).name === "ChainId not Supported") { + this.killSession(); + await this.setState({ connected: false }); + alert("ChainId missing or not supported"); + } this.onSessionUpdate(accounts, chainId); }); @@ -246,6 +252,13 @@ class App extends React.Component { public onConnect = async (payload: IInternalEvent) => { const { chainId, accounts } = payload.params[0]; const address = accounts[0]; + const chainData = getChainData(chainId); + if (chainData.name === "ChainId not Supported") { + await this.setState({ connected: false }); + alert("ChainId missing or not supported"); + this.killSession(); + return; + } await this.setState({ connected: true, chainId, diff --git a/src/helpers/utilities.ts b/src/helpers/utilities.ts index 7b03b4c..3331835 100644 --- a/src/helpers/utilities.ts +++ b/src/helpers/utilities.ts @@ -105,7 +105,22 @@ export function getChainData(chainId: number): IChainData { const chainData = SUPPORTED_CHAINS.filter((chain: any) => chain.chain_id === chainId)[0]; if (!chainData) { - throw new Error("ChainId missing or not supported"); + console.log("ChainId missing or not supported"); + return { + name: "ChainId not Supported", + short_name: "UnSupported chainId", + chain: "", + network: "", + chain_id: chainId, + network_id: 0, + rpc_url: "", + native_currency: { + symbol: "", + name: "", + decimals: "", + contractAddress: "", + }, + }; } const API_KEY = process.env.REACT_APP_INFURA_PROJECT_ID;