@revoke.cash/chains 42.0.0 → 44.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  Helper module for getting EVM chain info from [chainid.network](https://chainid.network/).
6
6
 
7
- Note: This package was initially created by @taylorjdawson. We forked the repository so we can control the release process with an automated script. The original package can be found [here](https://github.com/taylorjdawson/eth-chains).
7
+ Note: This package was initially created by @taylorjdawson. We forked the repository so we can control the release process with an automated script and make additional changes. The original package can be found [here](https://github.com/taylorjdawson/eth-chains).
8
8
 
9
9
  ## Installation
10
10
 
@@ -21,17 +21,7 @@ yarn add @revoke.cash/chains
21
21
  Import `chains` methods and enums:
22
22
 
23
23
  ```ts
24
- import chains, { ChainId, ChainName } from '@revoke.cash/chains'
25
- ```
26
-
27
- ### Easily get most popular chains:
28
-
29
- ```ts
30
- import { chain } from '@revoke.cash/chains'
31
-
32
- console.log(chain.ethereum.rinkeby)
33
-
34
- console.log(chain.polygon.mumbai)
24
+ import allChains, { ChainId, ChainName } from '@revoke.cash/chains'
35
25
  ```
36
26
 
37
27
  ### Chain names and ids via Enums:
@@ -46,23 +36,23 @@ console.log(ChainName.Rinkeby) // "Rinkeby"
46
36
  ### Chain by ID:
47
37
 
48
38
  ```ts
49
- chains.getById(ChainId.EthereumMainnet) // { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" }
39
+ getChainById(ChainId.EthereumMainnet) // { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" }
50
40
  // Equivalent
51
- chains.getById(1)
41
+ getChainById(1)
52
42
  ```
53
43
 
54
44
  ### Chain by Name:
55
45
 
56
46
  ```ts
57
- chains.getByName(ChainName.EthereumMainnet) // { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" }
47
+ getChainByName(ChainName.EthereumMainnet) // { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" }
58
48
  // Equivalent
59
- chains.getByName('Ethereum Mainnet')
49
+ getChainByName('Ethereum Mainnet')
60
50
  ```
61
51
 
62
52
  ### Get all Chains:
63
53
 
64
54
  ```ts
65
- const allChains = chains.all()
55
+ const chains = allChains()
66
56
  // { 1: { name: "Ethereum Mainnet", ..., "infoURL": "https://ethereum.org" }, 2: {...}}
67
57
  ```
68
58
 
@@ -70,6 +60,6 @@ const allChains = chains.all()
70
60
 
71
61
  ```ts
72
62
  import { Chain, NativeCurrency, Explorer } from '@revoke.cash/chains'
73
- const ethereum: Chain = chains.getById(ChainId.EthereumMainnet)
63
+ const ethereum: Chain = getChainById(ChainId.EthereumMainnet)
74
64
  ethereum.chain // 'ETH'
75
65
  ```
package/dist/src/build.js CHANGED
@@ -83,16 +83,19 @@ var generateEnumFile = function (chains) { return __awaiter(void 0, void 0, void
83
83
  });
84
84
  }); };
85
85
  var generateChainsFile = function () { return __awaiter(void 0, void 0, void 0, function () {
86
- var chains, chainsJs;
86
+ var initialChains, chains, chainsJs;
87
87
  return __generator(this, function (_a) {
88
88
  switch (_a.label) {
89
89
  case 0: return [4 /*yield*/, got_1.default('https://chainid.network/chains.json').json()];
90
90
  case 1:
91
+ initialChains = _a.sent();
92
+ return [4 /*yield*/, annotateIconUrls(initialChains)];
93
+ case 2:
91
94
  chains = _a.sent();
92
95
  return [4 /*yield*/, generateEnumFile(chains).catch(function () {
93
96
  console.log('Error generating enum file');
94
97
  })];
95
- case 2:
98
+ case 3:
96
99
  _a.sent();
97
100
  chainsJs = chains
98
101
  .map(function (chain) { return chain.chainId + ": " + util_1.inspect(chain, { depth: null }); })
@@ -102,4 +105,24 @@ var generateChainsFile = function () { return __awaiter(void 0, void 0, void 0,
102
105
  }
103
106
  });
104
107
  }); };
108
+ var annotateIconUrls = function (chains) { return __awaiter(void 0, void 0, void 0, function () {
109
+ return __generator(this, function (_a) {
110
+ return [2 /*return*/, Promise.all(chains.map(function (chain) { return __awaiter(void 0, void 0, void 0, function () {
111
+ var icon, iconURL;
112
+ var _a;
113
+ return __generator(this, function (_b) {
114
+ switch (_b.label) {
115
+ case 0:
116
+ if (!chain.icon)
117
+ return [2 /*return*/, chain];
118
+ return [4 /*yield*/, got_1.default("https://raw.githubusercontent.com/ethereum-lists/chains/master/_data/icons/" + chain.icon + ".json").json()];
119
+ case 1:
120
+ icon = (_b.sent())[0];
121
+ iconURL = (_a = icon === null || icon === void 0 ? void 0 : icon.url) === null || _a === void 0 ? void 0 : _a.replace('ipfs://', 'https://cloudflare-ipfs.com/ipfs/');
122
+ return [2 /*return*/, __assign(__assign({}, chain), { iconURL: iconURL })];
123
+ }
124
+ });
125
+ }); }))];
126
+ });
127
+ }); };
105
128
  generateChainsFile();