@suilend/sui-fe-next 2.0.8 → 2.0.10
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.
|
@@ -51,9 +51,7 @@ export interface WalletContext {
|
|
|
51
51
|
switchAccount: (account: WalletAccount, addressNameServiceName?: string) => void;
|
|
52
52
|
address?: string;
|
|
53
53
|
dryRunTransaction: (transaction: Transaction, setGasBudget?: boolean) => Promise<DevInspectResults>;
|
|
54
|
-
signExecuteAndWaitForTransaction: (transaction: Transaction,
|
|
55
|
-
auction?: boolean;
|
|
56
|
-
}, onSetGasBudget?: (transaction: Transaction) => void, onSign?: (signedTransaction: SignedTransaction) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<SuiTransactionBlockResponse>;
|
|
54
|
+
signExecuteAndWaitForTransaction: (transaction: Transaction, onSetGasBudget?: (transaction: Transaction) => void, onSign?: (signedTransaction: SignedTransaction) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<SuiTransactionBlockResponse>;
|
|
57
55
|
isUsingLedger: boolean;
|
|
58
56
|
setIsUsingLedger: (isUsingLedger: boolean) => void;
|
|
59
57
|
signPersonalMessage: (message: Uint8Array) => Promise<{
|
|
@@ -64,7 +64,6 @@ import { Transaction } from "@mysten/sui/transactions";
|
|
|
64
64
|
import { SUI_DECIMALS, toBase64 } from "@mysten/sui/utils";
|
|
65
65
|
import BigNumber from "bignumber.js";
|
|
66
66
|
import { useLDClient } from "launchdarkly-react-client-sdk";
|
|
67
|
-
import { executeAuction } from "shio-sdk";
|
|
68
67
|
import { useLocalStorage } from "usehooks-ts";
|
|
69
68
|
import { API_URL, formatAddress, isInMsafeApp } from "@suilend/sui-fe";
|
|
70
69
|
import { getUniversalConnector } from "../lib/connector";
|
|
@@ -387,37 +386,50 @@ function Inner(_a) {
|
|
|
387
386
|
});
|
|
388
387
|
}); }, [sessionAddress, universalConnector]);
|
|
389
388
|
var connectWalletWrapper = useCallback(function (_wallet) { return __awaiter(_this, void 0, void 0, function () {
|
|
390
|
-
var res, err_1;
|
|
391
|
-
return __generator(this, function (
|
|
392
|
-
switch (
|
|
389
|
+
var res, _a, err_1;
|
|
390
|
+
return __generator(this, function (_b) {
|
|
391
|
+
switch (_b.label) {
|
|
393
392
|
case 0:
|
|
394
|
-
|
|
395
|
-
if (!(_wallet === null || _wallet === void 0 ? void 0 : _wallet.walletConnect)) return [3 /*break*/,
|
|
393
|
+
_b.trys.push([0, 8, , 9]);
|
|
394
|
+
if (!(_wallet === null || _wallet === void 0 ? void 0 : _wallet.walletConnect)) return [3 /*break*/, 6];
|
|
396
395
|
return [4 /*yield*/, universalConnector.connect()];
|
|
397
396
|
case 1:
|
|
398
|
-
res =
|
|
399
|
-
|
|
397
|
+
res = _b.sent();
|
|
398
|
+
_b.label = 2;
|
|
400
399
|
case 2:
|
|
401
|
-
|
|
400
|
+
_b.trys.push([2, 4, , 5]);
|
|
401
|
+
return [4 /*yield*/, disconnectWallet()];
|
|
402
|
+
case 3:
|
|
403
|
+
_b.sent();
|
|
404
|
+
return [3 /*break*/, 5];
|
|
405
|
+
case 4:
|
|
406
|
+
_a = _b.sent();
|
|
407
|
+
return [3 /*break*/, 5];
|
|
408
|
+
case 5:
|
|
402
409
|
setSession(res.session);
|
|
403
410
|
return [2 /*return*/];
|
|
404
|
-
case
|
|
411
|
+
case 6:
|
|
405
412
|
if (!_wallet.raw)
|
|
406
413
|
throw new Error("Missing wallet");
|
|
407
414
|
return [4 /*yield*/, connectWallet({ wallet: _wallet.raw })];
|
|
408
|
-
case
|
|
409
|
-
|
|
410
|
-
|
|
415
|
+
case 7:
|
|
416
|
+
_b.sent();
|
|
417
|
+
try {
|
|
418
|
+
universalConnector.disconnect();
|
|
419
|
+
}
|
|
420
|
+
catch (_c) {
|
|
421
|
+
// WalletConnect may not have an active session — safe to ignore
|
|
422
|
+
}
|
|
411
423
|
setSession(null);
|
|
412
424
|
showInfoToast("Connected ".concat(_wallet.name));
|
|
413
425
|
setIsConnectWalletDropdownOpen(false);
|
|
414
|
-
return [3 /*break*/,
|
|
415
|
-
case
|
|
416
|
-
err_1 =
|
|
426
|
+
return [3 /*break*/, 9];
|
|
427
|
+
case 8:
|
|
428
|
+
err_1 = _b.sent();
|
|
417
429
|
showErrorToast("Failed to connect ".concat(_wallet.name), err_1);
|
|
418
430
|
console.error(err_1);
|
|
419
|
-
return [3 /*break*/,
|
|
420
|
-
case
|
|
431
|
+
return [3 /*break*/, 9];
|
|
432
|
+
case 9: return [2 /*return*/];
|
|
421
433
|
}
|
|
422
434
|
});
|
|
423
435
|
}); }, [connectWallet, disconnectWallet, universalConnector]);
|
|
@@ -585,11 +597,33 @@ function Inner(_a) {
|
|
|
585
597
|
});
|
|
586
598
|
});
|
|
587
599
|
}, [impersonatedAddress, account === null || account === void 0 ? void 0 : account.address, gasBudget, suiClient]);
|
|
588
|
-
var
|
|
589
|
-
var
|
|
600
|
+
var waitForTransactionWithCheck = useCallback(function (digest) { return __awaiter(_this, void 0, void 0, function () {
|
|
601
|
+
var res;
|
|
590
602
|
var _a, _b;
|
|
591
603
|
return __generator(this, function (_c) {
|
|
592
604
|
switch (_c.label) {
|
|
605
|
+
case 0: return [4 /*yield*/, suiClient.waitForTransaction({
|
|
606
|
+
digest: digest,
|
|
607
|
+
options: {
|
|
608
|
+
showBalanceChanges: true,
|
|
609
|
+
showEffects: true,
|
|
610
|
+
showEvents: true,
|
|
611
|
+
showObjectChanges: true,
|
|
612
|
+
},
|
|
613
|
+
})];
|
|
614
|
+
case 1:
|
|
615
|
+
res = _c.sent();
|
|
616
|
+
if (((_a = res.effects) === null || _a === void 0 ? void 0 : _a.status) !== undefined &&
|
|
617
|
+
res.effects.status.status === "failure")
|
|
618
|
+
throw new Error((_b = res.effects.status.error) !== null && _b !== void 0 ? _b : "Transaction failed");
|
|
619
|
+
return [2 /*return*/, res];
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
}); }, [suiClient]);
|
|
623
|
+
var signExecuteAndWaitForTransaction = useCallback(function (transaction, onSetGasBudget, onSign, onExecute) { return __awaiter(_this, void 0, void 0, function () {
|
|
624
|
+
var _address, txBytes, res, signedTransaction, res1, signError_1, message, res, digest, err_5;
|
|
625
|
+
return __generator(this, function (_a) {
|
|
626
|
+
switch (_a.label) {
|
|
593
627
|
case 0:
|
|
594
628
|
_address = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
595
629
|
if (_address) {
|
|
@@ -598,9 +632,9 @@ function Inner(_a) {
|
|
|
598
632
|
}
|
|
599
633
|
catch (err) { }
|
|
600
634
|
}
|
|
601
|
-
|
|
635
|
+
_a.label = 1;
|
|
602
636
|
case 1:
|
|
603
|
-
|
|
637
|
+
_a.trys.push([1, 13, , 14]);
|
|
604
638
|
// Gas budget
|
|
605
639
|
if (gasBudget !== "")
|
|
606
640
|
transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
@@ -609,71 +643,64 @@ function Inner(_a) {
|
|
|
609
643
|
onSetGasBudget === null || onSetGasBudget === void 0 ? void 0 : onSetGasBudget(transaction);
|
|
610
644
|
// Log
|
|
611
645
|
console.log("[WalletContext] signExecuteAndWaitForTransaction - transaction.getData():", transaction.getData());
|
|
612
|
-
|
|
613
|
-
|
|
646
|
+
if (!(sessionAddress && universalConnector)) return [3 /*break*/, 5];
|
|
647
|
+
// WalletConnect: use combined sign+execute so institutional
|
|
648
|
+
// wallets (e.g. Fireblocks) don't drop the channel.
|
|
614
649
|
transaction.setSender(sessionAddress);
|
|
615
650
|
return [4 /*yield*/, transaction.build({ client: suiClient })];
|
|
616
651
|
case 2:
|
|
617
|
-
txBytes =
|
|
652
|
+
txBytes = _a.sent();
|
|
618
653
|
return [4 /*yield*/, universalConnector.request({
|
|
619
|
-
method: "
|
|
654
|
+
method: "sui_signAndExecuteTransaction",
|
|
620
655
|
params: {
|
|
621
656
|
transaction: toBase64(txBytes),
|
|
622
657
|
address: sessionAddress,
|
|
623
658
|
},
|
|
624
659
|
}, "sui:mainnet")];
|
|
625
660
|
case 3:
|
|
626
|
-
res =
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
signature: res.signature,
|
|
630
|
-
};
|
|
631
|
-
return [3 /*break*/, 6];
|
|
632
|
-
case 4: return [4 /*yield*/, dAppKit.signTransaction({
|
|
633
|
-
transaction: transaction,
|
|
634
|
-
})];
|
|
661
|
+
res = _a.sent();
|
|
662
|
+
return [4 /*yield*/, waitForTransactionWithCheck(res.digest)];
|
|
663
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
635
664
|
case 5:
|
|
636
|
-
|
|
637
|
-
|
|
665
|
+
_a.trys.push([5, 9, , 12]);
|
|
666
|
+
return [4 /*yield*/, dAppKit.signTransaction({
|
|
667
|
+
transaction: transaction,
|
|
668
|
+
})];
|
|
638
669
|
case 6:
|
|
670
|
+
signedTransaction = _a.sent();
|
|
639
671
|
onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction);
|
|
640
|
-
|
|
641
|
-
|
|
672
|
+
return [4 /*yield*/, suiClient.executeTransactionBlock({
|
|
673
|
+
transactionBlock: signedTransaction.bytes,
|
|
674
|
+
signature: signedTransaction.signature,
|
|
675
|
+
})];
|
|
642
676
|
case 7:
|
|
643
|
-
|
|
644
|
-
return [4 /*yield*/, executeAuction(signedTransaction.bytes, signedTransaction.signature)];
|
|
645
|
-
case 8:
|
|
646
|
-
_c.sent();
|
|
647
|
-
return [3 /*break*/, 10];
|
|
648
|
-
case 9:
|
|
649
|
-
err_5 = _c.sent();
|
|
650
|
-
return [3 /*break*/, 10];
|
|
651
|
-
case 10: return [4 /*yield*/, suiClient.executeTransactionBlock({
|
|
652
|
-
transactionBlock: signedTransaction.bytes,
|
|
653
|
-
signature: signedTransaction.signature,
|
|
654
|
-
})];
|
|
655
|
-
case 11:
|
|
656
|
-
res1 = _c.sent();
|
|
677
|
+
res1 = _a.sent();
|
|
657
678
|
onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1);
|
|
658
|
-
return [4 /*yield*/,
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
679
|
+
return [4 /*yield*/, waitForTransactionWithCheck(res1.digest)];
|
|
680
|
+
case 8:
|
|
681
|
+
// Wait
|
|
682
|
+
return [2 /*return*/, _a.sent()];
|
|
683
|
+
case 9:
|
|
684
|
+
signError_1 = _a.sent();
|
|
685
|
+
message = signError_1 instanceof Error ? signError_1.message : String(signError_1);
|
|
686
|
+
if (!message.includes("does not support signing"))
|
|
687
|
+
throw signError_1;
|
|
688
|
+
console.warn("[WalletContext] Wallet does not support sign-only, falling back to signAndExecuteTransaction");
|
|
689
|
+
return [4 /*yield*/, dAppKit.signAndExecuteTransaction({
|
|
690
|
+
transaction: transaction,
|
|
666
691
|
})];
|
|
667
|
-
case
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
return [
|
|
692
|
+
case 10:
|
|
693
|
+
res = _a.sent();
|
|
694
|
+
digest = res.$kind === "Transaction"
|
|
695
|
+
? res.Transaction.digest
|
|
696
|
+
: res.FailedTransaction.digest;
|
|
697
|
+
return [4 /*yield*/, waitForTransactionWithCheck(digest)];
|
|
698
|
+
case 11: return [2 /*return*/, _a.sent()];
|
|
699
|
+
case 12: return [3 /*break*/, 14];
|
|
673
700
|
case 13:
|
|
674
|
-
|
|
675
|
-
console.error(
|
|
676
|
-
throw
|
|
701
|
+
err_5 = _a.sent();
|
|
702
|
+
console.error(err_5);
|
|
703
|
+
throw err_5;
|
|
677
704
|
case 14: return [2 /*return*/];
|
|
678
705
|
}
|
|
679
706
|
});
|
|
@@ -686,6 +713,7 @@ function Inner(_a) {
|
|
|
686
713
|
dryRunTransaction,
|
|
687
714
|
suiClient,
|
|
688
715
|
dAppKit,
|
|
716
|
+
waitForTransactionWithCheck,
|
|
689
717
|
]);
|
|
690
718
|
// Using Ledger
|
|
691
719
|
var _o = useLocalStorage("isUsingLedger-".concat(impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address), false), isUsingLedger = _o[0], setIsUsingLedger = _o[1];
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sui-fe-next","version":"2.0.
|
|
1
|
+
{"name":"@suilend/sui-fe-next","version":"2.0.10","private":false,"description":"A collection of TypeScript frontend components and hooks","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./contexts/WalletContext":"./contexts/WalletContext.jsx","./contexts/SettingsContext":"./contexts/SettingsContext.jsx","./contexts":"./contexts/index.js","./fetchers":"./fetchers/index.js","./fetchers/useFetchBalances":"./fetchers/useFetchBalances.js","./hooks/useRefreshOnBalancesChange":"./hooks/useRefreshOnBalancesChange.js","./hooks/useLedgerHashDialog":"./hooks/useLedgerHashDialog.js","./hooks/useIsAndroid":"./hooks/useIsAndroid.jsx","./hooks/useCoinMetadataMap":"./hooks/useCoinMetadataMap.js","./hooks":"./hooks/index.js","./hooks/useIsTouchscreen":"./hooks/useIsTouchscreen.jsx","./hooks/useIsiOS":"./hooks/useIsiOS.jsx","./hooks/keypair":"./hooks/keypair.js","./lib/track":"./lib/track.js","./lib":"./lib/index.js","./lib/router":"./lib/router.js","./lib/toasts":"./lib/toasts.jsx","./lib/connector":"./lib/connector.js"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix src/","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":{"@reown/appkit":"^1.8.10","@reown/appkit-common":"^1.8.10","@reown/appkit-universal-connector":"^1.8.19","@tanstack/react-query":"^5.60.2","bignumber.js":"^9.1.2","launchdarkly-react-client-sdk":"^3.6.0","lodash":"^4.17.21","mixpanel-browser":"^2.72.0","next":"^15.0.3","react":"18.3.1","react-dom":"18.3.1","react-responsive":"^10.0.0","sonner":"1.4.41","swr":"^2.2.5","tailwind-merge":"^2.5.4","usehooks-ts":"^3.1.1"},"devDependencies":{"@tsconfig/next":"^2.0.3","@types/lodash":"^4.17.13","@types/node":"^22.9.0","@types/react":"^18.3.12","@types/react-dom":"^18.3.1","@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/dapp-kit-core":"1.0.3","@mysten/dapp-kit-react":"1.0.1","@mysten/sui":"2.3.1","@mysten/wallet-standard":"0.20.0","@suilend/sui-fe":"^2.0.10"}}
|