diff --git a/.changeset/loose-steaks-heal.md b/.changeset/loose-steaks-heal.md new file mode 100644 index 0000000..58095ae --- /dev/null +++ b/.changeset/loose-steaks-heal.md @@ -0,0 +1,6 @@ +--- +"@macalinao/gill-extra": patch +"@macalinao/grill": patch +--- + +Allow opting out of the certified token list for unknown token metadata diff --git a/packages/gill-extra/src/fetch-token-info.ts b/packages/gill-extra/src/fetch-token-info.ts index 4cdc2e9..68f3e30 100644 --- a/packages/gill-extra/src/fetch-token-info.ts +++ b/packages/gill-extra/src/fetch-token-info.ts @@ -8,6 +8,11 @@ import { tokenMetadataSchema } from "@macalinao/zod-solana"; export interface FetchTokenInfoParams { mint: AccountInfo>; metadata: Metadata | null; + /** + * Whether to fetch from the certified token list as a fallback. + * Defaults to true for backwards compatibility. + */ + fetchFromCertifiedTokenList?: boolean; } /** @@ -18,6 +23,7 @@ export interface FetchTokenInfoParams { export async function fetchTokenInfo({ mint, metadata, + fetchFromCertifiedTokenList = true, }: FetchTokenInfoParams): Promise { const uri = metadata?.data.uri; const decimals = mint.data.decimals; @@ -74,8 +80,8 @@ export async function fetchTokenInfo({ metadataUriJson, }); - // Fallback: Try to fetch from certified token list if no icon URL - if (!tokenInfo.iconURL) { + // Fallback: Try to fetch from certified token list if no icon URL and enabled + if (fetchFromCertifiedTokenList && !tokenInfo.iconURL) { const certifiedTokenInfoUrl = `https://raw.githubusercontent.com/CLBExchange/certified-token-list/refs/heads/master/101/${mint.address}.json`; try { const response = await fetch(certifiedTokenInfoUrl); diff --git a/packages/grill/src/contexts/grill-context.ts b/packages/grill/src/contexts/grill-context.ts index 706de7d..f8bf5c7 100644 --- a/packages/grill/src/contexts/grill-context.ts +++ b/packages/grill/src/contexts/grill-context.ts @@ -36,6 +36,12 @@ export interface GrillContextValue { * This overrides whatever is on-chain, and useTokenInfo will load it instantly. */ staticTokenInfo: ReadonlyMap; + + /** + * Whether to fetch from the certified token list as a fallback. + * Defaults to true for backwards compatibility. + */ + fetchFromCertifiedTokenList: boolean; } /** diff --git a/packages/grill/src/hooks/use-token-info.ts b/packages/grill/src/hooks/use-token-info.ts index 90590a7..6e0360c 100644 --- a/packages/grill/src/hooks/use-token-info.ts +++ b/packages/grill/src/hooks/use-token-info.ts @@ -23,7 +23,7 @@ export interface UseTokenInfoInput { export function useTokenInfo({ mint, }: UseTokenInfoInput): UseQueryResult { - const { staticTokenInfo } = useGrillContext(); + const { staticTokenInfo, fetchFromCertifiedTokenList } = useGrillContext(); const { data: metadataAccount } = useTokenMetadataAccount({ mint }); const { data: mintAccount } = useMintAccount({ address: mint }); @@ -51,6 +51,7 @@ export function useTokenInfo({ return fetchTokenInfo({ mint: mintAccount, metadata: metadataAccount?.data ?? null, + fetchFromCertifiedTokenList, }); }, enabled: diff --git a/packages/grill/src/providers/grill-headless-provider.tsx b/packages/grill/src/providers/grill-headless-provider.tsx index 28b9249..8b26bbf 100644 --- a/packages/grill/src/providers/grill-headless-provider.tsx +++ b/packages/grill/src/providers/grill-headless-provider.tsx @@ -27,6 +27,11 @@ export interface GrillHeadlessProviderProps { * useTokenInfo will load these instantly without fetching from chain. */ staticTokenInfo?: TokenInfo[]; + /** + * Whether to fetch from the certified token list as a fallback when token metadata is missing. + * Defaults to true for backwards compatibility. + */ + fetchFromCertifiedTokenList?: boolean; } /** @@ -45,6 +50,7 @@ export const GrillHeadlessProvider: FC = ({ }, getExplorerLink = defaultGetExplorerLink, staticTokenInfo = [], + fetchFromCertifiedTokenList = true, }) => { const { rpc } = useSolanaClient(); const queryClient = useQueryClient(); @@ -96,6 +102,7 @@ export const GrillHeadlessProvider: FC = ({ sendTX, getExplorerLink, staticTokenInfo: staticTokenInfoMap, + fetchFromCertifiedTokenList, }} > {children}