@pancakeswap/token-lists 0.0.2 → 0.0.4
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 +6 -6
- package/CHANGELOG.md +12 -0
- package/dist/react.d.ts +3 -3
- package/dist/react.js +29 -13
- package/dist/react.mjs +30 -14
- package/package.json +4 -4
- package/react/lists.ts +32 -11
- package/react/reducer.ts +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -8,15 +8,15 @@ $ tsup
|
|
|
8
8
|
[34mESM[39m Build start
|
|
9
9
|
[34mCJS[39m Build start
|
|
10
10
|
[32mESM[39m [1mdist/index.mjs [22m[32m208.00 B[39m
|
|
11
|
-
[32mESM[39m [1mdist/react.mjs [22m[
|
|
11
|
+
[32mESM[39m [1mdist/react.mjs [22m[32m8.17 KB[39m
|
|
12
12
|
[32mESM[39m [1mdist/chunk-YBVZDUCZ.mjs [22m[32m1.92 KB[39m
|
|
13
13
|
[32mESM[39m [1mdist/getTokenList-T45DK2AY.mjs [22m[32m13.04 KB[39m
|
|
14
|
-
[32mESM[39m ⚡️ Build success in
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 118ms
|
|
15
15
|
[32mCJS[39m [1mdist/index.js [22m[32m3.11 KB[39m
|
|
16
|
-
[32mCJS[39m [1mdist/react.js [22m[32m25.
|
|
17
|
-
[32mCJS[39m ⚡️ Build success in
|
|
16
|
+
[32mCJS[39m [1mdist/react.js [22m[32m25.75 KB[39m
|
|
17
|
+
[32mCJS[39m ⚡️ Build success in 116ms
|
|
18
18
|
[34mDTS[39m Build start
|
|
19
|
-
[32mDTS[39m ⚡️ Build success in
|
|
19
|
+
[32mDTS[39m ⚡️ Build success in 9485ms
|
|
20
20
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m1.54 KB[39m
|
|
21
|
-
[32mDTS[39m [1mdist/react.d.ts [22m[32m2.
|
|
21
|
+
[32mDTS[39m [1mdist/react.d.ts [22m[32m2.51 KB[39m
|
|
22
22
|
[32mDTS[39m [1mdist/types-b620c9be.d.ts [22m[32m1.03 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @pancakeswap/token-lists
|
|
2
2
|
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5dda2c74f: Fix duplicate active list url issue
|
|
8
|
+
|
|
9
|
+
## 0.0.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 64dbde8e2: Fix token list getting from indexeddb not updating when version bump
|
|
14
|
+
|
|
3
15
|
## 0.0.2
|
|
4
16
|
|
|
5
17
|
### 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,
|
|
50
|
-
|
|
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
|
@@ -571,7 +571,7 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
571
571
|
error: null
|
|
572
572
|
};
|
|
573
573
|
}).addCase(fetchTokenList.fulfilled, (state, { payload: { requestId, tokenList, url } }) => {
|
|
574
|
-
var _a, _b
|
|
574
|
+
var _a, _b;
|
|
575
575
|
const current = (_a = state.byUrl[url]) == null ? void 0 : _a.current;
|
|
576
576
|
const loadingRequestId = (_b = state.byUrl[url]) == null ? void 0 : _b.loadingRequestId;
|
|
577
577
|
if (current) {
|
|
@@ -588,8 +588,8 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
588
588
|
};
|
|
589
589
|
}
|
|
590
590
|
} else {
|
|
591
|
-
if (DEFAULT_ACTIVE_LIST_URLS.includes(url)) {
|
|
592
|
-
|
|
591
|
+
if (DEFAULT_ACTIVE_LIST_URLS.includes(url) && state.activeListUrls && !state.activeListUrls.includes(url)) {
|
|
592
|
+
state.activeListUrls.push(url);
|
|
593
593
|
}
|
|
594
594
|
state.byUrl[url] = {
|
|
595
595
|
...state.byUrl[url],
|
|
@@ -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 (
|
|
715
|
-
return
|
|
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
|
|
724
|
+
const listsStorageAtom = (0, import_utils.atomWithStorage)(
|
|
726
725
|
"lists",
|
|
727
|
-
|
|
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,
|
|
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
|
@@ -40,7 +40,7 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
40
40
|
error: null
|
|
41
41
|
};
|
|
42
42
|
}).addCase(fetchTokenList.fulfilled, (state, { payload: { requestId, tokenList, url } }) => {
|
|
43
|
-
var _a, _b
|
|
43
|
+
var _a, _b;
|
|
44
44
|
const current = (_a = state.byUrl[url]) == null ? void 0 : _a.current;
|
|
45
45
|
const loadingRequestId = (_b = state.byUrl[url]) == null ? void 0 : _b.loadingRequestId;
|
|
46
46
|
if (current) {
|
|
@@ -57,8 +57,8 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
} else {
|
|
60
|
-
if (DEFAULT_ACTIVE_LIST_URLS.includes(url)) {
|
|
61
|
-
|
|
60
|
+
if (DEFAULT_ACTIVE_LIST_URLS.includes(url) && state.activeListUrls && !state.activeListUrls.includes(url)) {
|
|
61
|
+
state.activeListUrls.push(url);
|
|
62
62
|
}
|
|
63
63
|
state.byUrl[url] = {
|
|
64
64
|
...state.byUrl[url],
|
|
@@ -150,7 +150,8 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
150
150
|
);
|
|
151
151
|
|
|
152
152
|
// react/lists.ts
|
|
153
|
-
import {
|
|
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 (
|
|
184
|
-
return
|
|
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
|
|
193
|
+
const listsStorageAtom = atomWithStorage(
|
|
195
194
|
"lists",
|
|
196
|
-
|
|
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
|
|
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.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"@pancakeswap/swap-sdk-core": "*"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@reduxjs/toolkit": "^1.
|
|
20
|
+
"@reduxjs/toolkit": "^1.9.1",
|
|
21
21
|
"localforage": "^1.10.0",
|
|
22
|
-
"jotai": "^1.
|
|
22
|
+
"jotai": "^1.11.1",
|
|
23
23
|
"react": "^18.2.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@reduxjs/toolkit": "^1.
|
|
26
|
+
"@reduxjs/toolkit": "^1.9.1",
|
|
27
27
|
"react": "^18.2.0"
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|
package/react/lists.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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 (
|
|
39
|
-
|
|
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
|
|
51
|
+
const listsStorageAtom = atomWithStorage<ListsState | typeof EMPTY>(
|
|
51
52
|
'lists',
|
|
52
|
-
|
|
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
|
|
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
|
}
|
package/react/reducer.ts
CHANGED
|
@@ -74,8 +74,8 @@ export const createTokenListReducer = (
|
|
|
74
74
|
}
|
|
75
75
|
} else {
|
|
76
76
|
// activate if on default active
|
|
77
|
-
if (DEFAULT_ACTIVE_LIST_URLS.includes(url)) {
|
|
78
|
-
state.activeListUrls
|
|
77
|
+
if (DEFAULT_ACTIVE_LIST_URLS.includes(url) && state.activeListUrls && !state.activeListUrls.includes(url)) {
|
|
78
|
+
state.activeListUrls.push(url)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
state.byUrl[url] = {
|