[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"; return "https://explorer.ont.io";
case CoinType.name(CoinType.gochain).toLowerCase(): 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 CoinType.name(CoinType.thundertoken).toLowerCase():
case "thundertoken": case "thundertoken":
return `https://scan.thundercore.com/`; return `https://viewblock.io/thundercore/address/${contract}`;
case CoinType.name(CoinType.classic).toLowerCase(): case CoinType.name(CoinType.classic).toLowerCase():
case "classic": 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 ""; return "";
@ -223,29 +227,38 @@ function isAssetInfoOK(chain: string, address: string, errors: string[], warning
fixedInfo = fixedInfo2; fixedInfo = fixedInfo2;
} }
const explorerExpected = explorerUrl(chain, address);
const hasExplorer = Object.prototype.hasOwnProperty.call(info, 'explorer'); const hasExplorer = Object.prototype.hasOwnProperty.call(info, 'explorer');
if (!hasExplorer) { const explorerActual = info['explorer'] || '';
errors.push(`Missing explorer key`); const explorerActualLower = explorerActual.toLowerCase();
} else { const explorerExpectedLower = explorerExpected.toLowerCase();
const explorerActual = info['explorer']; if (checkOnly) {
const explorerActualLower = explorerActual.toLowerCase(); if (!hasExplorer) {
const explorerExpected = explorerUrl(chain, address); errors.push(`Missing explorer key`);
if (explorerActualLower != explorerExpected.toLowerCase() && explorerExpected) { } else {
// doesn't match, check for alternatives if (explorerActualLower !== explorerExpectedLower && explorerExpected) {
const explorersAlt = explorerUrlAlternatives(chain, address, info['name']); // doesn't match, check for alternatives
if (explorersAlt && explorersAlt.length > 0) { const explorersAlt = explorerUrlAlternatives(chain, address, info['name']);
let matchCount = 0; if (explorersAlt && explorersAlt.length > 0) {
explorersAlt.forEach(exp => { if (exp.toLowerCase() == explorerActualLower) { ++matchCount; }}); let matchCount = 0;
if (matchCount == 0) { explorersAlt.forEach(exp => { if (exp.toLowerCase() == explorerActualLower) { ++matchCount; }});
// none matches, this is warning/error if (matchCount == 0) {
if (chain.toLowerCase() == CoinType.name(CoinType.ethereum) || chain.toLowerCase() == CoinType.name(CoinType.smartchain)) { // none matches, this is warning/error
errors.push(`Incorrect explorer, ${explorerActual} instead of ${explorerExpected} (${explorersAlt.join(', ')})`); if (chain.toLowerCase() == CoinType.name(CoinType.ethereum) || chain.toLowerCase() == CoinType.name(CoinType.smartchain)) {
} else { errors.push(`Incorrect explorer, ${explorerActual} instead of ${explorerExpected} (${explorersAlt.join(', ')})`);
warnings.push(`Unexpected 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) { if (fixedInfo && !checkOnly) {