@pancakeswap/token-lists 0.0.6 → 0.0.8

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.mjs CHANGED
@@ -1,17 +1,11 @@
1
- import {
2
- getVersionUpgrade
3
- } from "./chunk-YBVZDUCZ.mjs";
4
- import {
5
- __async,
6
- __spreadProps,
7
- __spreadValues
8
- } from "./chunk-2L3ZO4UM.mjs";
1
+ import { getVersionUpgrade } from './chunk-COROHIJN.mjs';
2
+ import { __spreadProps, __spreadValues, __async } from './chunk-2L3ZO4UM.mjs';
3
+ import { createAction, createReducer, nanoid } from '@reduxjs/toolkit';
4
+ import { atom, useAtom, useAtomValue } from 'jotai';
5
+ import { atomWithStorage } from 'jotai/utils';
6
+ import localForage from 'localforage';
7
+ import { useCallback } from 'react';
9
8
 
10
- // react/reducer.ts
11
- import { createReducer } from "@reduxjs/toolkit";
12
-
13
- // react/actions.ts
14
- import { createAction } from "@reduxjs/toolkit";
15
9
  var fetchTokenList = {
16
10
  pending: createAction("lists/fetchTokenList/pending"),
17
11
  fulfilled: createAction("lists/fetchTokenList/fulfilled"),
@@ -149,11 +143,6 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
149
143
  }
150
144
  })
151
145
  );
152
-
153
- // react/lists.ts
154
- import { atom, useAtom, useAtomValue } from "jotai";
155
- import { atomWithStorage } from "jotai/utils";
156
- import localForage from "localforage";
157
146
  function noop() {
158
147
  }
159
148
  var noopStorage = {
@@ -204,9 +193,9 @@ var createListsAtom = (storeName, reducer, initialState) => {
204
193
  }
205
194
  return got;
206
195
  },
207
- (get, set, action) => {
208
- set(listsStorageAtom, reducer(get(defaultStateAtom), action));
209
- }
196
+ (get, set, action) => __async(void 0, null, function* () {
197
+ set(listsStorageAtom, reducer(yield get(defaultStateAtom), action));
198
+ })
210
199
  );
211
200
  const isReadyAtom = atom((get) => get(listsStorageAtom) !== EMPTY);
212
201
  function useListState() {
@@ -221,10 +210,6 @@ var createListsAtom = (storeName, reducer, initialState) => {
221
210
  useListState
222
211
  };
223
212
  };
224
-
225
- // react/useFetchListCallback.ts
226
- import { nanoid } from "@reduxjs/toolkit";
227
- import { useCallback } from "react";
228
213
  function useFetchListCallback(dispatch) {
229
214
  return useCallback(
230
215
  (listUrl, sendDispatch = true) => __async(this, null, function* () {
@@ -232,7 +217,7 @@ function useFetchListCallback(dispatch) {
232
217
  if (sendDispatch) {
233
218
  dispatch(fetchTokenList.pending({ requestId, url: listUrl }));
234
219
  }
235
- const getTokenList = (yield import("./getTokenList-2FAKUE6D.mjs")).default;
220
+ const getTokenList = (yield import('./getTokenList-2FAKUE6D.mjs')).default;
236
221
  return getTokenList(listUrl).then((tokenList) => {
237
222
  if (sendDispatch) {
238
223
  dispatch(fetchTokenList.fulfilled({ url: listUrl, tokenList, requestId }));
@@ -250,17 +235,5 @@ function useFetchListCallback(dispatch) {
250
235
  );
251
236
  }
252
237
  var useFetchListCallback_default = useFetchListCallback;
253
- export {
254
- NEW_LIST_STATE,
255
- acceptListUpdate,
256
- addList,
257
- createListsAtom,
258
- createTokenListReducer,
259
- disableList,
260
- enableList,
261
- fetchTokenList,
262
- rejectVersionUpdate,
263
- removeList,
264
- updateListVersion,
265
- useFetchListCallback_default as useFetchListCallback
266
- };
238
+
239
+ export { NEW_LIST_STATE, acceptListUpdate, addList, createListsAtom, createTokenListReducer, disableList, enableList, fetchTokenList, rejectVersionUpdate, removeList, updateListVersion, useFetchListCallback_default as useFetchListCallback };
@@ -1,7 +1,7 @@
1
1
  type ExtensionValue = string | number | boolean | null | undefined;
2
2
  interface TokenInfo {
3
3
  readonly chainId: number;
4
- readonly address: string;
4
+ readonly address: `0x${string}`;
5
5
  readonly name: string;
6
6
  readonly decimals: number;
7
7
  readonly symbol: string;
package/package.json CHANGED
@@ -1,30 +1,28 @@
1
1
  {
2
2
  "name": "@pancakeswap/token-lists",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
7
- "scripts": {
8
- "build": "tsup",
9
- "dev": "tsup --watch",
10
- "prepublishOnly": "yarn run build",
11
- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
12
- },
13
7
  "dependencies": {
14
8
  "ajv": "^6.12.3",
15
9
  "lodash": "^4.17.21",
16
- "@pancakeswap/swap-sdk-core": "*"
10
+ "@pancakeswap/swap-sdk-core": "1.0.0"
17
11
  },
18
12
  "peerDependencies": {
19
13
  "@reduxjs/toolkit": "^1.9.1",
20
14
  "localforage": "^1.10.0",
21
- "jotai": "^2.0.3",
15
+ "jotai": "^2.2.1",
22
16
  "react": "^18.2.0"
23
17
  },
24
18
  "devDependencies": {
19
+ "@types/react": "^18.0.17",
20
+ "localforage": "^1.10.0",
21
+ "jotai": "^2.2.1",
25
22
  "@reduxjs/toolkit": "^1.9.1",
26
23
  "react": "^18.2.0",
27
- "tsup": "^6.6.3"
24
+ "tsup": "^6.7.0",
25
+ "@pancakeswap/utils": "2.0.1"
28
26
  },
29
27
  "exports": {
30
28
  ".": {
@@ -51,5 +49,10 @@
51
49
  "jotai": {
52
50
  "optional": true
53
51
  }
52
+ },
53
+ "scripts": {
54
+ "build": "tsup",
55
+ "dev": "tsup --watch",
56
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
54
57
  }
55
- }
58
+ }
package/react/lists.ts CHANGED
@@ -62,8 +62,8 @@ export const createListsAtom = (storeName: string, reducer: any, initialState: a
62
62
  }
63
63
  return got
64
64
  },
65
- (get, set, action) => {
66
- set(listsStorageAtom, reducer(get(defaultStateAtom), action))
65
+ async (get, set, action) => {
66
+ set(listsStorageAtom, reducer(await get(defaultStateAtom), action))
67
67
  },
68
68
  )
69
69
 
@@ -0,0 +1,34 @@
1
+ import { Token } from '@pancakeswap/swap-sdk-core'
2
+ import { TokenInfo } from './types'
3
+
4
+ export function createFilterToken<T extends TokenInfo | Token>(
5
+ search: string,
6
+ isAddress: (address: string) => boolean,
7
+ ): (token: T) => boolean {
8
+ if (isAddress(search)) {
9
+ const address = search.toLowerCase()
10
+ return (t: T) => 'address' in t && address === t.address.toLowerCase()
11
+ }
12
+
13
+ const lowerSearchParts = search
14
+ .toLowerCase()
15
+ .split(/\s+/)
16
+ .filter((s) => s.length > 0)
17
+
18
+ if (lowerSearchParts.length === 0) {
19
+ return () => true
20
+ }
21
+
22
+ const matchesSearch = (s: string): boolean => {
23
+ const sParts = s
24
+ .toLowerCase()
25
+ .split(/\s+/)
26
+ .filter((s_) => s_.length > 0)
27
+
28
+ return lowerSearchParts.every((p) => p.length === 0 || sParts.some((sp) => sp.startsWith(p) || sp.endsWith(p)))
29
+ }
30
+ return (token) => {
31
+ const { symbol, name } = token
32
+ return Boolean((symbol && matchesSearch(symbol)) || (name && matchesSearch(name)))
33
+ }
34
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './wrappedTokenInfo'
2
2
  export * from './types'
3
3
  export * from './getVersionUpgrade'
4
+ export * from './filtering'
package/src/types.ts CHANGED
@@ -2,7 +2,7 @@ type ExtensionValue = string | number | boolean | null | undefined
2
2
 
3
3
  export interface TokenInfo {
4
4
  readonly chainId: number
5
- readonly address: string
5
+ readonly address: `0x${string}`
6
6
  readonly name: string
7
7
  readonly decimals: number
8
8
  readonly symbol: string
@@ -3,7 +3,7 @@ import { TokenInfo, TokenList } from './types'
3
3
 
4
4
  export interface SerializedWrappedToken extends SerializedToken {
5
5
  chainId: number
6
- address: string
6
+ address: `0x${string}`
7
7
  decimals: number
8
8
  symbol: string
9
9
  name?: string
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "tsconfig/react-library",
2
+ "extends": "@pancakeswap/tsconfig/react-library",
3
3
  "compilerOptions": {
4
4
  "esModuleInterop": true,
5
5
  "resolveJsonModule": true,
package/tsup.config.ts CHANGED
@@ -7,4 +7,6 @@ export default defineConfig({
7
7
  },
8
8
  format: ['esm', 'cjs'],
9
9
  dts: true,
10
+ treeshake: true,
11
+ splitting: true,
10
12
  })