Enforce value of the ID field. (#5488)

Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
Adam R 2021-02-05 11:59:21 +01:00 committed by GitHub
parent 0a5f146c8c
commit 55c5a48652
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,17 +24,21 @@ function isAssetInfoHasAllKeys(info: unknown, path: string): [boolean, string] {
return [hasAllKeys, `Info at path '${path}' missing next key(s): ${arrayDiff(requiredKeys, infoKeys)}`];
}
function isAssetInfoValid(info: unknown, path: string): [string, string] {
function isAssetInfoValid(info: unknown, path: string, address: string): [string, string] {
const isKeys1CorrectType =
typeof info['name'] === "string" && info['name'] !== "" &&
typeof info['type'] === "string" && info['type'] !== "" &&
typeof info['symbol'] === "string" && info['symbol'] !== "" &&
typeof info['decimals'] === "number" && //(info['description'] === "-" || info['decimals'] !== 0) &&
typeof info['id'] === "string" && info['id'] !== "";
typeof info['decimals'] === "number" //(info['description'] === "-" || info['decimals'] !== 0) &&
;
if (!isKeys1CorrectType) {
return [`Check keys1 '${info['name']}' '${info['type']}' '${info['symbol']}' '${info['decimals']}' '${info['id']}' ${path}`, ""];
}
if (typeof info['id'] !== "string" || info['id'] !== address ) {
return [`Incorrect id '${info['id']}' '${path}`, ""];
}
const isKeys2CorrectType =
typeof info['description'] === "string" && info['description'] !== "" &&
// website should be set (exception description='-' marks empty infos)
@ -138,7 +142,7 @@ function isAssetInfoOK(chain: string, address: string, errors: string[], warning
errors.push(msg1);
}
const [err2, warn2] = isAssetInfoValid(info, assetInfoPath);
const [err2, warn2] = isAssetInfoValid(info, assetInfoPath, address);
if (err2) {
errors.push(err2);
}