Skip to content

Commit

Permalink
[ts] Simplify fetch to one request (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 authored Apr 16, 2024
1 parent f1cbb3a commit e9a3105
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
6 changes: 6 additions & 0 deletions npm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @penumbra-labs/registry

## 1.1.0

### Minor Changes

- Simplify registry to one fetch

## 1.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@penumbra-labs/registry",
"version": "1.0.0",
"version": "1.1.0",
"description": "Chain and asset registry for Penumbra",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
18 changes: 2 additions & 16 deletions npm/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface GithubContentsRes {
};
}

const REGISTRY_URL = 'https://api.github.com/repos/prax-wallet/registry';
const REGISTRY_BASE_URL = 'https://raw.githubusercontent.com/prax-wallet/registry/main/registry';

type ChainId = string;

Expand All @@ -26,15 +26,7 @@ export class GithubFetcher {

async fetchRegistryData(chainId: ChainId): Promise<Registry> {
if (this.cache[chainId]) return this.cache[chainId]!;

const chains = await this.typedFetcher<GithubContentsRes[]>(
`${REGISTRY_URL}/contents/registry`,
);

const match = chains.find(res => this.matchesChain(res, chainId));
if (!match) throw new Error(`Could not find registry for ${chainId}`);

return await this.typedFetcher<Registry>(match.download_url);
return this.typedFetcher<Registry>(`${REGISTRY_BASE_URL}/${chainId}.json`);
}

clearCache(): void {
Expand All @@ -48,10 +40,4 @@ export class GithubFetcher {
}
return (await response.json()) as T;
}

private matchesChain({ name }: GithubContentsRes, chain: ChainId): boolean {
if (!name.endsWith('.json')) return false;
const withoutExt = name.replace('.json', '');
return chain === withoutExt;
}
}

0 comments on commit e9a3105

Please sign in to comment.