File tree Expand file tree Collapse file tree 5 files changed +29
-3
lines changed Expand file tree Collapse file tree 5 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @macalinao/gill-extra " : patch
3+ " @macalinao/grill " : patch
4+ ---
5+
6+ Allow opting out of the certified token list for unknown token metadata
Original file line number Diff line number Diff line change @@ -8,6 +8,11 @@ import { tokenMetadataSchema } from "@macalinao/zod-solana";
88export 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 {
1823export 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 ) ;
Original file line number Diff line number Diff 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/**
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ export interface UseTokenInfoInput {
2323export 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 :
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments