@pancakeswap/token-lists 0.0.8 → 0.0.9
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 +6 -0
- package/dist/react.d.ts +1 -1
- package/dist/react.js +14 -21
- package/dist/react.mjs +15 -22
- package/package.json +8 -6
- package/react/index.test.ts +21 -0
- package/react/lists.ts +18 -24
- package/react/reducer.test.ts +51 -22
- package/react/reducer.ts +1 -1
- package/src/index.test.ts +14 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pancakeswap/token-lists@0.0.
|
|
2
|
+
> @pancakeswap/token-lists@0.0.9 build /home/runner/work/pancake-frontend/pancake-frontend/packages/token-lists
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: {"index":"./src/index.ts","react":"./react/index.ts"}
|
|
@@ -10,20 +10,20 @@
|
|
|
10
10
|
[34mESM[39m Build start
|
|
11
11
|
[34mCJS[39m Build start
|
|
12
12
|
Entry module "dist/getTokenList-YNKBKHZ3.js" is using named and default exports together. Consumers of your bundle will have to use `chunk.default` to access the default export, which may not be what you want. Use `output.exports: "named"` to disable this warning.
|
|
13
|
-
[32mESM[39m [1mdist/chunk-2L3ZO4UM.mjs [22m[32m1.42 KB[39m
|
|
14
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m160.00 B[39m
|
|
15
|
-
[32mESM[39m [1mdist/chunk-COROHIJN.mjs [22m[32m2.67 KB[39m
|
|
16
|
-
[32mESM[39m [1mdist/getTokenList-2FAKUE6D.mjs [22m[32m13.40 KB[39m
|
|
17
|
-
[32mESM[39m [1mdist/react.mjs [22m[32m8.29 KB[39m
|
|
18
|
-
[32mESM[39m ⚡️ Build success in 996ms
|
|
19
13
|
[32mCJS[39m [1mdist/chunk-4TPCCB4K.js [22m[32m1.49 KB[39m
|
|
20
14
|
[32mCJS[39m [1mdist/index.js [22m[32m815.00 B[39m
|
|
21
15
|
[32mCJS[39m [1mdist/chunk-OGWZ2K32.js [22m[32m2.83 KB[39m
|
|
22
16
|
[32mCJS[39m [1mdist/getTokenList-YNKBKHZ3.js [22m[32m13.76 KB[39m
|
|
23
|
-
[32mCJS[39m [1mdist/react.js [22m[
|
|
24
|
-
[32mCJS[39m ⚡️ Build success in
|
|
17
|
+
[32mCJS[39m [1mdist/react.js [22m[32m9.13 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 1438ms
|
|
19
|
+
[32mESM[39m [1mdist/chunk-2L3ZO4UM.mjs [22m[32m1.42 KB[39m
|
|
20
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m160.00 B[39m
|
|
21
|
+
[32mESM[39m [1mdist/chunk-COROHIJN.mjs [22m[32m2.67 KB[39m
|
|
22
|
+
[32mESM[39m [1mdist/getTokenList-2FAKUE6D.mjs [22m[32m13.40 KB[39m
|
|
23
|
+
[32mESM[39m [1mdist/react.mjs [22m[32m8.43 KB[39m
|
|
24
|
+
[32mESM[39m ⚡️ Build success in 1447ms
|
|
25
25
|
[34mDTS[39m Build start
|
|
26
|
-
[32mDTS[39m ⚡️ Build success in
|
|
26
|
+
[32mDTS[39m ⚡️ Build success in 11919ms
|
|
27
27
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m1.68 KB[39m
|
|
28
|
-
[32mDTS[39m [1mdist/react.d.ts [22m[32m2.
|
|
28
|
+
[32mDTS[39m [1mdist/react.d.ts [22m[32m2.52 KB[39m
|
|
29
29
|
[32mDTS[39m [1mdist/types-d6730d17.d.ts [22m[32m1.03 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/react.d.ts
CHANGED
|
@@ -52,4 +52,4 @@ declare const createListsAtom: (storeName: string, reducer: any, initialState: a
|
|
|
52
52
|
|
|
53
53
|
declare function useFetchListCallback(dispatch: (action?: unknown) => void): (listUrl: string, sendDispatch?: boolean) => Promise<TokenList>;
|
|
54
54
|
|
|
55
|
-
export { ListsState, NEW_LIST_STATE, acceptListUpdate, addList, createListsAtom, createTokenListReducer, disableList, enableList, fetchTokenList, rejectVersionUpdate, removeList, updateListVersion, useFetchListCallback };
|
|
55
|
+
export { ListByUrlState, ListsState, NEW_LIST_STATE, acceptListUpdate, addList, createListsAtom, createTokenListReducer, disableList, enableList, fetchTokenList, rejectVersionUpdate, removeList, updateListVersion, useFetchListCallback };
|
package/dist/react.js
CHANGED
|
@@ -152,11 +152,9 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
152
152
|
function noop() {
|
|
153
153
|
}
|
|
154
154
|
var noopStorage = {
|
|
155
|
-
getItem: noop,
|
|
156
|
-
setItem: noop,
|
|
157
|
-
removeItem: noop
|
|
158
|
-
keys: [],
|
|
159
|
-
getAllKeys: noop
|
|
155
|
+
getItem: () => Promise.resolve(noop()),
|
|
156
|
+
setItem: () => Promise.resolve(noop()),
|
|
157
|
+
removeItem: () => Promise.resolve(noop())
|
|
160
158
|
};
|
|
161
159
|
var EMPTY = Symbol();
|
|
162
160
|
var createListsAtom = (storeName, reducer, initialState) => {
|
|
@@ -167,7 +165,6 @@ var createListsAtom = (storeName, reducer, initialState) => {
|
|
|
167
165
|
storeName
|
|
168
166
|
});
|
|
169
167
|
return {
|
|
170
|
-
db,
|
|
171
168
|
getItem: (key) => chunk4TPCCB4K_js.__async(this, null, function* () {
|
|
172
169
|
const value = yield db.getItem(key);
|
|
173
170
|
if (value) {
|
|
@@ -175,40 +172,36 @@ var createListsAtom = (storeName, reducer, initialState) => {
|
|
|
175
172
|
}
|
|
176
173
|
return initialState;
|
|
177
174
|
}),
|
|
178
|
-
setItem: (k, v) => {
|
|
175
|
+
setItem: (k, v) => chunk4TPCCB4K_js.__async(this, null, function* () {
|
|
179
176
|
if (v === EMPTY)
|
|
180
177
|
return;
|
|
181
|
-
|
|
182
|
-
},
|
|
178
|
+
yield db.setItem(k, v);
|
|
179
|
+
}),
|
|
183
180
|
removeItem: db.removeItem
|
|
184
181
|
};
|
|
185
182
|
}
|
|
186
183
|
return noopStorage;
|
|
187
184
|
}
|
|
188
|
-
const listsStorageAtom = utils.atomWithStorage(
|
|
189
|
-
"lists",
|
|
190
|
-
EMPTY,
|
|
191
|
-
// @ts-ignore
|
|
192
|
-
IndexedDBStorage("lists")
|
|
193
|
-
);
|
|
185
|
+
const listsStorageAtom = utils.atomWithStorage("lists", EMPTY, IndexedDBStorage("lists"));
|
|
194
186
|
const defaultStateAtom = jotai.atom(
|
|
195
187
|
(get) => {
|
|
196
|
-
const
|
|
197
|
-
if (
|
|
198
|
-
return
|
|
188
|
+
const value = get(utils.loadable(listsStorageAtom));
|
|
189
|
+
if (value.state === "hasData" && value.data !== EMPTY) {
|
|
190
|
+
return value.data;
|
|
199
191
|
}
|
|
200
|
-
return
|
|
192
|
+
return initialState;
|
|
201
193
|
},
|
|
202
194
|
(get, set, action) => chunk4TPCCB4K_js.__async(void 0, null, function* () {
|
|
203
195
|
set(listsStorageAtom, reducer(yield get(defaultStateAtom), action));
|
|
204
196
|
})
|
|
205
197
|
);
|
|
206
|
-
const isReadyAtom =
|
|
198
|
+
const isReadyAtom = utils.loadable(listsStorageAtom);
|
|
207
199
|
function useListState() {
|
|
208
200
|
return jotai.useAtom(defaultStateAtom);
|
|
209
201
|
}
|
|
210
202
|
function useListStateReady() {
|
|
211
|
-
|
|
203
|
+
const value = jotai.useAtomValue(isReadyAtom);
|
|
204
|
+
return value.state === "hasData" && value.data !== EMPTY;
|
|
212
205
|
}
|
|
213
206
|
return {
|
|
214
207
|
listsAtom: defaultStateAtom,
|
package/dist/react.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { getVersionUpgrade } from './chunk-COROHIJN.mjs';
|
|
|
2
2
|
import { __spreadProps, __spreadValues, __async } from './chunk-2L3ZO4UM.mjs';
|
|
3
3
|
import { createAction, createReducer, nanoid } from '@reduxjs/toolkit';
|
|
4
4
|
import { atom, useAtom, useAtomValue } from 'jotai';
|
|
5
|
-
import { atomWithStorage } from 'jotai/utils';
|
|
5
|
+
import { atomWithStorage, loadable } from 'jotai/utils';
|
|
6
6
|
import localForage from 'localforage';
|
|
7
7
|
import { useCallback } from 'react';
|
|
8
8
|
|
|
@@ -146,11 +146,9 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
|
|
|
146
146
|
function noop() {
|
|
147
147
|
}
|
|
148
148
|
var noopStorage = {
|
|
149
|
-
getItem: noop,
|
|
150
|
-
setItem: noop,
|
|
151
|
-
removeItem: noop
|
|
152
|
-
keys: [],
|
|
153
|
-
getAllKeys: noop
|
|
149
|
+
getItem: () => Promise.resolve(noop()),
|
|
150
|
+
setItem: () => Promise.resolve(noop()),
|
|
151
|
+
removeItem: () => Promise.resolve(noop())
|
|
154
152
|
};
|
|
155
153
|
var EMPTY = Symbol();
|
|
156
154
|
var createListsAtom = (storeName, reducer, initialState) => {
|
|
@@ -161,7 +159,6 @@ var createListsAtom = (storeName, reducer, initialState) => {
|
|
|
161
159
|
storeName
|
|
162
160
|
});
|
|
163
161
|
return {
|
|
164
|
-
db,
|
|
165
162
|
getItem: (key) => __async(this, null, function* () {
|
|
166
163
|
const value = yield db.getItem(key);
|
|
167
164
|
if (value) {
|
|
@@ -169,40 +166,36 @@ var createListsAtom = (storeName, reducer, initialState) => {
|
|
|
169
166
|
}
|
|
170
167
|
return initialState;
|
|
171
168
|
}),
|
|
172
|
-
setItem: (k, v) => {
|
|
169
|
+
setItem: (k, v) => __async(this, null, function* () {
|
|
173
170
|
if (v === EMPTY)
|
|
174
171
|
return;
|
|
175
|
-
|
|
176
|
-
},
|
|
172
|
+
yield db.setItem(k, v);
|
|
173
|
+
}),
|
|
177
174
|
removeItem: db.removeItem
|
|
178
175
|
};
|
|
179
176
|
}
|
|
180
177
|
return noopStorage;
|
|
181
178
|
}
|
|
182
|
-
const listsStorageAtom = atomWithStorage(
|
|
183
|
-
"lists",
|
|
184
|
-
EMPTY,
|
|
185
|
-
// @ts-ignore
|
|
186
|
-
IndexedDBStorage("lists")
|
|
187
|
-
);
|
|
179
|
+
const listsStorageAtom = atomWithStorage("lists", EMPTY, IndexedDBStorage("lists"));
|
|
188
180
|
const defaultStateAtom = atom(
|
|
189
181
|
(get) => {
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
192
|
-
return
|
|
182
|
+
const value = get(loadable(listsStorageAtom));
|
|
183
|
+
if (value.state === "hasData" && value.data !== EMPTY) {
|
|
184
|
+
return value.data;
|
|
193
185
|
}
|
|
194
|
-
return
|
|
186
|
+
return initialState;
|
|
195
187
|
},
|
|
196
188
|
(get, set, action) => __async(void 0, null, function* () {
|
|
197
189
|
set(listsStorageAtom, reducer(yield get(defaultStateAtom), action));
|
|
198
190
|
})
|
|
199
191
|
);
|
|
200
|
-
const isReadyAtom =
|
|
192
|
+
const isReadyAtom = loadable(listsStorageAtom);
|
|
201
193
|
function useListState() {
|
|
202
194
|
return useAtom(defaultStateAtom);
|
|
203
195
|
}
|
|
204
196
|
function useListStateReady() {
|
|
205
|
-
|
|
197
|
+
const value = useAtomValue(isReadyAtom);
|
|
198
|
+
return value.state === "hasData" && value.data !== EMPTY;
|
|
206
199
|
}
|
|
207
200
|
return {
|
|
208
201
|
listsAtom: defaultStateAtom,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pancakeswap/token-lists",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -11,18 +11,19 @@
|
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {
|
|
13
13
|
"@reduxjs/toolkit": "^1.9.1",
|
|
14
|
+
"jotai": "^2.4.3",
|
|
14
15
|
"localforage": "^1.10.0",
|
|
15
|
-
"jotai": "^2.2.1",
|
|
16
16
|
"react": "^18.2.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@types/react": "^18.0.17",
|
|
20
|
-
"localforage": "^1.10.0",
|
|
21
|
-
"jotai": "^2.2.1",
|
|
22
19
|
"@reduxjs/toolkit": "^1.9.1",
|
|
20
|
+
"@types/react": "^18.2.21",
|
|
21
|
+
"jotai": "^2.4.3",
|
|
22
|
+
"localforage": "^1.10.0",
|
|
23
23
|
"react": "^18.2.0",
|
|
24
24
|
"tsup": "^6.7.0",
|
|
25
|
-
"
|
|
25
|
+
"vitest": "^0.34.4",
|
|
26
|
+
"@pancakeswap/utils": "5.0.6"
|
|
26
27
|
},
|
|
27
28
|
"exports": {
|
|
28
29
|
".": {
|
|
@@ -53,6 +54,7 @@
|
|
|
53
54
|
"scripts": {
|
|
54
55
|
"build": "tsup",
|
|
55
56
|
"dev": "tsup --watch",
|
|
57
|
+
"test": "vitest --run",
|
|
56
58
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
57
59
|
}
|
|
58
60
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { expect, test } from 'vitest'
|
|
2
|
+
import * as exports from './index'
|
|
3
|
+
|
|
4
|
+
test('exports', () => {
|
|
5
|
+
expect(Object.keys(exports)).toMatchInlineSnapshot(`
|
|
6
|
+
[
|
|
7
|
+
"NEW_LIST_STATE",
|
|
8
|
+
"createTokenListReducer",
|
|
9
|
+
"fetchTokenList",
|
|
10
|
+
"addList",
|
|
11
|
+
"removeList",
|
|
12
|
+
"enableList",
|
|
13
|
+
"disableList",
|
|
14
|
+
"acceptListUpdate",
|
|
15
|
+
"rejectVersionUpdate",
|
|
16
|
+
"updateListVersion",
|
|
17
|
+
"createListsAtom",
|
|
18
|
+
"useFetchListCallback",
|
|
19
|
+
]
|
|
20
|
+
`)
|
|
21
|
+
})
|
package/react/lists.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { atom, useAtom, useAtomValue } from 'jotai'
|
|
2
|
-
import { atomWithStorage } from 'jotai/utils'
|
|
2
|
+
import { atomWithStorage, loadable } from 'jotai/utils'
|
|
3
|
+
import { type AsyncStorage } from 'jotai/vanilla/utils/atomWithStorage'
|
|
3
4
|
import localForage from 'localforage'
|
|
4
5
|
import { ListsState } from './reducer'
|
|
5
6
|
|
|
6
7
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
7
8
|
function noop() {}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
getAllKeys: noop,
|
|
9
|
+
|
|
10
|
+
const noopStorage: AsyncStorage<any> = {
|
|
11
|
+
getItem: () => Promise.resolve(noop()),
|
|
12
|
+
setItem: () => Promise.resolve(noop()),
|
|
13
|
+
removeItem: () => Promise.resolve(noop()),
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
// eslint-disable-next-line symbol-description
|
|
@@ -21,14 +21,13 @@ export const createListsAtom = (storeName: string, reducer: any, initialState: a
|
|
|
21
21
|
* Persist you redux state using IndexedDB
|
|
22
22
|
* @param {string} dbName - IndexedDB database name
|
|
23
23
|
*/
|
|
24
|
-
function IndexedDBStorage(dbName: string) {
|
|
24
|
+
function IndexedDBStorage<Value>(dbName: string): AsyncStorage<Value> {
|
|
25
25
|
if (typeof window !== 'undefined') {
|
|
26
26
|
const db = localForage.createInstance({
|
|
27
27
|
name: dbName,
|
|
28
28
|
storeName,
|
|
29
29
|
})
|
|
30
30
|
return {
|
|
31
|
-
db,
|
|
32
31
|
getItem: async (key: string) => {
|
|
33
32
|
const value = await db.getItem(key)
|
|
34
33
|
if (value) {
|
|
@@ -36,10 +35,9 @@ export const createListsAtom = (storeName: string, reducer: any, initialState: a
|
|
|
36
35
|
}
|
|
37
36
|
return initialState
|
|
38
37
|
},
|
|
39
|
-
setItem: (k: string, v: any) => {
|
|
38
|
+
setItem: async (k: string, v: any) => {
|
|
40
39
|
if (v === EMPTY) return
|
|
41
|
-
|
|
42
|
-
return db.setItem(k, v)
|
|
40
|
+
await db.setItem(k, v)
|
|
43
41
|
},
|
|
44
42
|
removeItem: db.removeItem,
|
|
45
43
|
}
|
|
@@ -47,34 +45,30 @@ export const createListsAtom = (storeName: string, reducer: any, initialState: a
|
|
|
47
45
|
return noopStorage
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
const listsStorageAtom = atomWithStorage<ListsState | typeof EMPTY>(
|
|
51
|
-
'lists',
|
|
52
|
-
EMPTY,
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
IndexedDBStorage('lists'),
|
|
55
|
-
)
|
|
48
|
+
const listsStorageAtom = atomWithStorage<ListsState | typeof EMPTY>('lists', EMPTY, IndexedDBStorage('lists'))
|
|
56
49
|
|
|
57
50
|
const defaultStateAtom = atom<ListsState, any, void>(
|
|
58
51
|
(get) => {
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
return
|
|
52
|
+
const value = get(loadable(listsStorageAtom))
|
|
53
|
+
if (value.state === 'hasData' && value.data !== EMPTY) {
|
|
54
|
+
return value.data
|
|
62
55
|
}
|
|
63
|
-
return
|
|
56
|
+
return initialState
|
|
64
57
|
},
|
|
65
58
|
async (get, set, action) => {
|
|
66
59
|
set(listsStorageAtom, reducer(await get(defaultStateAtom), action))
|
|
67
60
|
},
|
|
68
61
|
)
|
|
69
62
|
|
|
70
|
-
const isReadyAtom =
|
|
63
|
+
const isReadyAtom = loadable(listsStorageAtom)
|
|
71
64
|
|
|
72
65
|
function useListState() {
|
|
73
66
|
return useAtom(defaultStateAtom)
|
|
74
67
|
}
|
|
75
68
|
|
|
76
69
|
function useListStateReady() {
|
|
77
|
-
|
|
70
|
+
const value = useAtomValue(isReadyAtom)
|
|
71
|
+
return value.state === 'hasData' && value.data !== EMPTY
|
|
78
72
|
}
|
|
79
73
|
|
|
80
74
|
return {
|
package/react/reducer.test.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach } from 'vitest'
|
|
2
|
-
import {
|
|
3
|
-
import { configureStore } from '@reduxjs/toolkit'
|
|
2
|
+
import { configureStore, type EnhancedStore } from '@reduxjs/toolkit'
|
|
4
3
|
|
|
5
4
|
import { fetchTokenList, acceptListUpdate, addList, removeList, enableList, updateListVersion } from './actions'
|
|
6
|
-
import { ListsState, createTokenListReducer, NEW_LIST_STATE } from './reducer'
|
|
5
|
+
import { ListsState, createTokenListReducer, NEW_LIST_STATE, type ListByUrlState } from './reducer'
|
|
7
6
|
|
|
8
|
-
const DEFAULT_ACTIVE_LIST_URLS = []
|
|
7
|
+
const DEFAULT_ACTIVE_LIST_URLS: string[] = []
|
|
9
8
|
const DEFAULT_LIST_OF_LISTS = ['https://tokens.pancakeswap.finance/pancakeswap-extended.json']
|
|
10
9
|
const STUB_TOKEN_LIST = {
|
|
11
10
|
name: '',
|
|
@@ -14,7 +13,7 @@ const STUB_TOKEN_LIST = {
|
|
|
14
13
|
tokens: [],
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
const UNSUPPORTED_LIST_URLS = []
|
|
16
|
+
const UNSUPPORTED_LIST_URLS: string[] = []
|
|
18
17
|
|
|
19
18
|
const reducer = createTokenListReducer(
|
|
20
19
|
{
|
|
@@ -23,7 +22,7 @@ const reducer = createTokenListReducer(
|
|
|
23
22
|
...DEFAULT_LIST_OF_LISTS.concat(...UNSUPPORTED_LIST_URLS).reduce((memo, listUrl) => {
|
|
24
23
|
memo[listUrl] = NEW_LIST_STATE
|
|
25
24
|
return memo
|
|
26
|
-
}, {}),
|
|
25
|
+
}, {} as Record<string, ListByUrlState>),
|
|
27
26
|
},
|
|
28
27
|
activeListUrls: DEFAULT_ACTIVE_LIST_URLS,
|
|
29
28
|
},
|
|
@@ -44,12 +43,24 @@ const MAJOR_UPDATED_STUB_LIST = {
|
|
|
44
43
|
version: { ...STUB_TOKEN_LIST.version, major: STUB_TOKEN_LIST.version.major + 1 },
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
const resetStore = (preloadedState?: ListsState) => {
|
|
47
|
+
return configureStore({ reducer, preloadedState })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('list reducer', () => {
|
|
51
|
+
let store: EnhancedStore<ListsState> = resetStore()
|
|
49
52
|
|
|
50
53
|
beforeEach(() => {
|
|
51
|
-
store =
|
|
52
|
-
|
|
54
|
+
store = resetStore({
|
|
55
|
+
byUrl: {
|
|
56
|
+
'fake-url': {
|
|
57
|
+
error: null,
|
|
58
|
+
current: STUB_TOKEN_LIST,
|
|
59
|
+
pendingUpdate: null,
|
|
60
|
+
loadingRequestId: null,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
activeListUrls: undefined,
|
|
53
64
|
})
|
|
54
65
|
})
|
|
55
66
|
|
|
@@ -62,7 +73,7 @@ describe.skip('list reducer', () => {
|
|
|
62
73
|
'fake-url': {
|
|
63
74
|
error: null,
|
|
64
75
|
loadingRequestId: 'request-id',
|
|
65
|
-
current:
|
|
76
|
+
current: STUB_TOKEN_LIST,
|
|
66
77
|
pendingUpdate: null,
|
|
67
78
|
},
|
|
68
79
|
},
|
|
@@ -71,7 +82,7 @@ describe.skip('list reducer', () => {
|
|
|
71
82
|
})
|
|
72
83
|
|
|
73
84
|
it('does not clear current list', () => {
|
|
74
|
-
store =
|
|
85
|
+
store = resetStore({
|
|
75
86
|
byUrl: {
|
|
76
87
|
'fake-url': {
|
|
77
88
|
error: null,
|
|
@@ -200,6 +211,7 @@ describe.skip('list reducer', () => {
|
|
|
200
211
|
|
|
201
212
|
describe('rejected', () => {
|
|
202
213
|
it('no-op if not loading', () => {
|
|
214
|
+
store = resetStore({ byUrl: {}, activeListUrls: undefined })
|
|
203
215
|
store.dispatch(fetchTokenList.rejected({ requestId: 'request-id', errorMessage: 'abcd', url: 'fake-url' }))
|
|
204
216
|
expect(store.getState()).toEqual({
|
|
205
217
|
byUrl: {},
|
|
@@ -208,7 +220,7 @@ describe.skip('list reducer', () => {
|
|
|
208
220
|
})
|
|
209
221
|
|
|
210
222
|
it('sets the error if loading', () => {
|
|
211
|
-
store =
|
|
223
|
+
store = resetStore({
|
|
212
224
|
byUrl: {
|
|
213
225
|
'fake-url': {
|
|
214
226
|
error: null,
|
|
@@ -237,9 +249,26 @@ describe.skip('list reducer', () => {
|
|
|
237
249
|
|
|
238
250
|
describe('addList', () => {
|
|
239
251
|
it('adds the list key to byUrl', () => {
|
|
252
|
+
store = resetStore({
|
|
253
|
+
byUrl: {
|
|
254
|
+
'fake-url': {
|
|
255
|
+
error: null,
|
|
256
|
+
current: STUB_TOKEN_LIST,
|
|
257
|
+
loadingRequestId: null,
|
|
258
|
+
pendingUpdate: null,
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
activeListUrls: undefined,
|
|
262
|
+
})
|
|
240
263
|
store.dispatch(addList('list-id'))
|
|
241
264
|
expect(store.getState()).toEqual({
|
|
242
265
|
byUrl: {
|
|
266
|
+
'fake-url': {
|
|
267
|
+
error: null,
|
|
268
|
+
current: STUB_TOKEN_LIST,
|
|
269
|
+
loadingRequestId: null,
|
|
270
|
+
pendingUpdate: null,
|
|
271
|
+
},
|
|
243
272
|
'list-id': {
|
|
244
273
|
error: null,
|
|
245
274
|
current: null,
|
|
@@ -251,7 +280,7 @@ describe.skip('list reducer', () => {
|
|
|
251
280
|
})
|
|
252
281
|
})
|
|
253
282
|
it('no op for existing list', () => {
|
|
254
|
-
store =
|
|
283
|
+
store = resetStore({
|
|
255
284
|
byUrl: {
|
|
256
285
|
'fake-url': {
|
|
257
286
|
error: null,
|
|
@@ -279,7 +308,7 @@ describe.skip('list reducer', () => {
|
|
|
279
308
|
|
|
280
309
|
describe('acceptListUpdate', () => {
|
|
281
310
|
it('swaps pending update into current', () => {
|
|
282
|
-
store =
|
|
311
|
+
store = resetStore({
|
|
283
312
|
byUrl: {
|
|
284
313
|
'fake-url': {
|
|
285
314
|
error: null,
|
|
@@ -307,7 +336,7 @@ describe.skip('list reducer', () => {
|
|
|
307
336
|
|
|
308
337
|
describe('removeList', () => {
|
|
309
338
|
it('deletes the list key', () => {
|
|
310
|
-
store =
|
|
339
|
+
store = resetStore({
|
|
311
340
|
byUrl: {
|
|
312
341
|
'fake-url': {
|
|
313
342
|
error: null,
|
|
@@ -325,7 +354,7 @@ describe.skip('list reducer', () => {
|
|
|
325
354
|
})
|
|
326
355
|
})
|
|
327
356
|
it('Removes from active lists if active list is removed', () => {
|
|
328
|
-
store =
|
|
357
|
+
store = resetStore({
|
|
329
358
|
byUrl: {
|
|
330
359
|
'fake-url': {
|
|
331
360
|
error: null,
|
|
@@ -346,7 +375,7 @@ describe.skip('list reducer', () => {
|
|
|
346
375
|
|
|
347
376
|
describe('enableList', () => {
|
|
348
377
|
it('enables a list url', () => {
|
|
349
|
-
store =
|
|
378
|
+
store = resetStore({
|
|
350
379
|
byUrl: {
|
|
351
380
|
'fake-url': {
|
|
352
381
|
error: null,
|
|
@@ -371,7 +400,7 @@ describe.skip('list reducer', () => {
|
|
|
371
400
|
})
|
|
372
401
|
})
|
|
373
402
|
it('adds to url keys if not present already on enable', () => {
|
|
374
|
-
store =
|
|
403
|
+
store = resetStore({
|
|
375
404
|
byUrl: {
|
|
376
405
|
'fake-url': {
|
|
377
406
|
error: null,
|
|
@@ -402,7 +431,7 @@ describe.skip('list reducer', () => {
|
|
|
402
431
|
})
|
|
403
432
|
})
|
|
404
433
|
it('enable works if list already added', () => {
|
|
405
|
-
store =
|
|
434
|
+
store = resetStore({
|
|
406
435
|
byUrl: {
|
|
407
436
|
'fake-url': {
|
|
408
437
|
error: null,
|
|
@@ -431,7 +460,7 @@ describe.skip('list reducer', () => {
|
|
|
431
460
|
describe('updateVersion', () => {
|
|
432
461
|
describe('never initialized', () => {
|
|
433
462
|
beforeEach(() => {
|
|
434
|
-
store =
|
|
463
|
+
store = resetStore({
|
|
435
464
|
byUrl: {
|
|
436
465
|
'https://unpkg.com/@uniswap/default-token-list@latest/uniswap-default.tokenlist.json': {
|
|
437
466
|
error: null,
|
|
@@ -481,7 +510,7 @@ describe.skip('list reducer', () => {
|
|
|
481
510
|
})
|
|
482
511
|
describe('initialized with a different set of lists', () => {
|
|
483
512
|
beforeEach(() => {
|
|
484
|
-
store =
|
|
513
|
+
store = resetStore({
|
|
485
514
|
byUrl: {
|
|
486
515
|
'https://unpkg.com/@uniswap/default-token-list@latest/uniswap-default.tokenlist.json': {
|
|
487
516
|
error: null,
|
package/react/reducer.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface ListsState {
|
|
|
27
27
|
readonly activeListUrls: string[] | undefined
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
type ListByUrlState = ListsState['byUrl'][string]
|
|
30
|
+
export type ListByUrlState = ListsState['byUrl'][string]
|
|
31
31
|
|
|
32
32
|
export const NEW_LIST_STATE: ListByUrlState = {
|
|
33
33
|
error: null,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { expect, test } from 'vitest'
|
|
2
|
+
import * as exports from './index'
|
|
3
|
+
|
|
4
|
+
test('exports', () => {
|
|
5
|
+
expect(Object.keys(exports)).toMatchInlineSnapshot(`
|
|
6
|
+
[
|
|
7
|
+
"WrappedTokenInfo",
|
|
8
|
+
"deserializeToken",
|
|
9
|
+
"VersionUpgrade",
|
|
10
|
+
"getVersionUpgrade",
|
|
11
|
+
"createFilterToken",
|
|
12
|
+
]
|
|
13
|
+
`)
|
|
14
|
+
})
|