Files
js/@3rdweb-sdk/react/hooks/useActiveChainId.ts
T
Jonas DanielsandNacho Iacovino 688dc80043 lots of changes to handle new routing (#310)
* lots of changes to handle new routing

* handle some redirect cases

* remove unused stuff

Co-authored-by: Nacho Iacovino <[email protected]>
2022-08-01 09:57:40 -07:00

19 lines
604 B
TypeScript

import { SUPPORTED_CHAIN_ID } from "@thirdweb-dev/sdk";
import { useSingleQueryParam } from "hooks/useQueryParam";
import {
SupportedNetwork,
getChainIdFromNetwork,
getNetworkFromChainId,
} from "utils/network";
export function useActiveChainId(): SUPPORTED_CHAIN_ID | undefined {
const networkFromUrl =
useSingleQueryParam<SupportedNetwork>("networkOrAddress");
return getChainIdFromNetwork(networkFromUrl);
}
export function useActiveNetwork(): SupportedNetwork | undefined {
const activeChainId = useActiveChainId();
return activeChainId && getNetworkFromChainId(activeChainId);
}