@pancakeswap/token-lists 0.0.17 → 0.1.1

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/dist/react.js CHANGED
@@ -1,15 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var chunkYOAEDKQH_js = require('./chunk-YOAEDKQH.js');
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: 0
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: 40,
247
- pattern: "^[ \\w.'+\\-%/\xC0-\xD6\xD8-\xF6\xF8-\xFF:&\\[\\]\\(\\)]+$",
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+\\-%/$.\\s]+$",
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: 40,
307
- pattern: "^[ \\w.'+\\-%/\xC0-\xD6\xD8-\xF6\xF8-\xFF:&\\[\\]\\(\\)]+$",
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"]
@@ -403,6 +410,15 @@ var pancakeswap_default = {
403
410
  description: "A URI for the logo of the token list; prefer SVG or PNG of size 256x256",
404
411
  format: "uri",
405
412
  examples: ["ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM"]
413
+ },
414
+ extensions: {
415
+ type: "object",
416
+ description: "An object containing arbitrary or vendor-specific token list metadata",
417
+ propertyNames: {
418
+ $ref: "#/definitions/ExtensionIdentifier"
419
+ },
420
+ additionalProperties: true,
421
+ maxProperties: 10
406
422
  }
407
423
  },
408
424
  if: {
@@ -440,7 +456,7 @@ var pancakeswap_default = {
440
456
 
441
457
  // react/getTokenList.ts
442
458
  function getTokenList(listUrl) {
443
- return chunkYOAEDKQH_js.__async(this, null, function* () {
459
+ return chunkY2NTTLTJ_js.__async(this, null, function* () {
444
460
  const urls = uriToHttp(listUrl);
445
461
  const { default: Ajv } = yield import('ajv');
446
462
  const validator = new Ajv({ allErrors: true }).compile(pancakeswap_default);
@@ -448,16 +464,15 @@ function getTokenList(listUrl) {
448
464
  try {
449
465
  const json = yield fetchJson(url);
450
466
  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] })));
467
+ json.tokens = json.tokens.filter((token) => validator(chunkY2NTTLTJ_js.__spreadProps(chunkY2NTTLTJ_js.__spreadValues({}, json), { tokens: [token] })));
453
468
  if (!validator(json)) {
454
- const errors = validator.errors;
469
+ const { errors } = validator;
455
470
  throw new Error(`Validation failed after filtering: ${JSON.stringify(errors)}`);
456
471
  }
457
- console.warn(`Pre-filter validation errors: ${JSON.stringify(preFilterErrors)}`);
458
472
  }
459
473
  return json;
460
474
  } catch (error) {
475
+ console.warn(`Failed to download or validate list from ${url}:`, error);
461
476
  return void 0;
462
477
  }
463
478
  }
@@ -465,7 +480,48 @@ function getTokenList(listUrl) {
465
480
  });
466
481
  }
467
482
  function fetchJson(url) {
468
- return chunkYOAEDKQH_js.__async(this, null, function* () {
483
+ return chunkY2NTTLTJ_js.__async(this, null, function* () {
484
+ const res = yield fetch(url);
485
+ if (!res.ok)
486
+ throw new Error(`Failed to fetch: ${url}`);
487
+ return res.json();
488
+ });
489
+ }
490
+ function normalizeTokenAddress(address) {
491
+ return address.startsWith("0x") ? address.toLowerCase() : address;
492
+ }
493
+ function getGeoBlockTokenKey(token) {
494
+ return `${token.chainId}:${normalizeTokenAddress(token.address)}`;
495
+ }
496
+ function normalizeTokenKey(key) {
497
+ const separatorIndex = key.indexOf(":");
498
+ if (separatorIndex < 0)
499
+ return key;
500
+ const chainId = key.slice(0, separatorIndex);
501
+ const address = key.slice(separatorIndex + 1);
502
+ return `${chainId}:${normalizeTokenAddress(address)}`;
503
+ }
504
+ function getGeoBlockedTokenKeys(geoBlockList, countryCode) {
505
+ const blockedTokenKeys = /* @__PURE__ */ new Set();
506
+ if (!countryCode || !(geoBlockList == null ? void 0 : geoBlockList.rules) || !geoBlockList.tokens) {
507
+ return blockedTokenKeys;
508
+ }
509
+ const country = countryCode.toUpperCase();
510
+ const blockedRuleIds = new Set(
511
+ Object.entries(geoBlockList.rules).filter(([, countries]) => countries.includes(country)).map(([ruleId]) => ruleId)
512
+ );
513
+ Object.entries(geoBlockList.tokens).forEach(([tokenKey, ruleIds]) => {
514
+ if (ruleIds.some((ruleId) => blockedRuleIds.has(ruleId))) {
515
+ blockedTokenKeys.add(normalizeTokenKey(tokenKey));
516
+ }
517
+ });
518
+ return blockedTokenKeys;
519
+ }
520
+ function isGeoBlockedToken(token, geoBlockList, countryCode) {
521
+ return getGeoBlockedTokenKeys(geoBlockList, countryCode).has(getGeoBlockTokenKey(token));
522
+ }
523
+ function fetchJson2(url) {
524
+ return chunkY2NTTLTJ_js.__async(this, null, function* () {
469
525
  const res = yield fetch(url);
470
526
  if (!res.ok)
471
527
  throw new Error(`Failed to fetch: ${url}`);
@@ -502,82 +558,278 @@ function findTokenBySymbol(state, chainId, symbol) {
502
558
  }
503
559
  return void 0;
504
560
  }
505
- var createListsAtom = (storeName, reducer, initialState) => {
561
+ var createListsAtom = (storeName, reducer, initialState, options = {}) => {
506
562
  function IndexedDBStorage(dbName) {
507
563
  if (typeof window !== "undefined") {
508
564
  const db = localForage__default.default.createInstance({
509
565
  name: dbName,
510
566
  storeName
511
567
  });
568
+ const mem = /* @__PURE__ */ new Map();
569
+ const debouncedSetItem = debounce__default.default((k, v) => chunkY2NTTLTJ_js.__async(this, null, function* () {
570
+ db.setItem(k, v);
571
+ }), 300);
512
572
  return {
513
- getItem: (key) => chunkYOAEDKQH_js.__async(this, null, function* () {
573
+ getItem: (key) => chunkY2NTTLTJ_js.__async(this, null, function* () {
574
+ if (mem.has(key)) {
575
+ return mem.get(key);
576
+ }
514
577
  const value = yield db.getItem(key);
515
578
  if (value) {
516
579
  return value;
517
580
  }
518
- return initialState;
581
+ return void 0;
519
582
  }),
520
- setItem: (k, v) => chunkYOAEDKQH_js.__async(this, null, function* () {
583
+ setItem: (k, v) => chunkY2NTTLTJ_js.__async(this, null, function* () {
521
584
  if (v === EMPTY)
522
585
  return;
523
- yield db.setItem(k, v);
586
+ mem.set(k, v);
587
+ debouncedSetItem(k, v);
524
588
  }),
525
589
  removeItem: db.removeItem
526
590
  };
527
591
  }
528
592
  return noopStorage;
529
593
  }
530
- const listsStorageAtom = utils.atomWithStorage("lists", EMPTY, IndexedDBStorage("lists"));
531
- const defaultStateAtom = jotai.atom(
532
- (get) => {
533
- const value = get(utils.loadable(listsStorageAtom));
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
- })
594
+ const tokenListsStorageAtom = utils.atomWithStorage(
595
+ "tokenLists",
596
+ EMPTY,
597
+ IndexedDBStorage("tokenLists"),
598
+ { getOnInit: true }
542
599
  );
543
- const isReadyAtom = utils.loadable(listsStorageAtom);
600
+ const geoBlockListStorageAtom = utils.atomWithStorage(
601
+ "geoBlockList",
602
+ EMPTY,
603
+ IndexedDBStorage("geoBlockList")
604
+ );
605
+ const geoBlockListAtom = jotai.atom((get) => {
606
+ const value = get(utils.loadable(geoBlockListStorageAtom));
607
+ if (value.state === "hasData" && value.data && value.data !== EMPTY) {
608
+ return value.data;
609
+ }
610
+ return void 0;
611
+ });
612
+ const fetchGeoBlockListAtom = jotai.atom(null, (_get, set) => chunkY2NTTLTJ_js.__async(void 0, null, function* () {
613
+ if (!options.geoBlockListUrl) {
614
+ return;
615
+ }
616
+ try {
617
+ set(geoBlockListStorageAtom, yield fetchJson2(options.geoBlockListUrl));
618
+ } catch (error) {
619
+ console.warn(`Failed to download geo block list from ${options.geoBlockListUrl}:`, error);
620
+ }
621
+ }));
622
+ const memoryStateAtom = jotai.atom(initialState);
623
+ const mergeStoredData = (baseState, storedData) => {
624
+ var _a;
625
+ const storedTokenLists = (_a = storedData.byUrl) != null ? _a : storedData;
626
+ const storedActiveListUrls = Array.isArray(storedData.activeListUrls) ? storedData.activeListUrls : void 0;
627
+ const mergedState = chunkY2NTTLTJ_js.__spreadValues({}, baseState);
628
+ const updatedByUrl = chunkY2NTTLTJ_js.__spreadValues({}, mergedState.byUrl);
629
+ Object.keys(storedTokenLists).forEach((url) => {
630
+ if (storedTokenLists[url]) {
631
+ updatedByUrl[url] = chunkY2NTTLTJ_js.__spreadProps(chunkY2NTTLTJ_js.__spreadValues({}, updatedByUrl[url]), {
632
+ current: storedTokenLists[url]
633
+ // Keep existing memory state for loading, error, pendingUpdate
634
+ });
635
+ }
636
+ });
637
+ mergedState.byUrl = updatedByUrl;
638
+ if (storedActiveListUrls) {
639
+ mergedState.activeListUrls = storedActiveListUrls;
640
+ }
641
+ return mergedState;
642
+ };
643
+ const listStateAtom = jotai.atom((get) => {
644
+ const memoryState = get(memoryStateAtom);
645
+ const value = get(utils.loadable(tokenListsStorageAtom));
646
+ if (value.state === "hasData" && value.data && value.data !== EMPTY) {
647
+ return mergeStoredData(memoryState, value.data);
648
+ }
649
+ return memoryState;
650
+ });
651
+ let hasHydratedActiveListUrls = false;
652
+ const updateListStateAtom = jotai.atom(null, (get, set, action) => chunkY2NTTLTJ_js.__async(void 0, null, function* () {
653
+ const baseState = get(memoryStateAtom);
654
+ if (!hasHydratedActiveListUrls) {
655
+ const storageValue = get(utils.loadable(tokenListsStorageAtom));
656
+ if (storageValue.state !== "hasData") {
657
+ const optimisticState = reducer(baseState, action);
658
+ set(memoryStateAtom, chunkY2NTTLTJ_js.__spreadValues({}, optimisticState));
659
+ return;
660
+ }
661
+ if (storageValue.data && storageValue.data !== EMPTY) {
662
+ set(memoryStateAtom, mergeStoredData(baseState, storageValue.data));
663
+ }
664
+ hasHydratedActiveListUrls = true;
665
+ }
666
+ const currentState = get(memoryStateAtom);
667
+ const newState = reducer(currentState, action);
668
+ set(memoryStateAtom, chunkY2NTTLTJ_js.__spreadValues({}, newState));
669
+ const tokenListsToStore = {};
670
+ Object.keys(newState.byUrl).forEach((url) => {
671
+ var _a;
672
+ if ((_a = newState.byUrl[url]) == null ? void 0 : _a.current) {
673
+ tokenListsToStore[url] = newState.byUrl[url].current;
674
+ }
675
+ });
676
+ set(tokenListsStorageAtom, { byUrl: tokenListsToStore, activeListUrls: newState.activeListUrls });
677
+ }));
678
+ const isReadyAtom = utils.loadable(tokenListsStorageAtom);
544
679
  const tokenAtom = utils.atomFamily(
545
- (key) => jotai.atom((get) => findTokenByAddress(get(defaultStateAtom), key.chainId, key.address))
680
+ (key) => jotai.atom((get) => findTokenByAddress(get(listStateAtom), key.chainId, key.address))
546
681
  );
547
682
  const tokenBySymbolAtom = utils.atomFamily(
548
- (key) => jotai.atom((get) => findTokenBySymbol(get(defaultStateAtom), key.chainId, key.symbol))
683
+ (key) => jotai.atom((get) => findTokenBySymbol(get(listStateAtom), key.chainId, key.symbol))
549
684
  );
550
- const fetchListAtom = jotai.atom(null, (get, set, url) => chunkYOAEDKQH_js.__async(void 0, null, function* () {
551
- const state = get(defaultStateAtom);
685
+ const fetchListAtom = jotai.atom(null, (get, set, url) => chunkY2NTTLTJ_js.__async(void 0, null, function* () {
686
+ const state = get(listStateAtom);
552
687
  const listState = state.byUrl[url];
553
688
  if ((listState == null ? void 0 : listState.current) || (listState == null ? void 0 : listState.loadingRequestId)) {
554
689
  return;
555
690
  }
556
691
  const requestId = toolkit.nanoid();
557
- set(defaultStateAtom, fetchTokenList.pending({ url, requestId }));
692
+ set(updateListStateAtom, fetchTokenList.pending({ url, requestId }));
558
693
  try {
559
694
  const tokenList = yield getTokenList(url);
560
- set(defaultStateAtom, fetchTokenList.fulfilled({ url, tokenList, requestId }));
695
+ set(updateListStateAtom, fetchTokenList.fulfilled({ url, tokenList, requestId }));
561
696
  } catch (error) {
562
- set(defaultStateAtom, fetchTokenList.rejected({ url, requestId, errorMessage: error.message }));
697
+ set(updateListStateAtom, fetchTokenList.rejected({ url, requestId, errorMessage: error.message }));
698
+ }
699
+ }));
700
+ const fetchListBatchAtom = jotai.atom(null, (get, set, urls) => chunkY2NTTLTJ_js.__async(void 0, null, function* () {
701
+ const state = get(listStateAtom);
702
+ const urlsToFetch = urls.filter((url) => {
703
+ const listState = state.byUrl[url];
704
+ return !(listState == null ? void 0 : listState.current) && !(listState == null ? void 0 : listState.loadingRequestId);
705
+ });
706
+ if (urlsToFetch.length === 0) {
707
+ return;
708
+ }
709
+ const requestId = toolkit.nanoid();
710
+ set(updateListStateAtom, batchFetchTokenListPending({ urls: urlsToFetch, requestId }));
711
+ try {
712
+ const results = yield Promise.allSettled(
713
+ urlsToFetch.map((url) => chunkY2NTTLTJ_js.__async(void 0, null, function* () {
714
+ const tokenList = yield getTokenList(url);
715
+ return { url, tokenList, requestId };
716
+ }))
717
+ );
718
+ const fulfilled = [];
719
+ const rejected = [];
720
+ results.forEach((result, index) => {
721
+ var _a;
722
+ const url = urlsToFetch[index];
723
+ if (result.status === "fulfilled") {
724
+ fulfilled.push(result.value);
725
+ } else {
726
+ rejected.push({
727
+ url,
728
+ errorMessage: ((_a = result.reason) == null ? void 0 : _a.message) || "Unknown error",
729
+ requestId
730
+ });
731
+ }
732
+ });
733
+ if (fulfilled.length > 0) {
734
+ set(updateListStateAtom, batchFetchTokenListFulfilled({ results: fulfilled }));
735
+ }
736
+ if (rejected.length > 0) {
737
+ set(updateListStateAtom, batchFetchTokenListRejected({ errors: rejected }));
738
+ }
739
+ } catch (error) {
740
+ const errors = urlsToFetch.map((url) => ({
741
+ url,
742
+ errorMessage: error.message,
743
+ requestId
744
+ }));
745
+ set(updateListStateAtom, batchFetchTokenListRejected({ errors }));
563
746
  }
564
747
  }));
565
748
  function useListState() {
566
- return jotai.useAtom(defaultStateAtom);
749
+ return jotai.useAtom(listStateAtom);
567
750
  }
568
751
  function useListStateReady() {
569
752
  const value = jotai.useAtomValue(isReadyAtom);
570
- return value.state === "hasData" && value.data !== EMPTY;
753
+ return value.state === "hasData";
571
754
  }
572
755
  return {
573
- listsAtom: defaultStateAtom,
756
+ listsAtom: listStateAtom,
757
+ updateListStateAtom,
574
758
  tokenAtom,
575
759
  tokenBySymbolAtom,
760
+ geoBlockListAtom,
761
+ fetchGeoBlockListAtom,
576
762
  fetchListAtom,
763
+ fetchListBatchAtom,
577
764
  useListStateReady,
578
765
  useListState
579
766
  };
580
767
  };
768
+
769
+ // react/reducerHelpers.ts
770
+ var setPendingTokenList = (state, url, requestId) => {
771
+ var _a, _b, _c, _d;
772
+ const current = (_b = (_a = state.byUrl[url]) == null ? void 0 : _a.current) != null ? _b : null;
773
+ const pendingUpdate = (_d = (_c = state.byUrl[url]) == null ? void 0 : _c.pendingUpdate) != null ? _d : null;
774
+ state.byUrl[url] = {
775
+ current,
776
+ pendingUpdate,
777
+ loadingRequestId: requestId,
778
+ error: null
779
+ };
780
+ };
781
+ var setFulfilledTokenList = (state, url, tokenList, requestId, DEFAULT_ACTIVE_LIST_URLS) => {
782
+ var _a, _b;
783
+ const current = (_a = state.byUrl[url]) == null ? void 0 : _a.current;
784
+ const loadingRequestId = (_b = state.byUrl[url]) == null ? void 0 : _b.loadingRequestId;
785
+ if (current) {
786
+ const upgradeType = chunkY2NTTLTJ_js.getVersionUpgrade(current.version, tokenList.version);
787
+ if (upgradeType === 0 /* NONE */)
788
+ return false;
789
+ if (loadingRequestId === null || loadingRequestId === requestId) {
790
+ state.byUrl[url] = chunkY2NTTLTJ_js.__spreadProps(chunkY2NTTLTJ_js.__spreadValues({}, state.byUrl[url]), {
791
+ loadingRequestId: null,
792
+ error: null,
793
+ current,
794
+ pendingUpdate: tokenList
795
+ });
796
+ }
797
+ return false;
798
+ }
799
+ if (DEFAULT_ACTIVE_LIST_URLS.includes(url) && state.activeListUrls && !state.activeListUrls.includes(url)) {
800
+ state.activeListUrls.push(url);
801
+ }
802
+ state.byUrl[url] = chunkY2NTTLTJ_js.__spreadProps(chunkY2NTTLTJ_js.__spreadValues({}, state.byUrl[url]), {
803
+ loadingRequestId: null,
804
+ error: null,
805
+ current: tokenList,
806
+ pendingUpdate: null
807
+ });
808
+ return true;
809
+ };
810
+ var setRejectedTokenList = (state, url, requestId, errorMessage) => {
811
+ var _a;
812
+ if (((_a = state.byUrl[url]) == null ? void 0 : _a.loadingRequestId) !== requestId) {
813
+ return;
814
+ }
815
+ state.byUrl[url] = chunkY2NTTLTJ_js.__spreadProps(chunkY2NTTLTJ_js.__spreadValues({}, state.byUrl[url]), {
816
+ loadingRequestId: null,
817
+ error: errorMessage,
818
+ current: null,
819
+ pendingUpdate: null
820
+ });
821
+ };
822
+ var batchActivateUrls = (state, urls) => {
823
+ if (urls.length > 0 && state.activeListUrls) {
824
+ urls.forEach((url) => {
825
+ if (!state.activeListUrls.includes(url)) {
826
+ state.activeListUrls.push(url);
827
+ }
828
+ });
829
+ }
830
+ };
831
+
832
+ // react/reducer.ts
581
833
  var NEW_LIST_STATE = {
582
834
  error: null,
583
835
  current: null,
@@ -587,53 +839,11 @@ var NEW_LIST_STATE = {
587
839
  var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIVE_LIST_URLS) => toolkit.createReducer(
588
840
  initialState,
589
841
  (builder) => builder.addCase(fetchTokenList.pending, (state, { payload: { requestId, url } }) => {
590
- var _a, _b, _c, _d;
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
- };
842
+ setPendingTokenList(state, url, requestId);
599
843
  }).addCase(fetchTokenList.fulfilled, (state, { payload: { requestId, tokenList, url } }) => {
600
- var _a, _b;
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
- }
844
+ setFulfilledTokenList(state, url, tokenList, requestId, DEFAULT_ACTIVE_LIST_URLS);
626
845
  }).addCase(fetchTokenList.rejected, (state, { payload: { url, requestId, errorMessage } }) => {
627
- var _a;
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
- });
846
+ setRejectedTokenList(state, url, requestId, errorMessage);
637
847
  }).addCase(addList, (state, { payload: url }) => {
638
848
  if (!state.byUrl[url]) {
639
849
  state.byUrl[url] = NEW_LIST_STATE;
@@ -664,7 +874,7 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
664
874
  if (!((_a = state.byUrl[url]) == null ? void 0 : _a.pendingUpdate)) {
665
875
  throw new Error("accept list update called without pending update");
666
876
  }
667
- state.byUrl[url] = chunkYOAEDKQH_js.__spreadProps(chunkYOAEDKQH_js.__spreadValues({}, state.byUrl[url]), {
877
+ state.byUrl[url] = chunkY2NTTLTJ_js.__spreadProps(chunkY2NTTLTJ_js.__spreadValues({}, state.byUrl[url]), {
668
878
  pendingUpdate: null,
669
879
  current: state.byUrl[url].pendingUpdate
670
880
  });
@@ -699,11 +909,28 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
699
909
  return true;
700
910
  });
701
911
  }
912
+ }).addCase(batchFetchTokenListPending, (state, { payload: { urls, requestId } }) => {
913
+ urls.forEach((url) => {
914
+ setPendingTokenList(state, url, requestId);
915
+ });
916
+ }).addCase(batchFetchTokenListFulfilled, (state, { payload: { results } }) => {
917
+ const urlsToActivate = [];
918
+ results.forEach(({ url, tokenList, requestId }) => {
919
+ const isNewList = setFulfilledTokenList(state, url, tokenList, requestId, DEFAULT_ACTIVE_LIST_URLS);
920
+ if (isNewList && DEFAULT_ACTIVE_LIST_URLS.includes(url)) {
921
+ urlsToActivate.push(url);
922
+ }
923
+ });
924
+ batchActivateUrls(state, urlsToActivate);
925
+ }).addCase(batchFetchTokenListRejected, (state, { payload: { errors } }) => {
926
+ errors.forEach(({ url, requestId, errorMessage }) => {
927
+ setRejectedTokenList(state, url, requestId, errorMessage);
928
+ });
702
929
  })
703
930
  );
704
931
  function useFetchListCallback(dispatch) {
705
932
  return react.useCallback(
706
- (listUrl, sendDispatch = true) => chunkYOAEDKQH_js.__async(this, null, function* () {
933
+ (listUrl, sendDispatch = true) => chunkY2NTTLTJ_js.__async(this, null, function* () {
707
934
  const requestId = toolkit.nanoid();
708
935
  if (sendDispatch) {
709
936
  dispatch(fetchTokenList.pending({ requestId, url: listUrl }));
@@ -717,7 +944,7 @@ function useFetchListCallback(dispatch) {
717
944
  }
718
945
  return tokenList;
719
946
  }).catch((error) => {
720
- console.error(`Failed to get list at url ${listUrl}`, error);
947
+ console.warn(`Failed to get list at url ${listUrl}`, error);
721
948
  if (sendDispatch) {
722
949
  dispatch(fetchTokenList.rejected({ url: listUrl, requestId, errorMessage: error.message }));
723
950
  }
@@ -732,6 +959,9 @@ var useFetchListCallback_default = useFetchListCallback;
732
959
  exports.NEW_LIST_STATE = NEW_LIST_STATE;
733
960
  exports.acceptListUpdate = acceptListUpdate;
734
961
  exports.addList = addList;
962
+ exports.batchFetchTokenListFulfilled = batchFetchTokenListFulfilled;
963
+ exports.batchFetchTokenListPending = batchFetchTokenListPending;
964
+ exports.batchFetchTokenListRejected = batchFetchTokenListRejected;
735
965
  exports.createListsAtom = createListsAtom;
736
966
  exports.createTokenListReducer = createTokenListReducer;
737
967
  exports.disableList = disableList;
@@ -739,7 +969,10 @@ exports.enableList = enableList;
739
969
  exports.fetchTokenList = fetchTokenList;
740
970
  exports.findTokenByAddress = findTokenByAddress;
741
971
  exports.findTokenBySymbol = findTokenBySymbol;
972
+ exports.getGeoBlockTokenKey = getGeoBlockTokenKey;
973
+ exports.getGeoBlockedTokenKeys = getGeoBlockedTokenKeys;
742
974
  exports.getTokenList = getTokenList;
975
+ exports.isGeoBlockedToken = isGeoBlockedToken;
743
976
  exports.rejectVersionUpdate = rejectVersionUpdate;
744
977
  exports.removeList = removeList;
745
978
  exports.updateListVersion = updateListVersion;