forked from MyEtherWallet/ethereum-lists
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerateMasterFile.js
46 lines (42 loc) · 1.61 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
46
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).sort();
folderNames.forEach(folderName => {
const distFiles = fs.readdirSync(`${MAIN_SRC}/${folderName}`).sort();
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).sort();
trimmedOffBurner.forEach(item => {
const matchedImage = images.find(img => {
return img.includes(
`${utils.toChecksumAddress(item.address).toLowerCase()}`
);
});
mainArr.push({
network: folderName,
contract_address: utils.toChecksumAddress(item.address).toLowerCase(),
icon: !!matchedImage ? `${ICON_LINK}${matchedImage}` : '',
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;