[Internal] Cleanup empty pairs[] from Eth tokenlist (#13933)

* Cleanup empty pairs[] from Eth tokenlist

* Small revert
This commit is contained in:
Adam R 2021-09-27 10:56:09 +02:00 committed by GitHub
parent 69bb712494
commit af967a8d91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 316 additions and 599 deletions

File diff suppressed because it is too large Load Diff

View File

@ -268,7 +268,9 @@ function sort(list: List) {
return t1.address.localeCompare(t2.address);
});
list.tokens.forEach(t => {
t.pairs.sort((p1, p2) => p1.base.localeCompare(p2.base));
if (t.pairs) {
t.pairs.sort((p1, p2) => p1.base.localeCompare(p2.base));
}
});
}
@ -296,6 +298,14 @@ export function diffTokenlist(listOrig1: List, listOrig2: List): unknown {
return diffs;
}
function adjustTokenList(list: List) {
list.tokens.forEach(t => {
if (t.pairs.length == 0) {
delete t.pairs;
}
});
}
export async function rebuildTokenlist(chainName: string, pairs: [TokenItem, TokenItem][], listName: string, forceExcludeList: string[]): Promise<void> {
// sanity check, prevent deletion of many pairs
if (!pairs || pairs.length < 5) {
@ -335,6 +345,8 @@ export async function rebuildTokenlist(chainName: string, pairs: [TokenItem, Tok
await addPairIfNeeded(p[0], p[1], list);
});
console.log(`Tokenlist updated: ${list.tokens.length} tokens`);
adjustTokenList(list);
console.log(`Tokenlist adjusted: ${list.tokens.length} tokens`);
const newList = createTokensList(listName, list.tokens,
"2021-01-29T01:02:03.000+00:00", // use constant here to prevent changing time every time