Files
js/@3rdweb-sdk/react/hooks/useSDK.ts
T
Jonas Daniels f81d732a8f various quick wins (#343)
* various quick wins

* fix more various things, unify table for functions, variables, events, etc

* input types table and markdown parsing for the fn comments

* attempt to fix the drawer behavior
2022-08-07 18:51:52 -07:00

28 lines
766 B
TypeScript

import { contractKeys, networkKeys } from "../cache-keys";
import { useQuery } from "@tanstack/react-query";
import { useReadonlySDK } from "@thirdweb-dev/react";
import { SUPPORTED_CHAIN_ID } from "@thirdweb-dev/sdk";
import {
StorageSingleton,
alchemyUrlMap,
} from "components/app-layouts/providers";
export function useContractList(
chainId: SUPPORTED_CHAIN_ID,
walletAddress?: string,
) {
const sdk = useReadonlySDK(
alchemyUrlMap[chainId],
undefined,
StorageSingleton,
);
return useQuery(
[...networkKeys.chain(chainId), ...contractKeys.list(walletAddress)],
async () =>
[...((await sdk?.getContractList(walletAddress || "")) || [])].reverse(),
{
enabled: !!sdk && !!walletAddress && !!chainId,
},
);
}