Skip to content

Commit

Permalink
fix: ci (#121)
Browse files Browse the repository at this point in the history
* fix: ci

* feat: add sei chain

* refator: remove json

---------

Co-authored-by: Wukong Sun <[email protected]>
  • Loading branch information
guanbinrui and swkatmask authored Jun 6, 2024
1 parent 053b7ea commit 8e1fbc8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ The token lists for Mask Network.
| Polygon | 137 | [latest][link-polygon] | [token-list][viewer-polygon] |
| X Layer Testnet | 195 | [latest][link-xlayertestnet] | [token-list][viewer-xlayertestnet] |
| X Layer | 196 | [latest][link-xlayer] | [token-list][viewer-xlayer] |
| Sei | 1329 | [latest][link-sei] | [token-list][viewer-sei] |
| Mumbai | 80001 | [latest][link-mumbai] | [token-list][viewer-mumbai] |
| Stardust | 588 | [latest][link-stardust] | [token-list][viewer-stardust] |
| Astar | 592 | [latest][link-astar] | [token-list][viewer-astar] |
Expand Down Expand Up @@ -68,6 +69,7 @@ The token lists for Mask Network.
[link-polygon]: https://tokens.r2d2.to/latest/137/tokens.json
[link-xlayertestnet]: https://tokens.r2d2.to/latest/195/tokens.json
[link-xlayer]: https://tokens.r2d2.to/latest/196/tokens.json
[link-sei]: https://tokens.r2d2.to/latest/1329/tokens.json
[link-mumbai]: https://tokens.r2d2.to/latest/80001/tokens.json
[link-stardust]: https://tokens.r2d2.to/latest/588/tokens.json
[link-astar]: https://tokens.r2d2.to/latest/592/tokens.json
Expand Down Expand Up @@ -104,6 +106,7 @@ The token lists for Mask Network.
[viewer-polygon]: https://tokenlists.org/token-list?url=https://tokens.r2d2.to/latest/137/tokens.json
[viewer-xlayertestnet]: https://tokenlists.org/token-list?url=https://tokens.r2d2.to/latest/195/tokens.json
[viewer-xlayer]: https://tokenlists.org/token-list?url=https://tokens.r2d2.to/latest/196/tokens.json
[viewer-sei]: https://tokenlists.org/token-list?url=https://tokens.r2d2.to/latest/1329/tokens.json
[viewer-mumbai]: https://tokenlists.org/token-list?url=https://tokens.r2d2.to/latest/80001/tokens.json
[viewer-stardust]: https://tokenlists.org/token-list?url=https://tokens.r2d2.to/latest/588/tokens.json
[viewer-astar]: https://tokenlists.org/token-list?url=https://tokens.r2d2.to/latest/592/tokens.json
Expand Down
5 changes: 5 additions & 0 deletions src/constants/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class NotFoundError extends Error {
constructor() {
super('Not found');
}
}
2 changes: 2 additions & 0 deletions src/helpers/fetchJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HttpsProxyAgent } from 'https-proxy-agent';

import { fetch } from '@/helpers/fetch';
import { RequestInfo as NodeFetchRequestInfo, RequestInit as NodeFetchRequestInit } from 'node-fetch';
import { NotFoundError } from '@/constants/error';

export async function fetchJSON<T = unknown>(request: RequestInfo, init?: RequestInit) {
const proxy = process.env.http_proxy ?? process.env.https_proxy;
Expand All @@ -13,6 +14,7 @@ export async function fetchJSON<T = unknown>(request: RequestInfo, init?: Reques
agent: proxy ? new HttpsProxyAgent(proxy) : undefined,
} as NodeFetchRequestInit,
);
if (response.status === 404) throw new NotFoundError();
if (!response.ok) throw new Error(`Failed to fetch JSON: ${response.status} ${response.statusText}`);

const json = await response.json();
Expand Down
17 changes: 13 additions & 4 deletions src/providers/mask/TokenList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { MASK_TOKEN_LIST_ROOT_URL } from '@/constants';
import { fetchJSON } from '@/helpers/fetchJSON';
import { Provider } from '@/providers/types/TokenList';
import { Chain, FungibleToken, NonFungibleToken, TokenList as ChainTokenList } from '@/types';
import { NotFoundError } from '@/constants/error';
import { createTokenList } from '@/helpers/createTokenList';

class TokenList implements Provider {
async getFungibleTokenList(chain: Chain, signal?: AbortSignal) {
Expand All @@ -19,10 +21,17 @@ class TokenList implements Provider {
}

async getNonFungibleTokenList(chain: Chain, signal?: AbortSignal): Promise<ChainTokenList<NonFungibleToken>> {
const url = urlcat(MASK_TOKEN_LIST_ROOT_URL, '/latest/:chainId/non-fungible-tokens.json', {
chainId: chain.chainId,
});
return fetchJSON<ChainTokenList<NonFungibleToken>>(url, { signal });
try {
const url = urlcat(MASK_TOKEN_LIST_ROOT_URL, '/latest/:chainId/non-fungible-tokens.json', {
chainId: chain.chainId,
});
return await fetchJSON<ChainTokenList<NonFungibleToken>>(url, { signal });
} catch (error) {
if (error instanceof NotFoundError) {
return createTokenList([]);
}
throw error;
}
}
}

Expand Down

0 comments on commit 8e1fbc8

Please sign in to comment.