mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
[internal] Add logo size check to all chains, logos. (#3133)
Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
parent
bda2c0a236
commit
c408d033e4
Binary file not shown.
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 10 KiB |
|
@ -21,16 +21,15 @@ import {
|
||||||
} from "../common/filesystem";
|
} from "../common/filesystem";
|
||||||
import { isChecksum, toChecksum } from "../common/eth-web3";
|
import { isChecksum, toChecksum } from "../common/eth-web3";
|
||||||
import { ActionInterface, CheckStepInterface } from "./interface";
|
import { ActionInterface, CheckStepInterface } from "./interface";
|
||||||
import { isLogoOK } from "../common/image";
|
|
||||||
import { isAssetInfoOK } from "../common/asset-info";
|
import { isAssetInfoOK } from "../common/asset-info";
|
||||||
import * as bluebird from "bluebird";
|
import * as bluebird from "bluebird";
|
||||||
|
|
||||||
function formatInfos() {
|
async function formatInfos() {
|
||||||
console.log(`Formatting info files...`);
|
console.log(`Formatting info files...`);
|
||||||
ethForkChains.forEach(chain => {
|
await bluebird.each(ethForkChains, async (chain) => {
|
||||||
let count: number = 0;
|
let count: number = 0;
|
||||||
const chainAssets = getChainAssetsList(chain);
|
const chainAssets = getChainAssetsList(chain);
|
||||||
chainAssets.forEach(address => {
|
await bluebird.each(chainAssets, async (address) => {
|
||||||
if (isChainAssetInfoExistSync(chain, address)) {
|
if (isChainAssetInfoExistSync(chain, address)) {
|
||||||
const chainAssetInfoPath = getChainAssetInfoPath(chain, address);
|
const chainAssetInfoPath = getChainAssetInfoPath(chain, address);
|
||||||
formatJsonFile(chainAssetInfoPath, true);
|
formatJsonFile(chainAssetInfoPath, true);
|
||||||
|
@ -49,13 +48,13 @@ function checkAddressChecksum(assetsFolderPath: string, address: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkAddressChecksums() {
|
async function checkAddressChecksums() {
|
||||||
console.log(`Checking for checksum formats ...`);
|
console.log(`Checking for checksum formats ...`);
|
||||||
ethForkChains.forEach(chain => {
|
await bluebird.each(ethForkChains, async (chain) => {
|
||||||
const assetsPath = getChainAssetsPath(chain);
|
const assetsPath = getChainAssetsPath(chain);
|
||||||
|
|
||||||
readDirSync(assetsPath).forEach(address => {
|
await bluebird.each(readDirSync(assetsPath), async (address) => {
|
||||||
getChainAssetFilesList(chain, address).forEach(file => {
|
await bluebird.each(getChainAssetFilesList(chain, address), async (file) => {
|
||||||
if (getFileName(file) == logoName && getFileExt(file) !== logoExtension) {
|
if (getFileName(file) == logoName && getFileExt(file) !== logoExtension) {
|
||||||
console.log(`Renaming incorrect asset logo extension ${file} ...`);
|
console.log(`Renaming incorrect asset logo extension ${file} ...`);
|
||||||
gitMove(getChainAssetPath(chain, address), file, logoFullName);
|
gitMove(getChainAssetPath(chain, address), file, logoFullName);
|
||||||
|
@ -92,10 +91,6 @@ export class EthForks implements ActionInterface {
|
||||||
if (!isPathExistsSync(assetLogoPath)) {
|
if (!isPathExistsSync(assetLogoPath)) {
|
||||||
error += `Missing file at path '${assetLogoPath}'\n`;
|
error += `Missing file at path '${assetLogoPath}'\n`;
|
||||||
}
|
}
|
||||||
const [isOK, dimensionMsg] = await isLogoOK(assetLogoPath);
|
|
||||||
if (!isOK) {
|
|
||||||
error += dimensionMsg + "\n";
|
|
||||||
}
|
|
||||||
const [isInfoOK, infoMsg] = isAssetInfoOK(chain, address);
|
const [isInfoOK, infoMsg] = isAssetInfoOK(chain, address);
|
||||||
if (!isInfoOK) {
|
if (!isInfoOK) {
|
||||||
error += infoMsg + "\n";
|
error += infoMsg + "\n";
|
||||||
|
@ -110,8 +105,8 @@ export class EthForks implements ActionInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fix(): Promise<void> {
|
async fix(): Promise<void> {
|
||||||
formatInfos();
|
await formatInfos();
|
||||||
checkAddressChecksums();
|
await checkAddressChecksums();
|
||||||
}
|
}
|
||||||
|
|
||||||
update = null;
|
update = null;
|
||||||
|
|
|
@ -12,20 +12,27 @@ import {
|
||||||
readFileSync,
|
readFileSync,
|
||||||
isPathExistsSync
|
isPathExistsSync
|
||||||
} from "../common/filesystem";
|
} from "../common/filesystem";
|
||||||
import { resizeIfTooLarge } from "../common/image";
|
import { checkResizeIfTooLarge } from "../common/image";
|
||||||
import { ActionInterface } from "./interface";
|
import { ActionInterface, CheckStepInterface } from "./interface";
|
||||||
|
|
||||||
async function downsize(chains) {
|
// return name of large logo, or empty
|
||||||
console.log(`Checking all logos for downsizing ...`);
|
async function checkDownsize(chains, checkOnly: boolean): Promise<string> {
|
||||||
|
console.log(`Checking all logos for size ...`);
|
||||||
let totalCountChecked: number = 0;
|
let totalCountChecked: number = 0;
|
||||||
|
let totalCountTooLarge: number = 0;
|
||||||
let totalCountUpdated: number = 0;
|
let totalCountUpdated: number = 0;
|
||||||
|
let largePath = "";
|
||||||
await bluebird.map(chains, async chain => {
|
await bluebird.map(chains, async chain => {
|
||||||
let countChecked: number = 0;
|
let countChecked: number = 0;
|
||||||
|
let countTooLarge: number = 0;
|
||||||
let countUpdated: number = 0;
|
let countUpdated: number = 0;
|
||||||
|
|
||||||
const path = getChainLogoPath(chain);
|
const path = getChainLogoPath(chain);
|
||||||
countChecked++;
|
countChecked++;
|
||||||
countUpdated += await resizeIfTooLarge(path) ? 1 : 0;
|
const [tooLarge, updated] = await checkResizeIfTooLarge(path, checkOnly);
|
||||||
|
if (tooLarge) { largePath = path; }
|
||||||
|
countTooLarge += tooLarge ? 1 : 0;
|
||||||
|
countUpdated += updated ? 1 : 0;
|
||||||
|
|
||||||
// Check and resize if needed chain assets
|
// Check and resize if needed chain assets
|
||||||
const assetsPath = getChainAssetsPath(chain);
|
const assetsPath = getChainAssetsPath(chain);
|
||||||
|
@ -33,7 +40,10 @@ async function downsize(chains) {
|
||||||
await bluebird.mapSeries(readDirSync(assetsPath), async asset => {
|
await bluebird.mapSeries(readDirSync(assetsPath), async asset => {
|
||||||
const path = getChainAssetLogoPath(chain, asset);
|
const path = getChainAssetLogoPath(chain, asset);
|
||||||
countChecked++;
|
countChecked++;
|
||||||
countUpdated += await resizeIfTooLarge(path) ? 1 : 0;
|
const [tooLarge, updated] = await checkResizeIfTooLarge(path, checkOnly);
|
||||||
|
if (tooLarge) { largePath = path; }
|
||||||
|
countTooLarge += tooLarge ? 1 : 0;
|
||||||
|
countUpdated += updated ? 1 : 0;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,25 +54,47 @@ async function downsize(chains) {
|
||||||
await bluebird.mapSeries(validatorsList, async ({ id }) => {
|
await bluebird.mapSeries(validatorsList, async ({ id }) => {
|
||||||
const path = getChainValidatorAssetLogoPath(chain, id);
|
const path = getChainValidatorAssetLogoPath(chain, id);
|
||||||
countChecked++;
|
countChecked++;
|
||||||
countUpdated += await resizeIfTooLarge(path) ? 1 : 0;
|
const [tooLarge, updated] = await checkResizeIfTooLarge(path, checkOnly);
|
||||||
|
if (tooLarge) { largePath = path; }
|
||||||
|
countTooLarge += tooLarge ? 1 : 0;
|
||||||
|
countUpdated += updated ? 1 : 0;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
totalCountChecked += countChecked;
|
totalCountChecked += countChecked;
|
||||||
|
totalCountTooLarge += countTooLarge;
|
||||||
totalCountUpdated += countUpdated;
|
totalCountUpdated += countUpdated;
|
||||||
if (countUpdated > 0) {
|
if (countTooLarge > 0 || countUpdated > 0) {
|
||||||
console.log(`Checking logos on chain ${chain} completed, ${countChecked} checked, ${countUpdated} logos updated`);
|
console.log(`Checking logos on chain ${chain} completed, ${countChecked} checked, ${countTooLarge} too large, ${largePath}, ${countUpdated} logos updated`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(`Checking logos completed, ${totalCountChecked} logos checked, ${totalCountUpdated} logos updated`);
|
console.log(`Checking logos completed, ${totalCountChecked} logos checked, ${totalCountTooLarge} too large, ${totalCountUpdated} logos updated`);
|
||||||
|
return largePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LogoSize implements ActionInterface {
|
export class LogoSize implements ActionInterface {
|
||||||
getName(): string { return "Logo sizes"; }
|
getName(): string { return "Logo sizes"; }
|
||||||
getChecks = null;
|
|
||||||
|
getChecks(): CheckStepInterface[] {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
getName: () => { return "Check that logos are not too large"},
|
||||||
|
check: async () => {
|
||||||
|
const foundChains = readDirSync(chainsPath);
|
||||||
|
var largePath = await checkDownsize(foundChains, true);
|
||||||
|
if (largePath.length > 0) {
|
||||||
|
return `Found at least one logo that is too large: ${largePath}`;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
async fix(): Promise<void> {
|
async fix(): Promise<void> {
|
||||||
const foundChains = readDirSync(chainsPath);
|
const foundChains = readDirSync(chainsPath);
|
||||||
await downsize(foundChains);
|
await checkDownsize(foundChains, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
update = null;
|
update = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { Tron } from "../common/blockchains";
|
||||||
import { readDirSync, isPathExistsSync } from "../common/filesystem";
|
import { readDirSync, isPathExistsSync } from "../common/filesystem";
|
||||||
import { getChainAssetLogoPath, getChainValidatorsAssets } from "../common/repo-structure";
|
import { getChainAssetLogoPath, getChainValidatorsAssets } from "../common/repo-structure";
|
||||||
import { isLowerCase, isUpperCase } from "../common/types";
|
import { isLowerCase, isUpperCase } from "../common/types";
|
||||||
import { isLogoOK } from "../common/image";
|
|
||||||
import * as bluebird from "bluebird";
|
import * as bluebird from "bluebird";
|
||||||
|
|
||||||
export function isTRC10(str: string): boolean {
|
export function isTRC10(str: string): boolean {
|
||||||
|
@ -37,10 +36,6 @@ export class TronAction implements ActionInterface {
|
||||||
if (!isPathExistsSync(assetsLogoPath)) {
|
if (!isPathExistsSync(assetsLogoPath)) {
|
||||||
error += `Missing file at path '${assetsLogoPath}'\n`;
|
error += `Missing file at path '${assetsLogoPath}'\n`;
|
||||||
}
|
}
|
||||||
const [isOk, sizeMsg] = await isLogoOK(assetsLogoPath);
|
|
||||||
if (!isOk) {
|
|
||||||
error += sizeMsg + "\n";
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,37 +71,50 @@ async function isLogoSizeOK(path: string): Promise<[boolean, string]> {
|
||||||
return [true, ''];
|
return [true, ''];
|
||||||
}
|
}
|
||||||
|
|
||||||
// return true if image updated
|
// return if image if too large, and if image has been updated
|
||||||
export async function resizeIfTooLarge(path: string): Promise<boolean> {
|
export async function checkResizeIfTooLarge(path: string, checkOnly: boolean): Promise<[boolean, boolean]> {
|
||||||
|
let tooLarge = false;
|
||||||
let updated: boolean = false;
|
let updated: boolean = false;
|
||||||
|
|
||||||
const { width: srcWidth, height: srcHeight } = getImageDimensions(path);
|
const { width: srcWidth, height: srcHeight } = getImageDimensions(path);
|
||||||
|
|
||||||
|
if (!isDimensionOK(srcWidth, srcHeight)) {
|
||||||
|
tooLarge = true; // may be too small as well
|
||||||
|
}
|
||||||
|
|
||||||
if (isDimensionTooLarge(srcWidth, srcHeight)) {
|
if (isDimensionTooLarge(srcWidth, srcHeight)) {
|
||||||
const { width, height } = calculateTargetSize(srcWidth, srcHeight, maxLogoWidth, maxLogoHeight);
|
tooLarge = true;
|
||||||
console.log(`Resizing image at ${path} from ${srcWidth}x${srcHeight} => ${width}x${height}`)
|
if (!checkOnly) {
|
||||||
await sharp(path).resize(width, height).toBuffer()
|
// resize
|
||||||
.then(data => {
|
const { width, height } = calculateTargetSize(srcWidth, srcHeight, maxLogoWidth, maxLogoHeight);
|
||||||
writeFileSync(path, data);
|
console.log(`Resizing image at ${path} from ${srcWidth}x${srcHeight} => ${width}x${height}`)
|
||||||
updated = true;
|
await sharp(path).resize(width, height).toBuffer()
|
||||||
})
|
.then(data => {
|
||||||
.catch(e => {
|
writeFileSync(path, data);
|
||||||
console.log(chalk.red(e.message));
|
updated = true;
|
||||||
});
|
})
|
||||||
|
.catch(e => {
|
||||||
|
console.log(chalk.red(e.message));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If file size > max limit, compress with tinypng
|
// If file size > max limit, compress with tinypng
|
||||||
const sizeKilobyte = getFileSizeInKilobyte(path);
|
const sizeKilobyte = getFileSizeInKilobyte(path);
|
||||||
if (sizeKilobyte > maxLogoSizeInKilobyte) {
|
if (sizeKilobyte > maxLogoSizeInKilobyte) {
|
||||||
console.log(`Resizing image at path ${path} from ${sizeKilobyte} kB`);
|
tooLarge = true;
|
||||||
await compressTinyPNG(path)
|
if (!checkOnly) {
|
||||||
.then(() => {
|
console.log(`Resizing image at path ${path} from ${sizeKilobyte} kB`);
|
||||||
updated = true;
|
await compressTinyPNG(path)
|
||||||
console.log(`Resized image at path ${path} from ${sizeKilobyte} kB => ${getFileSizeInKilobyte(path)} kB`);
|
.then(() => {
|
||||||
})
|
updated = true;
|
||||||
.catch(e => {
|
console.log(`Resized image at path ${path} from ${sizeKilobyte} kB => ${getFileSizeInKilobyte(path)} kB`);
|
||||||
console.log(chalk.red(e.message));
|
})
|
||||||
});
|
.catch(e => {
|
||||||
|
console.log(chalk.red(e.message));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return updated;
|
return [tooLarge, updated];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user