@suilend/sui-fe 0.4.2 → 0.4.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.
Files changed (2) hide show
  1. package/lib/keypair.js +13 -9
  2. package/package.json +1 -1
package/lib/keypair.js CHANGED
@@ -22,7 +22,7 @@ export class TransactionStatusError extends Error {
22
22
  }
23
23
  }
24
24
  export const keypairWaitForTransaction = (digest, suiClient) => __awaiter(void 0, void 0, void 0, function* () {
25
- var _a, _b, _c, _d, _e, _f, _g;
25
+ var _a, _b, _c;
26
26
  const res = yield suiClient.core.waitForTransaction({
27
27
  digest,
28
28
  include: {
@@ -32,13 +32,13 @@ export const keypairWaitForTransaction = (digest, suiClient) => __awaiter(void 0
32
32
  objectChanges: true,
33
33
  },
34
34
  });
35
- if (((_b = (_a = res.Transaction) === null || _a === void 0 ? void 0 : _a.effects) === null || _b === void 0 ? void 0 : _b.status) !== undefined &&
36
- !!((_d = (_c = res.Transaction) === null || _c === void 0 ? void 0 : _c.effects) === null || _d === void 0 ? void 0 : _d.status.error))
37
- throw new TransactionStatusError((_g = (_f = (_e = res.Transaction) === null || _e === void 0 ? void 0 : _e.effects) === null || _f === void 0 ? void 0 : _f.status.error.message) !== null && _g !== void 0 ? _g : "Transaction failed");
35
+ const txResult = (_a = res.Transaction) !== null && _a !== void 0 ? _a : res.FailedTransaction;
36
+ if ((txResult === null || txResult === void 0 ? void 0 : txResult.effects) && !txResult.effects.status.success)
37
+ throw new TransactionStatusError((_c = (_b = txResult.effects.status.error) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : "Transaction failed");
38
38
  return res;
39
39
  });
40
40
  export const keypairSignExecuteAndWaitForTransaction = (transaction, keypair, suiClient, onSign, onExecute) => __awaiter(void 0, void 0, void 0, function* () {
41
- var _a, _b;
41
+ var _a;
42
42
  // 1) Sign
43
43
  const builtTransaction = yield transaction.build({
44
44
  client: suiClient,
@@ -50,23 +50,27 @@ export const keypairSignExecuteAndWaitForTransaction = (transaction, keypair, su
50
50
  transaction: builtTransaction,
51
51
  signatures: [signedTransaction.signature],
52
52
  });
53
+ if (!((_a = res1.Transaction) === null || _a === void 0 ? void 0 : _a.digest))
54
+ throw new Error("Failed to get transaction digest");
53
55
  onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1);
54
56
  // 3) Wait
55
- const res2 = yield keypairWaitForTransaction((_b = (_a = res1.Transaction) === null || _a === void 0 ? void 0 : _a.digest) !== null && _b !== void 0 ? _b : "", suiClient);
57
+ const res2 = yield keypairWaitForTransaction(res1.Transaction.digest, suiClient);
56
58
  return res2;
57
59
  });
58
60
  export const checkLastTransactionSignature = (type, lastCurrentFlowTransaction, lastSignedTransaction, setLastSignedTransaction, suiClient, validCallback, invalidCallback) => __awaiter(void 0, void 0, void 0, function* () {
59
- var _a, _b, _c, _d;
61
+ var _a, _b;
60
62
  console.log("[checkLastTransactionSignature]", {
61
63
  type,
62
64
  lastCurrentFlowTransaction,
63
65
  lastSignedTransaction,
64
66
  });
67
+ if (!((_a = lastCurrentFlowTransaction === null || lastCurrentFlowTransaction === void 0 ? void 0 : lastCurrentFlowTransaction.Transaction) === null || _a === void 0 ? void 0 : _a.digest))
68
+ throw new Error("lastCurrentFlowTransaction digest is missing");
65
69
  if ((lastSignedTransaction === null || lastSignedTransaction === void 0 ? void 0 : lastSignedTransaction.type) === type &&
66
- ((_b = (_a = lastCurrentFlowTransaction === null || lastCurrentFlowTransaction === void 0 ? void 0 : lastCurrentFlowTransaction.Transaction) === null || _a === void 0 ? void 0 : _a.signatures) !== null && _b !== void 0 ? _b : []).includes(lastSignedTransaction.signedTransaction.signature)) {
70
+ ((_b = lastCurrentFlowTransaction.Transaction.signatures) !== null && _b !== void 0 ? _b : []).includes(lastSignedTransaction.signedTransaction.signature)) {
67
71
  console.log("[checkLastTransactionSignature] lastSignedTransaction type and signature MATCH");
68
72
  try {
69
- const res = yield keypairWaitForTransaction((_d = (_c = lastCurrentFlowTransaction === null || lastCurrentFlowTransaction === void 0 ? void 0 : lastCurrentFlowTransaction.Transaction) === null || _c === void 0 ? void 0 : _c.digest) !== null && _d !== void 0 ? _d : "", suiClient); // Assumed to only throw if the transaction was executed but failed (e.g. insufficient gas), or if the connection was lost
73
+ const res = yield keypairWaitForTransaction(lastCurrentFlowTransaction.Transaction.digest, suiClient); // Assumed to only throw if the transaction was executed but failed (e.g. insufficient gas), or if the connection was lost
70
74
  yield validCallback(res);
71
75
  setLastSignedTransaction(undefined);
72
76
  }
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sui-fe","version":"0.4.2","private":false,"description":"A collection of TypeScript frontend libraries","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./lib/constants":"./lib/constants.js","./lib/transactions":"./lib/transactions.js","./lib/format":"./lib/format.js","./lib/ledger":"./lib/ledger.js","./lib/coinMetadata":"./lib/coinMetadata.js","./lib":"./lib/index.js","./lib/indexedDB":"./lib/indexedDB.js","./lib/coinType":"./lib/coinType.js","./lib/coin":"./lib/coin.js","./lib/msafe":"./lib/msafe.js","./lib/keypair":"./lib/keypair.js","./lib/api":"./lib/api.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 ./release.js && 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.20.0","bignumber.js":"^9.1.2","blake2b":"^2.1.4","lodash":"^4.17.21","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-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":"2.1.0"}}
1
+ {"name":"@suilend/sui-fe","version":"0.4.4","private":false,"description":"A collection of TypeScript frontend libraries","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./lib/constants":"./lib/constants.js","./lib/transactions":"./lib/transactions.js","./lib/format":"./lib/format.js","./lib/ledger":"./lib/ledger.js","./lib/coinMetadata":"./lib/coinMetadata.js","./lib":"./lib/index.js","./lib/indexedDB":"./lib/indexedDB.js","./lib/coinType":"./lib/coinType.js","./lib/coin":"./lib/coin.js","./lib/msafe":"./lib/msafe.js","./lib/keypair":"./lib/keypair.js","./lib/api":"./lib/api.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 ./release.js && 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.20.0","bignumber.js":"^9.1.2","blake2b":"^2.1.4","lodash":"^4.17.21","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-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":"2.1.0"}}