Skip to content

Commit

Permalink
removed chainAttributes from allowedChainIds
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobHomanics committed Dec 7, 2024
1 parent 76a5472 commit f71717f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useTheme } from "next-themes";
import { useAccount, useSwitchChain } from "wagmi";
import { ArrowsRightLeftIcon } from "@heroicons/react/24/solid";
import { getNetworkColor } from "~~/hooks/scaffold-eth";
import { AllowedChainIds, getTargetNetworks } from "~~/utils/scaffold-eth";
import { getTargetNetworks } from "~~/utils/scaffold-eth";

const allowedNetworks = getTargetNetworks();

Expand Down Expand Up @@ -34,7 +34,7 @@ export const NetworkOptions = ({ hidden = false }: NetworkOptionsProps) => {
Switch to{" "}
<span
style={{
color: getNetworkColor(allowedNetwork.id as AllowedChainIds, isDarkMode),
color: getNetworkColor(allowedNetwork, isDarkMode),
}}
>
{allowedNetwork.name}
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/hooks/scaffold-eth/useAllowedChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scaffoldConfig from "~~/scaffold.config";
import { useGlobalState } from "~~/services/store/store";
import { AllowedChainIds } from "~~/utils/scaffold-eth";

export function useAllowedChain(chainId: AllowedChainIds) {
export function useAllowedChain(chainId?: AllowedChainIds) {
const targetNetwork = useGlobalState(({ targetNetwork }) => targetNetwork);
return scaffoldConfig.targetNetworks.find(targetNetwork => targetNetwork.id === chainId) ?? targetNetwork;
}
8 changes: 5 additions & 3 deletions packages/nextjs/hooks/scaffold-eth/useNetworkColor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useAllowedChain } from "./useAllowedChain";
import { useTargetNetwork } from "./useTargetNetwork";
import { useTheme } from "next-themes";
import { AllowedChainIds } from "~~/utils/scaffold-eth";
import { AllowedChainIds, ChainWithAttributes } from "~~/utils/scaffold-eth";

export const DEFAULT_NETWORK_COLOR: [string, string] = ["#666666", "#bbbbbb"];

export function getNetworkColor(network: AllowedChainIds, isDarkMode: boolean) {
export function getNetworkColor(network: ChainWithAttributes, isDarkMode: boolean) {
const colorConfig = network.color ?? DEFAULT_NETWORK_COLOR;
return Array.isArray(colorConfig) ? (isDarkMode ? colorConfig[1] : colorConfig[0]) : colorConfig;
}
Expand All @@ -16,7 +17,8 @@ export const useNetworkColor = (chainId?: AllowedChainIds) => {
const { resolvedTheme } = useTheme();
const { targetNetwork } = useTargetNetwork();

const chain = useAllowedChain(chainId);
const isDarkMode = resolvedTheme === "dark";

return getNetworkColor(chainId ? chainId : (targetNetwork.id as AllowedChainIds), isDarkMode);
return getNetworkColor(chain ? chain : targetNetwork, isDarkMode);
};
2 changes: 1 addition & 1 deletion packages/nextjs/utils/scaffold-eth/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type ChainAttributes = {

export type ChainWithAttributes = chains.Chain & Partial<ChainAttributes>;
export type TargetNetworks = typeof scaffoldConfig.targetNetworks;
export type AllowedChainIds = TargetNetworks[number]["id"] & Partial<ChainAttributes>;
export type AllowedChainIds = TargetNetworks[number]["id"];

// export type ConfiguredChains = (typeof scaffoldConfig)["targetNetworks"];

Expand Down

0 comments on commit f71717f

Please sign in to comment.