-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathgenerateMasterFile.js
More file actions
138 lines (130 loc) · 4.9 KB
/
Copy pathgenerateMasterFile.js
File metadata and controls
138 lines (130 loc) · 4.9 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const fs = require('fs');
const { print, getAddress, isAddress } = 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
});
});
}
});
// [...Object.keys(imageCache.png), ...Object.keys(imageCache.svg)].forEach(
// addr => {
// const split = addr.split('-');
// if (split.length < 2) return;
// const actualAddress = split[1].substring(0, split[1].length - 4);
// // non-evm address
// if (!isAddress(actualAddress)) {
// const isSol = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(actualAddress);
// const isDot = /^1[a-zA-Z0-9]{47}$/.test(actualAddress);
// const symbol = split[0];
// const mainURL =
// 'https://raw.githubusercontent.com/MyEtherWallet/ethereum-lists/master/src/icons/';
// if (actualAddress.length < 32) return;
// mainArr.push({
// network: isSol ? 'sol' : isDot ? 'dot' : 'sol',
// symbol: symbol,
// name: symbol,
// decimals: 0,
// contract_address: actualAddress,
// icon: `${
// imageCache.png[addr]
// ? imageCache.png[addr]
// : imageCache.svg[addr]
// ? imageCache.svg[addr]
// : ''
// }`,
// icon_png: `${
// imageCache.png[addr]
// ? imageCache.png[addr]
// : imageCache.svg[addr]
// ? imageCache.svg[addr]
// : ''
// }`,
// link: `${
// imageCache.png[addr]
// ? imageCache.png[addr]
// : imageCache.svg[addr]
// ? imageCache.svg[addr]
// : ''
// }`,
// website: ''
// });
// }
// }
// );
// mainArr.push({
// network: 'sol',
// symbol: 'SOL',
// name: 'Solana',
// decimals: 0,
// contract_address: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
// icon:
// 'https://raw.githubusercontent.com/MyEtherWallet/ethereum-lists/master/src/icons/SOL-0x570A5D26f7765Ecb712C0924E4De545B89fD43dF.png',
// icon_png:
// 'https://raw.githubusercontent.com/MyEtherWallet/ethereum-lists/master/src/icons/SOL-0x570A5D26f7765Ecb712C0924E4De545B89fD43dF.png',
// link:
// 'https://raw.githubusercontent.com/MyEtherWallet/ethereum-lists/master/src/icons/SOL-0x570A5D26f7765Ecb712C0924E4De545B89fD43dF.png',
// website: ''
// });
mainArr.push({
network: 'btc',
symbol: 'BTC',
name: 'Bitcoin',
decimals: 8,
contract_address: '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
icon:
'https://raw.githubusercontent.com/MyEtherWallet/ethereum-lists/master/src/icons/btc.svg',
icon_png:
'https://raw.githubusercontent.com/MyEtherWallet/ethereum-lists/master/src/icons/btc.png',
link:
'https://raw.githubusercontent.com/MyEtherWallet/ethereum-lists/master/src/icons/btc.svg',
website: ''
});
fs.writeFileSync('./dist/master-file.json', print(mainArr));
}
module.exports = generateMasterFile;