@suilend/sui-fe-next 2.0.20 → 2.0.22
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 +124 -78
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -682,10 +682,10 @@ function Inner(_a) {
|
|
|
682
682
|
});
|
|
683
683
|
}); }, [suiClient]);
|
|
684
684
|
var signExecuteAndWaitForTransaction = useCallback(function (transaction, onSetGasBudget, onSign, onExecute) { return __awaiter(_this, void 0, void 0, function () {
|
|
685
|
-
var _address, provider, txBytes, txBase64, params,
|
|
686
|
-
var _a, _b;
|
|
687
|
-
return __generator(this, function (
|
|
688
|
-
switch (
|
|
685
|
+
var _address, provider, txBytes, txBase64, params, topic_1, signClient_1, debugHandler, pendingBefore, wcRequest, methods, signRes, execDigest, _i, methods_1, method, res_1, err_5, execRes, msafeWallet, msafeFeature, msafeAccount, usedSignOnly, signedTransaction, res1, err_6, message, res, digest, err_7;
|
|
686
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
687
|
+
return __generator(this, function (_h) {
|
|
688
|
+
switch (_h.label) {
|
|
689
689
|
case 0:
|
|
690
690
|
_address = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
691
691
|
if (_address) {
|
|
@@ -694,9 +694,9 @@ function Inner(_a) {
|
|
|
694
694
|
}
|
|
695
695
|
catch (err) { }
|
|
696
696
|
}
|
|
697
|
-
|
|
697
|
+
_h.label = 1;
|
|
698
698
|
case 1:
|
|
699
|
-
|
|
699
|
+
_h.trys.push([1, 29, , 30]);
|
|
700
700
|
// Gas budget
|
|
701
701
|
if (gasBudget !== "")
|
|
702
702
|
transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
@@ -705,76 +705,122 @@ function Inner(_a) {
|
|
|
705
705
|
onSetGasBudget === null || onSetGasBudget === void 0 ? void 0 : onSetGasBudget(transaction);
|
|
706
706
|
// Log
|
|
707
707
|
console.log("[WalletContext] signExecuteAndWaitForTransaction - transaction.getData():", transaction.getData());
|
|
708
|
-
if (!sessionAddress) return [3 /*break*/,
|
|
708
|
+
if (!sessionAddress) return [3 /*break*/, 17];
|
|
709
709
|
return [4 /*yield*/, getWalletConnectProvider()];
|
|
710
710
|
case 2:
|
|
711
|
-
provider =
|
|
711
|
+
provider = _h.sent();
|
|
712
712
|
transaction.setSender(sessionAddress);
|
|
713
713
|
return [4 /*yield*/, transaction.build({ client: suiClient })];
|
|
714
714
|
case 3:
|
|
715
|
-
txBytes =
|
|
715
|
+
txBytes = _h.sent();
|
|
716
716
|
txBase64 = toBase64(txBytes);
|
|
717
717
|
params = {
|
|
718
718
|
transaction: txBase64,
|
|
719
719
|
address: wcRawAddress !== null && wcRawAddress !== void 0 ? wcRawAddress : sessionAddress,
|
|
720
720
|
};
|
|
721
|
-
|
|
722
|
-
console.log("[WalletContext] WalletConnect — session topic:",
|
|
721
|
+
topic_1 = (_a = provider.session) === null || _a === void 0 ? void 0 : _a.topic;
|
|
722
|
+
console.log("[WalletContext] WalletConnect — session topic:", topic_1);
|
|
723
723
|
console.log("[WalletContext] WalletConnect — session namespaces:", JSON.stringify((_b = provider.session) === null || _b === void 0 ? void 0 : _b.namespaces));
|
|
724
724
|
console.log("[WalletContext] WalletConnect — request params:", params);
|
|
725
|
-
if (!
|
|
725
|
+
if (!topic_1)
|
|
726
726
|
throw new Error("WalletConnect session not found");
|
|
727
|
-
|
|
728
|
-
|
|
727
|
+
signClient_1 = provider.client;
|
|
728
|
+
// Debug: check relay connectivity and session health
|
|
729
|
+
console.log("[WalletContext] WalletConnect — relay connected:", signClient_1.core.relayer.connected);
|
|
730
|
+
console.log("[WalletContext] WalletConnect — session expiry:", (_c = provider.session) === null || _c === void 0 ? void 0 : _c.expiry, "now:", Math.floor(Date.now() / 1000), "expired:", ((_d = provider.session) === null || _d === void 0 ? void 0 : _d.expiry)
|
|
731
|
+
? provider.session.expiry < Math.floor(Date.now() / 1000)
|
|
732
|
+
: "unknown");
|
|
733
|
+
debugHandler = function (event) {
|
|
734
|
+
console.log("[WalletContext] WalletConnect — relay message received:", event);
|
|
735
|
+
};
|
|
736
|
+
signClient_1.core.relayer.on("message", debugHandler);
|
|
737
|
+
pendingBefore = (_g = (_f = (_e = signClient_1.pendingRequest).getAll) === null || _f === void 0 ? void 0 : _f.call(_e)) !== null && _g !== void 0 ? _g : [];
|
|
738
|
+
console.log("[WalletContext] WalletConnect — pending requests before:", Array.isArray(pendingBefore) ? pendingBefore.length : pendingBefore);
|
|
739
|
+
wcRequest = function (method, requestParams, timeoutMs) {
|
|
740
|
+
if (timeoutMs === void 0) { timeoutMs = 15000; }
|
|
741
|
+
return new Promise(function (resolve, reject) {
|
|
742
|
+
var timer = setTimeout(function () {
|
|
743
|
+
reject(new Error("WalletConnect request \"".concat(method, "\" timed out after ").concat(timeoutMs / 1000, "s \u2014 the wallet did not respond. ") +
|
|
744
|
+
"This usually means the wallet does not support this method."));
|
|
745
|
+
}, timeoutMs);
|
|
746
|
+
signClient_1
|
|
747
|
+
.request({
|
|
748
|
+
topic: topic_1,
|
|
749
|
+
chainId: "sui:mainnet",
|
|
750
|
+
request: { method: method, params: requestParams },
|
|
751
|
+
})
|
|
752
|
+
.then(function (res) {
|
|
753
|
+
clearTimeout(timer);
|
|
754
|
+
resolve(res);
|
|
755
|
+
})
|
|
756
|
+
.catch(function (err) {
|
|
757
|
+
clearTimeout(timer);
|
|
758
|
+
reject(err);
|
|
759
|
+
});
|
|
760
|
+
});
|
|
761
|
+
};
|
|
762
|
+
methods = [
|
|
763
|
+
WC_SUI_METHODS.SIGN_TRANSACTION,
|
|
764
|
+
WC_SUI_METHODS.SIGN_AND_EXECUTE_TRANSACTION,
|
|
765
|
+
];
|
|
766
|
+
signRes = null;
|
|
767
|
+
execDigest = null;
|
|
768
|
+
_i = 0, methods_1 = methods;
|
|
769
|
+
_h.label = 4;
|
|
729
770
|
case 4:
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
topic: topic,
|
|
734
|
-
chainId: "sui:mainnet",
|
|
735
|
-
request: {
|
|
736
|
-
method: WC_SUI_METHODS.SIGN_AND_EXECUTE_TRANSACTION,
|
|
737
|
-
params: params,
|
|
738
|
-
},
|
|
739
|
-
})];
|
|
771
|
+
if (!(_i < methods_1.length)) return [3 /*break*/, 12];
|
|
772
|
+
method = methods_1[_i];
|
|
773
|
+
_h.label = 5;
|
|
740
774
|
case 5:
|
|
741
|
-
|
|
742
|
-
console.log("[WalletContext] WalletConnect
|
|
743
|
-
return [
|
|
744
|
-
|
|
745
|
-
case
|
|
746
|
-
|
|
747
|
-
console.
|
|
748
|
-
return [3 /*break*/,
|
|
775
|
+
_h.trys.push([5, 10, , 11]);
|
|
776
|
+
console.log("[WalletContext] WalletConnect \u2014 trying ".concat(method));
|
|
777
|
+
if (!(method === WC_SUI_METHODS.SIGN_TRANSACTION)) return [3 /*break*/, 7];
|
|
778
|
+
return [4 /*yield*/, wcRequest(method, params)];
|
|
779
|
+
case 6:
|
|
780
|
+
signRes = _h.sent();
|
|
781
|
+
console.log("[WalletContext] WalletConnect \u2014 ".concat(method, " succeeded"));
|
|
782
|
+
return [3 /*break*/, 12];
|
|
783
|
+
case 7: return [4 /*yield*/, wcRequest(method, params)];
|
|
749
784
|
case 8:
|
|
750
|
-
|
|
751
|
-
console.log("[WalletContext] WalletConnect
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
785
|
+
res_1 = _h.sent();
|
|
786
|
+
console.log("[WalletContext] WalletConnect \u2014 ".concat(method, " succeeded, digest:"), res_1.digest);
|
|
787
|
+
execDigest = res_1.digest;
|
|
788
|
+
return [3 /*break*/, 12];
|
|
789
|
+
case 9: return [3 /*break*/, 11];
|
|
790
|
+
case 10:
|
|
791
|
+
err_5 = _h.sent();
|
|
792
|
+
console.warn("[WalletContext] WalletConnect \u2014 ".concat(method, " failed:"), err_5);
|
|
793
|
+
return [3 /*break*/, 11];
|
|
794
|
+
case 11:
|
|
795
|
+
_i++;
|
|
796
|
+
return [3 /*break*/, 4];
|
|
797
|
+
case 12:
|
|
798
|
+
// Cleanup debug listener
|
|
799
|
+
signClient_1.core.relayer.off("message", debugHandler);
|
|
800
|
+
if (!execDigest) return [3 /*break*/, 14];
|
|
801
|
+
return [4 /*yield*/, waitForTransactionWithCheck(execDigest)];
|
|
802
|
+
case 13: return [2 /*return*/, _h.sent()];
|
|
803
|
+
case 14:
|
|
804
|
+
if (!signRes) {
|
|
805
|
+
throw new Error("WalletConnect: wallet did not respond to any signing method. " +
|
|
806
|
+
"Check that the wallet supports Sui transactions and that the session is active.");
|
|
807
|
+
}
|
|
808
|
+
console.log("[WalletContext] WalletConnect — executing signed transaction on-chain");
|
|
763
809
|
return [4 /*yield*/, suiClient.executeTransactionBlock({
|
|
764
810
|
transactionBlock: signRes.transactionBytes,
|
|
765
811
|
signature: signRes.signature,
|
|
766
812
|
})];
|
|
767
|
-
case
|
|
768
|
-
execRes =
|
|
813
|
+
case 15:
|
|
814
|
+
execRes = _h.sent();
|
|
769
815
|
return [4 /*yield*/, waitForTransactionWithCheck(execRes.digest)];
|
|
770
|
-
case
|
|
771
|
-
case
|
|
772
|
-
if (!isInMsafeApp()) return [3 /*break*/,
|
|
816
|
+
case 16: return [2 /*return*/, _h.sent()];
|
|
817
|
+
case 17:
|
|
818
|
+
if (!isInMsafeApp()) return [3 /*break*/, 20];
|
|
773
819
|
msafeWallet = getWallets()
|
|
774
820
|
.get()
|
|
775
821
|
.find(function (w) { return w.name === WalletName.MSAFE_WALLET; });
|
|
776
822
|
msafeFeature = msafeWallet === null || msafeWallet === void 0 ? void 0 : msafeWallet.features["sui:signAndExecuteTransactionBlock"];
|
|
777
|
-
if (!(msafeFeature && account)) return [3 /*break*/,
|
|
823
|
+
if (!(msafeFeature && account)) return [3 /*break*/, 19];
|
|
778
824
|
msafeAccount = msafeWallet.accounts.find(function (a) { return a.address === account.address; });
|
|
779
825
|
if (!msafeAccount)
|
|
780
826
|
throw new Error("MSafe account not found");
|
|
@@ -783,58 +829,58 @@ function Inner(_a) {
|
|
|
783
829
|
account: msafeAccount,
|
|
784
830
|
chain: "sui:mainnet",
|
|
785
831
|
})];
|
|
786
|
-
case
|
|
787
|
-
|
|
832
|
+
case 18:
|
|
833
|
+
_h.sent();
|
|
788
834
|
// MSafe proposes the transaction to the multisig queue;
|
|
789
835
|
// the promise never resolves (only rejects on cancel).
|
|
790
836
|
// If we reach here the proposal was accepted.
|
|
791
837
|
throw new Error("Unreachable");
|
|
792
|
-
case
|
|
793
|
-
case
|
|
838
|
+
case 19: throw new Error("MSafe wallet not found. Please reload the page inside MSafe.");
|
|
839
|
+
case 20:
|
|
794
840
|
usedSignOnly = false;
|
|
795
|
-
|
|
796
|
-
case
|
|
797
|
-
|
|
841
|
+
_h.label = 21;
|
|
842
|
+
case 21:
|
|
843
|
+
_h.trys.push([21, 25, , 26]);
|
|
798
844
|
return [4 /*yield*/, dAppKit.signTransaction({
|
|
799
845
|
transaction: transaction,
|
|
800
846
|
})];
|
|
801
|
-
case
|
|
802
|
-
signedTransaction =
|
|
847
|
+
case 22:
|
|
848
|
+
signedTransaction = _h.sent();
|
|
803
849
|
usedSignOnly = true;
|
|
804
850
|
onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction);
|
|
805
851
|
return [4 /*yield*/, suiClient.executeTransactionBlock({
|
|
806
852
|
transactionBlock: signedTransaction.bytes,
|
|
807
853
|
signature: signedTransaction.signature,
|
|
808
854
|
})];
|
|
809
|
-
case
|
|
810
|
-
res1 =
|
|
855
|
+
case 23:
|
|
856
|
+
res1 = _h.sent();
|
|
811
857
|
onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1);
|
|
812
858
|
return [4 /*yield*/, waitForTransactionWithCheck(res1.digest)];
|
|
813
|
-
case
|
|
814
|
-
case
|
|
815
|
-
|
|
859
|
+
case 24: return [2 /*return*/, _h.sent()];
|
|
860
|
+
case 25:
|
|
861
|
+
err_6 = _h.sent();
|
|
816
862
|
if (usedSignOnly)
|
|
817
|
-
throw
|
|
818
|
-
message =
|
|
863
|
+
throw err_6;
|
|
864
|
+
message = err_6 instanceof Error ? err_6.message : String(err_6);
|
|
819
865
|
if (!message.includes("does not support"))
|
|
820
|
-
throw
|
|
866
|
+
throw err_6;
|
|
821
867
|
console.warn("[WalletContext] Wallet does not support sign-only, falling back to signAndExecuteTransaction");
|
|
822
|
-
return [3 /*break*/,
|
|
823
|
-
case
|
|
868
|
+
return [3 /*break*/, 26];
|
|
869
|
+
case 26: return [4 /*yield*/, dAppKit.signAndExecuteTransaction({
|
|
824
870
|
transaction: transaction,
|
|
825
871
|
})];
|
|
826
|
-
case
|
|
827
|
-
res =
|
|
872
|
+
case 27:
|
|
873
|
+
res = _h.sent();
|
|
828
874
|
digest = res.$kind === "Transaction"
|
|
829
875
|
? res.Transaction.digest
|
|
830
876
|
: res.FailedTransaction.digest;
|
|
831
877
|
return [4 /*yield*/, waitForTransactionWithCheck(digest)];
|
|
832
|
-
case
|
|
833
|
-
case
|
|
834
|
-
|
|
835
|
-
console.error(
|
|
836
|
-
throw
|
|
837
|
-
case
|
|
878
|
+
case 28: return [2 /*return*/, _h.sent()];
|
|
879
|
+
case 29:
|
|
880
|
+
err_7 = _h.sent();
|
|
881
|
+
console.error(err_7);
|
|
882
|
+
throw err_7;
|
|
883
|
+
case 30: return [2 /*return*/];
|
|
838
884
|
}
|
|
839
885
|
});
|
|
840
886
|
}); }, [
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sui-fe-next","version":"2.0.
|
|
1
|
+
{"name":"@suilend/sui-fe-next","version":"2.0.22","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.2","@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"}}
|