Upload EtherX Token (#1509)

* Add files via upload

* Add script to move files /assets/0x..XX.png => /asstes/0x..XX/logo.png

Co-authored-by: Mykola <3277207+kolya182@users.noreply.github.com>
Co-authored-by: Mykola <kolya182@gmail.com>
This commit is contained in:
EtherX Project 2020-03-21 05:16:45 +07:00 committed by GitHub
parent 5859208399
commit 9f4ed41dd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

View File

@ -10,6 +10,7 @@
"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",
"arrange:all": "npm run cleanup && ts-node ./script/arrange_files",
"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",

38
script/arrange_files.ts Normal file
View File

@ -0,0 +1,38 @@
import * as fs from "fs"
import {
ethSidechains,
getChainAssetPath,
getChainAssetsPath,
getFileExt,
getFileName,
isChecksum,
isPathDir,
logo,
logoExtension,
makeDirIfDoestExist,
readDirSync,
toChecksum,
} from "../src/test/helpers"
ethSidechains.forEach(chain => {
const assetsPath = getChainAssetsPath(chain)
const chainAssets = readDirSync(assetsPath)
chainAssets.forEach(async asset => {
const assetPath = getChainAssetPath(chain, asset)
const isDir = await isPathDir(assetPath)
if (!isDir) {
const assetName = getFileName(asset)
const checksum = toChecksum(assetName)
if (isChecksum(checksum) && getFileExt(asset).toLocaleLowerCase() === logoExtension) {
// Moves file like /assets/0x..XX.png => /asstes/0x..XX/logo.png
await makeDirIfDoestExist(assetsPath, checksum)
const newPath = `${assetsPath}/${checksum}/${logo}`
fs.renameSync(assetPath, newPath)
}
}
})
})

View File

@ -99,6 +99,26 @@ export const isTRC20 = address => {
isUpperCase(address) == false
}
export const isPathDir = (path: string): boolean => {
try {
return fs.lstatSync(path).isDirectory()
} catch (e) {
console.log(`Path: ${path} is not a directory with error: ${e.message}`)
return false
}
}
export const makeDirIfDoestExist = async (dirPath: string, dirName: string) => {
const path = `${dirPath}/${dirName}`
await fs.mkdir(path, {recursive: true}, (err) => {
if (err) {
console.error(`Error creating dir at path ${path} with result ${err}`)
} else {
console.log(`Created direcotry at ${path}`)
}
})
}
export const sortDesc = arr => arr.sort((a, b) => a - b)
export const getUnique = arr => Array.from(new Set(arr))
export const mapList = arr => {

View File

@ -16,6 +16,7 @@ import {
readFileSync,
isLowerCase,
isChecksum,
isPathDir,
getBinanceBEP2Symbols,
isTRC10, isTRC20,
isLogoOK,
@ -86,10 +87,13 @@ describe(`Test "blockchains" folder`, () => {
const assetsPath = getChainAssetsPath(chain)
readDirSync(assetsPath).forEach(addr => {
const checksum: boolean = isChecksum(addr)
expect(checksum, `Address ${addr} on chain ${chain} must be in checksum`).toBe(true)
const assetPath = getChainAssetPath(chain, addr)
expect(isPathDir(assetPath), `Expect directory at path: ${assetPath}`).toBe(true)
const checksum = isChecksum(addr)
expect(checksum, `Expect asset at path ${assetPath} in checksum`).toBe(true)
const lowercase: boolean = isLowerCase(addr)
const lowercase = isLowerCase(addr)
if (lowercase) {
expect(checksum, `Lowercase address ${addr} on chain ${chain} should be in checksum`).toBe(true)
}