Skip to content

Commit

Permalink
Fix useAppConfig (#1431)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangoree authored Aug 30, 2024
1 parent 4e841fc commit eadfba4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 11 additions & 0 deletions apps/hyperdrive-trading/src/chains/isMainnetChain.ts
Original file line number Diff line number Diff line change
@@ -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);
}
16 changes: 8 additions & 8 deletions apps/hyperdrive-trading/src/ui/appconfig/useAppConfig.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
}

0 comments on commit eadfba4

Please sign in to comment.