mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
Binance update: Better error handling and safeguards (#7980)
Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
parent
7b005e2b50
commit
93f8abfcda
|
@ -26,7 +26,11 @@ let cachedAssets = [];
|
||||||
|
|
||||||
async function retrieveBep2AssetList(): Promise<unknown[]> {
|
async function retrieveBep2AssetList(): Promise<unknown[]> {
|
||||||
console.log(`Retrieving token asset infos from: ${binanceUrlTokenAssets}`);
|
console.log(`Retrieving token asset infos from: ${binanceUrlTokenAssets}`);
|
||||||
const { assetInfoList } = await axios.get(binanceUrlTokenAssets).then(r => r.data);
|
const { assetInfoList } = await axios.get(binanceUrlTokenAssets)
|
||||||
|
.then(r => r.data)
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(JSON.stringify(error))
|
||||||
|
});
|
||||||
console.log(`Retrieved ${assetInfoList.length} token asset infos`);
|
console.log(`Retrieved ${assetInfoList.length} token asset infos`);
|
||||||
return assetInfoList
|
return assetInfoList
|
||||||
}
|
}
|
||||||
|
@ -128,6 +132,10 @@ export class BinanceAction implements ActionInterface {
|
||||||
async updateAuto(): Promise<void> {
|
async updateAuto(): Promise<void> {
|
||||||
// retrieve missing token images; BEP2 (bep8 not supported)
|
// retrieve missing token images; BEP2 (bep8 not supported)
|
||||||
const bep2InfoList = await retrieveBep2AssetList();
|
const bep2InfoList = await retrieveBep2AssetList();
|
||||||
|
if (bep2InfoList.length < 5) {
|
||||||
|
console.log(`ERROR: No Binance token info is returned! ${bep2InfoList.length}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const denylist: string[] = readJsonFile(getChainDenylistPath(binanceChain)) as string[];
|
const denylist: string[] = readJsonFile(getChainDenylistPath(binanceChain)) as string[];
|
||||||
|
|
||||||
const toFetch = findImagesToFetch(bep2InfoList, denylist);
|
const toFetch = findImagesToFetch(bep2InfoList, denylist);
|
||||||
|
@ -140,6 +148,10 @@ export class BinanceAction implements ActionInterface {
|
||||||
|
|
||||||
// binance chain list
|
// binance chain list
|
||||||
const tokenList = await generateBinanceTokensList();
|
const tokenList = await generateBinanceTokensList();
|
||||||
|
if (tokenList.length < 5) {
|
||||||
|
console.log(`ERROR: no token pair info available from Binance DEX! ${tokenList.length}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const list = createTokensList("BNB", tokenList,
|
const list = createTokensList("BNB", tokenList,
|
||||||
"2020-10-03T12:37:57.000+00:00", // use constants here to prevent changing time every time
|
"2020-10-03T12:37:57.000+00:00", // use constants here to prevent changing time every time
|
||||||
0, 1, 0);
|
0, 1, 0);
|
||||||
|
@ -159,8 +171,24 @@ class BinanceMarket {
|
||||||
async function generateBinanceTokensList(): Promise<TokenItem[]> {
|
async function generateBinanceTokensList(): Promise<TokenItem[]> {
|
||||||
const decimals = CoinType.decimals(CoinType.binance)
|
const decimals = CoinType.decimals(CoinType.binance)
|
||||||
const BNBSymbol = CoinType.symbol(CoinType.binance)
|
const BNBSymbol = CoinType.symbol(CoinType.binance)
|
||||||
const markets: [BinanceMarket] = await axios.get(`${config.binanceDexURL}/v1/markets?limit=10000`).then(r => r.data);
|
const markets: BinanceMarket[] = await axios.get(`${config.binanceDexURL}/v1/markets?limit=10000`)
|
||||||
const tokens = await axios.get(`${config.binanceDexURL}/v1/tokens?limit=10000`).then(r => r.data);
|
.then(r => r.data)
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(JSON.stringify(error))
|
||||||
|
});
|
||||||
|
if (markets.length < 5) {
|
||||||
|
console.log(`ERROR: No markets info is returned from Binance DEX! ${markets.length}`);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const tokens = await axios.get(`${config.binanceDexURL}/v1/tokens?limit=10000`)
|
||||||
|
.then(r => r.data)
|
||||||
|
.catch(function (error) {
|
||||||
|
console.log(JSON.stringify(error))
|
||||||
|
});
|
||||||
|
if (tokens.length < 5) {
|
||||||
|
console.log(`ERROR: No tokens info is returned from Binance DEX! ${tokens.length}`);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
const tokensMap = Object.assign({}, ...tokens.map(s => ({[s.symbol]: s})));
|
const tokensMap = Object.assign({}, ...tokens.map(s => ({[s.symbol]: s})));
|
||||||
const pairsMap = {}
|
const pairsMap = {}
|
||||||
const pairsList = new Set();
|
const pairsList = new Set();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user