forked from MyEtherWallet/ethereum-lists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateMasterFile.js
62 lines (57 loc) · 2.15 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const fs = require('fs');
const { print, getAddress } = require('./utils');
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);
const images = fs.readdirSync(IMG_SRC);
const imageCache = { png: {}, svg: {} };
images.forEach(img => {
let addr = getAddress(img);
if (img.includes('.png') && !imageCache.png[addr])
imageCache.png[addr] = `${ICON_LINK}${img}`;
else if (img.includes('.svg') && !imageCache.svg[addr])
imageCache.svg[addr] = `${ICON_LINK}${img}`;
else if (!img.includes('.png') && !img.includes('.svg'))
console.log('\nBad File Type:\n%s', img);
});
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) {
trimmedOffBurner.forEach(item => {
const address = utils.toChecksumAddress(item.address);
const matchedImagePng = imageCache.png[address];
const matchedImage = imageCache.svg[address];
mainArr.push({
network: folderName,
symbol: item.symbol,
name: item.name,
decimals: item.decimals,
contract_address: address,
icon: !!matchedImage
? matchedImage
: !!matchedImagePng
? matchedImagePng
: '',
icon_png: !!matchedImagePng ? matchedImagePng : '',
link: `${CONTRACT_LINK}${folderName}/${address}.json`,
website: item.website
});
});
}
});
fs.writeFileSync('./dist/master-file.json', print(mainArr));
}
module.exports = generateMasterFile;