From 5243b1913eec85e469e9d4b0ef23e10b1024a9d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ti=E1=BA=BFn=20Nguy=E1=BB=85n=20Kh=E1=BA=AFc?= Date: Thu, 8 Aug 2024 17:11:23 +1200 Subject: [PATCH] feat: hook for getting all configured chain IDs (#88) --- .changeset/witty-seals-punch.md | 5 +++++ packages/react/src/hooks/use-chain-id.ts | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/witty-seals-punch.md diff --git a/.changeset/witty-seals-punch.md b/.changeset/witty-seals-punch.md new file mode 100644 index 00000000..f371d9d5 --- /dev/null +++ b/.changeset/witty-seals-punch.md @@ -0,0 +1,5 @@ +--- +"@reactive-dot/react": minor +--- + +Add hook for getting all configured chain IDs. diff --git a/packages/react/src/hooks/use-chain-id.ts b/packages/react/src/hooks/use-chain-id.ts index db4aeace..f25267a1 100644 --- a/packages/react/src/hooks/use-chain-id.ts +++ b/packages/react/src/hooks/use-chain-id.ts @@ -1,13 +1,24 @@ import { ChainIdContext } from "../contexts/index.js"; +import { chainConfigsAtom } from "../stores/config.js"; import type { ChainHookOptions } from "./types.js"; import { type ChainId, ReDotError } from "@reactive-dot/core"; +import { useAtomValue } from "jotai"; import { useContext } from "react"; +/** + * Hook for getting all configured chain IDs. + * + * @returns All configured chain IDs + */ +export function useChainIds() { + return Object.keys(useAtomValue(chainConfigsAtom)) as ChainId[]; +} + /** * Hook for getting the current chain ID. * * @param options - Additional options - * @returns + * @returns The current chain ID */ export function useChainId< const TAllowList extends ChainId[],