diff --git a/blockchains/ethereum/assets/0x500d15aA5b01E7eb77e4D4C8283Df3E6c49Da754/logo.png b/blockchains/ethereum/assets/0x500d15aA5b01E7eb77e4D4C8283Df3E6c49Da754/logo.png new file mode 100644 index 000000000..8a4cef5dd Binary files /dev/null and b/blockchains/ethereum/assets/0x500d15aA5b01E7eb77e4D4C8283Df3E6c49Da754/logo.png differ diff --git a/blockchains/ethereum/assets/0x51BC0DeaF7bBE82bC9006b0c3531668a4206D27F/logo.png b/blockchains/ethereum/assets/0x51BC0DeaF7bBE82bC9006b0c3531668a4206D27F/logo.png new file mode 100644 index 000000000..02e4264f7 Binary files /dev/null and b/blockchains/ethereum/assets/0x51BC0DeaF7bBE82bC9006b0c3531668a4206D27F/logo.png differ diff --git a/blockchains/ethereum/assets/0x5c5887E55bBe41472AcDBA5FAe989788C6f7ab59/logo.png b/blockchains/ethereum/assets/0x5c5887E55bBe41472AcDBA5FAe989788C6f7ab59/logo.png new file mode 100644 index 000000000..056c09815 Binary files /dev/null and b/blockchains/ethereum/assets/0x5c5887E55bBe41472AcDBA5FAe989788C6f7ab59/logo.png differ diff --git a/blockchains/ethereum/assets/0x720c2c93F5f9A6b82226e84095558B10F399b0FA/logo.png b/blockchains/ethereum/assets/0x720c2c93F5f9A6b82226e84095558B10F399b0FA/logo.png new file mode 100644 index 000000000..78794cadb Binary files /dev/null and b/blockchains/ethereum/assets/0x720c2c93F5f9A6b82226e84095558B10F399b0FA/logo.png differ diff --git a/package.json b/package.json index 8b619f44b..9122d05bf 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "cleanup": "find ./.. -iname '.DS_Store' -type f -delete", "update:bep2": "npm run cleanup && node ./script/updateBEP2", "checksum:erc20": "npm run cleanup && ts-node ./script/erc20_to_checksum", + "format:all": "npm run cleanup && ts-node ./script/format_files_name", "gen:list": "npm run cleanup && ts-node ./script/gen_list", "gen:info": "npm run cleanup && ts-node ./script/gen_info", "resize": "npm run cleanup && ts-node ./script/resize_images", diff --git a/script/erc20_to_checksum.ts b/script/erc20_to_checksum.ts index 91036fea2..1e9181be2 100644 --- a/script/erc20_to_checksum.ts +++ b/script/erc20_to_checksum.ts @@ -1,22 +1,10 @@ -const { execSync } = require('child_process'); -const path = require('path') -const Web3 = require('web3') -const web3 = new Web3('ws://localhost:8546'); -import { ethSidechains, readDirSync } from "../src/test/helpers" +import { ethSidechains, readDirSync, getChainAssetsPath } from "../src/test/helpers" +import { checksumAssetsFolder } from './format_files_name' ethSidechains.forEach(chain => { - const assetsPath = path.resolve(`${__dirname}/../blockchains/${chain}/assets`) - const chainAddresses = readDirSync(assetsPath) + const assetsPath = getChainAssetsPath(chain) - chainAddresses.forEach(addr => { - const isChecksum = web3.utils.checkAddressChecksum(addr) - - if (!isChecksum) { - console.log(`Renaming non checksum ${addr} ...`) - const checksum = web3.utils.toChecksumAddress(addr) - const moveToChecksum = `git mv ${addr} ${checksum}-temp && git mv ${checksum}-temp ${checksum}` - const renamed = execSync(`cd ${assetsPath} && ${moveToChecksum}`, {encoding: "utf-8"}) - console.log(` Result renaming ${addr} : ${renamed}`) - } + readDirSync(assetsPath).forEach(addr => { + checksumAssetsFolder(assetsPath, addr) }) -}); \ No newline at end of file +}) \ No newline at end of file diff --git a/script/format_files_name.ts b/script/format_files_name.ts new file mode 100644 index 000000000..de8c6ba6a --- /dev/null +++ b/script/format_files_name.ts @@ -0,0 +1,46 @@ +import { + ethSidechains, + readDirSync, + getChainAssetsPath, + getChainAssetFilesList, + isChecksum, + toChecksum, + getFileName, + getFileExt, + getMoveCommandFromTo, + execRename, + logoName, + logoExtension, + logo, + getChainAssetPath +} from "../src/test/helpers" + +ethSidechains.forEach(chain => { + const assetsPath = getChainAssetsPath(chain) + const chainAddresses = readDirSync(assetsPath) + + chainAddresses.forEach(address => { + checksumAssetsFolder(assetsPath, address) + + getChainAssetFilesList(chain, address).forEach(file => { + if (getFileName(file) == logoName && getFileExt(file) !== logoExtension) { + console.log(`Renaming incorrect asset logo extension ${file} ...`) + renameAndMove(getChainAssetPath(chain, address), file, logo) + } + }) + }) +}) + +export function checksumAssetsFolder(assetsFolderPath: string, addr: string) { + if (!isChecksum(addr)) { + const checksumAddr = toChecksum(addr) + renameAndMove(assetsFolderPath, addr, checksumAddr) + } +} + +export function renameAndMove(path: string, oldName: string, newName: string) { + console.log(` Renaming file or folder at path ${path}: ${oldName} => ${newName} ...`) + const renamed = execRename(path, getMoveCommandFromTo(oldName, newName)) + console.log(` Result renaming: ${renamed}`) +} + diff --git a/src/test/helpers.ts b/src/test/helpers.ts index a5ef48662..e2a841d39 100644 --- a/src/test/helpers.ts +++ b/src/test/helpers.ts @@ -6,6 +6,7 @@ const Web3 = require('web3') const web3 = new Web3('ws://localhost:8546'); import { CoinTypeUtils, CoinType } from "@trustwallet/types"; const sizeOf = require("image-size"); +const { execSync } = require('child_process'); export const getChainName = (id: CoinType): string => CoinTypeUtils.id(id) // 60 => ethereum export const Binance = getChainName(CoinType.binance) @@ -25,11 +26,18 @@ export const Waves = getChainName(CoinType.waves) export const ethSidechains = [Ethereum, Classic, POA, TomoChain, GoChain, Wanchain, ThunderCore] -const whiteList = 'whitelist.json' -const blackList = 'blacklist.json' +export const logoName = `logo` +export const infoName = `info` + +export const logoExtension = "png" +export const jsonExtension = "json" + +const whiteList = `whitelist.${jsonExtension}` +const blackList = `blacklist.${jsonExtension}` + +export const logo = `${logoName}.${logoExtension}` +export const info = `${infoName}.${jsonExtension}` -export const logo = `logo.png` -export const info = `info.json` export const root = './' export const chainsFolderPath = './blockchains' export const pricingFolderPath = './pricing' @@ -44,9 +52,10 @@ export const maxLogoHeight = 512 export const getChainAssetPath = (chain: string, address: string) => `${getChainAssetsPath(chain)}/${address}` export const getChainAssetLogoPath = (chain: string, address: string) => `${getChainAssetsPath(chain)}/${address}/${logo}` +export const getChainAssetFilesList = (chain: string, address: string) => readDirSync(getChainAssetPath(chain, address)) export const getChainValidatorsPath = (chain: string): string => `${chainsFolderPath}/${chain}/validators` export const getChainValidatorsAssets = (chain: string): string[] => readDirSync(getChainValidatorsAssetsPath(chain)) -export const getChainValidatorsListPath = (chain: string): string => `${(getChainValidatorsPath(chain))}/list.json` +export const getChainValidatorsListPath = (chain: string): string => `${(getChainValidatorsPath(chain))}/list.${jsonExtension}` export const getChainValidatorsAssetsPath = (chain: string): string => `${getChainValidatorsPath(chain)}/assets` export const getChainValidatorAssetLogoPath = (chain: string, asset: string): string => `${getChainValidatorsAssetsPath(chain)}/${asset}/${logo}` export const getChainWhitelistPath = (chain: string): string => `${chainsFolderPath}/${chain}/${whiteList}` @@ -79,6 +88,9 @@ export const isChecksum = (address: string): boolean => web3.utils.checkAddressC export const toChecksum = (address: string): string => web3.utils.toChecksumAddress(address) export const getBinanceBEP2Symbols = async () => axios.get(`https://dex-atlantic.binance.org/api/v1/tokens?limit=1000`).then(res => res.data.map(({symbol}) => symbol)) +export const getFileName = (fileName: string): string => path.basename(fileName, path.extname(fileName)) +export const getFileExt = (name: string): string => name.slice((Math.max(0, name.lastIndexOf(".")) || Infinity) + 1) + export const isTRC10 = (string: string): boolean => (/^\d+$/.test(string)) export const isTRC20 = address => { return address.length == 34 && @@ -141,6 +153,14 @@ export const calculateAspectRatioFit = (srcWidth: number, srcHeight: number, max } } +export function getMoveCommandFromTo(oldName: string, newName: string): string { + return `git mv ${oldName} ${newName}-temp && git mv ${newName}-temp ${newName}` +} + +export function execRename(path: string, command: string) { + execSync(`cd ${path} && ${command}`, {encoding: "utf-8"}) +} + export const isValidatorHasAllKeys = (val: ValidatorModel): boolean => { return typeof val.id === "string" && typeof val.name === "string" @@ -168,6 +188,6 @@ export const rootDirAllowedFiles = [ ] export const assetFolderAllowedFiles = [ - "logo.png", - "info.json" + logo, + info ] diff --git a/src/test/index.test.ts b/src/test/index.test.ts index b54c85411..00fa87826 100644 --- a/src/test/index.test.ts +++ b/src/test/index.test.ts @@ -72,7 +72,7 @@ describe(`Test "blockchains" folder`, () => { readDirSync(assetsPath).forEach(address => { const assetFiles = getChainAssetPath(chain, address) readDirSync(assetFiles).forEach(assetFolderFile => { - expect(assetFolderAllowedFiles.indexOf(assetFolderFile),`File "${assetFolderFile}" not allowed at this path`).not.toBe(-1) + expect(assetFolderAllowedFiles.indexOf(assetFolderFile),`File "${assetFolderFile}" not allowed at this path: ${assetsPath}`).not.toBe(-1) }) }) })