forked from MyEtherWallet/ethereum-lists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateMasterFile.js
61 lines (57 loc) · 2.04 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
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)}`) &&
img.includes('.png')
);
});
const matchedImage = images.find(img => {
return (
img.includes(`${utils.toChecksumAddress(item.address)}`) &&
img.includes('.svg')
);
});
mainArr.push({
network: folderName,
symbol: item.symbol,
name: item.name,
decimals: item.decimals,
contract_address: utils.toChecksumAddress(item.address),
icon: !!matchedImage
? `${ICON_LINK}${matchedImage}`
: !!matchedImagePng
? `${ICON_LINK}${matchedImagePng}`
: '',
icon_png: !!matchedImagePng ? `${ICON_LINK}${matchedImagePng}` : '',
link: `${CONTRACT_LINK}${folderName}/${utils.toChecksumAddress(
item.address
)}.json`,
website: item.website
});
});
}
});
fs.writeFileSync('./dist/master-file.json', JSON.stringify(mainArr));
}
module.exports = generateMasterFile;