@suilend/sui-fe 0.3.3 → 0.3.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.
- package/lib/keypair.js +25 -14
- package/package.json +1 -1
package/lib/keypair.js
CHANGED
|
@@ -135,37 +135,48 @@ const checkIfKeypairCanBeUsed = (lastSignedTransaction, currentFlowDigests, keyp
|
|
|
135
135
|
mostRecentToAddressTransaction,
|
|
136
136
|
].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];
|
|
137
137
|
console.log("[checkIfKeypairCanBeUsed] mostRecentFromAddressTransaction:", mostRecentFromAddressTransaction, "mostRecentToAddressTransaction:", mostRecentToAddressTransaction, "mostRecentFromOrToAddressTransaction:", mostRecentFromOrToAddressTransaction, "lastSignedTransaction:", lastSignedTransaction, "currentFlowDigests:", currentFlowDigests);
|
|
138
|
+
// 1) Check if wallet has no TO/FROM transactions
|
|
138
139
|
if (mostRecentFromOrToAddressTransaction === undefined) {
|
|
139
|
-
// Wallet
|
|
140
|
+
// Wallet has no TO/FROM transactions
|
|
140
141
|
// CONTINUE
|
|
141
142
|
return { lastCurrentFlowTransaction: undefined };
|
|
142
143
|
}
|
|
143
144
|
else {
|
|
144
|
-
//
|
|
145
|
+
// 2) Check if resuming/retrying current flow
|
|
145
146
|
if ((lastSignedTransaction !== undefined &&
|
|
146
147
|
((_b = (_a = mostRecentFromOrToAddressTransaction.transaction) === null || _a === void 0 ? void 0 : _a.txSignatures) !== null && _b !== void 0 ? _b : []).includes(lastSignedTransaction.signature)) ||
|
|
147
148
|
currentFlowDigests.includes(mostRecentFromOrToAddressTransaction.digest)) {
|
|
148
|
-
//
|
|
149
|
+
// Resuming/retrying current flow
|
|
149
150
|
// CONTINUE
|
|
150
151
|
return {
|
|
151
152
|
lastCurrentFlowTransaction: mostRecentFromOrToAddressTransaction,
|
|
152
153
|
};
|
|
153
154
|
}
|
|
154
155
|
else {
|
|
155
|
-
//
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
// Previous flow may be ongoing
|
|
161
|
-
// STOP
|
|
162
|
-
throw new Error("Please wait for previous flow to complete");
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
// Previous flow stopped before completion
|
|
156
|
+
// 3) Check if wallet has no owned objects
|
|
157
|
+
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; });
|
|
158
|
+
console.log("[checkIfKeypairCanBeUsed] ownedObjectIds:", ownedObjectIds);
|
|
159
|
+
if (ownedObjectIds.length === 0) {
|
|
160
|
+
// Previous flow completed
|
|
166
161
|
// CONTINUE
|
|
167
162
|
return { lastCurrentFlowTransaction: undefined };
|
|
168
163
|
}
|
|
164
|
+
else {
|
|
165
|
+
// 4) Check if last transaction from previous flow is recent
|
|
166
|
+
const timestampMs = mostRecentFromOrToAddressTransaction.timestampMs;
|
|
167
|
+
const isRecent = !!timestampMs && +timestampMs > Date.now() - 1000 * 60 * 5; // Less than 5 minutes ago
|
|
168
|
+
console.log("[checkIfKeypairCanBeUsed] isRecent:", isRecent);
|
|
169
|
+
if (isRecent) {
|
|
170
|
+
// Last transaction from previous flow is recent
|
|
171
|
+
// STOP
|
|
172
|
+
throw new Error("Please wait for previous flow to complete");
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// Last transaction from previous flow is NOT recent
|
|
176
|
+
// CONTINUE
|
|
177
|
+
return { lastCurrentFlowTransaction: undefined };
|
|
178
|
+
}
|
|
179
|
+
}
|
|
169
180
|
}
|
|
170
181
|
}
|
|
171
182
|
});
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sui-fe","version":"0.3.
|
|
1
|
+
{"name":"@suilend/sui-fe","version":"0.3.4","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"}}
|