Skip to content

Commit 06cfdcf

Browse files
committed
fix: catch errors at Solflare's api to render layout properly
1 parent 449ba08 commit 06cfdcf

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

app/utils/token-info.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,10 @@ function getChainId(cluster: Cluster): ChainId | undefined {
4949
function makeUtlClient(cluster: Cluster, connectionString: string): Client | undefined {
5050
const chainId = getChainId(cluster);
5151
if (!chainId) return undefined;
52-
5352
const config: UtlConfig = new UtlConfig({
5453
chainId,
5554
connection: new Connection(connectionString),
5655
});
57-
5856
return new Client(config);
5957
}
6058

@@ -67,9 +65,17 @@ export async function getTokenInfo(
6765
cluster: Cluster,
6866
connectionString: string
6967
): Promise<Token | undefined> {
68+
7069
const client = makeUtlClient(cluster, connectionString);
7170
if (!client) return undefined;
72-
const token = await client.fetchMint(address);
71+
72+
let token;
73+
try {
74+
token = await client.fetchMint(address);
75+
} catch (error){
76+
console.error(error);
77+
}
78+
7379
return token;
7480
}
7581

@@ -110,12 +116,14 @@ async function getFullLegacyTokenInfoUsingCdn(
110116
const tokenListResponse = await fetch(
111117
'https://cdn.jsdelivr.net/gh/solana-labs/token-list@latest/src/tokens/solana.tokenlist.json'
112118
);
119+
113120
if (tokenListResponse.status >= 400) {
114121
console.error(new Error('Error fetching token list from CDN'));
115122
return undefined;
116123
}
117124
const { tokens } = (await tokenListResponse.json()) as FullLegacyTokenInfoList;
118125
const tokenInfo = tokens.find(t => t.address === address.toString() && t.chainId === chainId);
126+
119127
return tokenInfo;
120128
}
121129

@@ -131,6 +139,7 @@ export async function getFullTokenInfo(
131139
connectionString: string
132140
): Promise<FullTokenInfo | undefined> {
133141
const chainId = getChainId(cluster);
142+
134143
if (!chainId) return undefined;
135144

136145
const [legacyCdnTokenInfo, sdkTokenInfo] = await Promise.all([
@@ -146,7 +155,6 @@ export async function getFullTokenInfo(
146155
}
147156
: undefined;
148157
}
149-
150158
// Merge the fields, prioritising the sdk ones which are more up to date
151159
let tags: string[] = [];
152160
if (sdkTokenInfo.tags) tags = Array.from(sdkTokenInfo.tags);

0 commit comments

Comments
 (0)