@suilend/sui-fe 0.3.39 → 0.3.40

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.
@@ -1,5 +1,4 @@
1
1
  import { Token } from "./coinMetadata";
2
- export declare const initDB: () => Promise<IDBDatabase>;
3
2
  export declare const getTokenMapByCoinTypeFromIndexedDB: (coinTypes: string[]) => Promise<Record<string, Token>>;
4
3
  export declare const setTokenMapToIndexedDB: (tokenMap: Record<string, Token>) => Promise<void>;
5
4
  export declare const removeTokensFromIndexedDB: (coinTypes: string[]) => Promise<void>;
package/lib/indexedDB.js CHANGED
@@ -9,28 +9,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.removeTokensFromIndexedDB = exports.setTokenMapToIndexedDB = exports.getTokenMapByCoinTypeFromIndexedDB = exports.initDB = void 0;
12
+ exports.removeTokensFromIndexedDB = exports.setTokenMapToIndexedDB = exports.getTokenMapByCoinTypeFromIndexedDB = void 0;
13
13
  const DB_NAME = "suilend";
14
14
  const DB_VERSION = 1;
15
15
  const TOKEN_STORE = "token";
16
16
  const initDB = () => {
17
- return new Promise((resolve, reject) => {
18
- const request = indexedDB.open(DB_NAME, DB_VERSION);
19
- request.onerror = () => reject(request.error);
20
- request.onsuccess = () => resolve(request.result);
21
- request.onupgradeneeded = (event) => {
22
- const db = event.target.result;
23
- if (!db.objectStoreNames.contains(TOKEN_STORE)) {
24
- db.createObjectStore(TOKEN_STORE, { keyPath: "coinType" });
25
- }
26
- };
17
+ return new Promise((resolve) => {
18
+ try {
19
+ const request = indexedDB.open(DB_NAME, DB_VERSION);
20
+ request.onerror = () => resolve(null); // Silently fail if IndexedDB is not available
21
+ request.onsuccess = () => resolve(request.result);
22
+ request.onupgradeneeded = (event) => {
23
+ const db = event.target.result;
24
+ if (!db.objectStoreNames.contains(TOKEN_STORE)) {
25
+ db.createObjectStore(TOKEN_STORE, { keyPath: "coinType" });
26
+ }
27
+ };
28
+ }
29
+ catch (err) {
30
+ resolve(null); // Silently fail if IndexedDB is not available
31
+ }
27
32
  });
28
33
  };
29
- exports.initDB = initDB;
30
34
  const getTokenMapByCoinTypeFromIndexedDB = (coinTypes) => __awaiter(void 0, void 0, void 0, function* () {
31
35
  if (coinTypes.length === 0)
32
36
  return {};
33
- const db = yield (0, exports.initDB)();
37
+ const db = yield initDB();
38
+ if (!db)
39
+ return {};
34
40
  return new Promise((resolve, reject) => {
35
41
  const transaction = db.transaction(TOKEN_STORE, "readonly");
36
42
  const store = transaction.objectStore(TOKEN_STORE);
@@ -54,7 +60,9 @@ exports.getTokenMapByCoinTypeFromIndexedDB = getTokenMapByCoinTypeFromIndexedDB;
54
60
  const setTokenMapToIndexedDB = (tokenMap) => __awaiter(void 0, void 0, void 0, function* () {
55
61
  if (Object.keys(tokenMap).length === 0)
56
62
  return;
57
- const db = yield (0, exports.initDB)();
63
+ const db = yield initDB();
64
+ if (!db)
65
+ return;
58
66
  return new Promise((resolve, reject) => {
59
67
  const transaction = db.transaction(TOKEN_STORE, "readwrite");
60
68
  const store = transaction.objectStore(TOKEN_STORE);
@@ -73,7 +81,9 @@ exports.setTokenMapToIndexedDB = setTokenMapToIndexedDB;
73
81
  const removeTokensFromIndexedDB = (coinTypes) => __awaiter(void 0, void 0, void 0, function* () {
74
82
  if (coinTypes.length === 0)
75
83
  return;
76
- const db = yield (0, exports.initDB)();
84
+ const db = yield initDB();
85
+ if (!db)
86
+ return;
77
87
  return new Promise((resolve, reject) => {
78
88
  const transaction = db.transaction(TOKEN_STORE, "readwrite");
79
89
  const store = transaction.objectStore(TOKEN_STORE);
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sui-fe","version":"0.3.39","private":false,"description":"A collection of TypeScript frontend libraries","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./lib/api":"./lib/api.js","./lib/coin":"./lib/coin.js","./lib/coinMetadata":"./lib/coinMetadata.js","./lib/coinType":"./lib/coinType.js","./lib/constants":"./lib/constants.js","./lib/format":"./lib/format.js","./lib":"./lib/index.js","./lib/indexedDB":"./lib/indexedDB.js","./lib/keypair":"./lib/keypair.js","./lib/ledger":"./lib/ledger.js","./lib/msafe":"./lib/msafe.js","./lib/track":"./lib/track.js","./lib/transactions":"./lib/transactions.js"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix \"./src/**/*.ts\"","prettier":"prettier --write \"./src/**/*\"","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ts-node ./release.ts && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/suilend/sui-fe.git"},"bugs":{"url":"https://github.com/suilend/sui-fe/issues"},"dependencies":{"@mysten/wallet-standard":"0.19.2","bignumber.js":"^9.1.2","blake2b":"^2.1.4","lodash":"^4.17.21","mixpanel-browser":"^2.71.0","next":"^15.0.3","p-limit":"3.1.0"},"devDependencies":{"@tsconfig/recommended":"^1.0.8","@types/blake2b":"^2.1.3","@types/lodash":"^4.17.13","@types/node":"^22.9.0","@typescript-eslint/eslint-plugin":"^8.14.0","@typescript-eslint/parser":"^8.14.0","eslint":"^9.14.0","eslint-config-next":"^15.0.3","eslint-config-prettier":"^9.1.0","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.2.1","prettier":"^3.3.3","ts-node":"^10.9.2","typescript":"^5.6.3"},"peerDependencies":{"@mysten/sui":"1.42.0","date-fns":"^4.1.0"}}
1
+ {"name":"@suilend/sui-fe","version":"0.3.40","private":false,"description":"A collection of TypeScript frontend libraries","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./lib/api":"./lib/api.js","./lib/coin":"./lib/coin.js","./lib/coinMetadata":"./lib/coinMetadata.js","./lib/coinType":"./lib/coinType.js","./lib/constants":"./lib/constants.js","./lib/format":"./lib/format.js","./lib":"./lib/index.js","./lib/indexedDB":"./lib/indexedDB.js","./lib/keypair":"./lib/keypair.js","./lib/ledger":"./lib/ledger.js","./lib/msafe":"./lib/msafe.js","./lib/track":"./lib/track.js","./lib/transactions":"./lib/transactions.js"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix \"./src/**/*.ts\"","prettier":"prettier --write \"./src/**/*\"","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ts-node ./release.ts && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/suilend/sui-fe.git"},"bugs":{"url":"https://github.com/suilend/sui-fe/issues"},"dependencies":{"@mysten/wallet-standard":"0.19.2","bignumber.js":"^9.1.2","blake2b":"^2.1.4","lodash":"^4.17.21","mixpanel-browser":"^2.71.0","next":"^15.0.3","p-limit":"3.1.0"},"devDependencies":{"@tsconfig/recommended":"^1.0.8","@types/blake2b":"^2.1.3","@types/lodash":"^4.17.13","@types/node":"^22.9.0","@typescript-eslint/eslint-plugin":"^8.14.0","@typescript-eslint/parser":"^8.14.0","eslint":"^9.14.0","eslint-config-next":"^15.0.3","eslint-config-prettier":"^9.1.0","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.2.1","prettier":"^3.3.3","ts-node":"^10.9.2","typescript":"^5.6.3"},"peerDependencies":{"@mysten/sui":"1.42.0","date-fns":"^4.1.0"}}