@suilend/sui-fe 0.2.97 → 0.2.99

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/lib/keypair.d.ts CHANGED
@@ -13,6 +13,9 @@ export declare const createKeypair: (account: WalletAccount, signPersonalMessage
13
13
  export declare const checkIfKeypairCanBeUsed: (lastSignedTransaction: SignatureWithBytes | undefined, currentFlowDigests: string[], keypair: Ed25519Keypair, suiClient: SuiClient) => Promise<{
14
14
  lastCurrentFlowTransaction: SuiTransactionBlockResponse | undefined;
15
15
  }>;
16
+ export declare class TransactionStatusError extends Error {
17
+ constructor(message: string);
18
+ }
16
19
  export declare const keypairWaitForTransaction: (digest: string, suiClient: SuiClient) => Promise<SuiTransactionBlockResponse>;
17
20
  export declare const keypairSignExecuteAndWaitForTransaction: (transaction: Transaction, keypair: Ed25519Keypair, suiClient: SuiClient, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<SuiTransactionBlockResponse>;
18
21
  export type FundKeypairResult = {
package/lib/keypair.js CHANGED
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.returnAllOwnedObjectsAndSuiToUser = exports.fundKeypair = exports.keypairSignExecuteAndWaitForTransaction = exports.keypairWaitForTransaction = exports.checkIfKeypairCanBeUsed = exports.createKeypair = void 0;
15
+ exports.returnAllOwnedObjectsAndSuiToUser = exports.fundKeypair = exports.keypairSignExecuteAndWaitForTransaction = exports.keypairWaitForTransaction = exports.TransactionStatusError = exports.checkIfKeypairCanBeUsed = exports.createKeypair = void 0;
16
16
  const ed25519_1 = require("@mysten/sui/keypairs/ed25519");
17
17
  const transactions_1 = require("@mysten/sui/transactions");
18
18
  const utils_1 = require("@mysten/sui/utils");
@@ -37,59 +37,57 @@ const createKeypair = (account, signPersonalMessage) => __awaiter(void 0, void 0
37
37
  exports.createKeypair = createKeypair;
38
38
  const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigests, keypair, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
39
39
  var _a, _b;
40
- const ownedObjectIds = (yield (0, transactions_2.getAllOwnedObjects)(suiClient, keypair.toSuiAddress())).map((obj) => { var _a; return (_a = obj.data) === null || _a === void 0 ? void 0 : _a.objectId; });
41
- console.log("[checkIfKeypairCanBeUsed] ownedObjectIds:", ownedObjectIds);
42
- if (ownedObjectIds.length === 0) {
43
- // Empty wallet
40
+ const [mostRecentFromAddressTransaction, mostRecentToAddressTransaction] = yield Promise.all([
41
+ (0, transactions_2.getMostRecentAddressTransaction)(suiClient, keypair.toSuiAddress(), "from"),
42
+ (0, transactions_2.getMostRecentAddressTransaction)(suiClient, keypair.toSuiAddress(), "to"),
43
+ ]);
44
+ const mostRecentFromOrToAddressTransaction = [
45
+ mostRecentFromAddressTransaction,
46
+ mostRecentToAddressTransaction,
47
+ ].sort((a, b) => { var _a, _b; return +((_a = b === null || b === void 0 ? void 0 : b.timestampMs) !== null && _a !== void 0 ? _a : 0) - +((_b = a === null || a === void 0 ? void 0 : a.timestampMs) !== null && _b !== void 0 ? _b : 0); })[0];
48
+ console.log("[checkIfKeypairCanBeUsed] mostRecentFromAddressTransaction:", mostRecentFromAddressTransaction, "mostRecentToAddressTransaction:", mostRecentToAddressTransaction, "mostRecentFromOrToAddressTransaction:", mostRecentFromOrToAddressTransaction, "lastSignedTransaction:", lastSignedTransaction, "currentFlowDigests:", currentFlowDigests);
49
+ if (mostRecentFromOrToAddressTransaction === undefined) {
50
+ // Wallet with no TO/FROM transactions
44
51
  // CONTINUE
45
52
  return { lastCurrentFlowTransaction: undefined };
46
53
  }
47
54
  else {
48
- const [mostRecentFromAddressTransaction, mostRecentToAddressTransaction] = yield Promise.all([
49
- (0, transactions_2.getMostRecentAddressTransaction)(suiClient, keypair.toSuiAddress(), "from"),
50
- (0, transactions_2.getMostRecentAddressTransaction)(suiClient, keypair.toSuiAddress(), "to"),
51
- ]);
52
- const mostRecentFromOrToAddressTransaction = [
53
- mostRecentFromAddressTransaction,
54
- mostRecentToAddressTransaction,
55
- ].sort((a, b) => { var _a, _b; return +((_a = b === null || b === void 0 ? void 0 : b.timestampMs) !== null && _a !== void 0 ? _a : 0) - +((_b = a === null || a === void 0 ? void 0 : a.timestampMs) !== null && _b !== void 0 ? _b : 0); })[0];
56
- console.log("[checkIfKeypairCanBeUsed] mostRecentFromAddressTransaction:", mostRecentFromAddressTransaction, "mostRecentToAddressTransaction:", mostRecentToAddressTransaction, "mostRecentFromOrToAddressTransaction:", mostRecentFromOrToAddressTransaction, "lastSignedTransaction:", lastSignedTransaction, "currentFlowDigests:", currentFlowDigests);
57
- if (mostRecentFromOrToAddressTransaction === undefined) {
58
- // Non-empty wallet with no FROM transactions
55
+ // Wallet with TO/FROM transactions
56
+ if ((lastSignedTransaction !== undefined &&
57
+ ((_b = (_a = mostRecentFromOrToAddressTransaction.transaction) === null || _a === void 0 ? void 0 : _a.txSignatures) !== null && _b !== void 0 ? _b : []).includes(lastSignedTransaction.signature)) ||
58
+ currentFlowDigests.includes(mostRecentFromOrToAddressTransaction.digest)) {
59
+ // Retrying current flow
59
60
  // CONTINUE
60
- return { lastCurrentFlowTransaction: undefined };
61
+ return {
62
+ lastCurrentFlowTransaction: mostRecentFromOrToAddressTransaction,
63
+ };
61
64
  }
62
65
  else {
63
- // Non-empty wallet with FROM transactions
64
- if ((lastSignedTransaction !== undefined &&
65
- ((_b = (_a = mostRecentFromOrToAddressTransaction.transaction) === null || _a === void 0 ? void 0 : _a.txSignatures) !== null && _b !== void 0 ? _b : []).includes(lastSignedTransaction.signature)) ||
66
- currentFlowDigests.includes(mostRecentFromOrToAddressTransaction.digest)) {
67
- // Retrying current flow
68
- // CONTINUE
69
- return {
70
- lastCurrentFlowTransaction: mostRecentFromOrToAddressTransaction,
71
- };
66
+ // Previous flow
67
+ const timestampMs = mostRecentFromOrToAddressTransaction.timestampMs;
68
+ const isRecent = !!timestampMs && +timestampMs > Date.now() - 1000 * 60 * 2; // Less than 2 minutes ago
69
+ console.log("[checkIfKeypairCanBeUsed] isRecent:", isRecent, timestampMs, Date.now() - 1000 * 60 * 2);
70
+ if (isRecent) {
71
+ // Previous flow may be ongoing
72
+ // STOP
73
+ throw new Error("Please wait for previous flow to complete");
72
74
  }
73
75
  else {
74
- // Previous flow
75
- const timestampMs = mostRecentFromOrToAddressTransaction.timestampMs;
76
- const isRecent = !!timestampMs && +timestampMs > Date.now() - 1000 * 60 * 2; // Less than 2 minutes ago
77
- console.log("[checkIfKeypairCanBeUsed] isRecent:", isRecent, timestampMs, Date.now() - 1000 * 60 * 2);
78
- if (isRecent) {
79
- // Previous flow may be ongoing
80
- // STOP
81
- throw new Error("Please wait for previous flow to complete");
82
- }
83
- else {
84
- // Previous flow stopped before completion
85
- // CONTINUE
86
- return { lastCurrentFlowTransaction: undefined };
87
- }
76
+ // Previous flow stopped before completion
77
+ // CONTINUE
78
+ return { lastCurrentFlowTransaction: undefined };
88
79
  }
89
80
  }
90
81
  }
91
82
  });
92
83
  exports.checkIfKeypairCanBeUsed = checkIfKeypairCanBeUsed;
84
+ class TransactionStatusError extends Error {
85
+ constructor(message) {
86
+ super(message);
87
+ this.name = "TxStatusError";
88
+ }
89
+ }
90
+ exports.TransactionStatusError = TransactionStatusError;
93
91
  const keypairWaitForTransaction = (digest, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
94
92
  var _a, _b;
95
93
  const res = yield suiClient.waitForTransaction({
@@ -103,7 +101,7 @@ const keypairWaitForTransaction = (digest, suiClient) => __awaiter(void 0, void
103
101
  });
104
102
  if (((_a = res.effects) === null || _a === void 0 ? void 0 : _a.status) !== undefined &&
105
103
  res.effects.status.status === "failure")
106
- throw new Error((_b = res.effects.status.error) !== null && _b !== void 0 ? _b : "Transaction failed");
104
+ throw new TransactionStatusError((_b = res.effects.status.error) !== null && _b !== void 0 ? _b : "Transaction failed");
107
105
  return res;
108
106
  });
109
107
  exports.keypairWaitForTransaction = keypairWaitForTransaction;
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sui-fe","version":"0.2.97","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/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.14.7","@pythnetwork/pyth-sui-js":"^2.1.0","bignumber.js":"^9.1.2","lodash":"^4.17.21","mixpanel-browser":"^2.56.0","next":"^15.0.3","p-limit":"3.1.0"},"devDependencies":{"@tsconfig/recommended":"^1.0.8","@types/lodash":"^4.17.13","@types/mixpanel-browser":"^2.50.2","@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.28.2","date-fns":"^4.1.0"}}
1
+ {"name":"@suilend/sui-fe","version":"0.2.99","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/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.14.7","@pythnetwork/pyth-sui-js":"^2.1.0","bignumber.js":"^9.1.2","lodash":"^4.17.21","mixpanel-browser":"^2.56.0","next":"^15.0.3","p-limit":"3.1.0"},"devDependencies":{"@tsconfig/recommended":"^1.0.8","@types/lodash":"^4.17.13","@types/mixpanel-browser":"^2.50.2","@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.28.2","date-fns":"^4.1.0"}}