@pancakeswap/token-lists 0.0.13 → 0.0.15
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/.turbo/turbo-build.log +11 -16
- package/CHANGELOG.md +15 -0
- package/dist/{chunk-COROHIJN.mjs → chunk-DC45HQOL.mjs} +40 -2
- package/dist/{chunk-OGWZ2K32.js → chunk-YOAEDKQH.js} +42 -1
- package/dist/index.js +6 -7
- package/dist/index.mjs +1 -2
- package/dist/react.d.ts +25 -19
- package/dist/react.js +518 -70
- package/dist/react.mjs +512 -65
- package/package.json +3 -3
- package/react/getTokenList.ts +24 -43
- package/react/index.test.ts +3 -2
- package/react/index.ts +2 -1
- package/react/useFetchListCallback.ts +2 -3
- package/dist/chunk-2L3ZO4UM.mjs +0 -41
- package/dist/chunk-4TPCCB4K.js +0 -45
- package/dist/getTokenList-A3DXVBCD.js +0 -481
- package/dist/getTokenList-PEH2JP67.mjs +0 -471
package/dist/react.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var chunk4TPCCB4K_js = require('./chunk-4TPCCB4K.js');
|
|
3
|
+
var chunkYOAEDKQH_js = require('./chunk-YOAEDKQH.js');
|
|
5
4
|
var toolkit = require('@reduxjs/toolkit');
|
|
6
5
|
var jotai = require('jotai');
|
|
7
6
|
var utils = require('jotai/utils');
|
|
@@ -25,7 +24,516 @@ var acceptListUpdate = toolkit.createAction("lists/acceptListUpdate");
|
|
|
25
24
|
var rejectVersionUpdate = toolkit.createAction("lists/rejectVersionUpdate");
|
|
26
25
|
var updateListVersion = toolkit.createAction("lists/updateListVersion");
|
|
27
26
|
|
|
28
|
-
//
|
|
27
|
+
// ../utils/uriToHttp.ts
|
|
28
|
+
function uriToHttp(uri) {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
const protocol = uri.split(":")[0].toLowerCase();
|
|
31
|
+
switch (protocol) {
|
|
32
|
+
case "https":
|
|
33
|
+
return [uri];
|
|
34
|
+
case "http":
|
|
35
|
+
return [`https${uri.substring(4)}`, uri];
|
|
36
|
+
case "ipfs":
|
|
37
|
+
const hash = (_a = uri.match(/^ipfs:(\/\/)?(.*)$/i)) == null ? void 0 : _a[2];
|
|
38
|
+
return [`https://cloudflare-ipfs.com/ipfs/${hash}/`, `https://ipfs.io/ipfs/${hash}/`];
|
|
39
|
+
case "ipns":
|
|
40
|
+
const name = (_b = uri.match(/^ipns:(\/\/)?(.*)$/i)) == null ? void 0 : _b[2];
|
|
41
|
+
return [`https://cloudflare-ipfs.com/ipns/${name}/`, `https://ipfs.io/ipns/${name}/`];
|
|
42
|
+
default:
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// schema/pancakeswap.json
|
|
48
|
+
var pancakeswap_default = {
|
|
49
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
50
|
+
$id: "pancakeswap",
|
|
51
|
+
title: "PancakeSwap Token List",
|
|
52
|
+
description: "Schema for lists of tokens compatible with the PancakeSwap Interface, including Uniswap standard and PancakeSwap Aptos",
|
|
53
|
+
definitions: {
|
|
54
|
+
Version: {
|
|
55
|
+
type: "object",
|
|
56
|
+
description: "The version of the list, used in change detection",
|
|
57
|
+
examples: [
|
|
58
|
+
{
|
|
59
|
+
major: 1,
|
|
60
|
+
minor: 0,
|
|
61
|
+
patch: 0
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
properties: {
|
|
66
|
+
major: {
|
|
67
|
+
type: "integer",
|
|
68
|
+
description: "The major version of the list. Must be incremented when tokens are removed from the list or token addresses are changed.",
|
|
69
|
+
minimum: 0,
|
|
70
|
+
examples: [1, 2]
|
|
71
|
+
},
|
|
72
|
+
minor: {
|
|
73
|
+
type: "integer",
|
|
74
|
+
description: "The minor version of the list. Must be incremented when tokens are added to the list.",
|
|
75
|
+
minimum: 0,
|
|
76
|
+
examples: [0, 1]
|
|
77
|
+
},
|
|
78
|
+
patch: {
|
|
79
|
+
type: "integer",
|
|
80
|
+
description: "The patch version of the list. Must be incremented for any changes to the list.",
|
|
81
|
+
minimum: 0,
|
|
82
|
+
examples: [0, 1]
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
required: ["major", "minor", "patch"]
|
|
86
|
+
},
|
|
87
|
+
TagIdentifier: {
|
|
88
|
+
type: "string",
|
|
89
|
+
description: "The unique identifier of a tag",
|
|
90
|
+
minLength: 1,
|
|
91
|
+
maxLength: 10,
|
|
92
|
+
pattern: "^[\\w]+$",
|
|
93
|
+
examples: ["compound", "stablecoin"]
|
|
94
|
+
},
|
|
95
|
+
ExtensionIdentifier: {
|
|
96
|
+
type: "string",
|
|
97
|
+
description: "The name of a token extension property",
|
|
98
|
+
minLength: 1,
|
|
99
|
+
maxLength: 40,
|
|
100
|
+
pattern: "^[\\w]+$",
|
|
101
|
+
examples: ["color", "is_fee_on_transfer", "aliases"]
|
|
102
|
+
},
|
|
103
|
+
ExtensionMap: {
|
|
104
|
+
type: "object",
|
|
105
|
+
description: "An object containing any arbitrary or vendor-specific token metadata",
|
|
106
|
+
maxProperties: 10,
|
|
107
|
+
propertyNames: {
|
|
108
|
+
$ref: "#/definitions/ExtensionIdentifier"
|
|
109
|
+
},
|
|
110
|
+
additionalProperties: {
|
|
111
|
+
$ref: "#/definitions/ExtensionValue"
|
|
112
|
+
},
|
|
113
|
+
examples: [
|
|
114
|
+
{
|
|
115
|
+
color: "#000000",
|
|
116
|
+
is_verified_by_me: true
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"x-bridged-addresses-by-chain": {
|
|
120
|
+
"1": {
|
|
121
|
+
bridgeAddress: "0x4200000000000000000000000000000000000010",
|
|
122
|
+
tokenAddress: "0x4200000000000000000000000000000000000010"
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
ExtensionPrimitiveValue: {
|
|
129
|
+
anyOf: [
|
|
130
|
+
{
|
|
131
|
+
type: "string",
|
|
132
|
+
minLength: 1,
|
|
133
|
+
maxLength: 42,
|
|
134
|
+
examples: ["#00000"]
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
type: "boolean",
|
|
138
|
+
examples: [true]
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
type: "number",
|
|
142
|
+
examples: [15]
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
type: "null"
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
},
|
|
149
|
+
ExtensionValue: {
|
|
150
|
+
anyOf: [
|
|
151
|
+
{
|
|
152
|
+
$ref: "#/definitions/ExtensionPrimitiveValue"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
type: "object",
|
|
156
|
+
maxProperties: 10,
|
|
157
|
+
propertyNames: {
|
|
158
|
+
$ref: "#/definitions/ExtensionIdentifier"
|
|
159
|
+
},
|
|
160
|
+
additionalProperties: {
|
|
161
|
+
$ref: "#/definitions/ExtensionValueInner0"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
]
|
|
165
|
+
},
|
|
166
|
+
ExtensionValueInner0: {
|
|
167
|
+
anyOf: [
|
|
168
|
+
{
|
|
169
|
+
$ref: "#/definitions/ExtensionPrimitiveValue"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
type: "object",
|
|
173
|
+
maxProperties: 10,
|
|
174
|
+
propertyNames: {
|
|
175
|
+
$ref: "#/definitions/ExtensionIdentifier"
|
|
176
|
+
},
|
|
177
|
+
additionalProperties: {
|
|
178
|
+
$ref: "#/definitions/ExtensionValueInner1"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
},
|
|
183
|
+
ExtensionValueInner1: {
|
|
184
|
+
anyOf: [
|
|
185
|
+
{
|
|
186
|
+
$ref: "#/definitions/ExtensionPrimitiveValue"
|
|
187
|
+
}
|
|
188
|
+
]
|
|
189
|
+
},
|
|
190
|
+
TagDefinition: {
|
|
191
|
+
type: "object",
|
|
192
|
+
description: "Definition of a tag that can be associated with a token via its identifier",
|
|
193
|
+
additionalProperties: false,
|
|
194
|
+
properties: {
|
|
195
|
+
name: {
|
|
196
|
+
type: "string",
|
|
197
|
+
description: "The name of the tag",
|
|
198
|
+
pattern: "^[ \\w]+$",
|
|
199
|
+
minLength: 1,
|
|
200
|
+
maxLength: 20
|
|
201
|
+
},
|
|
202
|
+
description: {
|
|
203
|
+
type: "string",
|
|
204
|
+
description: "A user-friendly description of the tag",
|
|
205
|
+
pattern: "^[ \\w\\.,:]+$",
|
|
206
|
+
minLength: 1,
|
|
207
|
+
maxLength: 200
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
required: ["name", "description"],
|
|
211
|
+
examples: [
|
|
212
|
+
{
|
|
213
|
+
name: "Stablecoin",
|
|
214
|
+
description: "A token with value pegged to another asset"
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
TokenInfo: {
|
|
219
|
+
type: "object",
|
|
220
|
+
description: "Metadata for a single token in a token list",
|
|
221
|
+
additionalProperties: false,
|
|
222
|
+
properties: {
|
|
223
|
+
chainId: {
|
|
224
|
+
type: "integer",
|
|
225
|
+
description: "The chain ID of the Ethereum network where this token is deployed",
|
|
226
|
+
minimum: 1,
|
|
227
|
+
examples: [1, 42]
|
|
228
|
+
},
|
|
229
|
+
address: {
|
|
230
|
+
type: "string",
|
|
231
|
+
description: "The checksummed address of the token on the specified chain ID",
|
|
232
|
+
pattern: "^0x[a-fA-F0-9]{40}$",
|
|
233
|
+
examples: ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]
|
|
234
|
+
},
|
|
235
|
+
decimals: {
|
|
236
|
+
type: "integer",
|
|
237
|
+
description: "The number of decimals for the token balance",
|
|
238
|
+
minimum: 0,
|
|
239
|
+
maximum: 255,
|
|
240
|
+
examples: [18]
|
|
241
|
+
},
|
|
242
|
+
name: {
|
|
243
|
+
type: "string",
|
|
244
|
+
description: "The name of the token",
|
|
245
|
+
minLength: 1,
|
|
246
|
+
maxLength: 40,
|
|
247
|
+
pattern: "^[ \\w.'+\\-%/\xC0-\xD6\xD8-\xF6\xF8-\xFF:&\\[\\]\\(\\)]+$",
|
|
248
|
+
examples: ["USD Coin"]
|
|
249
|
+
},
|
|
250
|
+
symbol: {
|
|
251
|
+
type: "string",
|
|
252
|
+
description: "The symbol for the token; must be alphanumeric",
|
|
253
|
+
pattern: "^[a-zA-Z0-9+\\-%/$.\\s]+$",
|
|
254
|
+
minLength: 1,
|
|
255
|
+
maxLength: 20,
|
|
256
|
+
examples: ["USDC"]
|
|
257
|
+
},
|
|
258
|
+
logoURI: {
|
|
259
|
+
type: "string",
|
|
260
|
+
description: "A URI to the token logo asset; if not set, interface will attempt to find a logo based on the token address; suggest SVG or PNG of size 64x64",
|
|
261
|
+
format: "uri",
|
|
262
|
+
examples: ["ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM"]
|
|
263
|
+
},
|
|
264
|
+
tags: {
|
|
265
|
+
type: "array",
|
|
266
|
+
description: "An array of tag identifiers associated with the token; tags are defined at the list level",
|
|
267
|
+
items: {
|
|
268
|
+
$ref: "#/definitions/TagIdentifier"
|
|
269
|
+
},
|
|
270
|
+
maxItems: 10,
|
|
271
|
+
examples: ["stablecoin", "compound"]
|
|
272
|
+
},
|
|
273
|
+
extensions: {
|
|
274
|
+
$ref: "#/definitions/ExtensionMap"
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
required: ["chainId", "address", "decimals", "name", "symbol"]
|
|
278
|
+
},
|
|
279
|
+
AptosTokenInfo: {
|
|
280
|
+
type: "object",
|
|
281
|
+
description: "Metadata for a single token in a token list",
|
|
282
|
+
additionalProperties: false,
|
|
283
|
+
properties: {
|
|
284
|
+
chainId: {
|
|
285
|
+
type: "integer",
|
|
286
|
+
description: "The chain ID of the Aptos network where this token is deployed, 0 is devent",
|
|
287
|
+
minimum: 0,
|
|
288
|
+
examples: [1, 42]
|
|
289
|
+
},
|
|
290
|
+
address: {
|
|
291
|
+
type: "string",
|
|
292
|
+
description: "The address of the coin on the specified chain ID",
|
|
293
|
+
examples: ["0x1::aptos_coin::AptosCoin"]
|
|
294
|
+
},
|
|
295
|
+
decimals: {
|
|
296
|
+
type: "integer",
|
|
297
|
+
description: "The number of decimals for the token balance",
|
|
298
|
+
minimum: 0,
|
|
299
|
+
maximum: 255,
|
|
300
|
+
examples: [18]
|
|
301
|
+
},
|
|
302
|
+
name: {
|
|
303
|
+
type: "string",
|
|
304
|
+
description: "The name of the token",
|
|
305
|
+
minLength: 1,
|
|
306
|
+
maxLength: 40,
|
|
307
|
+
pattern: "^[ \\w.'+\\-%/\xC0-\xD6\xD8-\xF6\xF8-\xFF:&\\[\\]\\(\\)]+$",
|
|
308
|
+
examples: ["USD Coin"]
|
|
309
|
+
},
|
|
310
|
+
symbol: {
|
|
311
|
+
type: "string",
|
|
312
|
+
description: "The symbol for the token; must be alphanumeric",
|
|
313
|
+
pattern: "^[a-zA-Z0-9+\\-%/$.]+$",
|
|
314
|
+
minLength: 1,
|
|
315
|
+
maxLength: 20,
|
|
316
|
+
examples: ["USDC"]
|
|
317
|
+
},
|
|
318
|
+
logoURI: {
|
|
319
|
+
type: "string",
|
|
320
|
+
description: "A URI to the token logo asset; if not set, interface will attempt to find a logo based on the token address; suggest SVG or PNG of size 64x64",
|
|
321
|
+
format: "uri",
|
|
322
|
+
examples: ["ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM"]
|
|
323
|
+
},
|
|
324
|
+
tags: {
|
|
325
|
+
type: "array",
|
|
326
|
+
description: "An array of tag identifiers associated with the token; tags are defined at the list level",
|
|
327
|
+
items: {
|
|
328
|
+
$ref: "#/definitions/TagIdentifier"
|
|
329
|
+
},
|
|
330
|
+
maxItems: 10,
|
|
331
|
+
examples: ["stablecoin", "compound"]
|
|
332
|
+
},
|
|
333
|
+
extensions: {
|
|
334
|
+
$ref: "#/definitions/ExtensionMap"
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
required: ["chainId", "address", "decimals", "name", "symbol"]
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
type: "object",
|
|
341
|
+
additionalProperties: false,
|
|
342
|
+
properties: {
|
|
343
|
+
name: {
|
|
344
|
+
type: "string",
|
|
345
|
+
description: "The name of the token list",
|
|
346
|
+
minLength: 1,
|
|
347
|
+
maxLength: 30,
|
|
348
|
+
pattern: "^[\\w ]+$",
|
|
349
|
+
examples: ["My Token List"]
|
|
350
|
+
},
|
|
351
|
+
timestamp: {
|
|
352
|
+
type: "string",
|
|
353
|
+
format: "date-time",
|
|
354
|
+
description: "The timestamp of this list version; i.e. when this immutable version of the list was created"
|
|
355
|
+
},
|
|
356
|
+
schema: {
|
|
357
|
+
type: "string"
|
|
358
|
+
},
|
|
359
|
+
version: {
|
|
360
|
+
$ref: "#/definitions/Version"
|
|
361
|
+
},
|
|
362
|
+
tokens: {
|
|
363
|
+
type: "array",
|
|
364
|
+
description: "The list of tokens included in the list",
|
|
365
|
+
minItems: 1,
|
|
366
|
+
maxItems: 1e4
|
|
367
|
+
},
|
|
368
|
+
keywords: {
|
|
369
|
+
type: "array",
|
|
370
|
+
description: "Keywords associated with the contents of the list; may be used in list discoverability",
|
|
371
|
+
items: {
|
|
372
|
+
type: "string",
|
|
373
|
+
description: "A keyword to describe the contents of the list",
|
|
374
|
+
minLength: 1,
|
|
375
|
+
maxLength: 20,
|
|
376
|
+
pattern: "^[\\w ]+$",
|
|
377
|
+
examples: ["compound", "lending", "personal tokens"]
|
|
378
|
+
},
|
|
379
|
+
maxItems: 20,
|
|
380
|
+
uniqueItems: true
|
|
381
|
+
},
|
|
382
|
+
tags: {
|
|
383
|
+
type: "object",
|
|
384
|
+
description: "A mapping of tag identifiers to their name and description",
|
|
385
|
+
propertyNames: {
|
|
386
|
+
$ref: "#/definitions/TagIdentifier"
|
|
387
|
+
},
|
|
388
|
+
additionalProperties: {
|
|
389
|
+
$ref: "#/definitions/TagDefinition"
|
|
390
|
+
},
|
|
391
|
+
maxProperties: 20,
|
|
392
|
+
examples: [
|
|
393
|
+
{
|
|
394
|
+
stablecoin: {
|
|
395
|
+
name: "Stablecoin",
|
|
396
|
+
description: "A token with value pegged to another asset"
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
]
|
|
400
|
+
},
|
|
401
|
+
logoURI: {
|
|
402
|
+
type: "string",
|
|
403
|
+
description: "A URI for the logo of the token list; prefer SVG or PNG of size 256x256",
|
|
404
|
+
format: "uri",
|
|
405
|
+
examples: ["ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM"]
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
if: {
|
|
409
|
+
properties: { schema: { const: "aptos" } },
|
|
410
|
+
required: ["name", "timestamp", "version", "tokens", "schema"]
|
|
411
|
+
},
|
|
412
|
+
then: {
|
|
413
|
+
properties: {
|
|
414
|
+
tokens: {
|
|
415
|
+
items: {
|
|
416
|
+
$ref: "#/definitions/AptosTokenInfo"
|
|
417
|
+
},
|
|
418
|
+
type: "array",
|
|
419
|
+
description: "The list of tokens included in the list",
|
|
420
|
+
minItems: 1,
|
|
421
|
+
maxItems: 1e4
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
},
|
|
425
|
+
else: {
|
|
426
|
+
properties: {
|
|
427
|
+
tokens: {
|
|
428
|
+
items: {
|
|
429
|
+
$ref: "#/definitions/TokenInfo"
|
|
430
|
+
},
|
|
431
|
+
type: "array",
|
|
432
|
+
description: "The list of tokens included in the list",
|
|
433
|
+
minItems: 1,
|
|
434
|
+
maxItems: 1e4
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
required: ["name", "timestamp", "version", "tokens"]
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
// react/getTokenList.ts
|
|
442
|
+
function getTokenList(listUrl) {
|
|
443
|
+
return chunkYOAEDKQH_js.__async(this, null, function* () {
|
|
444
|
+
const urls = uriToHttp(listUrl);
|
|
445
|
+
const { default: Ajv } = yield import('ajv');
|
|
446
|
+
const validator = new Ajv({ allErrors: true }).compile(pancakeswap_default);
|
|
447
|
+
for (const [i, url] of urls.entries()) {
|
|
448
|
+
try {
|
|
449
|
+
const json = yield fetchJson(url);
|
|
450
|
+
if (!validator(json)) {
|
|
451
|
+
const preFilterErrors = validator.errors;
|
|
452
|
+
json.tokens = json.tokens.filter((token) => validator(chunkYOAEDKQH_js.__spreadProps(chunkYOAEDKQH_js.__spreadValues({}, json), { tokens: [token] })));
|
|
453
|
+
if (!validator(json)) {
|
|
454
|
+
const errors = validator.errors;
|
|
455
|
+
throw new Error(`Validation failed after filtering: ${JSON.stringify(errors)}`);
|
|
456
|
+
}
|
|
457
|
+
console.warn(`Pre-filter validation errors: ${JSON.stringify(preFilterErrors)}`);
|
|
458
|
+
}
|
|
459
|
+
return json;
|
|
460
|
+
} catch (error) {
|
|
461
|
+
if (i === urls.length - 1) {
|
|
462
|
+
throw new Error(`Failed to download list ${listUrl}`);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
throw new Error("Unrecognized list URL protocol.");
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
function fetchJson(url) {
|
|
470
|
+
return chunkYOAEDKQH_js.__async(this, null, function* () {
|
|
471
|
+
const res = yield fetch(url);
|
|
472
|
+
if (!res.ok)
|
|
473
|
+
throw new Error(`Failed to fetch: ${url}`);
|
|
474
|
+
return res.json();
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
function noop() {
|
|
478
|
+
}
|
|
479
|
+
var noopStorage = {
|
|
480
|
+
getItem: () => Promise.resolve(noop()),
|
|
481
|
+
setItem: () => Promise.resolve(noop()),
|
|
482
|
+
removeItem: () => Promise.resolve(noop())
|
|
483
|
+
};
|
|
484
|
+
var EMPTY = Symbol();
|
|
485
|
+
var createListsAtom = (storeName, reducer, initialState) => {
|
|
486
|
+
function IndexedDBStorage(dbName) {
|
|
487
|
+
if (typeof window !== "undefined") {
|
|
488
|
+
const db = localForage__default.default.createInstance({
|
|
489
|
+
name: dbName,
|
|
490
|
+
storeName
|
|
491
|
+
});
|
|
492
|
+
return {
|
|
493
|
+
getItem: (key) => chunkYOAEDKQH_js.__async(this, null, function* () {
|
|
494
|
+
const value = yield db.getItem(key);
|
|
495
|
+
if (value) {
|
|
496
|
+
return value;
|
|
497
|
+
}
|
|
498
|
+
return initialState;
|
|
499
|
+
}),
|
|
500
|
+
setItem: (k, v) => chunkYOAEDKQH_js.__async(this, null, function* () {
|
|
501
|
+
if (v === EMPTY)
|
|
502
|
+
return;
|
|
503
|
+
yield db.setItem(k, v);
|
|
504
|
+
}),
|
|
505
|
+
removeItem: db.removeItem
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
return noopStorage;
|
|
509
|
+
}
|
|
510
|
+
const listsStorageAtom = utils.atomWithStorage("lists", EMPTY, IndexedDBStorage("lists"));
|
|
511
|
+
const defaultStateAtom = jotai.atom(
|
|
512
|
+
(get) => {
|
|
513
|
+
const value = get(utils.loadable(listsStorageAtom));
|
|
514
|
+
if (value.state === "hasData" && value.data !== EMPTY) {
|
|
515
|
+
return value.data;
|
|
516
|
+
}
|
|
517
|
+
return initialState;
|
|
518
|
+
},
|
|
519
|
+
(get, set, action) => chunkYOAEDKQH_js.__async(void 0, null, function* () {
|
|
520
|
+
set(listsStorageAtom, reducer(yield get(defaultStateAtom), action));
|
|
521
|
+
})
|
|
522
|
+
);
|
|
523
|
+
const isReadyAtom = utils.loadable(listsStorageAtom);
|
|
524
|
+
function useListState() {
|
|
525
|
+
return jotai.useAtom(defaultStateAtom);
|
|
526
|
+
}
|
|
527
|
+
function useListStateReady() {
|
|
528
|
+
const value = jotai.useAtomValue(isReadyAtom);
|
|
529
|
+
return value.state === "hasData" && value.data !== EMPTY;
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
listsAtom: defaultStateAtom,
|
|
533
|
+
useListStateReady,
|
|
534
|
+
useListState
|
|
535
|
+
};
|
|
536
|
+
};
|
|
29
537
|
var NEW_LIST_STATE = {
|
|
30
538
|
error: null,
|
|
31
539
|
current: null,
|
|
@@ -49,11 +557,11 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
49
557
|
const current = (_a = state.byUrl[url]) == null ? void 0 : _a.current;
|
|
50
558
|
const loadingRequestId = (_b = state.byUrl[url]) == null ? void 0 : _b.loadingRequestId;
|
|
51
559
|
if (current) {
|
|
52
|
-
const upgradeType =
|
|
560
|
+
const upgradeType = chunkYOAEDKQH_js.getVersionUpgrade(current.version, tokenList.version);
|
|
53
561
|
if (upgradeType === 0 /* NONE */)
|
|
54
562
|
return;
|
|
55
563
|
if (loadingRequestId === null || loadingRequestId === requestId) {
|
|
56
|
-
state.byUrl[url] =
|
|
564
|
+
state.byUrl[url] = chunkYOAEDKQH_js.__spreadProps(chunkYOAEDKQH_js.__spreadValues({}, state.byUrl[url]), {
|
|
57
565
|
loadingRequestId: null,
|
|
58
566
|
error: null,
|
|
59
567
|
current,
|
|
@@ -64,7 +572,7 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
64
572
|
if (DEFAULT_ACTIVE_LIST_URLS.includes(url) && state.activeListUrls && !state.activeListUrls.includes(url)) {
|
|
65
573
|
state.activeListUrls.push(url);
|
|
66
574
|
}
|
|
67
|
-
state.byUrl[url] =
|
|
575
|
+
state.byUrl[url] = chunkYOAEDKQH_js.__spreadProps(chunkYOAEDKQH_js.__spreadValues({}, state.byUrl[url]), {
|
|
68
576
|
loadingRequestId: null,
|
|
69
577
|
error: null,
|
|
70
578
|
current: tokenList,
|
|
@@ -76,7 +584,7 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
76
584
|
if (((_a = state.byUrl[url]) == null ? void 0 : _a.loadingRequestId) !== requestId) {
|
|
77
585
|
return;
|
|
78
586
|
}
|
|
79
|
-
state.byUrl[url] =
|
|
587
|
+
state.byUrl[url] = chunkYOAEDKQH_js.__spreadProps(chunkYOAEDKQH_js.__spreadValues({}, state.byUrl[url]), {
|
|
80
588
|
loadingRequestId: null,
|
|
81
589
|
error: errorMessage,
|
|
82
590
|
current: null,
|
|
@@ -112,7 +620,7 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
112
620
|
if (!((_a = state.byUrl[url]) == null ? void 0 : _a.pendingUpdate)) {
|
|
113
621
|
throw new Error("accept list update called without pending update");
|
|
114
622
|
}
|
|
115
|
-
state.byUrl[url] =
|
|
623
|
+
state.byUrl[url] = chunkYOAEDKQH_js.__spreadProps(chunkYOAEDKQH_js.__spreadValues({}, state.byUrl[url]), {
|
|
116
624
|
pendingUpdate: null,
|
|
117
625
|
current: state.byUrl[url].pendingUpdate
|
|
118
626
|
});
|
|
@@ -149,74 +657,13 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
149
657
|
}
|
|
150
658
|
})
|
|
151
659
|
);
|
|
152
|
-
function noop() {
|
|
153
|
-
}
|
|
154
|
-
var noopStorage = {
|
|
155
|
-
getItem: () => Promise.resolve(noop()),
|
|
156
|
-
setItem: () => Promise.resolve(noop()),
|
|
157
|
-
removeItem: () => Promise.resolve(noop())
|
|
158
|
-
};
|
|
159
|
-
var EMPTY = Symbol();
|
|
160
|
-
var createListsAtom = (storeName, reducer, initialState) => {
|
|
161
|
-
function IndexedDBStorage(dbName) {
|
|
162
|
-
if (typeof window !== "undefined") {
|
|
163
|
-
const db = localForage__default.default.createInstance({
|
|
164
|
-
name: dbName,
|
|
165
|
-
storeName
|
|
166
|
-
});
|
|
167
|
-
return {
|
|
168
|
-
getItem: (key) => chunk4TPCCB4K_js.__async(this, null, function* () {
|
|
169
|
-
const value = yield db.getItem(key);
|
|
170
|
-
if (value) {
|
|
171
|
-
return value;
|
|
172
|
-
}
|
|
173
|
-
return initialState;
|
|
174
|
-
}),
|
|
175
|
-
setItem: (k, v) => chunk4TPCCB4K_js.__async(this, null, function* () {
|
|
176
|
-
if (v === EMPTY)
|
|
177
|
-
return;
|
|
178
|
-
yield db.setItem(k, v);
|
|
179
|
-
}),
|
|
180
|
-
removeItem: db.removeItem
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
return noopStorage;
|
|
184
|
-
}
|
|
185
|
-
const listsStorageAtom = utils.atomWithStorage("lists", EMPTY, IndexedDBStorage("lists"));
|
|
186
|
-
const defaultStateAtom = jotai.atom(
|
|
187
|
-
(get) => {
|
|
188
|
-
const value = get(utils.loadable(listsStorageAtom));
|
|
189
|
-
if (value.state === "hasData" && value.data !== EMPTY) {
|
|
190
|
-
return value.data;
|
|
191
|
-
}
|
|
192
|
-
return initialState;
|
|
193
|
-
},
|
|
194
|
-
(get, set, action) => chunk4TPCCB4K_js.__async(void 0, null, function* () {
|
|
195
|
-
set(listsStorageAtom, reducer(yield get(defaultStateAtom), action));
|
|
196
|
-
})
|
|
197
|
-
);
|
|
198
|
-
const isReadyAtom = utils.loadable(listsStorageAtom);
|
|
199
|
-
function useListState() {
|
|
200
|
-
return jotai.useAtom(defaultStateAtom);
|
|
201
|
-
}
|
|
202
|
-
function useListStateReady() {
|
|
203
|
-
const value = jotai.useAtomValue(isReadyAtom);
|
|
204
|
-
return value.state === "hasData" && value.data !== EMPTY;
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
listsAtom: defaultStateAtom,
|
|
208
|
-
useListStateReady,
|
|
209
|
-
useListState
|
|
210
|
-
};
|
|
211
|
-
};
|
|
212
660
|
function useFetchListCallback(dispatch) {
|
|
213
661
|
return react.useCallback(
|
|
214
|
-
(listUrl, sendDispatch = true) =>
|
|
662
|
+
(listUrl, sendDispatch = true) => chunkYOAEDKQH_js.__async(this, null, function* () {
|
|
215
663
|
const requestId = toolkit.nanoid();
|
|
216
664
|
if (sendDispatch) {
|
|
217
665
|
dispatch(fetchTokenList.pending({ requestId, url: listUrl }));
|
|
218
666
|
}
|
|
219
|
-
const getTokenList = (yield import('./getTokenList-A3DXVBCD.js')).default;
|
|
220
667
|
return getTokenList(listUrl).then((tokenList) => {
|
|
221
668
|
if (sendDispatch) {
|
|
222
669
|
dispatch(fetchTokenList.fulfilled({ url: listUrl, tokenList, requestId }));
|
|
@@ -243,6 +690,7 @@ exports.createTokenListReducer = createTokenListReducer;
|
|
|
243
690
|
exports.disableList = disableList;
|
|
244
691
|
exports.enableList = enableList;
|
|
245
692
|
exports.fetchTokenList = fetchTokenList;
|
|
693
|
+
exports.getTokenList = getTokenList;
|
|
246
694
|
exports.rejectVersionUpdate = rejectVersionUpdate;
|
|
247
695
|
exports.removeList = removeList;
|
|
248
696
|
exports.updateListVersion = updateListVersion;
|