Skip to content

Commit 377a4a6

Browse files
macalinaoclaude
andcommitted
Add fetchFromCertifiedTokenList option to GrillHeadlessProvider
Adds a new optional parameter to control whether token info fetching should fall back to the certified-token-list. This allows users to disable the external API call if they don't want to use the certified token list. - Add fetchFromCertifiedTokenList option to fetchTokenInfo (defaults to true) - Add fetchFromCertifiedTokenList prop to GrillHeadlessProvider - Pass option through GrillContext to useTokenInfo hook - Maintains backwards compatibility with default value of true 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 9dd7b9a commit 377a4a6

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

packages/gill-extra/src/fetch-token-info.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import { tokenMetadataSchema } from "@macalinao/zod-solana";
88
export interface FetchTokenInfoParams {
99
mint: AccountInfo<Pick<Mint, "decimals">>;
1010
metadata: Metadata | null;
11+
/**
12+
* Whether to fetch from the certified token list as a fallback.
13+
* Defaults to true for backwards compatibility.
14+
*/
15+
fetchFromCertifiedTokenList?: boolean;
1116
}
1217

1318
/**
@@ -18,6 +23,7 @@ export interface FetchTokenInfoParams {
1823
export async function fetchTokenInfo({
1924
mint,
2025
metadata,
26+
fetchFromCertifiedTokenList = true,
2127
}: FetchTokenInfoParams): Promise<TokenInfo | null> {
2228
const uri = metadata?.data.uri;
2329
const decimals = mint.data.decimals;
@@ -74,8 +80,8 @@ export async function fetchTokenInfo({
7480
metadataUriJson,
7581
});
7682

77-
// Fallback: Try to fetch from certified token list if no icon URL
78-
if (!tokenInfo.iconURL) {
83+
// Fallback: Try to fetch from certified token list if no icon URL and enabled
84+
if (fetchFromCertifiedTokenList && !tokenInfo.iconURL) {
7985
const certifiedTokenInfoUrl = `https://raw.githubusercontent.com/CLBExchange/certified-token-list/refs/heads/master/101/${mint.address}.json`;
8086
try {
8187
const response = await fetch(certifiedTokenInfoUrl);

packages/grill/src/contexts/grill-context.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ export interface GrillContextValue {
3636
* This overrides whatever is on-chain, and useTokenInfo will load it instantly.
3737
*/
3838
staticTokenInfo: ReadonlyMap<Address, TokenInfo>;
39+
40+
/**
41+
* Whether to fetch from the certified token list as a fallback.
42+
* Defaults to true for backwards compatibility.
43+
*/
44+
fetchFromCertifiedTokenList: boolean;
3945
}
4046

4147
/**

packages/grill/src/hooks/use-token-info.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface UseTokenInfoInput {
2323
export function useTokenInfo({
2424
mint,
2525
}: UseTokenInfoInput): UseQueryResult<TokenInfo | null> {
26-
const { staticTokenInfo } = useGrillContext();
26+
const { staticTokenInfo, fetchFromCertifiedTokenList } = useGrillContext();
2727
const { data: metadataAccount } = useTokenMetadataAccount({ mint });
2828
const { data: mintAccount } = useMintAccount({ address: mint });
2929

@@ -51,6 +51,7 @@ export function useTokenInfo({
5151
return fetchTokenInfo({
5252
mint: mintAccount,
5353
metadata: metadataAccount?.data ?? null,
54+
fetchFromCertifiedTokenList,
5455
});
5556
},
5657
enabled:

packages/grill/src/providers/grill-headless-provider.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export interface GrillHeadlessProviderProps {
2727
* useTokenInfo will load these instantly without fetching from chain.
2828
*/
2929
staticTokenInfo?: TokenInfo[];
30+
/**
31+
* Whether to fetch from the certified token list as a fallback when token metadata is missing.
32+
* Defaults to true for backwards compatibility.
33+
*/
34+
fetchFromCertifiedTokenList?: boolean;
3035
}
3136

3237
/**
@@ -45,6 +50,7 @@ export const GrillHeadlessProvider: FC<GrillHeadlessProviderProps> = ({
4550
},
4651
getExplorerLink = defaultGetExplorerLink,
4752
staticTokenInfo = [],
53+
fetchFromCertifiedTokenList = true,
4854
}) => {
4955
const { rpc } = useSolanaClient();
5056
const queryClient = useQueryClient();
@@ -96,6 +102,7 @@ export const GrillHeadlessProvider: FC<GrillHeadlessProviderProps> = ({
96102
sendTX,
97103
getExplorerLink,
98104
staticTokenInfo: staticTokenInfoMap,
105+
fetchFromCertifiedTokenList,
99106
}}
100107
>
101108
{children}

0 commit comments

Comments
 (0)