@suilend/sui-fe 0.2.95 → 0.2.97

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.js CHANGED
@@ -45,9 +45,16 @@ const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigests, keyp
45
45
  return { lastCurrentFlowTransaction: undefined };
46
46
  }
47
47
  else {
48
- const mostRecentFromAddressTransaction = yield (0, transactions_2.getMostRecentFromAddressTransaction)(suiClient, keypair.toSuiAddress());
49
- console.log("[checkIfKeypairCanBeUsed] mostRecentFromAddressTransaction:", mostRecentFromAddressTransaction, "lastSignedTransaction:", lastSignedTransaction, "currentFlowDigests:", currentFlowDigests);
50
- if (mostRecentFromAddressTransaction === undefined) {
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) {
51
58
  // Non-empty wallet with no FROM transactions
52
59
  // CONTINUE
53
60
  return { lastCurrentFlowTransaction: undefined };
@@ -55,15 +62,17 @@ const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigests, keyp
55
62
  else {
56
63
  // Non-empty wallet with FROM transactions
57
64
  if ((lastSignedTransaction !== undefined &&
58
- ((_b = (_a = mostRecentFromAddressTransaction.transaction) === null || _a === void 0 ? void 0 : _a.txSignatures) !== null && _b !== void 0 ? _b : []).includes(lastSignedTransaction.signature)) ||
59
- currentFlowDigests.includes(mostRecentFromAddressTransaction.digest)) {
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)) {
60
67
  // Retrying current flow
61
68
  // CONTINUE
62
- return { lastCurrentFlowTransaction: mostRecentFromAddressTransaction };
69
+ return {
70
+ lastCurrentFlowTransaction: mostRecentFromOrToAddressTransaction,
71
+ };
63
72
  }
64
73
  else {
65
74
  // Previous flow
66
- const timestampMs = mostRecentFromAddressTransaction.timestampMs;
75
+ const timestampMs = mostRecentFromOrToAddressTransaction.timestampMs;
67
76
  const isRecent = !!timestampMs && +timestampMs > Date.now() - 1000 * 60 * 2; // Less than 2 minutes ago
68
77
  console.log("[checkIfKeypairCanBeUsed] isRecent:", isRecent, timestampMs, Date.now() - 1000 * 60 * 2);
69
78
  if (isRecent) {
@@ -5,4 +5,4 @@ export declare const getTotalGasFee: (res: SuiTransactionBlockResponse) => BigNu
5
5
  export declare const getBalanceChange: (res: SuiTransactionBlockResponse, address: string, token: Token, multiplier?: -1 | 1) => BigNumber | undefined;
6
6
  export declare const getAllOwnedObjects: (suiClient: SuiClient, address: string, filter?: SuiObjectDataFilter) => Promise<SuiObjectResponse[]>;
7
7
  export declare const getAllCoins: (suiClient: SuiClient, address: string, coinType: string) => Promise<import("@mysten/sui/client").CoinStruct[]>;
8
- export declare const getMostRecentFromAddressTransaction: (suiClient: SuiClient, address: string) => Promise<SuiTransactionBlockResponse | undefined>;
8
+ export declare const getMostRecentAddressTransaction: (suiClient: SuiClient, address: string, direction: "from" | "to") => Promise<SuiTransactionBlockResponse | undefined>;
@@ -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.getMostRecentFromAddressTransaction = exports.getAllCoins = exports.getAllOwnedObjects = exports.getBalanceChange = exports.getTotalGasFee = void 0;
15
+ exports.getMostRecentAddressTransaction = exports.getAllCoins = exports.getAllOwnedObjects = exports.getBalanceChange = exports.getTotalGasFee = void 0;
16
16
  const utils_1 = require("@mysten/sui/utils");
17
17
  const bignumber_js_1 = __importDefault(require("bignumber.js"));
18
18
  const coinType_1 = require("./coinType");
@@ -75,13 +75,15 @@ const getAllCoins = (suiClient, address, coinType) => __awaiter(void 0, void 0,
75
75
  return allCoins;
76
76
  });
77
77
  exports.getAllCoins = getAllCoins;
78
- const getMostRecentFromAddressTransaction = (suiClient, address) => __awaiter(void 0, void 0, void 0, function* () {
78
+ const getMostRecentAddressTransaction = (suiClient, address, direction) => __awaiter(void 0, void 0, void 0, function* () {
79
79
  const allTransactions = [];
80
80
  let cursor = null;
81
81
  let hasNextPage = true;
82
82
  while (hasNextPage) {
83
83
  const transactions = yield suiClient.queryTransactionBlocks({
84
- filter: { FromAddress: address },
84
+ filter: direction === "from"
85
+ ? { FromAddress: address }
86
+ : { ToAddress: address },
85
87
  cursor,
86
88
  limit: 1,
87
89
  order: "descending",
@@ -95,4 +97,4 @@ const getMostRecentFromAddressTransaction = (suiClient, address) => __awaiter(vo
95
97
  }
96
98
  return allTransactions[0];
97
99
  });
98
- exports.getMostRecentFromAddressTransaction = getMostRecentFromAddressTransaction;
100
+ exports.getMostRecentAddressTransaction = getMostRecentAddressTransaction;
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@suilend/sui-fe","version":"0.2.95","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.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"}}