@suilend/sui-fe-next 2.0.29 → 2.0.30
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/contexts/WalletContext.jsx +66 -27
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -62,6 +62,7 @@ import { DAppKitProvider, useCurrentAccount, useCurrentWallet, useDAppKit, useWa
|
|
|
62
62
|
import { SuiJsonRpcClient, } from "@mysten/sui/jsonRpc";
|
|
63
63
|
import { Transaction } from "@mysten/sui/transactions";
|
|
64
64
|
import { SUI_DECIMALS, toBase64 } from "@mysten/sui/utils";
|
|
65
|
+
import { getWallets } from "@wallet-standard/app";
|
|
65
66
|
import BigNumber from "bignumber.js";
|
|
66
67
|
import { useLDClient } from "launchdarkly-react-client-sdk";
|
|
67
68
|
import { useLocalStorage } from "usehooks-ts";
|
|
@@ -573,10 +574,10 @@ function Inner(_a) {
|
|
|
573
574
|
});
|
|
574
575
|
}, [impersonatedAddress, account === null || account === void 0 ? void 0 : account.address, gasBudget, suiClient]);
|
|
575
576
|
var signExecuteAndWaitForTransaction = useCallback(function (transaction, onSetGasBudget, onSign, onExecute) { return __awaiter(_this, void 0, void 0, function () {
|
|
576
|
-
var _address,
|
|
577
|
-
var _a, _b;
|
|
578
|
-
return __generator(this, function (
|
|
579
|
-
switch (
|
|
577
|
+
var _address, txBytes, res, signedTransaction_1, res1_1, res2_1, msafeWallet, msafeFeature, msafeAccount, signedTransaction, res1, res2, err_3;
|
|
578
|
+
var _a, _b, _c, _d;
|
|
579
|
+
return __generator(this, function (_e) {
|
|
580
|
+
switch (_e.label) {
|
|
580
581
|
case 0:
|
|
581
582
|
_address = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
582
583
|
if (_address) {
|
|
@@ -585,9 +586,9 @@ function Inner(_a) {
|
|
|
585
586
|
}
|
|
586
587
|
catch (err) { }
|
|
587
588
|
}
|
|
588
|
-
|
|
589
|
+
_e.label = 1;
|
|
589
590
|
case 1:
|
|
590
|
-
|
|
591
|
+
_e.trys.push([1, 13, , 14]);
|
|
591
592
|
// Gas budget
|
|
592
593
|
if (gasBudget !== "")
|
|
593
594
|
transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
@@ -596,12 +597,11 @@ function Inner(_a) {
|
|
|
596
597
|
onSetGasBudget === null || onSetGasBudget === void 0 ? void 0 : onSetGasBudget(transaction);
|
|
597
598
|
// Log
|
|
598
599
|
console.log("[WalletContext] signExecuteAndWaitForTransaction - transaction.getData():", transaction.getData());
|
|
599
|
-
|
|
600
|
-
if (!(sessionAddress && universalConnector)) return [3 /*break*/, 4];
|
|
600
|
+
if (!(sessionAddress && universalConnector)) return [3 /*break*/, 6];
|
|
601
601
|
transaction.setSender(sessionAddress);
|
|
602
602
|
return [4 /*yield*/, transaction.build({ client: suiClient })];
|
|
603
603
|
case 2:
|
|
604
|
-
txBytes =
|
|
604
|
+
txBytes = _e.sent();
|
|
605
605
|
return [4 /*yield*/, universalConnector.request({
|
|
606
606
|
method: "sui_signTransaction",
|
|
607
607
|
params: {
|
|
@@ -610,26 +610,65 @@ function Inner(_a) {
|
|
|
610
610
|
},
|
|
611
611
|
}, "sui:mainnet")];
|
|
612
612
|
case 3:
|
|
613
|
-
res =
|
|
614
|
-
|
|
613
|
+
res = _e.sent();
|
|
614
|
+
signedTransaction_1 = {
|
|
615
615
|
bytes: res.transactionBytes,
|
|
616
616
|
signature: res.signature,
|
|
617
617
|
};
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
618
|
+
onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction_1);
|
|
619
|
+
return [4 /*yield*/, suiClient.executeTransactionBlock({
|
|
620
|
+
transactionBlock: signedTransaction_1.bytes,
|
|
621
|
+
signature: signedTransaction_1.signature,
|
|
622
|
+
})];
|
|
623
|
+
case 4:
|
|
624
|
+
res1_1 = _e.sent();
|
|
625
|
+
onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1_1);
|
|
626
|
+
return [4 /*yield*/, suiClient.waitForTransaction({
|
|
627
|
+
digest: res1_1.digest,
|
|
628
|
+
options: {
|
|
629
|
+
showBalanceChanges: true,
|
|
630
|
+
showEffects: true,
|
|
631
|
+
showEvents: true,
|
|
632
|
+
showObjectChanges: true,
|
|
633
|
+
},
|
|
634
|
+
})];
|
|
622
635
|
case 5:
|
|
623
|
-
|
|
624
|
-
|
|
636
|
+
res2_1 = _e.sent();
|
|
637
|
+
if (((_a = res2_1.effects) === null || _a === void 0 ? void 0 : _a.status) !== undefined &&
|
|
638
|
+
res2_1.effects.status.status === "failure")
|
|
639
|
+
throw new Error((_b = res2_1.effects.status.error) !== null && _b !== void 0 ? _b : "Transaction failed");
|
|
640
|
+
return [2 /*return*/, res2_1];
|
|
625
641
|
case 6:
|
|
642
|
+
if (!isInMsafeApp()) return [3 /*break*/, 9];
|
|
643
|
+
msafeWallet = getWallets()
|
|
644
|
+
.get()
|
|
645
|
+
.find(function (w) { return w.name === WalletName.MSAFE_WALLET; });
|
|
646
|
+
msafeFeature = msafeWallet === null || msafeWallet === void 0 ? void 0 : msafeWallet.features["sui:signAndExecuteTransactionBlock"];
|
|
647
|
+
if (!(msafeFeature && account)) return [3 /*break*/, 8];
|
|
648
|
+
msafeAccount = msafeWallet.accounts.find(function (a) { return a.address === account.address; });
|
|
649
|
+
if (!msafeAccount)
|
|
650
|
+
throw new Error("MSafe account not found");
|
|
651
|
+
return [4 /*yield*/, msafeFeature.signAndExecuteTransactionBlock({
|
|
652
|
+
transactionBlock: transaction,
|
|
653
|
+
account: msafeAccount,
|
|
654
|
+
chain: "sui:mainnet",
|
|
655
|
+
})];
|
|
656
|
+
case 7:
|
|
657
|
+
_e.sent();
|
|
658
|
+
throw new Error("Unreachable");
|
|
659
|
+
case 8: throw new Error("MSafe wallet not found. Please reload the page inside MSafe.");
|
|
660
|
+
case 9: return [4 /*yield*/, dAppKit.signTransaction({
|
|
661
|
+
transaction: transaction,
|
|
662
|
+
})];
|
|
663
|
+
case 10:
|
|
664
|
+
signedTransaction = _e.sent();
|
|
626
665
|
onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction);
|
|
627
666
|
return [4 /*yield*/, suiClient.executeTransactionBlock({
|
|
628
667
|
transactionBlock: signedTransaction.bytes,
|
|
629
668
|
signature: signedTransaction.signature,
|
|
630
669
|
})];
|
|
631
|
-
case
|
|
632
|
-
res1 =
|
|
670
|
+
case 11:
|
|
671
|
+
res1 = _e.sent();
|
|
633
672
|
onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1);
|
|
634
673
|
return [4 /*yield*/, suiClient.waitForTransaction({
|
|
635
674
|
digest: res1.digest,
|
|
@@ -640,17 +679,17 @@ function Inner(_a) {
|
|
|
640
679
|
showObjectChanges: true,
|
|
641
680
|
},
|
|
642
681
|
})];
|
|
643
|
-
case
|
|
644
|
-
res2 =
|
|
645
|
-
if (((
|
|
682
|
+
case 12:
|
|
683
|
+
res2 = _e.sent();
|
|
684
|
+
if (((_c = res2.effects) === null || _c === void 0 ? void 0 : _c.status) !== undefined &&
|
|
646
685
|
res2.effects.status.status === "failure")
|
|
647
|
-
throw new Error((
|
|
686
|
+
throw new Error((_d = res2.effects.status.error) !== null && _d !== void 0 ? _d : "Transaction failed");
|
|
648
687
|
return [2 /*return*/, res2];
|
|
649
|
-
case
|
|
650
|
-
err_3 =
|
|
688
|
+
case 13:
|
|
689
|
+
err_3 = _e.sent();
|
|
651
690
|
console.error(err_3);
|
|
652
691
|
throw err_3;
|
|
653
|
-
case
|
|
692
|
+
case 14: return [2 /*return*/];
|
|
654
693
|
}
|
|
655
694
|
});
|
|
656
695
|
}); }, [
|
|
@@ -658,7 +697,7 @@ function Inner(_a) {
|
|
|
658
697
|
sessionAddress,
|
|
659
698
|
gasBudget,
|
|
660
699
|
impersonatedAddress,
|
|
661
|
-
account
|
|
700
|
+
account,
|
|
662
701
|
dryRunTransaction,
|
|
663
702
|
suiClient,
|
|
664
703
|
dAppKit,
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sui-fe-next","version":"2.0.
|
|
1
|
+
{"name":"@suilend/sui-fe-next","version":"2.0.30","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.10","@tanstack/react-query":"^5.60.2","@wallet-standard/app":"^1.1.0","@walletconnect/universal-provider":"2.21.1","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"}}
|