@suilend/sui-fe-next 2.0.17 → 2.0.19
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 +48 -39
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -222,17 +222,24 @@ function Inner(_a) {
|
|
|
222
222
|
// WalletConnect via @walletconnect/universal-provider
|
|
223
223
|
// Matches the reference implementation: https://github.com/WalletConnect/react-core-up-sui
|
|
224
224
|
var _g = useState(), wcSession = _g[0], setWcSession = _g[1];
|
|
225
|
-
|
|
225
|
+
// Raw address as returned by the wallet (e.g. Fireblocks returns an
|
|
226
|
+
// EVM-length address). We must send this back in WalletConnect request
|
|
227
|
+
// params so the wallet recognises it as its own account.
|
|
228
|
+
var wcRawAddress = useMemo(function () {
|
|
226
229
|
var _a, _b, _c;
|
|
227
230
|
var raw = (_c = (_b = (_a = wcSession === null || wcSession === void 0 ? void 0 : wcSession.namespaces) === null || _a === void 0 ? void 0 : _a.sui) === null || _b === void 0 ? void 0 : _b.accounts) === null || _c === void 0 ? void 0 : _c[0];
|
|
228
231
|
if (!raw)
|
|
229
232
|
return undefined;
|
|
230
|
-
|
|
231
|
-
|
|
233
|
+
return raw.split(":").pop();
|
|
234
|
+
}, [wcSession]);
|
|
235
|
+
// Normalised Sui address (zero-padded to 32 bytes) for on-chain use:
|
|
236
|
+
// transaction sender, RPC queries, etc.
|
|
237
|
+
var sessionAddress = useMemo(function () {
|
|
238
|
+
if (!wcRawAddress)
|
|
232
239
|
return undefined;
|
|
233
|
-
var normalized = normalizeSuiAddress(
|
|
240
|
+
var normalized = normalizeSuiAddress(wcRawAddress);
|
|
234
241
|
return isValidSuiAddress(normalized) ? normalized : undefined;
|
|
235
|
-
}, [
|
|
242
|
+
}, [wcRawAddress]);
|
|
236
243
|
useEffect(function () {
|
|
237
244
|
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
238
245
|
var provider;
|
|
@@ -387,7 +394,10 @@ function Inner(_a) {
|
|
|
387
394
|
provider = _a.sent();
|
|
388
395
|
return [4 /*yield*/, provider.request({
|
|
389
396
|
method: WC_SUI_METHODS.SIGN_PERSONAL_MESSAGE,
|
|
390
|
-
params: {
|
|
397
|
+
params: {
|
|
398
|
+
message: message.toString(),
|
|
399
|
+
address: wcRawAddress !== null && wcRawAddress !== void 0 ? wcRawAddress : sessionAddress,
|
|
400
|
+
},
|
|
391
401
|
}, "sui:mainnet")];
|
|
392
402
|
case 2:
|
|
393
403
|
res = _a.sent();
|
|
@@ -397,7 +407,7 @@ function Inner(_a) {
|
|
|
397
407
|
}];
|
|
398
408
|
}
|
|
399
409
|
});
|
|
400
|
-
}); }, [sessionAddress]);
|
|
410
|
+
}); }, [sessionAddress, wcRawAddress]);
|
|
401
411
|
var connectWalletWrapper = useCallback(function (_wallet) { return __awaiter(_this, void 0, void 0, function () {
|
|
402
412
|
var provider, modal, _a, provider, _b, err_1;
|
|
403
413
|
return __generator(this, function (_c) {
|
|
@@ -673,8 +683,9 @@ function Inner(_a) {
|
|
|
673
683
|
}); }, [suiClient]);
|
|
674
684
|
var signExecuteAndWaitForTransaction = useCallback(function (transaction, onSetGasBudget, onSign, onExecute) { return __awaiter(_this, void 0, void 0, function () {
|
|
675
685
|
var _address, provider, txBytes, txBase64, params, res_1, signAndExecErr_1, signRes, execRes, msafeWallet, msafeFeature, msafeAccount, usedSignOnly, signedTransaction, res1, err_5, message, res, digest, err_6;
|
|
676
|
-
|
|
677
|
-
|
|
686
|
+
var _a, _b;
|
|
687
|
+
return __generator(this, function (_c) {
|
|
688
|
+
switch (_c.label) {
|
|
678
689
|
case 0:
|
|
679
690
|
_address = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
680
691
|
if (_address) {
|
|
@@ -683,9 +694,9 @@ function Inner(_a) {
|
|
|
683
694
|
}
|
|
684
695
|
catch (err) { }
|
|
685
696
|
}
|
|
686
|
-
|
|
697
|
+
_c.label = 1;
|
|
687
698
|
case 1:
|
|
688
|
-
|
|
699
|
+
_c.trys.push([1, 24, , 25]);
|
|
689
700
|
// Gas budget
|
|
690
701
|
if (gasBudget !== "")
|
|
691
702
|
transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
@@ -697,31 +708,34 @@ function Inner(_a) {
|
|
|
697
708
|
if (!sessionAddress) return [3 /*break*/, 12];
|
|
698
709
|
return [4 /*yield*/, getWalletConnectProvider()];
|
|
699
710
|
case 2:
|
|
700
|
-
provider =
|
|
711
|
+
provider = _c.sent();
|
|
701
712
|
transaction.setSender(sessionAddress);
|
|
702
713
|
return [4 /*yield*/, transaction.build({ client: suiClient })];
|
|
703
714
|
case 3:
|
|
704
|
-
txBytes =
|
|
715
|
+
txBytes = _c.sent();
|
|
705
716
|
txBase64 = toBase64(txBytes);
|
|
706
717
|
params = {
|
|
707
718
|
transaction: txBase64,
|
|
708
|
-
address: sessionAddress,
|
|
719
|
+
address: wcRawAddress !== null && wcRawAddress !== void 0 ? wcRawAddress : sessionAddress,
|
|
709
720
|
};
|
|
710
|
-
|
|
721
|
+
console.log("[WalletContext] WalletConnect — session topic:", (_a = provider.session) === null || _a === void 0 ? void 0 : _a.topic);
|
|
722
|
+
console.log("[WalletContext] WalletConnect — session namespaces:", JSON.stringify((_b = provider.session) === null || _b === void 0 ? void 0 : _b.namespaces));
|
|
723
|
+
console.log("[WalletContext] WalletConnect — request params:", params);
|
|
724
|
+
_c.label = 4;
|
|
711
725
|
case 4:
|
|
712
|
-
|
|
726
|
+
_c.trys.push([4, 7, , 8]);
|
|
713
727
|
console.log("[WalletContext] WalletConnect — trying sui_signAndExecuteTransaction");
|
|
714
728
|
return [4 /*yield*/, provider.request({
|
|
715
729
|
method: WC_SUI_METHODS.SIGN_AND_EXECUTE_TRANSACTION,
|
|
716
730
|
params: params,
|
|
717
731
|
}, "sui:mainnet")];
|
|
718
732
|
case 5:
|
|
719
|
-
res_1 =
|
|
733
|
+
res_1 = _c.sent();
|
|
720
734
|
console.log("[WalletContext] WalletConnect — sui_signAndExecuteTransaction succeeded, digest:", res_1.digest);
|
|
721
735
|
return [4 /*yield*/, waitForTransactionWithCheck(res_1.digest)];
|
|
722
|
-
case 6: return [2 /*return*/,
|
|
736
|
+
case 6: return [2 /*return*/, _c.sent()];
|
|
723
737
|
case 7:
|
|
724
|
-
signAndExecErr_1 =
|
|
738
|
+
signAndExecErr_1 = _c.sent();
|
|
725
739
|
console.warn("[WalletContext] WalletConnect — sui_signAndExecuteTransaction failed:", signAndExecErr_1);
|
|
726
740
|
return [3 /*break*/, 8];
|
|
727
741
|
case 8:
|
|
@@ -729,16 +743,16 @@ function Inner(_a) {
|
|
|
729
743
|
console.log("[WalletContext] WalletConnect — trying sui_signTransaction (sign-only fallback)");
|
|
730
744
|
return [4 /*yield*/, provider.request({ method: WC_SUI_METHODS.SIGN_TRANSACTION, params: params }, "sui:mainnet")];
|
|
731
745
|
case 9:
|
|
732
|
-
signRes =
|
|
746
|
+
signRes = _c.sent();
|
|
733
747
|
console.log("[WalletContext] WalletConnect — sui_signTransaction succeeded, executing on-chain");
|
|
734
748
|
return [4 /*yield*/, suiClient.executeTransactionBlock({
|
|
735
749
|
transactionBlock: signRes.transactionBytes,
|
|
736
750
|
signature: signRes.signature,
|
|
737
751
|
})];
|
|
738
752
|
case 10:
|
|
739
|
-
execRes =
|
|
753
|
+
execRes = _c.sent();
|
|
740
754
|
return [4 /*yield*/, waitForTransactionWithCheck(execRes.digest)];
|
|
741
|
-
case 11: return [2 /*return*/,
|
|
755
|
+
case 11: return [2 /*return*/, _c.sent()];
|
|
742
756
|
case 12:
|
|
743
757
|
if (!isInMsafeApp()) return [3 /*break*/, 15];
|
|
744
758
|
msafeWallet = getWallets()
|
|
@@ -755,7 +769,7 @@ function Inner(_a) {
|
|
|
755
769
|
chain: "sui:mainnet",
|
|
756
770
|
})];
|
|
757
771
|
case 13:
|
|
758
|
-
|
|
772
|
+
_c.sent();
|
|
759
773
|
// MSafe proposes the transaction to the multisig queue;
|
|
760
774
|
// the promise never resolves (only rejects on cancel).
|
|
761
775
|
// If we reach here the proposal was accepted.
|
|
@@ -763,14 +777,14 @@ function Inner(_a) {
|
|
|
763
777
|
case 14: throw new Error("MSafe wallet not found. Please reload the page inside MSafe.");
|
|
764
778
|
case 15:
|
|
765
779
|
usedSignOnly = false;
|
|
766
|
-
|
|
780
|
+
_c.label = 16;
|
|
767
781
|
case 16:
|
|
768
|
-
|
|
782
|
+
_c.trys.push([16, 20, , 21]);
|
|
769
783
|
return [4 /*yield*/, dAppKit.signTransaction({
|
|
770
784
|
transaction: transaction,
|
|
771
785
|
})];
|
|
772
786
|
case 17:
|
|
773
|
-
signedTransaction =
|
|
787
|
+
signedTransaction = _c.sent();
|
|
774
788
|
usedSignOnly = true;
|
|
775
789
|
onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction);
|
|
776
790
|
return [4 /*yield*/, suiClient.executeTransactionBlock({
|
|
@@ -778,12 +792,12 @@ function Inner(_a) {
|
|
|
778
792
|
signature: signedTransaction.signature,
|
|
779
793
|
})];
|
|
780
794
|
case 18:
|
|
781
|
-
res1 =
|
|
795
|
+
res1 = _c.sent();
|
|
782
796
|
onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1);
|
|
783
797
|
return [4 /*yield*/, waitForTransactionWithCheck(res1.digest)];
|
|
784
|
-
case 19: return [2 /*return*/,
|
|
798
|
+
case 19: return [2 /*return*/, _c.sent()];
|
|
785
799
|
case 20:
|
|
786
|
-
err_5 =
|
|
800
|
+
err_5 = _c.sent();
|
|
787
801
|
if (usedSignOnly)
|
|
788
802
|
throw err_5;
|
|
789
803
|
message = err_5 instanceof Error ? err_5.message : String(err_5);
|
|
@@ -795,14 +809,14 @@ function Inner(_a) {
|
|
|
795
809
|
transaction: transaction,
|
|
796
810
|
})];
|
|
797
811
|
case 22:
|
|
798
|
-
res =
|
|
812
|
+
res = _c.sent();
|
|
799
813
|
digest = res.$kind === "Transaction"
|
|
800
814
|
? res.Transaction.digest
|
|
801
815
|
: res.FailedTransaction.digest;
|
|
802
816
|
return [4 /*yield*/, waitForTransactionWithCheck(digest)];
|
|
803
|
-
case 23: return [2 /*return*/,
|
|
817
|
+
case 23: return [2 /*return*/, _c.sent()];
|
|
804
818
|
case 24:
|
|
805
|
-
err_6 =
|
|
819
|
+
err_6 = _c.sent();
|
|
806
820
|
console.error(err_6);
|
|
807
821
|
throw err_6;
|
|
808
822
|
case 25: return [2 /*return*/];
|
|
@@ -810,6 +824,7 @@ function Inner(_a) {
|
|
|
810
824
|
});
|
|
811
825
|
}); }, [
|
|
812
826
|
sessionAddress,
|
|
827
|
+
wcRawAddress,
|
|
813
828
|
gasBudget,
|
|
814
829
|
impersonatedAddress,
|
|
815
830
|
account,
|
|
@@ -833,13 +848,7 @@ function Inner(_a) {
|
|
|
833
848
|
accounts: accounts,
|
|
834
849
|
account: account,
|
|
835
850
|
switchAccount: switchAccountWrapper,
|
|
836
|
-
address:
|
|
837
|
-
var raw = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
838
|
-
if (!raw)
|
|
839
|
-
return undefined;
|
|
840
|
-
var normalized = normalizeSuiAddress(raw);
|
|
841
|
-
return isValidSuiAddress(normalized) ? normalized : undefined;
|
|
842
|
-
})(),
|
|
851
|
+
address: impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address,
|
|
843
852
|
dryRunTransaction: dryRunTransaction,
|
|
844
853
|
signExecuteAndWaitForTransaction: signExecuteAndWaitForTransaction,
|
|
845
854
|
isUsingLedger: isUsingLedger,
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sui-fe-next","version":"2.0.
|
|
1
|
+
{"name":"@suilend/sui-fe-next","version":"2.0.19","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"}}
|