@pancakeswap/token-lists 0.0.2 → 0.0.3

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.
@@ -8,15 +8,15 @@ $ tsup
8
8
  ESM Build start
9
9
  CJS Build start
10
10
  ESM dist/index.mjs 208.00 B
11
- ESM dist/react.mjs 7.70 KB
11
+ ESM dist/react.mjs 8.15 KB
12
12
  ESM dist/chunk-YBVZDUCZ.mjs 1.92 KB
13
13
  ESM dist/getTokenList-T45DK2AY.mjs 13.04 KB
14
- ESM ⚡️ Build success in 111ms
14
+ ESM ⚡️ Build success in 175ms
15
15
  CJS dist/index.js 3.11 KB
16
- CJS dist/react.js 25.22 KB
17
- CJS ⚡️ Build success in 104ms
16
+ CJS dist/react.js 25.72 KB
17
+ CJS ⚡️ Build success in 173ms
18
18
  DTS Build start
19
- DTS ⚡️ Build success in 9781ms
19
+ DTS ⚡️ Build success in 13296ms
20
20
  DTS dist/index.d.ts 1.54 KB
21
- DTS dist/react.d.ts 2.63 KB
21
+ DTS dist/react.d.ts 2.51 KB
22
22
  DTS dist/types-b620c9be.d.ts 1.03 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @pancakeswap/token-lists
2
2
 
3
+ ## 0.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 64dbde8e2: Fix token list getting from indexeddb not updating when version bump
8
+
3
9
  ## 0.0.2
4
10
 
5
11
  ### Patch Changes
package/dist/react.d.ts CHANGED
@@ -3,7 +3,6 @@ import { a as TokenList, V as Version } from './types-b620c9be.js';
3
3
  import * as _reduxjs_toolkit from '@reduxjs/toolkit';
4
4
  import { ActionCreatorWithPayload } from '@reduxjs/toolkit';
5
5
  import * as jotai from 'jotai';
6
- import * as jotai_utils from 'jotai/utils';
7
6
 
8
7
  interface ListsState {
9
8
  readonly byUrl: {
@@ -46,8 +45,9 @@ declare const rejectVersionUpdate: ActionCreatorWithPayload<Version, string>;
46
45
  declare const updateListVersion: _reduxjs_toolkit.ActionCreatorWithoutPayload<"lists/updateListVersion">;
47
46
 
48
47
  declare const createListsAtom: (storeName: string, reducer: any, initialState: any) => {
49
- listsAtom: jotai.WritableAtom<ListsState, ListsState | typeof jotai_utils.RESET | ((prev: ListsState) => ListsState | typeof jotai_utils.RESET), Promise<void>>;
50
- useListState: () => [ListsState, (action?: unknown) => void];
48
+ listsAtom: jotai.WritableAtom<ListsState, any, void>;
49
+ useListStateReady: () => boolean;
50
+ useListState: () => [ListsState, (update?: any) => void];
51
51
  };
52
52
 
53
53
  declare function useFetchListCallback(dispatch: (action?: unknown) => void): (listUrl: string, sendDispatch?: boolean) => Promise<TokenList>;
package/dist/react.js CHANGED
@@ -681,6 +681,7 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
681
681
  );
682
682
 
683
683
  // react/lists.ts
684
+ var import_jotai = require("jotai");
684
685
  var import_utils = require("jotai/utils");
685
686
  var import_localforage = __toESM(require("localforage"));
686
687
  function noop() {
@@ -692,8 +693,8 @@ var noopStorage = {
692
693
  keys: [],
693
694
  getAllKeys: noop
694
695
  };
696
+ var EMPTY = Symbol();
695
697
  var createListsAtom = (storeName, reducer, initialState) => {
696
- let gotOnce = false;
697
698
  function IndexedDBStorage(dbName) {
698
699
  if (typeof window !== "undefined") {
699
700
  const db = import_localforage.default.createInstance({
@@ -704,17 +705,15 @@ var createListsAtom = (storeName, reducer, initialState) => {
704
705
  db,
705
706
  getItem: async (key) => {
706
707
  const value = await db.getItem(key);
707
- gotOnce = true;
708
708
  if (value) {
709
709
  return value;
710
710
  }
711
711
  return initialState;
712
712
  },
713
713
  setItem: (k, v) => {
714
- if (gotOnce) {
715
- return db.setItem(k, v);
716
- }
717
- return void 0;
714
+ if (v === EMPTY)
715
+ return;
716
+ return db.setItem(k, v);
718
717
  },
719
718
  removeItem: db.removeItem,
720
719
  delayInit: true
@@ -722,16 +721,33 @@ var createListsAtom = (storeName, reducer, initialState) => {
722
721
  }
723
722
  return noopStorage;
724
723
  }
725
- const listsAtom = (0, import_utils.atomWithStorage)(
724
+ const listsStorageAtom = (0, import_utils.atomWithStorage)(
726
725
  "lists",
727
- initialState,
726
+ EMPTY,
728
727
  IndexedDBStorage("lists")
729
728
  );
729
+ const defaultStateAtom = (0, import_jotai.atom)(
730
+ (get) => {
731
+ const got = get(listsStorageAtom);
732
+ if (got === EMPTY) {
733
+ return initialState;
734
+ }
735
+ return got;
736
+ },
737
+ (get, set, action) => {
738
+ set(listsStorageAtom, reducer(get(defaultStateAtom), action));
739
+ }
740
+ );
741
+ const isReadyAtom = (0, import_jotai.atom)((get) => get(listsStorageAtom) !== EMPTY);
730
742
  function useListState() {
731
- return (0, import_utils.useReducerAtom)(listsAtom, reducer);
743
+ return (0, import_jotai.useAtom)(defaultStateAtom);
744
+ }
745
+ function useListStateReady() {
746
+ return (0, import_jotai.useAtomValue)(isReadyAtom);
732
747
  }
733
748
  return {
734
- listsAtom,
749
+ listsAtom: defaultStateAtom,
750
+ useListStateReady,
735
751
  useListState
736
752
  };
737
753
  };
package/dist/react.mjs CHANGED
@@ -150,7 +150,8 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
150
150
  );
151
151
 
152
152
  // react/lists.ts
153
- import { atomWithStorage, useReducerAtom } from "jotai/utils";
153
+ import { atom, useAtom, useAtomValue } from "jotai";
154
+ import { atomWithStorage } from "jotai/utils";
154
155
  import localForage from "localforage";
155
156
  function noop() {
156
157
  }
@@ -161,8 +162,8 @@ var noopStorage = {
161
162
  keys: [],
162
163
  getAllKeys: noop
163
164
  };
165
+ var EMPTY = Symbol();
164
166
  var createListsAtom = (storeName, reducer, initialState) => {
165
- let gotOnce = false;
166
167
  function IndexedDBStorage(dbName) {
167
168
  if (typeof window !== "undefined") {
168
169
  const db = localForage.createInstance({
@@ -173,17 +174,15 @@ var createListsAtom = (storeName, reducer, initialState) => {
173
174
  db,
174
175
  getItem: async (key) => {
175
176
  const value = await db.getItem(key);
176
- gotOnce = true;
177
177
  if (value) {
178
178
  return value;
179
179
  }
180
180
  return initialState;
181
181
  },
182
182
  setItem: (k, v) => {
183
- if (gotOnce) {
184
- return db.setItem(k, v);
185
- }
186
- return void 0;
183
+ if (v === EMPTY)
184
+ return;
185
+ return db.setItem(k, v);
187
186
  },
188
187
  removeItem: db.removeItem,
189
188
  delayInit: true
@@ -191,16 +190,33 @@ var createListsAtom = (storeName, reducer, initialState) => {
191
190
  }
192
191
  return noopStorage;
193
192
  }
194
- const listsAtom = atomWithStorage(
193
+ const listsStorageAtom = atomWithStorage(
195
194
  "lists",
196
- initialState,
195
+ EMPTY,
197
196
  IndexedDBStorage("lists")
198
197
  );
198
+ const defaultStateAtom = atom(
199
+ (get) => {
200
+ const got = get(listsStorageAtom);
201
+ if (got === EMPTY) {
202
+ return initialState;
203
+ }
204
+ return got;
205
+ },
206
+ (get, set, action) => {
207
+ set(listsStorageAtom, reducer(get(defaultStateAtom), action));
208
+ }
209
+ );
210
+ const isReadyAtom = atom((get) => get(listsStorageAtom) !== EMPTY);
199
211
  function useListState() {
200
- return useReducerAtom(listsAtom, reducer);
212
+ return useAtom(defaultStateAtom);
213
+ }
214
+ function useListStateReady() {
215
+ return useAtomValue(isReadyAtom);
201
216
  }
202
217
  return {
203
- listsAtom,
218
+ listsAtom: defaultStateAtom,
219
+ useListStateReady,
204
220
  useListState
205
221
  };
206
222
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pancakeswap/token-lists",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "sideEffects": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
package/react/lists.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { atomWithStorage, useReducerAtom } from 'jotai/utils'
1
+ import { atom, useAtom, useAtomValue } from 'jotai'
2
+ import { atomWithStorage } from 'jotai/utils'
2
3
  import localForage from 'localforage'
3
4
  import { ListsState } from './reducer'
4
5
 
@@ -12,8 +13,10 @@ const noopStorage = {
12
13
  getAllKeys: noop,
13
14
  }
14
15
 
16
+ // eslint-disable-next-line symbol-description
17
+ const EMPTY = Symbol()
18
+
15
19
  export const createListsAtom = (storeName: string, reducer: any, initialState: any) => {
16
- let gotOnce = false
17
20
  /**
18
21
  * Persist you redux state using IndexedDB
19
22
  * @param {string} dbName - IndexedDB database name
@@ -28,17 +31,15 @@ export const createListsAtom = (storeName: string, reducer: any, initialState: a
28
31
  db,
29
32
  getItem: async (key: string) => {
30
33
  const value = await db.getItem(key)
31
- gotOnce = true
32
34
  if (value) {
33
35
  return value
34
36
  }
35
37
  return initialState
36
38
  },
37
39
  setItem: (k: string, v: any) => {
38
- if (gotOnce) {
39
- return db.setItem(k, v)
40
- }
41
- return undefined
40
+ if (v === EMPTY) return
41
+ // eslint-disable-next-line consistent-return
42
+ return db.setItem(k, v)
42
43
  },
43
44
  removeItem: db.removeItem,
44
45
  delayInit: true,
@@ -47,19 +48,39 @@ export const createListsAtom = (storeName: string, reducer: any, initialState: a
47
48
  return noopStorage
48
49
  }
49
50
 
50
- const listsAtom = atomWithStorage<ListsState>(
51
+ const listsStorageAtom = atomWithStorage<ListsState | typeof EMPTY>(
51
52
  'lists',
52
- initialState,
53
+ EMPTY,
53
54
  // @ts-ignore
54
55
  IndexedDBStorage('lists'),
55
56
  )
56
57
 
58
+ const defaultStateAtom = atom<ListsState, any>(
59
+ (get) => {
60
+ const got = get(listsStorageAtom)
61
+ if (got === EMPTY) {
62
+ return initialState
63
+ }
64
+ return got
65
+ },
66
+ (get, set, action) => {
67
+ set(listsStorageAtom, reducer(get(defaultStateAtom), action))
68
+ },
69
+ )
70
+
71
+ const isReadyAtom = atom((get) => get(listsStorageAtom) !== EMPTY)
72
+
57
73
  function useListState() {
58
- return useReducerAtom(listsAtom, reducer)
74
+ return useAtom(defaultStateAtom)
75
+ }
76
+
77
+ function useListStateReady() {
78
+ return useAtomValue(isReadyAtom)
59
79
  }
60
80
 
61
81
  return {
62
- listsAtom,
82
+ listsAtom: defaultStateAtom,
83
+ useListStateReady,
63
84
  useListState,
64
85
  }
65
86
  }