Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.
Open
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
13 changes: 13 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -193,6 +194,11 @@ class App extends React.Component<any, any> {
}

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);
});

Expand Down Expand Up @@ -246,6 +252,13 @@ class App extends React.Component<any, any> {
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,
Expand Down
17 changes: 16 additions & 1 deletion src/helpers/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down