Skip to content

Commit

Permalink
Revert "Add addNetwork feature"
Browse files Browse the repository at this point in the history
This reverts commit 56ddbb4.
  • Loading branch information
barebind committed Feb 7, 2024
1 parent 44fd6f2 commit 2ca168c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 28 deletions.
6 changes: 0 additions & 6 deletions static/scripts/rewards/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ export const networkNames = {
[NetworkIds.Gnosis]: "Gnosis Chain",
};

export const networkCurrencies: Record<number, object> = {
[NetworkIds.Mainnet]: { symbol: "ETH", decimals: 18 },
[NetworkIds.Goerli]: { symbol: "GoerliETH", decimals: 18 },
[NetworkIds.Gnosis]: { symbol: "XDAI", decimals: 18 },
};

export function getNetworkName(networkId?: number) {
const networkName = networkNames[networkId as keyof typeof networkNames];
if (!networkName) {
Expand Down
23 changes: 1 addition & 22 deletions static/scripts/rewards/web3/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from "ethers";
import { claimButton, loadingClaimButton, resetClaimButton, toaster } from "../toaster";
import { getNetworkName, networkCurrencies, networkExplorers, networkRpcs } from "../constants";
import { getNetworkName } from "../constants";
import invalidateButton from "../invalidate-component";
import { JsonRpcSigner } from "@ethersproject/providers";

Expand Down Expand Up @@ -70,27 +70,6 @@ export async function switchNetwork(provider: ethers.providers.Web3Provider, net
try {
await provider.send("wallet_switchEthereumChain", [{ chainId: "0x" + networkId.toString(16) }]);
return true;
} catch (error: any) {
// Add network if it doesn't exist.
if (error.code == 4902) {
return await addNetwork(provider, networkId);
}
return false;
}
}

export async function addNetwork(provider: ethers.providers.Web3Provider, networkId: number): Promise<boolean> {
try {
await provider.send("wallet_addEthereumChain", [
{
chainId: "0x" + networkId.toString(16),
chainName: getNetworkName(networkId),
rpcUrls: networkRpcs[networkId],
blockExplorerUrls: [networkExplorers[networkId]],
nativeCurrency: networkCurrencies[networkId],
},
]);
return true;
} catch (error: any) {
return false;
}
Expand Down

0 comments on commit 2ca168c

Please sign in to comment.