mirror of
https://github.com/Instadapp/trustwallet-assets.git
synced 2024-07-29 22:37:31 +00:00
[Internal][WIP] Refactoring: smaller changes (#2827)
* Minor improvement in eth side-chain check, remove extra check. * Typo fix, Dimension. Co-authored-by: Catenocrypt <catenocrypt@users.noreply.github.com>
This commit is contained in:
parent
b48198e9a7
commit
3acdcbc251
|
@ -5,7 +5,7 @@ import {
|
||||||
chainsFolderPath,
|
chainsFolderPath,
|
||||||
getChainLogoPath,
|
getChainLogoPath,
|
||||||
calculateAspectRatioFit,
|
calculateAspectRatioFit,
|
||||||
getImageDimentions,
|
getImageDimensions,
|
||||||
getChainAssetsPath,
|
getChainAssetsPath,
|
||||||
getChainAssetLogoPath,
|
getChainAssetLogoPath,
|
||||||
isPathExistsSync,
|
isPathExistsSync,
|
||||||
|
@ -27,7 +27,7 @@ function downsize() {
|
||||||
bluebird.map(foundChains, async chain => {
|
bluebird.map(foundChains, async chain => {
|
||||||
console.log(`Resizing assets on chain ${chain}`)
|
console.log(`Resizing assets on chain ${chain}`)
|
||||||
const chainLogoPath = getChainLogoPath(chain)
|
const chainLogoPath = getChainLogoPath(chain)
|
||||||
const { width: srcWidth, heigth: srcHeight } = getImageDimentions(chainLogoPath)
|
const { width: srcWidth, heigth: srcHeight } = getImageDimensions(chainLogoPath)
|
||||||
|
|
||||||
// Check and resize if needed chain logo
|
// Check and resize if needed chain logo
|
||||||
if (isDownsizing(srcWidth, srcHeight)) {
|
if (isDownsizing(srcWidth, srcHeight)) {
|
||||||
|
@ -39,7 +39,7 @@ function downsize() {
|
||||||
if (isPathExistsSync(assetsPath)) {
|
if (isPathExistsSync(assetsPath)) {
|
||||||
bluebird.mapSeries(readDirSync(assetsPath), async asset => {
|
bluebird.mapSeries(readDirSync(assetsPath), async asset => {
|
||||||
const assetPath = getChainAssetLogoPath(chain, asset)
|
const assetPath = getChainAssetLogoPath(chain, asset)
|
||||||
const { width: srcWidth, height: srcHeight } = getImageDimentions(assetPath)
|
const { width: srcWidth, height: srcHeight } = getImageDimensions(assetPath)
|
||||||
if (isDownsizing(srcWidth, srcHeight)) {
|
if (isDownsizing(srcWidth, srcHeight)) {
|
||||||
await resize(srcWidth, srcHeight, assetPath)
|
await resize(srcWidth, srcHeight, assetPath)
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ function downsize() {
|
||||||
const validatorsList = JSON.parse(readFileSync(getChainValidatorsListPath(chain)))
|
const validatorsList = JSON.parse(readFileSync(getChainValidatorsListPath(chain)))
|
||||||
bluebird.mapSeries(validatorsList, async ({ id }) => {
|
bluebird.mapSeries(validatorsList, async ({ id }) => {
|
||||||
const path = getChainValidatorAssetLogoPath(chain, id)
|
const path = getChainValidatorAssetLogoPath(chain, id)
|
||||||
const { width: srcWidth, height: srcHeight } = getImageDimentions(path)
|
const { width: srcWidth, height: srcHeight } = getImageDimensions(path)
|
||||||
if (isDownsizing(srcWidth, srcHeight)) {
|
if (isDownsizing(srcWidth, srcHeight)) {
|
||||||
await resize(srcWidth, srcHeight, path)
|
await resize(srcWidth, srcHeight, path)
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,10 +199,10 @@ export function findCommonElementOrDuplicate(list1: string[], list2: string[]) {
|
||||||
return findDuplicate(list1.concat(list2))
|
return findDuplicate(list1.concat(list2))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getImageDimentions = (path: string) => sizeOf(path)
|
export const getImageDimensions = (path: string) => sizeOf(path)
|
||||||
|
|
||||||
export function isLogoDimentionOK(path: string): [boolean, string] {
|
export function isLogoDimensionOK(path: string): [boolean, string] {
|
||||||
const { width, height } = getImageDimentions(path)
|
const { width, height } = getImageDimensions(path)
|
||||||
if (((width >= minLogoWidth && width <= maxLogoWidth) && (height >= minLogoHeight && height <= maxLogoHeight))) {
|
if (((width >= minLogoWidth && width <= maxLogoWidth) && (height >= minLogoHeight && height <= maxLogoHeight))) {
|
||||||
return [true, '']
|
return [true, '']
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -23,7 +23,7 @@ import {
|
||||||
findDuplicate,
|
findDuplicate,
|
||||||
findCommonElementOrDuplicate,
|
findCommonElementOrDuplicate,
|
||||||
isChecksum,
|
isChecksum,
|
||||||
isLogoDimentionOK,
|
isLogoDimensionOK,
|
||||||
isLogoSizeOK,
|
isLogoSizeOK,
|
||||||
isLowerCase,
|
isLowerCase,
|
||||||
isPathDir,
|
isPathDir,
|
||||||
|
@ -58,7 +58,7 @@ describe(`Test "blockchains" folder`, () => {
|
||||||
foundChains.forEach(chain => {
|
foundChains.forEach(chain => {
|
||||||
const chainLogoPath = getChainLogoPath(chain)
|
const chainLogoPath = getChainLogoPath(chain)
|
||||||
expect(isPathExistsSync(chainLogoPath), `File missing at path "${chainLogoPath}"`).toBe(true)
|
expect(isPathExistsSync(chainLogoPath), `File missing at path "${chainLogoPath}"`).toBe(true)
|
||||||
const [isOk, msg] = isLogoDimentionOK(chainLogoPath)
|
const [isOk, msg] = isLogoDimensionOK(chainLogoPath)
|
||||||
expect(isOk, msg).toBe(true)
|
expect(isOk, msg).toBe(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -96,25 +96,21 @@ describe(`Test "blockchains" folder`, () => {
|
||||||
|
|
||||||
describe("Check Ethereum side-chain folders", () => {
|
describe("Check Ethereum side-chain folders", () => {
|
||||||
ethSidechains.forEach(chain => {
|
ethSidechains.forEach(chain => {
|
||||||
test(`Test chain ${chain} folder`, () => {
|
const assetsFolder = getChainAssetsPath(chain)
|
||||||
|
const assetsList = getChainAssetsList(chain)
|
||||||
getChainAssetsList(chain).forEach(address => {
|
test(`Test chain ${chain} folder, folder (${assetsList.length})`, () => {
|
||||||
const assetPath = getChainAssetPath(chain, address)
|
assetsList.forEach(address => {
|
||||||
|
const assetPath = `${assetsFolder}/${address}`
|
||||||
expect(isPathDir(assetPath), `Expect directory at path: ${assetPath}`).toBe(true)
|
expect(isPathDir(assetPath), `Expect directory at path: ${assetPath}`).toBe(true)
|
||||||
|
|
||||||
const checksum = isChecksum(address)
|
const checksum = isChecksum(address)
|
||||||
expect(checksum, `Expect asset at path ${assetPath} in checksum`).toBe(true)
|
expect(checksum, `Expect asset at path ${assetPath} in checksum`).toBe(true)
|
||||||
|
|
||||||
const lowercase = isLowerCase(address)
|
|
||||||
if (lowercase) {
|
|
||||||
expect(checksum, `Lowercase address ${address} on chain ${chain} should be in checksum`).toBe(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
const assetLogoPath = getChainAssetLogoPath(chain, address)
|
const assetLogoPath = getChainAssetLogoPath(chain, address)
|
||||||
expect(isPathExistsSync(assetLogoPath), `Missing file at path "${assetLogoPath}"`).toBe(true)
|
expect(isPathExistsSync(assetLogoPath), `Missing file at path "${assetLogoPath}"`).toBe(true)
|
||||||
|
|
||||||
const [isDimentionOK, dimensionMsg] = isLogoDimentionOK(assetLogoPath)
|
const [isDimensionOK, dimensionMsg] = isLogoDimensionOK(assetLogoPath)
|
||||||
expect(isDimentionOK, dimensionMsg).toBe(true)
|
expect(isDimensionOK, dimensionMsg).toBe(true)
|
||||||
|
|
||||||
const [isLogoOK, sizeMsg] = isLogoSizeOK(assetLogoPath)
|
const [isLogoOK, sizeMsg] = isLogoSizeOK(assetLogoPath)
|
||||||
expect(isLogoOK, sizeMsg).toBe(true)
|
expect(isLogoOK, sizeMsg).toBe(true)
|
||||||
|
@ -146,7 +142,7 @@ describe(`Test "blockchains" folder`, () => {
|
||||||
|
|
||||||
const assetsLogoPath = getChainAssetLogoPath(Tron, asset)
|
const assetsLogoPath = getChainAssetLogoPath(Tron, asset)
|
||||||
expect(isPathExistsSync(assetsLogoPath), `Missing file at path "${assetsLogoPath}"`).toBe(true)
|
expect(isPathExistsSync(assetsLogoPath), `Missing file at path "${assetsLogoPath}"`).toBe(true)
|
||||||
const [isOk, msg] = isLogoDimentionOK(assetsLogoPath)
|
const [isOk, msg] = isLogoDimensionOK(assetsLogoPath)
|
||||||
expect(isOk, msg).toBe(true)
|
expect(isOk, msg).toBe(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -174,7 +170,7 @@ describe(`Test "blockchains" folder`, () => {
|
||||||
const path = getChainValidatorAssetLogoPath(chain, id)
|
const path = getChainValidatorAssetLogoPath(chain, id)
|
||||||
expect(isPathExistsSync(path), `Chain ${chain} asset ${id} logo must be present at path ${path}`).toBe(true)
|
expect(isPathExistsSync(path), `Chain ${chain} asset ${id} logo must be present at path ${path}`).toBe(true)
|
||||||
|
|
||||||
const [isOk, msg] = isLogoDimentionOK(path)
|
const [isOk, msg] = isLogoDimensionOK(path)
|
||||||
expect(isOk, msg).toBe(true)
|
expect(isOk, msg).toBe(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -406,7 +402,7 @@ describe("Test blacklist and whitelist", () => {
|
||||||
// test by a single check: checking for duplicates in the concatenated list.
|
// test by a single check: checking for duplicates in the concatenated list.
|
||||||
const whiteList = JSON.parse(readFileSync(getChainWhitelistPath(chain)))
|
const whiteList = JSON.parse(readFileSync(getChainWhitelistPath(chain)))
|
||||||
const blackList = JSON.parse(readFileSync(getChainBlacklistPath(chain)))
|
const blackList = JSON.parse(readFileSync(getChainBlacklistPath(chain)))
|
||||||
test(`Blacklist and whitelist should have no common elements or duplicates`, () => {
|
test(`Blacklist and whitelist should have no common elements or duplicates (${chain})`, () => {
|
||||||
expect(findCommonElementOrDuplicate(whiteList, blackList), `Found a duplicate or common element`).toBe(null)
|
expect(findCommonElementOrDuplicate(whiteList, blackList), `Found a duplicate or common element`).toBe(null)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user