[Internal] Change all explorers to standard explorer (#7655)

* In fix, overwrite Explorer to computed version.

* Ignore case-only diff

* Add VeChain explorer

* Revert "Add VeChain explorer"

This reverts commit 0a0b22c6beda4648c41cf307bbb9b4f421d7d773.

* Add VeChain explorer template

* Update thundertoken explorer

* Lint fix

* Lint fix

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
Adam R 2021-05-10 15:08:10 +02:00 committed by GitHub
parent f96a9a803b
commit f905bad945
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -161,15 +161,19 @@ export function explorerUrl(chain: string, contract: string): string {
return "https://explorer.ont.io";
case CoinType.name(CoinType.gochain).toLowerCase():
return `https://explorer.gochain.io/addr/${contract}`;
return `https://explorer.gochain.io/addr/${contract}`;
case CoinType.name(CoinType.thundertoken).toLowerCase():
case "thundertoken":
return `https://scan.thundercore.com/`;
return `https://viewblock.io/thundercore/address/${contract}`;
case CoinType.name(CoinType.classic).toLowerCase():
case "classic":
return `https://blockscout.com/etc/mainnet/tokens/${contract}`;
return `https://blockscout.com/etc/mainnet/tokens/${contract}`;
case CoinType.name(CoinType.vechain).toLowerCase():
case "vechain":
return `https://explore.vechain.org/accounts/${contract}`;
}
}
return "";
@ -223,29 +227,38 @@ function isAssetInfoOK(chain: string, address: string, errors: string[], warning
fixedInfo = fixedInfo2;
}
const explorerExpected = explorerUrl(chain, address);
const hasExplorer = Object.prototype.hasOwnProperty.call(info, 'explorer');
if (!hasExplorer) {
errors.push(`Missing explorer key`);
} else {
const explorerActual = info['explorer'];
const explorerActualLower = explorerActual.toLowerCase();
const explorerExpected = explorerUrl(chain, address);
if (explorerActualLower != explorerExpected.toLowerCase() && explorerExpected) {
// doesn't match, check for alternatives
const explorersAlt = explorerUrlAlternatives(chain, address, info['name']);
if (explorersAlt && explorersAlt.length > 0) {
let matchCount = 0;
explorersAlt.forEach(exp => { if (exp.toLowerCase() == explorerActualLower) { ++matchCount; }});
if (matchCount == 0) {
// none matches, this is warning/error
if (chain.toLowerCase() == CoinType.name(CoinType.ethereum) || chain.toLowerCase() == CoinType.name(CoinType.smartchain)) {
errors.push(`Incorrect explorer, ${explorerActual} instead of ${explorerExpected} (${explorersAlt.join(', ')})`);
} else {
warnings.push(`Unexpected explorer, ${explorerActual} instead of ${explorerExpected} (${explorersAlt.join(', ')})`);
const explorerActual = info['explorer'] || '';
const explorerActualLower = explorerActual.toLowerCase();
const explorerExpectedLower = explorerExpected.toLowerCase();
if (checkOnly) {
if (!hasExplorer) {
errors.push(`Missing explorer key`);
} else {
if (explorerActualLower !== explorerExpectedLower && explorerExpected) {
// doesn't match, check for alternatives
const explorersAlt = explorerUrlAlternatives(chain, address, info['name']);
if (explorersAlt && explorersAlt.length > 0) {
let matchCount = 0;
explorersAlt.forEach(exp => { if (exp.toLowerCase() == explorerActualLower) { ++matchCount; }});
if (matchCount == 0) {
// none matches, this is warning/error
if (chain.toLowerCase() == CoinType.name(CoinType.ethereum) || chain.toLowerCase() == CoinType.name(CoinType.smartchain)) {
errors.push(`Incorrect explorer, ${explorerActual} instead of ${explorerExpected} (${explorersAlt.join(', ')})`);
} else {
warnings.push(`Unexpected explorer, ${explorerActual} instead of ${explorerExpected} (${explorersAlt.join(', ')})`);
}
}
}
}
}
} else {
// fix: simply replace with expected (case-only deviation is accepted)
if (explorerActualLower !== explorerExpectedLower) {
if (!fixedInfo) { fixedInfo = info; }
fixedInfo['explorer'] = explorerExpected;
}
}
if (fixedInfo && !checkOnly) {