forked from rainbow-me/rainbow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add offline metadata script * consume offline metadata * add migration to wipe metadata from localstorage * clean up * dont use metadata img for token family icon * dont use metadata img for nfts previews * Improve fallback coin icon colors Co-authored-by: Christian Baroni <[email protected]>
- Loading branch information
1 parent
51a2a9b
commit 9733ee5
Showing
11 changed files
with
16,313 additions
and
738 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable import/no-commonjs */ | ||
const { readdirSync, writeFileSync } = require('fs'); | ||
const sizeOf = require('image-size'); | ||
const { | ||
default: makeColorMoreChill, | ||
isBlackOrWhite, | ||
} = require('make-color-more-chill'); | ||
const Vibrant = require('node-vibrant'); | ||
|
||
const start = Date.now(); | ||
|
||
const args = process.argv.slice(2); | ||
const assets_dir = args[0]; | ||
console.log('Extracting metadata...'); | ||
|
||
const getDirectories = source => | ||
readdirSync(source, { withFileTypes: true }) | ||
.filter(dirent => dirent.isDirectory()) | ||
.map(dirent => dirent.name); | ||
|
||
const tokenAddresses = getDirectories(assets_dir); | ||
let allItems = {}; | ||
const init = async () => { | ||
for (let i = 0; i < tokenAddresses.length; i++) { | ||
const address = tokenAddresses[i]; | ||
const imageUrl = `https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/${address}/logo.png`; | ||
let metadata = {}; | ||
try { | ||
const filePath = `${assets_dir}/${address}/logo.png`; | ||
const { width, height } = sizeOf(filePath); | ||
metadata.dimensions = { | ||
height, | ||
isSquare: height === width, | ||
width, | ||
}; | ||
|
||
const palette = await Vibrant.from(filePath).getPalette(); | ||
const primaryColor = palette.Vibrant.hex; | ||
const secondaryColor = palette.Muted.hex; | ||
let color = makeColorMoreChill(primaryColor); | ||
if (isBlackOrWhite(secondaryColor)) { | ||
color = makeColorMoreChill(primaryColor); | ||
} | ||
if (isBlackOrWhite(primaryColor)) { | ||
color = makeColorMoreChill(secondaryColor); | ||
} | ||
if (color) { | ||
metadata.color = color; | ||
} | ||
// eslint-disable-next-line no-empty | ||
} catch (e) { | ||
} finally { | ||
allItems[imageUrl] = metadata; | ||
} | ||
} | ||
|
||
const data = JSON.stringify(allItems); | ||
writeFileSync('tokens-metadata.json', data); | ||
|
||
const end = Date.now(); | ||
const time = (end - start) / 1000; | ||
console.log(`Processed ${tokenAddresses.length} images`); | ||
console.log(`Took ${time} seconds`); | ||
}; | ||
|
||
init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
git clone https://github.com/trustwallet/assets assets-tmp | ||
node ./scripts/extract-metadata.js assets-tmp/blockchains/ethereum/assets/ | ||
mv -f tokens-metadata.json ./src/references/meta/tokens-metadata.json | ||
rm -rf assets-tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.