forked from MyEtherWallet/ethereum-lists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateMasterFile.js
45 lines (41 loc) · 1.85 KB
/
generateMasterFile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const fs = require('fs');
const utils = require('web3').utils;
const MAIN_SRC = './dist/tokens';
const IMG_SRC = './src/icons';
const ICON_LINK = 'https://raw.githubusercontent.com/MyEtherWallet/ethereum-lists/master/src/icons/'
const CONTRACT_LINK = 'https://raw.githubusercontent.com/MyEtherWallet/ethereum-lists/master/src/tokens/'
function generateMasterFile() {
const mainArr = [];
const folderNames = fs.readdirSync(MAIN_SRC);
folderNames.forEach(folderName => {
const distFiles = fs.readdirSync(`${MAIN_SRC}/${folderName}`);
const readFile = JSON.parse(fs.readFileSync(`${MAIN_SRC}/${folderName}/${distFiles[0]}`, 'utf8'));
const trimmedOffBurner = readFile.filter(item => {
return item.address !== "0x0000000000000000000000000000000000000000";
})
if (trimmedOffBurner.length > 0) {
const images = fs.readdirSync(IMG_SRC);
trimmedOffBurner.forEach(item => {
const matchedImagePng = images.find(img => {
return img.includes(`${utils.toChecksumAddress(item.address).toLowerCase()}`) && img.includes('.png')
})
const matchedImage = images.find(img => {
return img.includes(`${utils.toChecksumAddress(item.address).toLowerCase()}`) && img.includes('.svg')
})
mainArr.push({
network: folderName,
contract_address: utils.toChecksumAddress(item.address).toLowerCase(),
icon: !!matchedImage ? `${ICON_LINK}${matchedImage}` : !!matchedImagePng ? `${ICON_LINK}${matchedImagePng}` : '',
icon_png: !!matchedImagePng ? `${ICON_LINK}${matchedImagePng}` : '',
link: `${CONTRACT_LINK}${folderName}/${utils.toChecksumAddress(item.address).toLowerCase()}.json`,
website: item.website
})
})
}
})
fs.writeFileSync(
'./dist/master-file.json',
JSON.stringify(mainArr)
);
}
module.exports = generateMasterFile;