@suilend/sui-fe-next 0.1.55 → 0.1.57
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.
|
@@ -9,8 +9,6 @@ interface SettingsContext {
|
|
|
9
9
|
setExplorerId: (id: ExplorerId) => void;
|
|
10
10
|
gasBudget: string;
|
|
11
11
|
setGasBudget: (value: string) => void;
|
|
12
|
-
isUsingLedger: boolean;
|
|
13
|
-
setIsUsingLedger: (value: boolean) => void;
|
|
14
12
|
suiClient: SuiClient;
|
|
15
13
|
}
|
|
16
14
|
declare const SettingsContext: import("react").Context<SettingsContext>;
|
|
@@ -29,10 +29,6 @@ var defaultContextValue = {
|
|
|
29
29
|
setGasBudget: function () {
|
|
30
30
|
throw Error("SettingsContextProvider not initialized");
|
|
31
31
|
},
|
|
32
|
-
isUsingLedger: false,
|
|
33
|
-
setIsUsingLedger: function () {
|
|
34
|
-
throw Error("SettingsContextProvider not initialized");
|
|
35
|
-
},
|
|
36
32
|
suiClient: new SuiClient({ url: getFullnodeUrl("mainnet") }),
|
|
37
33
|
};
|
|
38
34
|
var SettingsContext = createContext(defaultContextValue);
|
|
@@ -55,8 +51,6 @@ export function SettingsContextProvider(_a) {
|
|
|
55
51
|
}, [explorerId]);
|
|
56
52
|
// Gas budget
|
|
57
53
|
var _e = useLocalStorage("gasBudget", defaultContextValue.gasBudget), gasBudget = _e[0], setGasBudget = _e[1];
|
|
58
|
-
// Using Ledger
|
|
59
|
-
var _f = useLocalStorage("isUsingLedger", false), isUsingLedger = _f[0], setIsUsingLedger = _f[1];
|
|
60
54
|
// Sui client
|
|
61
55
|
var suiClient = useMemo(function () { return new SuiClient({ url: rpc.url }); }, [rpc.url]);
|
|
62
56
|
// Context
|
|
@@ -68,8 +62,6 @@ export function SettingsContextProvider(_a) {
|
|
|
68
62
|
setExplorerId: setExplorerId,
|
|
69
63
|
gasBudget: gasBudget,
|
|
70
64
|
setGasBudget: setGasBudget,
|
|
71
|
-
isUsingLedger: isUsingLedger,
|
|
72
|
-
setIsUsingLedger: setIsUsingLedger,
|
|
73
65
|
suiClient: suiClient,
|
|
74
66
|
}); }, [
|
|
75
67
|
rpc,
|
|
@@ -79,8 +71,6 @@ export function SettingsContextProvider(_a) {
|
|
|
79
71
|
setExplorerId,
|
|
80
72
|
gasBudget,
|
|
81
73
|
setGasBudget,
|
|
82
|
-
isUsingLedger,
|
|
83
|
-
setIsUsingLedger,
|
|
84
74
|
suiClient,
|
|
85
75
|
]);
|
|
86
76
|
return (<SettingsContext.Provider value={contextValue}>
|
|
@@ -46,7 +46,9 @@ export interface WalletContext {
|
|
|
46
46
|
dryRunTransaction: (transaction: Transaction, setGasBudget?: boolean) => Promise<DevInspectResults>;
|
|
47
47
|
signExecuteAndWaitForTransaction: (transaction: Transaction, options?: {
|
|
48
48
|
auction?: boolean;
|
|
49
|
-
}, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<SuiTransactionBlockResponse>;
|
|
49
|
+
}, onSetGasBudget?: (transaction: Transaction) => void, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<SuiTransactionBlockResponse>;
|
|
50
|
+
isUsingLedger: boolean;
|
|
51
|
+
setIsUsingLedger: (isUsingLedger: boolean) => void;
|
|
50
52
|
}
|
|
51
53
|
export declare const useWalletContext: () => WalletContext;
|
|
52
54
|
interface WalletContextProviderProps extends PropsWithChildren {
|
|
@@ -59,12 +59,14 @@ import { useRouter } from "next/router";
|
|
|
59
59
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
60
60
|
import { WalletProvider as MystenWalletProvider, SuiClientProvider, createNetworkConfig, } from "@mysten/dapp-kit";
|
|
61
61
|
import { useAccounts, useConnectWallet, useCurrentAccount, useCurrentWallet, useDisconnectWallet, useSignTransaction, useSwitchAccount, useWallets, } from "@mysten/dapp-kit";
|
|
62
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
62
63
|
import { SUI_DECIMALS } from "@mysten/sui/utils";
|
|
63
64
|
import * as Sentry from "@sentry/nextjs";
|
|
64
65
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
65
66
|
import BigNumber from "bignumber.js";
|
|
66
67
|
import { useLDClient } from "launchdarkly-react-client-sdk";
|
|
67
68
|
import { executeAuction } from "shio-sdk";
|
|
69
|
+
import { useLocalStorage } from "usehooks-ts";
|
|
68
70
|
import { API_URL, formatAddress, isInMsafeApp } from "@suilend/sui-fe";
|
|
69
71
|
import { showErrorToast, showInfoToast } from "../lib";
|
|
70
72
|
import { useSettingsContext } from "./SettingsContext";
|
|
@@ -189,6 +191,10 @@ var WalletContext = createContext({
|
|
|
189
191
|
throw new Error("WalletContextProvider not initialized");
|
|
190
192
|
});
|
|
191
193
|
}); },
|
|
194
|
+
isUsingLedger: false,
|
|
195
|
+
setIsUsingLedger: function () {
|
|
196
|
+
throw new Error("WalletContextProvider not initialized");
|
|
197
|
+
},
|
|
192
198
|
});
|
|
193
199
|
export var useWalletContext = function () { return useContext(WalletContext); };
|
|
194
200
|
function Inner(_a) {
|
|
@@ -456,23 +462,24 @@ function Inner(_a) {
|
|
|
456
462
|
args_1[_i - 1] = arguments[_i];
|
|
457
463
|
}
|
|
458
464
|
return __awaiter(_this, __spreadArray([transaction_1], args_1, true), void 0, function (transaction, setGasBudget) {
|
|
459
|
-
var _address, inspectResults, err_2;
|
|
465
|
+
var _address, _transaction, inspectResults, err_2;
|
|
460
466
|
if (setGasBudget === void 0) { setGasBudget = true; }
|
|
461
467
|
return __generator(this, function (_a) {
|
|
462
468
|
switch (_a.label) {
|
|
463
469
|
case 0:
|
|
464
470
|
_address = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
471
|
+
_transaction = Transaction.from(transaction);
|
|
465
472
|
_a.label = 1;
|
|
466
473
|
case 1:
|
|
467
474
|
_a.trys.push([1, 3, , 4]);
|
|
468
475
|
// Gas budget
|
|
469
476
|
if (setGasBudget && gasBudget !== "")
|
|
470
|
-
|
|
477
|
+
_transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
471
478
|
.times(Math.pow(10, SUI_DECIMALS))
|
|
472
479
|
.integerValue(BigNumber.ROUND_DOWN));
|
|
473
480
|
return [4 /*yield*/, suiClient.devInspectTransactionBlock({
|
|
474
481
|
sender: _address !== null && _address !== void 0 ? _address : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
475
|
-
transactionBlock:
|
|
482
|
+
transactionBlock: _transaction,
|
|
476
483
|
})];
|
|
477
484
|
case 2:
|
|
478
485
|
inspectResults = _a.sent();
|
|
@@ -482,11 +489,11 @@ function Inner(_a) {
|
|
|
482
489
|
return [2 /*return*/, inspectResults];
|
|
483
490
|
case 3:
|
|
484
491
|
err_2 = _a.sent();
|
|
485
|
-
//
|
|
492
|
+
// _transaction.getData().inputs.filter(input=>!!input.Object).map(input=>input.)
|
|
486
493
|
Sentry.captureException(err_2, {
|
|
487
494
|
tags: {
|
|
488
495
|
simulation: true,
|
|
489
|
-
transactionData: JSON.stringify(
|
|
496
|
+
transactionData: JSON.stringify(_transaction.getData()),
|
|
490
497
|
},
|
|
491
498
|
});
|
|
492
499
|
console.error(err_2);
|
|
@@ -496,7 +503,7 @@ function Inner(_a) {
|
|
|
496
503
|
});
|
|
497
504
|
});
|
|
498
505
|
}, [impersonatedAddress, account === null || account === void 0 ? void 0 : account.address, gasBudget, suiClient]);
|
|
499
|
-
var signExecuteAndWaitForTransaction = useCallback(function (transaction, options, onSign, onExecute) { return __awaiter(_this, void 0, void 0, function () {
|
|
506
|
+
var signExecuteAndWaitForTransaction = useCallback(function (transaction, options, onSetGasBudget, onSign, onExecute) { return __awaiter(_this, void 0, void 0, function () {
|
|
500
507
|
var _address, signedTransaction, err_3, res1, res2, err_4;
|
|
501
508
|
var _a, _b;
|
|
502
509
|
return __generator(this, function (_c) {
|
|
@@ -517,6 +524,7 @@ function Inner(_a) {
|
|
|
517
524
|
transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
518
525
|
.times(Math.pow(10, SUI_DECIMALS))
|
|
519
526
|
.integerValue(BigNumber.ROUND_DOWN));
|
|
527
|
+
onSetGasBudget === null || onSetGasBudget === void 0 ? void 0 : onSetGasBudget(transaction);
|
|
520
528
|
return [4 /*yield*/, signTransaction({
|
|
521
529
|
transaction: transaction,
|
|
522
530
|
chain: "sui:mainnet",
|
|
@@ -573,6 +581,8 @@ function Inner(_a) {
|
|
|
573
581
|
suiClient,
|
|
574
582
|
signTransaction,
|
|
575
583
|
]);
|
|
584
|
+
// Using Ledger
|
|
585
|
+
var _e = useLocalStorage("isUsingLedger-".concat(impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address), false), isUsingLedger = _e[0], setIsUsingLedger = _e[1];
|
|
576
586
|
// Context
|
|
577
587
|
var contextValue = useMemo(function () { return ({
|
|
578
588
|
isImpersonating: !!impersonatedAddress,
|
|
@@ -588,6 +598,8 @@ function Inner(_a) {
|
|
|
588
598
|
address: impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address,
|
|
589
599
|
dryRunTransaction: dryRunTransaction,
|
|
590
600
|
signExecuteAndWaitForTransaction: signExecuteAndWaitForTransaction,
|
|
601
|
+
isUsingLedger: isUsingLedger,
|
|
602
|
+
setIsUsingLedger: setIsUsingLedger,
|
|
591
603
|
}); }, [
|
|
592
604
|
impersonatedAddress,
|
|
593
605
|
isConnectWalletDropdownOpen,
|
|
@@ -600,6 +612,8 @@ function Inner(_a) {
|
|
|
600
612
|
switchAccountWrapper,
|
|
601
613
|
dryRunTransaction,
|
|
602
614
|
signExecuteAndWaitForTransaction,
|
|
615
|
+
isUsingLedger,
|
|
616
|
+
setIsUsingLedger,
|
|
603
617
|
]);
|
|
604
618
|
return (<WalletContext.Provider value={contextValue}>
|
|
605
619
|
{children}
|
|
@@ -38,8 +38,8 @@ import { useCallback, useState } from "react";
|
|
|
38
38
|
import { getLedgerHash } from "@suilend/sui-fe";
|
|
39
39
|
import { useSettingsContext, useWalletContext } from "../contexts";
|
|
40
40
|
var useLedgerHashDialog = function () {
|
|
41
|
-
var
|
|
42
|
-
var
|
|
41
|
+
var suiClient = useSettingsContext().suiClient;
|
|
42
|
+
var _a = useWalletContext(), address = _a.address, isUsingLedger = _a.isUsingLedger;
|
|
43
43
|
var _b = useState(undefined), ledgerHash = _b[0], setLedgerHash = _b[1];
|
|
44
44
|
var _c = useState(false), isOpen = _c[0], setIsOpen = _c[1];
|
|
45
45
|
var open = useCallback(function (transaction) { return __awaiter(void 0, void 0, void 0, function () {
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sui-fe-next","version":"0.1.
|
|
1
|
+
{"name":"@suilend/sui-fe-next","version":"0.1.57","private":false,"description":"A collection of TypeScript frontend components and hooks","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./contexts/SettingsContext":"./contexts/SettingsContext.jsx","./contexts/WalletContext":"./contexts/WalletContext.jsx","./contexts":"./contexts/index.js","./fetchers":"./fetchers/index.js","./fetchers/useFetchBalances":"./fetchers/useFetchBalances.js","./hooks":"./hooks/index.js","./hooks/keypair":"./hooks/keypair.js","./hooks/useCoinMetadataMap":"./hooks/useCoinMetadataMap.js","./hooks/useIsAndroid":"./hooks/useIsAndroid.jsx","./hooks/useIsTouchscreen":"./hooks/useIsTouchscreen.jsx","./hooks/useIsiOS":"./hooks/useIsiOS.jsx","./hooks/useLedgerHashDialog":"./hooks/useLedgerHashDialog.js","./hooks/useRefreshOnBalancesChange":"./hooks/useRefreshOnBalancesChange.js","./lib":"./lib/index.js","./lib/router":"./lib/router.js","./lib/toasts":"./lib/toasts.jsx"},"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":{"@sentry/nextjs":"^8.38.0","@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.56.0","next":"^15.0.3","react":"18.3.1","react-dom":"18.3.1","react-responsive":"^10.0.0","shio-sdk":"^1.0.8","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/mixpanel-browser":"^2.50.2","@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":"0.16.0","@mysten/sui":"1.28.2","@mysten/wallet-standard":"0.14.7","@suilend/sui-fe":"^0.3.10"}}
|