Skip to content

Commit

Permalink
Update solana-program-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Woody4618 committed Dec 12, 2024
1 parent dd56f91 commit 2eca813
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
28 changes: 4 additions & 24 deletions app/providers/program-metadata.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
import { Connection, PublicKey } from '@solana/web3.js';
import { fetchProgramMetadata } from 'solana-program-metadata';
import { fetchProgramMetadata, ProgramMetaData } from 'solana-program-metadata';

const cachedLogoProgramPromises: Record<
string,
void | { __type: 'promise'; promise: Promise<void> } | { __type: 'result'; result: ProgramMetaData | null }
> = {};

interface ProgramMetaData {
name: string;
logo?: string;
description?: string;
notification?: string;
sdk?: string;
version?: string;
project_url?: string;
contacts?: string[];
policy?: string;
preferred_languages?: string[];
encryption?: string;
source_code?: string;
source_release?: string;
source_revision?: string;
auditors?: string[] | string;
acknowledgements?: string;
expiry?: string;
}

async function fetchProgramMetaData(programAddress: string, connection: Connection): Promise<ProgramMetaData | null> {
try {
const programMetadata = await fetchProgramMetadata(new PublicKey(programAddress), connection.rpcEndpoint);
Expand All @@ -40,14 +20,14 @@ function useProgramMetaData(programAddress: string, url: string): ProgramMetaDat
const key = `${programAddress}-${url}-logo`;
const cacheEntry = cachedLogoProgramPromises[key];

// If there's no cached entry, start fetching the IDL
// If there's no cached entry, start fetching the program metadata
if (cacheEntry === undefined) {
const connection = new Connection(url);
const promise = fetchProgramMetaData(programAddress, connection)
.then(idl => {
.then(programMetadata => {
cachedLogoProgramPromises[key] = {
__type: 'result',
result: idl,
result: programMetadata,
};
})
.catch(err => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@solana/web3.js": "^1.66.6",
"@solflare-wallet/utl-sdk": "^1.4.0",
"@types/bn.js": "5.1.0",
"solana-program-metadata": "^0.0.15",
"solana-program-metadata": "^0.0.17",
"axios": "^0.28.0",
"bignumber.js": "^9.0.2",
"bn.js": "5.2.1",
Expand Down

0 comments on commit 2eca813

Please sign in to comment.