add logo in hashthereum (#1508)

* add files via upload

* STK Coin (STK)

* Checksum test

* Add wrong asset naming

* Add script checking logo extension

Co-authored-by: Mykola <kolya182@gmail.com>
This commit is contained in:
xion30 2020-03-21 04:48:55 +08:00 committed by GitHub
parent 4d91cb645c
commit 5892457e09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 81 additions and 26 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -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",

View File

@ -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)
})
});
})

View File

@ -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}`)
}

View File

@ -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
]

View File

@ -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)
})
})
})