Skip to content

Commit

Permalink
Cache token symbol names (#243)
Browse files Browse the repository at this point in the history
* Cache token symbol names

* fmt

* fmt

* lint
  • Loading branch information
brittcyr authored Oct 31, 2024
1 parent a9a858e commit 332c100
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions debug-ui/lib/address-labels.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Connection, PublicKey } from '@solana/web3.js';
import { Metaplex } from '@metaplex-foundation/js';
import { TOKEN_2022_PROGRAM_ID } from '@solana/spl-token';
import { ENV, TokenInfo, TokenListProvider } from '@solana/spl-token-registry';
import { Market } from '@cks-systems/manifest-sdk';
import { LabelsByAddr } from './types';
Expand Down Expand Up @@ -37,19 +36,6 @@ export const getTokenSymbol = async (
return tokenSymbol || shortenPub(mintPub);
};

export const checkForBase22 = async (
conn: Connection,
mint: PublicKey,
): Promise<boolean> => {
const acc = await conn.getAccountInfo(mint);
if (!acc) {
throw new Error('checkForBase22: account does not exist');
}

return acc.owner === TOKEN_2022_PROGRAM_ID;
};

// TODO: find a way to cache this between reloads or some other way to prevent rate limiting...
export const fetchAndSetMfxAddrLabels = async (
conn: Connection,
marketAddrs: Array<string>,
Expand All @@ -73,9 +59,13 @@ export const fetchAndSetMfxAddrLabels = async (
await Promise.all(
Array.from(mints.values()).map(async (m) => {
try {
const symbol = await getTokenSymbol(conn, new PublicKey(m));

mintLabels[m] = symbol;
if (localStorage.getItem(m)) {
mintLabels[m] = localStorage.getItem(m)!;
} else {
const symbol = await getTokenSymbol(conn, new PublicKey(m));
mintLabels[m] = symbol;
localStorage.setItem(m, symbol);
}
} catch (e) {
console.error('getTokenSymbol:', e);
}
Expand Down

0 comments on commit 332c100

Please sign in to comment.