Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/loose-steaks-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@macalinao/gill-extra": patch
"@macalinao/grill": patch
---

Allow opting out of the certified token list for unknown token metadata
10 changes: 8 additions & 2 deletions packages/gill-extra/src/fetch-token-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { tokenMetadataSchema } from "@macalinao/zod-solana";
export interface FetchTokenInfoParams {
mint: AccountInfo<Pick<Mint, "decimals">>;
metadata: Metadata | null;
/**
* Whether to fetch from the certified token list as a fallback.
* Defaults to true for backwards compatibility.
*/
fetchFromCertifiedTokenList?: boolean;
}

/**
Expand All @@ -18,6 +23,7 @@ export interface FetchTokenInfoParams {
export async function fetchTokenInfo({
mint,
metadata,
fetchFromCertifiedTokenList = true,
}: FetchTokenInfoParams): Promise<TokenInfo | null> {
const uri = metadata?.data.uri;
const decimals = mint.data.decimals;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions packages/grill/src/contexts/grill-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export interface GrillContextValue {
* This overrides whatever is on-chain, and useTokenInfo will load it instantly.
*/
staticTokenInfo: ReadonlyMap<Address, TokenInfo>;

/**
* Whether to fetch from the certified token list as a fallback.
* Defaults to true for backwards compatibility.
*/
fetchFromCertifiedTokenList: boolean;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/grill/src/hooks/use-token-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface UseTokenInfoInput {
export function useTokenInfo({
mint,
}: UseTokenInfoInput): UseQueryResult<TokenInfo | null> {
const { staticTokenInfo } = useGrillContext();
const { staticTokenInfo, fetchFromCertifiedTokenList } = useGrillContext();
const { data: metadataAccount } = useTokenMetadataAccount({ mint });
const { data: mintAccount } = useMintAccount({ address: mint });

Expand Down Expand Up @@ -51,6 +51,7 @@ export function useTokenInfo({
return fetchTokenInfo({
mint: mintAccount,
metadata: metadataAccount?.data ?? null,
fetchFromCertifiedTokenList,
});
},
enabled:
Expand Down
7 changes: 7 additions & 0 deletions packages/grill/src/providers/grill-headless-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -45,6 +50,7 @@ export const GrillHeadlessProvider: FC<GrillHeadlessProviderProps> = ({
},
getExplorerLink = defaultGetExplorerLink,
staticTokenInfo = [],
fetchFromCertifiedTokenList = true,
}) => {
const { rpc } = useSolanaClient();
const queryClient = useQueryClient();
Expand Down Expand Up @@ -96,6 +102,7 @@ export const GrillHeadlessProvider: FC<GrillHeadlessProviderProps> = ({
sendTX,
getExplorerLink,
staticTokenInfo: staticTokenInfoMap,
fetchFromCertifiedTokenList,
}}
>
{children}
Expand Down