Skip to content

Commit

Permalink
919: Fix switch network button showing instead of connect button
Browse files Browse the repository at this point in the history
  • Loading branch information
piersss committed Jun 12, 2024
1 parent d74a517 commit c33a108
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ const ActionButtons: FC<{
// First determine the next action.
let nextAction: ButtonActions;
// Note that wallet is not considered "active" if connected to wrong network
if (isNetworkUnsupported) nextAction = ButtonActions.switchNetwork;
else if (!walletIsActive) nextAction = ButtonActions.connectWallet;
if (!walletIsActive) nextAction = ButtonActions.connectWallet;
else if (isNetworkUnsupported) nextAction = ButtonActions.switchNetwork;
else if (hasError) nextAction = ButtonActions.goBack;
else if (requiresReload) nextAction = ButtonActions.reloadPage;
else if (hasQuote && needsApproval) nextAction = ButtonActions.approve;
Expand Down
5 changes: 4 additions & 1 deletion src/components/TransactionsTab/TransactionsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { formatUnits } from "ethers/lib/utils";
import { AnimatePresence, useReducedMotion } from "framer-motion";

import { useAppSelector } from "../../app/hooks";
import { supportedNetworks } from "../../constants/supportedNetworks";
import { SubmittedTransaction } from "../../entities/SubmittedTransaction/SubmittedTransaction";
import { getSubmittedTransactionKey } from "../../entities/SubmittedTransaction/SubmittedTransactionHelpers";
import { BalancesState } from "../../features/balances/balancesSlice";
Expand Down Expand Up @@ -179,7 +180,9 @@ const TransactionsTab = ({
<WalletHeader>
<NetworkInfoContainer>
<NetworkName>
{chainNames[chainId] || t("wallet.unsupported")}
{isActive &&
!supportedNetworks.includes(chainId) &&
t("wallet.unsupported")}
</NetworkName>
{isActive && (
<Balances>
Expand Down
10 changes: 0 additions & 10 deletions src/constants/supportedChains.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/constants/supportedNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export const supportedNetworks: number[] = [
ChainIds.BSC,
ChainIds.RSK,
];

export type SupportedNetwork = typeof supportedNetworks[number];
3 changes: 1 addition & 2 deletions src/helpers/ethers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TransactionReceipt, Web3Provider } from "@ethersproject/providers";

import { rpcUrls } from "../constants/rpc";
import { SupportedChain } from "../constants/supportedChains";

let cachedLibrary: Record<number, Web3Provider> = {};

Expand All @@ -20,7 +19,7 @@ export const clearedCachedLibrary = (): void => {
};

export const getRpcUrl = (chainId: number): string | undefined => {
const rpcUrl = rpcUrls[chainId as SupportedChain] as string;
const rpcUrl = rpcUrls[chainId];

if (!rpcUrl) {
console.error(
Expand Down
4 changes: 2 additions & 2 deletions src/web3-connectors/chainInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AddEthereumChainParameter } from "@web3-react/types";

import nativeCurrency from "../constants/nativeCurrency";
import { rpcUrls } from "../constants/rpc";
import { SupportedChain } from "../constants/supportedChains";
import { SupportedNetwork } from "../constants/supportedNetworks";

interface NativeCurrencyTokenInfo extends TokenInfo {
decimals: 18;
Expand All @@ -16,7 +16,7 @@ interface ChainInfo extends Partial<AddEthereumChainParameter> {
rpcUrl: string;
}

export const chainInfo: Record<SupportedChain, ChainInfo> = {
export const chainInfo: Record<SupportedNetwork, ChainInfo> = {
[ChainIds.MAINNET]: {
explorer: "https://etherscan.io/",
label: "Ethereum",
Expand Down
4 changes: 2 additions & 2 deletions src/web3-connectors/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AddEthereumChainParameter, Connector } from "@web3-react/types";

import { SupportedChain } from "../constants/supportedChains";
import { SupportedNetwork } from "../constants/supportedNetworks";
import { chainInfo } from "./chainInfo";
import { ConnectionType, getConnection } from "./connections";

Expand Down Expand Up @@ -32,7 +32,7 @@ export const switchNetwork = async (
return;
}

const info = chainInfo[chainId as SupportedChain];
const info = chainInfo[chainId as SupportedNetwork];
const addChainParameter: AddEthereumChainParameter = {
chainId,
chainName: info.nativeCurrency.name,
Expand Down

0 comments on commit c33a108

Please sign in to comment.