forked from mistswapdex/default-token-list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.js
85 lines (63 loc) · 2.26 KB
/
sync.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const XLSX = require("xlsx");
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit();
const { ChainId } = require("@mistswapdex/sdk");
const fs = require("fs");
const { resolve } = require("path");
const NAME = {
[ChainId.SMARTBCH]: "smartbch",
[ChainId.SMARTBCH_AMBER]: "smartbch_amber",
};
(async () => {
try {
const book = XLSX.utils.book_new();
for (const key of Object.keys(ChainId)) {
const path = resolve(__dirname, `../tokens/${NAME[key]}.json`);
if (!fs.existsSync(path)) {
continue;
}
const tokens = require(path);
// Grab file file names of the mistswapdex/icons repo at the token path
// we can use this to see if our default list is missing icons
const { data } = await octokit.rest.repos.getContent({
owner: "mistswapdex",
repo: "icons",
path: "token",
});
const icons = data.map((data) => data.name.replace(".jpg", ""));
const json = [];
for (const token of tokens) {
const listIcon = icons.find(
(icon) => icon === token.symbol.toLowerCase()
);
// TODO: Check Figma and get icon if available
const figmaIcon = undefined;
const icon = listIcon || figmaIcon;
if ((!token.logoURI && !icon) || !icon) {
json.push({
network: NAME[key],
address: token.address,
name: token.name,
symbol: token.symbol,
logoURI: token?.logoURI || "",
});
console.log("Add to list to send to chester");
continue;
}
// Check if logoURI has correct path
if (!token.logoURI.includes("mistswapdex/icons")) {
// TODO: Automate this part...
const logoURI = `https://raw.githubusercontent.com/mistswapdex/icons/master/token/${icon}.jpg`;
console.log(`Update Logo URI for ${token.symbol} with ${logoURI}`);
} else {
console.log(`Logo URI for ${token.symbol} is correct`);
}
}
const sheet = XLSX.utils.json_to_sheet(json);
XLSX.utils.book_append_sheet(book, sheet, NAME[key]);
}
XLSX.writeFile(book, resolve(__dirname, `../generated/missing-icons.xlsx`));
} catch (error) {
console.error(error);
}
})();