Skip to content

Commit

Permalink
Pr/1874 (trustwallet#1879)
Browse files Browse the repository at this point in the history
* LikeApp Update Logo and Info

popular global platform for creating and sharing original videos.

* move

* short_description

* Check info asset keys

* f

* Try access gituhb token

* Optimised images with calibre/image-actions

* Use corret size to match agains existing file

* Access branch name

Co-authored-by: likeappofc18 <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 15, 2020
1 parent d966785 commit d6d2606
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ jobs:
npm run gen:list
git config --local user.email "[email protected]"
git config --local user.name "Trust Wallet Actions Bot"
git diff
git commit -m "Generate whitelist and blacklist" -a
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.DANGER_GITHUB_API_TOKEN }}
branch: ${GITHUB_REF}
branch: ${GITHUB_REF##*/}
18 changes: 12 additions & 6 deletions Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@ require 'find'
require 'image_size'
require 'json-schema'

assets_folder = './blockchains'
blockchains_folder = './blockchains'
allowed_extensions = ['png', 'json']
allowed_file_names = ['info', 'list', 'logo', 'whitelist', 'blacklist']

maxAssetLogoSizeInKilobyte = 100
minLogoWidth = 64
minLogoHeight = 64
maxLogoWidth = 512
maxLogoHeight = 512

# Failures
# Do not allow files in this directory
Dir.foreach(assets_folder) \
.map { |x| File.expand_path("#{assets_folder}/#{x}") } \
Dir.foreach(blockchains_folder) \
.map { |x| File.expand_path("#{blockchains_folder}/#{x}") } \
.select { |x| File.file?(x) }
.map { |x|
fail("Not allowed to have files inside blockchains folder itself. You have to add them inside specific blockchain folder as blockchain/ethereum or blockchain/binance for file: " + x)
}

Find.find(assets_folder) do |file|
Find.find(blockchains_folder) do |file|
file_extension = File.extname(file).delete('.')
file_name = File.basename(file, File.extname(file))

Expand Down Expand Up @@ -93,7 +99,7 @@ Find.find(assets_folder) do |file|
if file_extension == 'png'
image_size = ImageSize.path(file)

if image_size.width > 512 || image_size.height > 512
if image_size.width > maxLogoWidth || image_size.height > maxLogoHeight
fail("Image width or height is higher than 512px for file: " + file)
end

Expand All @@ -102,7 +108,7 @@ Find.find(assets_folder) do |file|
end

# Make sure file size only 100kb
if File.size(file).to_f / 1024 > 100
if File.size(file).to_f / 1024 > maxAssetLogoSizeInKilobyte
fail("Image should less than 100kb for file: " + file)
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "LikeApp",
"short_description": "popular global platform for creating and sharing original videos.",
"website": "",
"socials": [
{
"name": "Telegram",
"url": "https://t.me/likeapptoken",
"handle": "likeapptoken"
}

],
"explorer": "https://etherscan.io/token/0x92298Fa0647b5dcFf6eEaBAb97c9Bd81b5c30D06"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 32 additions & 12 deletions src/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,28 +218,48 @@ export const isValidatorHasAllKeys = (val: ValidatorModel): boolean => {
&& typeof val.website === "string"
}

export function isAssetInfoOK(chain: string, address: string): boolean {
if (isChainAssetInfoExistSync(chain, address)) {
const assetInfoPath = getChainAssetInfoPath(chain, address)
const isInfoOK = isValidJSON(assetInfoPath)
if (isInfoOK && isAssetInfoHasAllKeys(assetInfoPath)) {
return true
}
export function isAssetInfoOK(chain: string, address: string): [boolean, string] {
if (!isChainAssetInfoExistSync(chain, address)) {
return [true, `Info file doest exist, non eed to check`]
}

return false
const assetInfoPath = getChainAssetInfoPath(chain, address)
const isInfoJSONValid = isValidJSON(assetInfoPath)
if (!isInfoJSONValid) {
console.log(`JSON at path: ${assetInfoPath} is invalid`)
return [false, `JSON at path: ${assetInfoPath} is invalid`]
}
return true

const [hasAllKeys, msg] = isAssetInfoHasAllKeys(assetInfoPath)
if (!hasAllKeys) {
console.log({msg})
return [false, msg]
}

return [true, ``]
}

export function isAssetInfoHasAllKeys(path: string): boolean {
const info: AssetInfo = JSON.parse(readFileSync(path))
export function isAssetInfoHasAllKeys(path: string): [boolean, string] {
const info = JSON.parse(readFileSync(path))
const infoKeys = Object.keys(info)
const requiredKeys = ["explorer", "name", "website", "short_description"] // Find better solution getting AssetInfo interface keys

const hasAllKeys = requiredKeys.every(k => info.hasOwnProperty(k))

if (!hasAllKeys) {
return [false, `Info at path ${path} missing next key(s): ${getArraysDiff(requiredKeys, infoKeys)}`]
}

const isKeysCorrentType = typeof info.explorer === "string" && info.explorer != ""
&& typeof info.name === "string" && info.name != ""
&& typeof info.website === "string"
&& typeof info.short_description === "string"

return isKeysCorrentType
return [isKeysCorrentType, `Check keys ${requiredKeys} vs ${infoKeys}`]
}

function getArraysDiff(arr1 :string[], arr2: string[]): string[] {
return arr1.filter(d => !arr2.includes(d))
}

export const getFileSizeInKilobyte = (path: string): number => fs.statSync(path).size / 1000
Expand Down
5 changes: 2 additions & 3 deletions src/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ describe(`Test "blockchains" folder`, () => {
const [isLogoOK, sizeMsg] = isLogoSizeOK(assetLogoPath)
expect(isLogoOK, sizeMsg).toBe(true)

if (isChainAssetInfoExistSync(chain, address)) {
expect(isAssetInfoOK(chain, address), `Asset file info at path ${assetPath} is not OK`).toBe(true)
}
const [isInfoOK, InfoMsg] = isAssetInfoOK(chain, address)
expect(isInfoOK, InfoMsg).toBe(true)
})
})
})
Expand Down

0 comments on commit d6d2606

Please sign in to comment.