Skip to content

Commit

Permalink
chore: Simplify load idls
Browse files Browse the repository at this point in the history
  • Loading branch information
CCristi committed Jun 13, 2024
1 parent ae01c5f commit d40c49e
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions packages/explorerkit-server/src/components/idls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,23 @@ export async function loadAllIdls(programIds: string[]): Promise<IdlsMap> {
if (res.status === "fulfilled" && res.value) {
const idl = deserializeIdl(res.value);

if (idl) {
idls.set(programId, new SolanaFMParser(idl, programId));
}
idls.set(programId, idl && new SolanaFMParser(idl, programId));

return undefined;
return;
}

return programId;
})
.filter(Boolean)
.map((id) => id!);

const missingIdls = await Promise.allSettled(programIdsWithMissingIdls.map((id) => getProgramIdl(id)));

await Promise.allSettled(
missingIdls.map(async (res, i) => {
if (res.status !== "fulfilled") {
return;
}
programIdsWithMissingIdls.map(async (programId) => {
const idl = await getProgramIdl(programId);

const programId = programIdsWithMissingIdls[i]!;
await cache.set(programId, serializeIdl(res.value), { EX: IDL_CACHE_TTL });
void cache.set(programId, serializeIdl(idl), { EX: IDL_CACHE_TTL });

idls.set(programId, res.value ? new SolanaFMParser(res.value, programId) : null);
idls.set(programId, idl && new SolanaFMParser(idl, programId));
})
);

Expand Down

0 comments on commit d40c49e

Please sign in to comment.