From e930d2711b13addb951588ceac069c0c30be385f Mon Sep 17 00:00:00 2001 From: Gabe Rodriguez Date: Tue, 16 Apr 2024 23:09:51 +0200 Subject: [PATCH] [ts] Simplify fetch to one request --- npm/CHANGELOG.md | 6 ++++++ npm/package.json | 2 +- npm/src/github.ts | 18 ++---------------- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/npm/CHANGELOG.md b/npm/CHANGELOG.md index f369799..d9952eb 100644 --- a/npm/CHANGELOG.md +++ b/npm/CHANGELOG.md @@ -1,5 +1,11 @@ # @penumbra-labs/registry +## 1.1.0 + +### Minor Changes + +- Simplify registry to one fetch + ## 1.0.0 ### Major Changes diff --git a/npm/package.json b/npm/package.json index 87a1b6f..3d6e666 100644 --- a/npm/package.json +++ b/npm/package.json @@ -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", diff --git a/npm/src/github.ts b/npm/src/github.ts index d80b3e4..e759461 100644 --- a/npm/src/github.ts +++ b/npm/src/github.ts @@ -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; @@ -26,15 +26,7 @@ export class GithubFetcher { async fetchRegistryData(chainId: ChainId): Promise { if (this.cache[chainId]) return this.cache[chainId]!; - - const chains = await this.typedFetcher( - `${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(match.download_url); + return this.typedFetcher(`${REGISTRY_BASE_URL}/${chainId}.json`); } clearCache(): void { @@ -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; - } }