From 59fb1a99dc3c6e831f8f08e6c84e1a4d43106852 Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Wed, 23 Aug 2023 16:55:47 +0800 Subject: [PATCH] feat: add ability to fetch token list --- src/alexSDK.ts | 5 +++++ src/utils/tokenlist.ts | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/utils/tokenlist.ts diff --git a/src/alexSDK.ts b/src/alexSDK.ts index 40a4ee8..ca22bfc 100644 --- a/src/alexSDK.ts +++ b/src/alexSDK.ts @@ -16,6 +16,7 @@ import { broadcastSponsoredTx, isSponsoredSwapEnabled, } from './utils/sponsoredTx'; +import { fetchTokenList, TokenInfo } from './utils/tokenlist'; export { SponsoredTxError, SponsoredTxErrorCode } from './utils/sponsoredTx'; export class AlexSDK { @@ -109,4 +110,8 @@ export class AlexSDK { isSponsoredSwapEnabled(): Promise { return isSponsoredSwapEnabled().catch(() => false); } + + fetchTokenList(): Promise { + return fetchTokenList() + } } diff --git a/src/utils/tokenlist.ts b/src/utils/tokenlist.ts new file mode 100644 index 0000000..dd5f729 --- /dev/null +++ b/src/utils/tokenlist.ts @@ -0,0 +1,17 @@ +export type TokenInfo = { + type: 'fungibleToken', + id: string, + displayPrecision: number, + icon: string, + availableInSwap: boolean, + contractAddress: string, + decimals: number +} + +export function fetchTokenList(): Promise { + return fetch('https://token-list.alexlab.co', { + mode: 'cors' + }) + .then(res => res.json()) + .then(data => data.tokens) +}