From eadfba4cab0b89f16906c3b6dedd93242db5f1cf Mon Sep 17 00:00:00 2001 From: Ryan Goree Date: Fri, 30 Aug 2024 01:05:42 -0500 Subject: [PATCH] Fix `useAppConfig` (#1431) --- .../src/chains/isMainnetChain.ts | 11 +++++++++++ .../src/ui/appconfig/useAppConfig.ts | 16 ++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 apps/hyperdrive-trading/src/chains/isMainnetChain.ts diff --git a/apps/hyperdrive-trading/src/chains/isMainnetChain.ts b/apps/hyperdrive-trading/src/chains/isMainnetChain.ts new file mode 100644 index 000000000..b7b431b9e --- /dev/null +++ b/apps/hyperdrive-trading/src/chains/isMainnetChain.ts @@ -0,0 +1,11 @@ +import { gnosis, mainnet } from "viem/chains"; + +/** + * Checks if the given chain ID corresponds to a mainnet chain. + * @param chainId - The chain ID to check. + * @returns True if the chain ID corresponds to a mainnet chain, false otherwise. + */ +export function isMainnetChain(chainId: number): boolean { + const mainnetChainIds: number[] = [mainnet.id, gnosis.id]; + return mainnetChainIds.includes(chainId); +} diff --git a/apps/hyperdrive-trading/src/ui/appconfig/useAppConfig.ts b/apps/hyperdrive-trading/src/ui/appconfig/useAppConfig.ts index 67f4a0f9a..e5a1b4ff1 100644 --- a/apps/hyperdrive-trading/src/ui/appconfig/useAppConfig.ts +++ b/apps/hyperdrive-trading/src/ui/appconfig/useAppConfig.ts @@ -1,6 +1,6 @@ import { AppConfig, appConfig } from "@hyperdrive/appconfig"; import { useMemo } from "react"; -import { isTestnetChain } from "src/chains/isTestnetChain"; +import { isMainnetChain } from "src/chains/isMainnetChain"; import { useChainId } from "wagmi"; export function useAppConfig(): AppConfig { @@ -24,24 +24,24 @@ export function useAppConfig(): AppConfig { // registries for (const [chainIdString, registry] of Object.entries(registries)) { const chainId = +chainIdString; - if (isTestnetChain(chainId)) { - testnetConfig.registries[chainId] = registry; - } else { + if (isMainnetChain(chainId)) { mainnetConfig.registries[chainId] = registry; + } else { + testnetConfig.registries[chainId] = registry; } } // hyperdrives for (const hyperdrive of hyperdrives) { - if (isTestnetChain(hyperdrive.chainId)) { - testnetConfig.hyperdrives.push(hyperdrive); - } else { + if (isMainnetChain(hyperdrive.chainId)) { mainnetConfig.hyperdrives.push(hyperdrive); + } else { + testnetConfig.hyperdrives.push(hyperdrive); } } return { testnetConfig, mainnetConfig }; }, []); - return isTestnetChain(chainId) ? testnetConfig : mainnetConfig; + return isMainnetChain(chainId) ? mainnetConfig : testnetConfig; }