@pancakeswap/token-lists 0.0.17 → 0.1.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/.turbo/turbo-build.log +11 -11
- package/CHANGELOG.md +12 -0
- package/dist/{chunk-DC45HQOL.mjs → chunk-UUVLERWJ.mjs} +1 -60
- package/dist/{chunk-YOAEDKQH.js → chunk-Y2NTTLTJ.js} +0 -62
- package/dist/index.js +63 -15
- package/dist/index.mjs +62 -1
- package/dist/react.d.ts +32 -9
- package/dist/react.js +223 -88
- package/dist/react.mjs +212 -81
- package/package.json +4 -3
- package/react/actions.ts +11 -0
- package/react/getTokenList.ts +2 -1
- package/react/index.test.ts +3 -0
- package/react/lists.ts +145 -27
- package/react/reducer.ts +34 -53
- package/react/reducerHelpers.ts +111 -0
- package/schema/pancakeswap.json +9 -9
package/dist/react.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkY2NTTLTJ_js = require('./chunk-Y2NTTLTJ.js');
|
|
4
4
|
var toolkit = require('@reduxjs/toolkit');
|
|
5
5
|
var jotai = require('jotai');
|
|
6
6
|
var utils = require('jotai/utils');
|
|
7
7
|
var localForage = require('localforage');
|
|
8
|
+
var debounce = require('lodash/debounce');
|
|
8
9
|
var react = require('react');
|
|
9
10
|
|
|
10
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
12
|
|
|
12
13
|
var localForage__default = /*#__PURE__*/_interopDefault(localForage);
|
|
14
|
+
var debounce__default = /*#__PURE__*/_interopDefault(debounce);
|
|
13
15
|
|
|
14
16
|
var fetchTokenList = {
|
|
15
17
|
pending: toolkit.createAction("lists/fetchTokenList/pending"),
|
|
@@ -23,6 +25,11 @@ var disableList = toolkit.createAction("lists/disableList");
|
|
|
23
25
|
var acceptListUpdate = toolkit.createAction("lists/acceptListUpdate");
|
|
24
26
|
var rejectVersionUpdate = toolkit.createAction("lists/rejectVersionUpdate");
|
|
25
27
|
var updateListVersion = toolkit.createAction("lists/updateListVersion");
|
|
28
|
+
var batchFetchTokenListPending = toolkit.createAction(
|
|
29
|
+
"lists/batchFetchTokenList/pending"
|
|
30
|
+
);
|
|
31
|
+
var batchFetchTokenListFulfilled = toolkit.createAction("lists/batchFetchTokenList/fulfilled");
|
|
32
|
+
var batchFetchTokenListRejected = toolkit.createAction("lists/batchFetchTokenList/rejected");
|
|
26
33
|
|
|
27
34
|
// ../utils/uriToHttp.ts
|
|
28
35
|
function uriToHttp(uri) {
|
|
@@ -58,7 +65,7 @@ var pancakeswap_default = {
|
|
|
58
65
|
{
|
|
59
66
|
major: 1,
|
|
60
67
|
minor: 0,
|
|
61
|
-
patch:
|
|
68
|
+
patch: 1
|
|
62
69
|
}
|
|
63
70
|
],
|
|
64
71
|
additionalProperties: false,
|
|
@@ -243,17 +250,17 @@ var pancakeswap_default = {
|
|
|
243
250
|
type: "string",
|
|
244
251
|
description: "The name of the token",
|
|
245
252
|
minLength: 1,
|
|
246
|
-
maxLength:
|
|
247
|
-
pattern: "^[ \\w.'
|
|
248
|
-
examples: ["USD Coin"]
|
|
253
|
+
maxLength: 60,
|
|
254
|
+
pattern: "^[ \\w.'+\\-%/,\\$\xC0-\xD6\xD8-\xF6\xF8-\xFF:&\\[\\]\\(\\)\\u4e00-\\u9fa5]+$",
|
|
255
|
+
examples: ["USD Coin", "\u5E01\u5B89\u5E01"]
|
|
249
256
|
},
|
|
250
257
|
symbol: {
|
|
251
258
|
type: "string",
|
|
252
259
|
description: "The symbol for the token; must be alphanumeric",
|
|
253
|
-
pattern: "^[a-zA-Z0-9+\\-%/$.\\
|
|
260
|
+
pattern: "^[a-zA-Z0-9+\\-%/$.\\s_\\u4e00-\\u9fa5]+$",
|
|
254
261
|
minLength: 1,
|
|
255
262
|
maxLength: 20,
|
|
256
|
-
examples: ["USDC"]
|
|
263
|
+
examples: ["USDC", "\u5E01\u5B89"]
|
|
257
264
|
},
|
|
258
265
|
logoURI: {
|
|
259
266
|
type: "string",
|
|
@@ -303,14 +310,14 @@ var pancakeswap_default = {
|
|
|
303
310
|
type: "string",
|
|
304
311
|
description: "The name of the token",
|
|
305
312
|
minLength: 1,
|
|
306
|
-
maxLength:
|
|
307
|
-
pattern: "^[ \\w.'
|
|
313
|
+
maxLength: 60,
|
|
314
|
+
pattern: "^[ \\w.'+\\-%/,\\$\xC0-\xD6\xD8-\xF6\xF8-\xFF:&\\[\\]\\(\\)]+$",
|
|
308
315
|
examples: ["USD Coin"]
|
|
309
316
|
},
|
|
310
317
|
symbol: {
|
|
311
318
|
type: "string",
|
|
312
319
|
description: "The symbol for the token; must be alphanumeric",
|
|
313
|
-
pattern: "^[a-zA-Z0-9+\\-%/$.]+$",
|
|
320
|
+
pattern: "^[a-zA-Z0-9+\\-%/$._]+$",
|
|
314
321
|
minLength: 1,
|
|
315
322
|
maxLength: 20,
|
|
316
323
|
examples: ["USDC"]
|
|
@@ -440,7 +447,7 @@ var pancakeswap_default = {
|
|
|
440
447
|
|
|
441
448
|
// react/getTokenList.ts
|
|
442
449
|
function getTokenList(listUrl) {
|
|
443
|
-
return
|
|
450
|
+
return chunkY2NTTLTJ_js.__async(this, null, function* () {
|
|
444
451
|
const urls = uriToHttp(listUrl);
|
|
445
452
|
const { default: Ajv } = yield import('ajv');
|
|
446
453
|
const validator = new Ajv({ allErrors: true }).compile(pancakeswap_default);
|
|
@@ -449,15 +456,16 @@ function getTokenList(listUrl) {
|
|
|
449
456
|
const json = yield fetchJson(url);
|
|
450
457
|
if (!validator(json)) {
|
|
451
458
|
const preFilterErrors = validator.errors;
|
|
452
|
-
json.tokens = json.tokens.filter((token) => validator(
|
|
459
|
+
json.tokens = json.tokens.filter((token) => validator(chunkY2NTTLTJ_js.__spreadProps(chunkY2NTTLTJ_js.__spreadValues({}, json), { tokens: [token] })));
|
|
453
460
|
if (!validator(json)) {
|
|
454
|
-
const errors = validator
|
|
461
|
+
const { errors } = validator;
|
|
455
462
|
throw new Error(`Validation failed after filtering: ${JSON.stringify(errors)}`);
|
|
456
463
|
}
|
|
457
464
|
console.warn(`Pre-filter validation errors: ${JSON.stringify(preFilterErrors)}`);
|
|
458
465
|
}
|
|
459
466
|
return json;
|
|
460
467
|
} catch (error) {
|
|
468
|
+
console.error(`Failed to download or validate list from ${url}:`, error);
|
|
461
469
|
return void 0;
|
|
462
470
|
}
|
|
463
471
|
}
|
|
@@ -465,7 +473,7 @@ function getTokenList(listUrl) {
|
|
|
465
473
|
});
|
|
466
474
|
}
|
|
467
475
|
function fetchJson(url) {
|
|
468
|
-
return
|
|
476
|
+
return chunkY2NTTLTJ_js.__async(this, null, function* () {
|
|
469
477
|
const res = yield fetch(url);
|
|
470
478
|
if (!res.ok)
|
|
471
479
|
throw new Error(`Failed to fetch: ${url}`);
|
|
@@ -509,75 +517,224 @@ var createListsAtom = (storeName, reducer, initialState) => {
|
|
|
509
517
|
name: dbName,
|
|
510
518
|
storeName
|
|
511
519
|
});
|
|
520
|
+
const mem = /* @__PURE__ */ new Map();
|
|
521
|
+
const debouncedSetItem = debounce__default.default((k, v) => chunkY2NTTLTJ_js.__async(this, null, function* () {
|
|
522
|
+
db.setItem(k, v);
|
|
523
|
+
}), 300);
|
|
512
524
|
return {
|
|
513
|
-
getItem: (key) =>
|
|
525
|
+
getItem: (key) => chunkY2NTTLTJ_js.__async(this, null, function* () {
|
|
526
|
+
if (mem.has(key)) {
|
|
527
|
+
return mem.get(key);
|
|
528
|
+
}
|
|
514
529
|
const value = yield db.getItem(key);
|
|
515
530
|
if (value) {
|
|
516
531
|
return value;
|
|
517
532
|
}
|
|
518
|
-
return
|
|
533
|
+
return void 0;
|
|
519
534
|
}),
|
|
520
|
-
setItem: (k, v) =>
|
|
535
|
+
setItem: (k, v) => chunkY2NTTLTJ_js.__async(this, null, function* () {
|
|
521
536
|
if (v === EMPTY)
|
|
522
537
|
return;
|
|
523
|
-
|
|
538
|
+
mem.set(k, v);
|
|
539
|
+
debouncedSetItem(k, v);
|
|
524
540
|
}),
|
|
525
541
|
removeItem: db.removeItem
|
|
526
542
|
};
|
|
527
543
|
}
|
|
528
544
|
return noopStorage;
|
|
529
545
|
}
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
if (value.state === "hasData" && value.data !== EMPTY) {
|
|
535
|
-
return value.data;
|
|
536
|
-
}
|
|
537
|
-
return initialState;
|
|
538
|
-
},
|
|
539
|
-
(get, set, action) => chunkYOAEDKQH_js.__async(void 0, null, function* () {
|
|
540
|
-
set(listsStorageAtom, reducer(yield get(defaultStateAtom), action));
|
|
541
|
-
})
|
|
546
|
+
const tokenListsStorageAtom = utils.atomWithStorage(
|
|
547
|
+
"tokenLists",
|
|
548
|
+
EMPTY,
|
|
549
|
+
IndexedDBStorage("tokenLists")
|
|
542
550
|
);
|
|
543
|
-
const
|
|
551
|
+
const memoryStateAtom = jotai.atom(initialState);
|
|
552
|
+
const listStateAtom = jotai.atom((get) => {
|
|
553
|
+
const memoryState = get(memoryStateAtom);
|
|
554
|
+
const value = get(utils.loadable(tokenListsStorageAtom));
|
|
555
|
+
if (value.state === "hasData" && value.data && value.data !== EMPTY) {
|
|
556
|
+
const storedTokenLists = value.data;
|
|
557
|
+
const reconstructedState = chunkY2NTTLTJ_js.__spreadValues({}, memoryState);
|
|
558
|
+
const updatedByUrl = chunkY2NTTLTJ_js.__spreadValues({}, reconstructedState.byUrl);
|
|
559
|
+
Object.keys(storedTokenLists).forEach((url) => {
|
|
560
|
+
if (storedTokenLists[url]) {
|
|
561
|
+
updatedByUrl[url] = chunkY2NTTLTJ_js.__spreadProps(chunkY2NTTLTJ_js.__spreadValues({}, updatedByUrl[url]), {
|
|
562
|
+
current: storedTokenLists[url]
|
|
563
|
+
// Keep existing memory state for loading, error, pendingUpdate
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
reconstructedState.byUrl = updatedByUrl;
|
|
568
|
+
return reconstructedState;
|
|
569
|
+
}
|
|
570
|
+
return memoryState;
|
|
571
|
+
});
|
|
572
|
+
const updateListStateAtom = jotai.atom(null, (get, set, action) => chunkY2NTTLTJ_js.__async(void 0, null, function* () {
|
|
573
|
+
const currentMemoryState = get(memoryStateAtom);
|
|
574
|
+
const newState = reducer(currentMemoryState, action);
|
|
575
|
+
set(memoryStateAtom, chunkY2NTTLTJ_js.__spreadValues({}, newState));
|
|
576
|
+
const tokenListsToStore = {};
|
|
577
|
+
Object.keys(newState.byUrl).forEach((url) => {
|
|
578
|
+
var _a;
|
|
579
|
+
if ((_a = newState.byUrl[url]) == null ? void 0 : _a.current) {
|
|
580
|
+
tokenListsToStore[url] = newState.byUrl[url].current;
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
set(tokenListsStorageAtom, tokenListsToStore);
|
|
584
|
+
}));
|
|
585
|
+
const isReadyAtom = utils.loadable(tokenListsStorageAtom);
|
|
544
586
|
const tokenAtom = utils.atomFamily(
|
|
545
|
-
(key) => jotai.atom((get) => findTokenByAddress(get(
|
|
587
|
+
(key) => jotai.atom((get) => findTokenByAddress(get(listStateAtom), key.chainId, key.address))
|
|
546
588
|
);
|
|
547
589
|
const tokenBySymbolAtom = utils.atomFamily(
|
|
548
|
-
(key) => jotai.atom((get) => findTokenBySymbol(get(
|
|
590
|
+
(key) => jotai.atom((get) => findTokenBySymbol(get(listStateAtom), key.chainId, key.symbol))
|
|
549
591
|
);
|
|
550
|
-
const fetchListAtom = jotai.atom(null, (get, set, url) =>
|
|
551
|
-
const state = get(
|
|
592
|
+
const fetchListAtom = jotai.atom(null, (get, set, url) => chunkY2NTTLTJ_js.__async(void 0, null, function* () {
|
|
593
|
+
const state = get(listStateAtom);
|
|
552
594
|
const listState = state.byUrl[url];
|
|
553
595
|
if ((listState == null ? void 0 : listState.current) || (listState == null ? void 0 : listState.loadingRequestId)) {
|
|
554
596
|
return;
|
|
555
597
|
}
|
|
556
598
|
const requestId = toolkit.nanoid();
|
|
557
|
-
set(
|
|
599
|
+
set(updateListStateAtom, fetchTokenList.pending({ url, requestId }));
|
|
558
600
|
try {
|
|
559
601
|
const tokenList = yield getTokenList(url);
|
|
560
|
-
set(
|
|
602
|
+
set(updateListStateAtom, fetchTokenList.fulfilled({ url, tokenList, requestId }));
|
|
561
603
|
} catch (error) {
|
|
562
|
-
set(
|
|
604
|
+
set(updateListStateAtom, fetchTokenList.rejected({ url, requestId, errorMessage: error.message }));
|
|
605
|
+
}
|
|
606
|
+
}));
|
|
607
|
+
const fetchListBatchAtom = jotai.atom(null, (get, set, urls) => chunkY2NTTLTJ_js.__async(void 0, null, function* () {
|
|
608
|
+
const state = get(listStateAtom);
|
|
609
|
+
const urlsToFetch = urls.filter((url) => {
|
|
610
|
+
const listState = state.byUrl[url];
|
|
611
|
+
return !(listState == null ? void 0 : listState.current) && !(listState == null ? void 0 : listState.loadingRequestId);
|
|
612
|
+
});
|
|
613
|
+
if (urlsToFetch.length === 0) {
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
const requestId = toolkit.nanoid();
|
|
617
|
+
set(updateListStateAtom, batchFetchTokenListPending({ urls: urlsToFetch, requestId }));
|
|
618
|
+
try {
|
|
619
|
+
const results = yield Promise.allSettled(
|
|
620
|
+
urlsToFetch.map((url) => chunkY2NTTLTJ_js.__async(void 0, null, function* () {
|
|
621
|
+
const tokenList = yield getTokenList(url);
|
|
622
|
+
return { url, tokenList, requestId };
|
|
623
|
+
}))
|
|
624
|
+
);
|
|
625
|
+
const fulfilled = [];
|
|
626
|
+
const rejected = [];
|
|
627
|
+
results.forEach((result, index) => {
|
|
628
|
+
var _a;
|
|
629
|
+
const url = urlsToFetch[index];
|
|
630
|
+
if (result.status === "fulfilled") {
|
|
631
|
+
fulfilled.push(result.value);
|
|
632
|
+
} else {
|
|
633
|
+
rejected.push({
|
|
634
|
+
url,
|
|
635
|
+
errorMessage: ((_a = result.reason) == null ? void 0 : _a.message) || "Unknown error",
|
|
636
|
+
requestId
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
if (fulfilled.length > 0) {
|
|
641
|
+
set(updateListStateAtom, batchFetchTokenListFulfilled({ results: fulfilled }));
|
|
642
|
+
}
|
|
643
|
+
if (rejected.length > 0) {
|
|
644
|
+
set(updateListStateAtom, batchFetchTokenListRejected({ errors: rejected }));
|
|
645
|
+
}
|
|
646
|
+
} catch (error) {
|
|
647
|
+
const errors = urlsToFetch.map((url) => ({
|
|
648
|
+
url,
|
|
649
|
+
errorMessage: error.message,
|
|
650
|
+
requestId
|
|
651
|
+
}));
|
|
652
|
+
set(updateListStateAtom, batchFetchTokenListRejected({ errors }));
|
|
563
653
|
}
|
|
564
654
|
}));
|
|
565
655
|
function useListState() {
|
|
566
|
-
return jotai.useAtom(
|
|
656
|
+
return jotai.useAtom(listStateAtom);
|
|
567
657
|
}
|
|
568
658
|
function useListStateReady() {
|
|
569
659
|
const value = jotai.useAtomValue(isReadyAtom);
|
|
570
|
-
return value.state === "hasData"
|
|
660
|
+
return value.state === "hasData";
|
|
571
661
|
}
|
|
572
662
|
return {
|
|
573
|
-
listsAtom:
|
|
663
|
+
listsAtom: listStateAtom,
|
|
664
|
+
updateListStateAtom,
|
|
574
665
|
tokenAtom,
|
|
575
666
|
tokenBySymbolAtom,
|
|
576
667
|
fetchListAtom,
|
|
668
|
+
fetchListBatchAtom,
|
|
577
669
|
useListStateReady,
|
|
578
670
|
useListState
|
|
579
671
|
};
|
|
580
672
|
};
|
|
673
|
+
|
|
674
|
+
// react/reducerHelpers.ts
|
|
675
|
+
var setPendingTokenList = (state, url, requestId) => {
|
|
676
|
+
var _a, _b, _c, _d;
|
|
677
|
+
const current = (_b = (_a = state.byUrl[url]) == null ? void 0 : _a.current) != null ? _b : null;
|
|
678
|
+
const pendingUpdate = (_d = (_c = state.byUrl[url]) == null ? void 0 : _c.pendingUpdate) != null ? _d : null;
|
|
679
|
+
state.byUrl[url] = {
|
|
680
|
+
current,
|
|
681
|
+
pendingUpdate,
|
|
682
|
+
loadingRequestId: requestId,
|
|
683
|
+
error: null
|
|
684
|
+
};
|
|
685
|
+
};
|
|
686
|
+
var setFulfilledTokenList = (state, url, tokenList, requestId, DEFAULT_ACTIVE_LIST_URLS) => {
|
|
687
|
+
var _a, _b;
|
|
688
|
+
const current = (_a = state.byUrl[url]) == null ? void 0 : _a.current;
|
|
689
|
+
const loadingRequestId = (_b = state.byUrl[url]) == null ? void 0 : _b.loadingRequestId;
|
|
690
|
+
if (current) {
|
|
691
|
+
const upgradeType = chunkY2NTTLTJ_js.getVersionUpgrade(current.version, tokenList.version);
|
|
692
|
+
if (upgradeType === 0 /* NONE */)
|
|
693
|
+
return false;
|
|
694
|
+
if (loadingRequestId === null || loadingRequestId === requestId) {
|
|
695
|
+
state.byUrl[url] = chunkY2NTTLTJ_js.__spreadProps(chunkY2NTTLTJ_js.__spreadValues({}, state.byUrl[url]), {
|
|
696
|
+
loadingRequestId: null,
|
|
697
|
+
error: null,
|
|
698
|
+
current,
|
|
699
|
+
pendingUpdate: tokenList
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
if (DEFAULT_ACTIVE_LIST_URLS.includes(url) && state.activeListUrls && !state.activeListUrls.includes(url)) {
|
|
705
|
+
state.activeListUrls.push(url);
|
|
706
|
+
}
|
|
707
|
+
state.byUrl[url] = chunkY2NTTLTJ_js.__spreadProps(chunkY2NTTLTJ_js.__spreadValues({}, state.byUrl[url]), {
|
|
708
|
+
loadingRequestId: null,
|
|
709
|
+
error: null,
|
|
710
|
+
current: tokenList,
|
|
711
|
+
pendingUpdate: null
|
|
712
|
+
});
|
|
713
|
+
return true;
|
|
714
|
+
};
|
|
715
|
+
var setRejectedTokenList = (state, url, requestId, errorMessage) => {
|
|
716
|
+
var _a;
|
|
717
|
+
if (((_a = state.byUrl[url]) == null ? void 0 : _a.loadingRequestId) !== requestId) {
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
state.byUrl[url] = chunkY2NTTLTJ_js.__spreadProps(chunkY2NTTLTJ_js.__spreadValues({}, state.byUrl[url]), {
|
|
721
|
+
loadingRequestId: null,
|
|
722
|
+
error: errorMessage,
|
|
723
|
+
current: null,
|
|
724
|
+
pendingUpdate: null
|
|
725
|
+
});
|
|
726
|
+
};
|
|
727
|
+
var batchActivateUrls = (state, urls) => {
|
|
728
|
+
if (urls.length > 0 && state.activeListUrls) {
|
|
729
|
+
urls.forEach((url) => {
|
|
730
|
+
if (!state.activeListUrls.includes(url)) {
|
|
731
|
+
state.activeListUrls.push(url);
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
// react/reducer.ts
|
|
581
738
|
var NEW_LIST_STATE = {
|
|
582
739
|
error: null,
|
|
583
740
|
current: null,
|
|
@@ -587,53 +744,11 @@ var NEW_LIST_STATE = {
|
|
|
587
744
|
var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIVE_LIST_URLS) => toolkit.createReducer(
|
|
588
745
|
initialState,
|
|
589
746
|
(builder) => builder.addCase(fetchTokenList.pending, (state, { payload: { requestId, url } }) => {
|
|
590
|
-
|
|
591
|
-
const current = (_b = (_a = state.byUrl[url]) == null ? void 0 : _a.current) != null ? _b : null;
|
|
592
|
-
const pendingUpdate = (_d = (_c = state.byUrl[url]) == null ? void 0 : _c.pendingUpdate) != null ? _d : null;
|
|
593
|
-
state.byUrl[url] = {
|
|
594
|
-
current,
|
|
595
|
-
pendingUpdate,
|
|
596
|
-
loadingRequestId: requestId,
|
|
597
|
-
error: null
|
|
598
|
-
};
|
|
747
|
+
setPendingTokenList(state, url, requestId);
|
|
599
748
|
}).addCase(fetchTokenList.fulfilled, (state, { payload: { requestId, tokenList, url } }) => {
|
|
600
|
-
|
|
601
|
-
const current = (_a = state.byUrl[url]) == null ? void 0 : _a.current;
|
|
602
|
-
const loadingRequestId = (_b = state.byUrl[url]) == null ? void 0 : _b.loadingRequestId;
|
|
603
|
-
if (current) {
|
|
604
|
-
const upgradeType = chunkYOAEDKQH_js.getVersionUpgrade(current.version, tokenList.version);
|
|
605
|
-
if (upgradeType === 0 /* NONE */)
|
|
606
|
-
return;
|
|
607
|
-
if (loadingRequestId === null || loadingRequestId === requestId) {
|
|
608
|
-
state.byUrl[url] = chunkYOAEDKQH_js.__spreadProps(chunkYOAEDKQH_js.__spreadValues({}, state.byUrl[url]), {
|
|
609
|
-
loadingRequestId: null,
|
|
610
|
-
error: null,
|
|
611
|
-
current,
|
|
612
|
-
pendingUpdate: tokenList
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
|
-
} else {
|
|
616
|
-
if (DEFAULT_ACTIVE_LIST_URLS.includes(url) && state.activeListUrls && !state.activeListUrls.includes(url)) {
|
|
617
|
-
state.activeListUrls.push(url);
|
|
618
|
-
}
|
|
619
|
-
state.byUrl[url] = chunkYOAEDKQH_js.__spreadProps(chunkYOAEDKQH_js.__spreadValues({}, state.byUrl[url]), {
|
|
620
|
-
loadingRequestId: null,
|
|
621
|
-
error: null,
|
|
622
|
-
current: tokenList,
|
|
623
|
-
pendingUpdate: null
|
|
624
|
-
});
|
|
625
|
-
}
|
|
749
|
+
setFulfilledTokenList(state, url, tokenList, requestId, DEFAULT_ACTIVE_LIST_URLS);
|
|
626
750
|
}).addCase(fetchTokenList.rejected, (state, { payload: { url, requestId, errorMessage } }) => {
|
|
627
|
-
|
|
628
|
-
if (((_a = state.byUrl[url]) == null ? void 0 : _a.loadingRequestId) !== requestId) {
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
state.byUrl[url] = chunkYOAEDKQH_js.__spreadProps(chunkYOAEDKQH_js.__spreadValues({}, state.byUrl[url]), {
|
|
632
|
-
loadingRequestId: null,
|
|
633
|
-
error: errorMessage,
|
|
634
|
-
current: null,
|
|
635
|
-
pendingUpdate: null
|
|
636
|
-
});
|
|
751
|
+
setRejectedTokenList(state, url, requestId, errorMessage);
|
|
637
752
|
}).addCase(addList, (state, { payload: url }) => {
|
|
638
753
|
if (!state.byUrl[url]) {
|
|
639
754
|
state.byUrl[url] = NEW_LIST_STATE;
|
|
@@ -664,7 +779,7 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
664
779
|
if (!((_a = state.byUrl[url]) == null ? void 0 : _a.pendingUpdate)) {
|
|
665
780
|
throw new Error("accept list update called without pending update");
|
|
666
781
|
}
|
|
667
|
-
state.byUrl[url] =
|
|
782
|
+
state.byUrl[url] = chunkY2NTTLTJ_js.__spreadProps(chunkY2NTTLTJ_js.__spreadValues({}, state.byUrl[url]), {
|
|
668
783
|
pendingUpdate: null,
|
|
669
784
|
current: state.byUrl[url].pendingUpdate
|
|
670
785
|
});
|
|
@@ -699,11 +814,28 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
699
814
|
return true;
|
|
700
815
|
});
|
|
701
816
|
}
|
|
817
|
+
}).addCase(batchFetchTokenListPending, (state, { payload: { urls, requestId } }) => {
|
|
818
|
+
urls.forEach((url) => {
|
|
819
|
+
setPendingTokenList(state, url, requestId);
|
|
820
|
+
});
|
|
821
|
+
}).addCase(batchFetchTokenListFulfilled, (state, { payload: { results } }) => {
|
|
822
|
+
const urlsToActivate = [];
|
|
823
|
+
results.forEach(({ url, tokenList, requestId }) => {
|
|
824
|
+
const isNewList = setFulfilledTokenList(state, url, tokenList, requestId, DEFAULT_ACTIVE_LIST_URLS);
|
|
825
|
+
if (isNewList && DEFAULT_ACTIVE_LIST_URLS.includes(url)) {
|
|
826
|
+
urlsToActivate.push(url);
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
batchActivateUrls(state, urlsToActivate);
|
|
830
|
+
}).addCase(batchFetchTokenListRejected, (state, { payload: { errors } }) => {
|
|
831
|
+
errors.forEach(({ url, requestId, errorMessage }) => {
|
|
832
|
+
setRejectedTokenList(state, url, requestId, errorMessage);
|
|
833
|
+
});
|
|
702
834
|
})
|
|
703
835
|
);
|
|
704
836
|
function useFetchListCallback(dispatch) {
|
|
705
837
|
return react.useCallback(
|
|
706
|
-
(listUrl, sendDispatch = true) =>
|
|
838
|
+
(listUrl, sendDispatch = true) => chunkY2NTTLTJ_js.__async(this, null, function* () {
|
|
707
839
|
const requestId = toolkit.nanoid();
|
|
708
840
|
if (sendDispatch) {
|
|
709
841
|
dispatch(fetchTokenList.pending({ requestId, url: listUrl }));
|
|
@@ -732,6 +864,9 @@ var useFetchListCallback_default = useFetchListCallback;
|
|
|
732
864
|
exports.NEW_LIST_STATE = NEW_LIST_STATE;
|
|
733
865
|
exports.acceptListUpdate = acceptListUpdate;
|
|
734
866
|
exports.addList = addList;
|
|
867
|
+
exports.batchFetchTokenListFulfilled = batchFetchTokenListFulfilled;
|
|
868
|
+
exports.batchFetchTokenListPending = batchFetchTokenListPending;
|
|
869
|
+
exports.batchFetchTokenListRejected = batchFetchTokenListRejected;
|
|
735
870
|
exports.createListsAtom = createListsAtom;
|
|
736
871
|
exports.createTokenListReducer = createTokenListReducer;
|
|
737
872
|
exports.disableList = disableList;
|