mirror of
https://github.com/alexgo-io/alex-sdk.git
synced 2026-01-12 14:25:02 +08:00
feat: add fetchSwappableCurrency
This commit is contained in:
@@ -16,7 +16,11 @@ import {
|
||||
broadcastSponsoredTx,
|
||||
isSponsoredSwapEnabled,
|
||||
} from './utils/sponsoredTx';
|
||||
import { fetchTokenList, TokenInfo } from './utils/tokenlist';
|
||||
import {
|
||||
fetchSwappableCurrency,
|
||||
fetchTokenList,
|
||||
TokenInfo,
|
||||
} from './utils/tokenlist';
|
||||
export { SponsoredTxError, SponsoredTxErrorCode } from './utils/sponsoredTx';
|
||||
|
||||
export class AlexSDK {
|
||||
@@ -112,6 +116,10 @@ export class AlexSDK {
|
||||
}
|
||||
|
||||
fetchTokenList(): Promise<TokenInfo[]> {
|
||||
return fetchTokenList()
|
||||
return fetchTokenList();
|
||||
}
|
||||
|
||||
fetchSwappableCurrency(): Promise<TokenInfo[]> {
|
||||
return fetchSwappableCurrency();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
import { Currency } from '../currency';
|
||||
|
||||
export type TokenInfo = {
|
||||
type: 'fungibleToken',
|
||||
id: string,
|
||||
name: string
|
||||
displayPrecision: number,
|
||||
icon: string,
|
||||
availableInSwap: boolean,
|
||||
contractAddress: string,
|
||||
decimals: number
|
||||
}
|
||||
type: 'fungibleToken';
|
||||
id: string;
|
||||
name: string;
|
||||
displayPrecision: number;
|
||||
icon: string;
|
||||
availableInSwap: boolean;
|
||||
contractAddress: string;
|
||||
decimals: number;
|
||||
};
|
||||
|
||||
export function fetchTokenList(): Promise<TokenInfo[]> {
|
||||
return fetch('https://token-list.alexlab.co', {
|
||||
mode: 'cors'
|
||||
mode: 'cors',
|
||||
})
|
||||
.then(res => res.json())
|
||||
.then(data => data.tokens)
|
||||
.then((res) => res.json())
|
||||
.then((data) => data.tokens);
|
||||
}
|
||||
|
||||
export async function fetchSwappableCurrency(): Promise<TokenInfo[]> {
|
||||
const tokens = await fetchTokenList();
|
||||
return tokens.filter(
|
||||
(x) =>
|
||||
x.availableInSwap && Object.values(Currency).includes(x.id as Currency)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user