@suilend/sui-fe-next 0.1.84 → 0.4.0
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/SettingsContext.d.ts +4 -2
- package/contexts/SettingsContext.jsx +16 -3
- package/contexts/WalletContext.d.ts +7 -9
- package/contexts/WalletContext.jsx +188 -175
- package/fetchers/useFetchBalances.js +5 -4
- package/hooks/useCoinMetadataMap.d.ts +1 -1
- package/hooks/useRefreshOnBalancesChange.js +5 -5
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
3
|
+
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
3
4
|
import { Explorer, ExplorerId, Rpc, RpcId } from "@suilend/sui-fe";
|
|
4
5
|
interface SettingsContext {
|
|
5
6
|
rpc: Rpc;
|
|
@@ -9,7 +10,8 @@ interface SettingsContext {
|
|
|
9
10
|
setExplorerId: (id: ExplorerId) => void;
|
|
10
11
|
gasBudget: string;
|
|
11
12
|
setGasBudget: (value: string) => void;
|
|
12
|
-
suiClient:
|
|
13
|
+
suiClient: SuiGrpcClient;
|
|
14
|
+
suiJsonRpcClient: SuiJsonRpcClient;
|
|
13
15
|
}
|
|
14
16
|
declare const SettingsContext: import("react").Context<SettingsContext>;
|
|
15
17
|
export declare const useSettingsContext: () => SettingsContext;
|
|
@@ -10,7 +10,8 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
import { createContext, useContext, useMemo } from "react";
|
|
13
|
-
import {
|
|
13
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
14
|
+
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
14
15
|
import { useLocalStorage } from "usehooks-ts";
|
|
15
16
|
import { EXPLORERS, RPCS, RpcId, } from "@suilend/sui-fe";
|
|
16
17
|
var defaultContextValue = {
|
|
@@ -29,7 +30,8 @@ var defaultContextValue = {
|
|
|
29
30
|
setGasBudget: function () {
|
|
30
31
|
throw Error("SettingsContextProvider not initialized");
|
|
31
32
|
},
|
|
32
|
-
suiClient:
|
|
33
|
+
suiClient: null,
|
|
34
|
+
suiJsonRpcClient: null,
|
|
33
35
|
};
|
|
34
36
|
var SettingsContext = createContext(defaultContextValue);
|
|
35
37
|
export var useSettingsContext = function () { return useContext(SettingsContext); };
|
|
@@ -52,7 +54,16 @@ export function SettingsContextProvider(_a) {
|
|
|
52
54
|
// Gas budget
|
|
53
55
|
var _e = useLocalStorage("gasBudget", defaultContextValue.gasBudget), gasBudget = _e[0], setGasBudget = _e[1];
|
|
54
56
|
// Sui client
|
|
55
|
-
var
|
|
57
|
+
var _f = useMemo(function () { return [
|
|
58
|
+
new SuiGrpcClient({
|
|
59
|
+
baseUrl: rpc.url,
|
|
60
|
+
network: "mainnet",
|
|
61
|
+
}),
|
|
62
|
+
new SuiJsonRpcClient({
|
|
63
|
+
url: rpc.url,
|
|
64
|
+
network: "mainnet",
|
|
65
|
+
}),
|
|
66
|
+
]; }, [rpc.url]), suiClient = _f[0], suiJsonRpcClient = _f[1];
|
|
56
67
|
// Context
|
|
57
68
|
var contextValue = useMemo(function () { return ({
|
|
58
69
|
rpc: rpc,
|
|
@@ -63,6 +74,7 @@ export function SettingsContextProvider(_a) {
|
|
|
63
74
|
gasBudget: gasBudget,
|
|
64
75
|
setGasBudget: setGasBudget,
|
|
65
76
|
suiClient: suiClient,
|
|
77
|
+
suiJsonRpcClient: suiJsonRpcClient,
|
|
66
78
|
}); }, [
|
|
67
79
|
rpc,
|
|
68
80
|
setRpcId,
|
|
@@ -72,6 +84,7 @@ export function SettingsContextProvider(_a) {
|
|
|
72
84
|
gasBudget,
|
|
73
85
|
setGasBudget,
|
|
74
86
|
suiClient,
|
|
87
|
+
suiJsonRpcClient,
|
|
75
88
|
]);
|
|
76
89
|
return (<SettingsContext.Provider value={contextValue}>
|
|
77
90
|
{children}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Dispatch, PropsWithChildren, SetStateAction } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { UiWallet } from "@mysten/dapp-kit-core";
|
|
3
|
+
import { SuiClientTypes } from "@mysten/sui/client";
|
|
3
4
|
import { SignatureWithBytes } from "@mysten/sui/cryptography";
|
|
4
5
|
import { Transaction } from "@mysten/sui/transactions";
|
|
5
|
-
import { ReadonlyUint8Array, WalletIcon, WalletAccount as WalletStandardWalletAccount
|
|
6
|
+
import { ReadonlyUint8Array, WalletIcon, WalletAccount as WalletStandardWalletAccount } from "@mysten/wallet-standard";
|
|
6
7
|
export declare enum WalletType {
|
|
7
8
|
EXTENSION = "extension",
|
|
8
9
|
WEB = "web"
|
|
@@ -17,7 +18,7 @@ export type Wallet = {
|
|
|
17
18
|
iconUrl?: WalletIcon;
|
|
18
19
|
type: WalletType;
|
|
19
20
|
downloadUrls?: Record<WalletPlatform, string | undefined>;
|
|
20
|
-
raw?:
|
|
21
|
+
raw?: UiWallet;
|
|
21
22
|
walletConnect?: boolean;
|
|
22
23
|
};
|
|
23
24
|
declare enum WalletName {
|
|
@@ -50,16 +51,13 @@ export interface WalletContext {
|
|
|
50
51
|
account?: WalletAccount;
|
|
51
52
|
switchAccount: (account: WalletAccount, addressNameServiceName?: string) => void;
|
|
52
53
|
address?: string;
|
|
53
|
-
dryRunTransaction: (transaction: Transaction, setGasBudget?: boolean) => Promise<
|
|
54
|
+
dryRunTransaction: (transaction: Transaction, setGasBudget?: boolean) => Promise<SuiClientTypes.SimulateTransactionResult>;
|
|
54
55
|
signExecuteAndWaitForTransaction: (transaction: Transaction, options?: {
|
|
55
56
|
auction?: boolean;
|
|
56
|
-
}, onSetGasBudget?: (transaction: Transaction) => void, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res:
|
|
57
|
+
}, onSetGasBudget?: (transaction: Transaction) => void, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiClientTypes.TransactionResult) => void) => Promise<SuiClientTypes.TransactionResult>;
|
|
57
58
|
isUsingLedger: boolean;
|
|
58
59
|
setIsUsingLedger: (isUsingLedger: boolean) => void;
|
|
59
|
-
signPersonalMessage: (message: Uint8Array) => Promise<
|
|
60
|
-
bytes: string;
|
|
61
|
-
signature: string;
|
|
62
|
-
}>;
|
|
60
|
+
signPersonalMessage: (message: Uint8Array) => Promise<SignatureWithBytes>;
|
|
63
61
|
}
|
|
64
62
|
export declare const useWalletContext: () => WalletContext;
|
|
65
63
|
interface WalletContextProviderProps extends PropsWithChildren {
|
|
@@ -57,8 +57,8 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
57
57
|
var _a, _b;
|
|
58
58
|
import { useRouter } from "next/router";
|
|
59
59
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
60
|
-
import {
|
|
61
|
-
import {
|
|
60
|
+
import { DAppKitProvider, createDAppKit, useCurrentAccount, useCurrentWallet, useDAppKit, useWalletConnection, useWallets, } from "@mysten/dapp-kit-react";
|
|
61
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
62
62
|
import { Transaction } from "@mysten/sui/transactions";
|
|
63
63
|
import { SUI_DECIMALS, toBase64 } from "@mysten/sui/utils";
|
|
64
64
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
@@ -212,16 +212,16 @@ export var useWalletContext = function () { return useContext(WalletContext); };
|
|
|
212
212
|
function Inner(_a) {
|
|
213
213
|
var _b;
|
|
214
214
|
var _this = this;
|
|
215
|
-
var _c, _d, _e, _f;
|
|
215
|
+
var _c, _d, _e, _f, _g, _h;
|
|
216
216
|
var appName = _a.appName, children = _a.children;
|
|
217
217
|
var router = useRouter();
|
|
218
218
|
var queryParams = (_b = {},
|
|
219
219
|
_b[WalletContextQueryParams.WALLET] = router.query[WalletContextQueryParams.WALLET],
|
|
220
220
|
_b);
|
|
221
|
-
var
|
|
221
|
+
var _j = useSettingsContext(), rpc = _j.rpc, suiClient = _j.suiClient;
|
|
222
222
|
// Only used for wallet connect
|
|
223
|
-
var
|
|
224
|
-
var
|
|
223
|
+
var _k = useState(), universalConnector = _k[0], setUniversalConnector = _k[1];
|
|
224
|
+
var _l = useState(), session = _l[0], setSession = _l[1];
|
|
225
225
|
var sessionAddressWithout0x = (_e = (_d = (_c = session === null || session === void 0 ? void 0 : session.namespaces) === null || _c === void 0 ? void 0 : _c.sui) === null || _d === void 0 ? void 0 : _d.accounts) === null || _e === void 0 ? void 0 : _e[0];
|
|
226
226
|
var sessionAddress = sessionAddressWithout0x
|
|
227
227
|
? sessionAddressWithout0x.split(":").pop()
|
|
@@ -352,8 +352,9 @@ function Inner(_a) {
|
|
|
352
352
|
wallets__web,
|
|
353
353
|
]);
|
|
354
354
|
// Wallet
|
|
355
|
-
var
|
|
356
|
-
var
|
|
355
|
+
var _m = useState(false), isConnectWalletDropdownOpen = _m[0], setIsConnectWalletDropdownOpen = _m[1];
|
|
356
|
+
var dAppKit = useDAppKit();
|
|
357
|
+
var rawWallet = useCurrentWallet();
|
|
357
358
|
var wallet = useMemo(function () {
|
|
358
359
|
if (sessionAddress) {
|
|
359
360
|
return WALLET_CONNECT_WALLET;
|
|
@@ -362,9 +363,6 @@ function Inner(_a) {
|
|
|
362
363
|
? wallets.find(function (w) { return w.name === rawWallet.name; })
|
|
363
364
|
: undefined;
|
|
364
365
|
}, [rawWallet, wallets, sessionAddress]);
|
|
365
|
-
var connectWallet = useConnectWallet().mutate;
|
|
366
|
-
var disconnectWallet = useDisconnectWallet().mutate;
|
|
367
|
-
var signPersonalMessageRaw = useSignPersonalMessage().mutateAsync;
|
|
368
366
|
var walletConnectSignPersonalMessage = useCallback(function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
369
367
|
var res;
|
|
370
368
|
return __generator(this, function (_a) {
|
|
@@ -385,62 +383,70 @@ function Inner(_a) {
|
|
|
385
383
|
}
|
|
386
384
|
});
|
|
387
385
|
}); }, [sessionAddress, universalConnector]);
|
|
388
|
-
var connectWalletWrapper = useCallback(function (_wallet) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
386
|
+
var connectWalletWrapper = useCallback(function (_wallet) { return __awaiter(_this, void 0, void 0, function () {
|
|
387
|
+
var res, err_1;
|
|
388
|
+
return __generator(this, function (_a) {
|
|
389
|
+
switch (_a.label) {
|
|
390
|
+
case 0:
|
|
391
|
+
_a.trys.push([0, 5, , 6]);
|
|
392
|
+
if (!(_wallet === null || _wallet === void 0 ? void 0 : _wallet.walletConnect)) return [3 /*break*/, 3];
|
|
393
|
+
return [4 /*yield*/, universalConnector.connect()];
|
|
394
|
+
case 1:
|
|
395
|
+
res = _a.sent();
|
|
396
|
+
return [4 /*yield*/, dAppKit.disconnectWallet()];
|
|
397
|
+
case 2:
|
|
398
|
+
_a.sent();
|
|
393
399
|
setSession(res.session);
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
400
|
+
return [2 /*return*/];
|
|
401
|
+
case 3:
|
|
402
|
+
if (!_wallet.raw)
|
|
403
|
+
throw new Error("Missing wallet");
|
|
404
|
+
return [4 /*yield*/, dAppKit.connectWallet({ wallet: _wallet.raw })];
|
|
405
|
+
case 4:
|
|
406
|
+
_a.sent();
|
|
401
407
|
universalConnector.disconnect();
|
|
402
408
|
setSession(null);
|
|
403
409
|
showInfoToast("Connected ".concat(_wallet.name));
|
|
404
410
|
setIsConnectWalletDropdownOpen(false);
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
catch (err) {
|
|
413
|
-
showErrorToast("Failed to connect ".concat(_wallet.name), err);
|
|
414
|
-
console.error(err);
|
|
415
|
-
}
|
|
416
|
-
}, [connectWallet, disconnectWallet, universalConnector]);
|
|
417
|
-
var disconnectWalletWrapper = useCallback(function () {
|
|
418
|
-
try {
|
|
419
|
-
if (sessionAddress) {
|
|
420
|
-
universalConnector.disconnect();
|
|
421
|
-
setSession(null);
|
|
411
|
+
return [3 /*break*/, 6];
|
|
412
|
+
case 5:
|
|
413
|
+
err_1 = _a.sent();
|
|
414
|
+
showErrorToast("Failed to connect ".concat(_wallet.name), err_1);
|
|
415
|
+
console.error(err_1);
|
|
416
|
+
return [3 /*break*/, 6];
|
|
417
|
+
case 6: return [2 /*return*/];
|
|
422
418
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
419
|
+
});
|
|
420
|
+
}); }, [universalConnector, dAppKit]);
|
|
421
|
+
var disconnectWalletWrapper = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
422
|
+
var err_2;
|
|
423
|
+
return __generator(this, function (_a) {
|
|
424
|
+
switch (_a.label) {
|
|
425
|
+
case 0:
|
|
426
|
+
_a.trys.push([0, 4, , 5]);
|
|
427
|
+
if (!sessionAddress) return [3 /*break*/, 1];
|
|
428
|
+
universalConnector.disconnect();
|
|
429
|
+
setSession(null);
|
|
430
|
+
return [3 /*break*/, 3];
|
|
431
|
+
case 1: return [4 /*yield*/, dAppKit.disconnectWallet()];
|
|
432
|
+
case 2:
|
|
433
|
+
_a.sent();
|
|
434
|
+
showInfoToast("Disconnected wallet");
|
|
435
|
+
_a.label = 3;
|
|
436
|
+
case 3: return [3 /*break*/, 5];
|
|
437
|
+
case 4:
|
|
438
|
+
err_2 = _a.sent();
|
|
439
|
+
showErrorToast("Failed to disconnect wallet", err_2);
|
|
440
|
+
console.error(err_2);
|
|
441
|
+
return [3 /*break*/, 5];
|
|
442
|
+
case 5: return [2 /*return*/];
|
|
433
443
|
}
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
showErrorToast("Failed to disconnect wallet", err);
|
|
437
|
-
console.error(err);
|
|
438
|
-
}
|
|
439
|
-
}, [sessionAddress, universalConnector, disconnectWallet]);
|
|
444
|
+
});
|
|
445
|
+
}); }, [sessionAddress, universalConnector, dAppKit]);
|
|
440
446
|
// Accounts
|
|
441
|
-
var
|
|
442
|
-
var
|
|
443
|
-
var
|
|
447
|
+
var walletConnection = useWalletConnection();
|
|
448
|
+
var accountsRes = useMemo(function () { var _a, _b; return (_b = (_a = walletConnection.wallet) === null || _a === void 0 ? void 0 : _a.accounts) !== null && _b !== void 0 ? _b : []; }, [(_f = walletConnection.wallet) === null || _f === void 0 ? void 0 : _f.accounts]);
|
|
449
|
+
var accountRes = (_g = useCurrentAccount()) !== null && _g !== void 0 ? _g : undefined;
|
|
444
450
|
var account = useMemo(function () {
|
|
445
451
|
return sessionAddress
|
|
446
452
|
? {
|
|
@@ -463,49 +469,36 @@ function Inner(_a) {
|
|
|
463
469
|
]
|
|
464
470
|
: accountsRes;
|
|
465
471
|
}, [sessionAddress, accountsRes]);
|
|
466
|
-
var signPersonalMessage =
|
|
467
|
-
return
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
]);
|
|
476
|
-
var switchAccountWrapper = useCallback(function (_account, addressNameServiceName) {
|
|
472
|
+
var signPersonalMessage = useCallback(function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
473
|
+
return __generator(this, function (_a) {
|
|
474
|
+
return [2 /*return*/, sessionAddress
|
|
475
|
+
? walletConnectSignPersonalMessage(message)
|
|
476
|
+
: dAppKit.signPersonalMessage({ message: message })];
|
|
477
|
+
});
|
|
478
|
+
}); }, [sessionAddress, walletConnectSignPersonalMessage, dAppKit]);
|
|
479
|
+
var switchAccountWrapper = useCallback(function (_account, addressNameServiceName) { return __awaiter(_this, void 0, void 0, function () {
|
|
480
|
+
var accountLabel, walletAccount;
|
|
477
481
|
var _a, _b, _c;
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
},
|
|
499
|
-
onError: function (err) {
|
|
500
|
-
showErrorToast("Failed to switch to ".concat(accountLabel), err);
|
|
501
|
-
},
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
catch (err) {
|
|
505
|
-
showErrorToast("Failed to switch to ".concat(accountLabel), err);
|
|
506
|
-
console.error(err);
|
|
507
|
-
}
|
|
508
|
-
}, [switchAccount]);
|
|
482
|
+
return __generator(this, function (_d) {
|
|
483
|
+
accountLabel = (_b = (_a = _account === null || _account === void 0 ? void 0 : _account.label) !== null && _a !== void 0 ? _a : addressNameServiceName) !== null && _b !== void 0 ? _b : formatAddress(_account.address);
|
|
484
|
+
try {
|
|
485
|
+
walletAccount = (_c = walletConnection.wallet) === null || _c === void 0 ? void 0 : _c.accounts.find(function (acc) { return acc.address === _account.address; });
|
|
486
|
+
if (!walletAccount)
|
|
487
|
+
throw new Error("Account not found in wallet");
|
|
488
|
+
dAppKit.switchAccount({ account: walletAccount });
|
|
489
|
+
showInfoToast("Switched to ".concat(accountLabel), {
|
|
490
|
+
description: (_account === null || _account === void 0 ? void 0 : _account.label)
|
|
491
|
+
? (addressNameServiceName !== null && addressNameServiceName !== void 0 ? addressNameServiceName : formatAddress(_account.address))
|
|
492
|
+
: undefined,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
catch (err) {
|
|
496
|
+
showErrorToast("Failed to switch to ".concat(accountLabel), err);
|
|
497
|
+
console.error(err);
|
|
498
|
+
}
|
|
499
|
+
return [2 /*return*/];
|
|
500
|
+
});
|
|
501
|
+
}); }, [(_h = walletConnection.wallet) === null || _h === void 0 ? void 0 : _h.accounts, dAppKit]);
|
|
509
502
|
// LaunchDarkly
|
|
510
503
|
var ldClient = useLDClient();
|
|
511
504
|
var ldKeyRef = useRef(undefined);
|
|
@@ -534,7 +527,7 @@ function Inner(_a) {
|
|
|
534
527
|
if (!(wallet === null || wallet === void 0 ? void 0 : wallet.name))
|
|
535
528
|
return;
|
|
536
529
|
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
537
|
-
var
|
|
530
|
+
var err_3;
|
|
538
531
|
return __generator(this, function (_a) {
|
|
539
532
|
switch (_a.label) {
|
|
540
533
|
case 0:
|
|
@@ -554,8 +547,8 @@ function Inner(_a) {
|
|
|
554
547
|
_a.sent();
|
|
555
548
|
return [3 /*break*/, 3];
|
|
556
549
|
case 2:
|
|
557
|
-
|
|
558
|
-
console.error(
|
|
550
|
+
err_3 = _a.sent();
|
|
551
|
+
console.error(err_3);
|
|
559
552
|
return [3 /*break*/, 3];
|
|
560
553
|
case 3: return [2 /*return*/];
|
|
561
554
|
}
|
|
@@ -564,53 +557,59 @@ function Inner(_a) {
|
|
|
564
557
|
}, [impersonatedAddress, account === null || account === void 0 ? void 0 : account.address, wallet === null || wallet === void 0 ? void 0 : wallet.name, appName]);
|
|
565
558
|
// Tx
|
|
566
559
|
var gasBudget = useSettingsContext().gasBudget;
|
|
567
|
-
var signTransaction = useSignTransaction().mutateAsync;
|
|
568
560
|
var dryRunTransaction = useCallback(function (transaction_1) {
|
|
569
561
|
var args_1 = [];
|
|
570
562
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
571
563
|
args_1[_i - 1] = arguments[_i];
|
|
572
564
|
}
|
|
573
565
|
return __awaiter(_this, __spreadArray([transaction_1], args_1, true), void 0, function (transaction, setGasBudget) {
|
|
574
|
-
var _address, _transaction, inspectResults,
|
|
566
|
+
var _address, _transaction, inspectResults, _a, _b, err_4;
|
|
567
|
+
var _c;
|
|
568
|
+
var _d, _e, _f, _g;
|
|
575
569
|
if (setGasBudget === void 0) { setGasBudget = true; }
|
|
576
|
-
return __generator(this, function (
|
|
577
|
-
switch (
|
|
570
|
+
return __generator(this, function (_h) {
|
|
571
|
+
switch (_h.label) {
|
|
578
572
|
case 0:
|
|
579
573
|
_address = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
580
574
|
_transaction = Transaction.from(transaction);
|
|
581
|
-
|
|
575
|
+
_h.label = 1;
|
|
582
576
|
case 1:
|
|
583
|
-
|
|
577
|
+
_h.trys.push([1, 4, , 5]);
|
|
584
578
|
// Gas budget
|
|
585
579
|
if (setGasBudget && gasBudget !== "")
|
|
586
580
|
_transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
587
581
|
.times(Math.pow(10, SUI_DECIMALS))
|
|
588
582
|
.integerValue(BigNumber.ROUND_DOWN));
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
583
|
+
// Set sender for simulation
|
|
584
|
+
_transaction.setSender(_address !== null && _address !== void 0 ? _address : "0x0000000000000000000000000000000000000000000000000000000000000000");
|
|
585
|
+
_b = (_a = suiClient).simulateTransaction;
|
|
586
|
+
_c = {};
|
|
587
|
+
return [4 /*yield*/, _transaction.build({ client: suiClient })];
|
|
588
|
+
case 2: return [4 /*yield*/, _b.apply(_a, [(_c.transaction = _h.sent(),
|
|
589
|
+
_c)])];
|
|
590
|
+
case 3:
|
|
591
|
+
inspectResults = _h.sent();
|
|
595
592
|
console.log("[WalletContext] dryRunTransaction - inspectResults:", inspectResults);
|
|
596
|
-
|
|
597
|
-
|
|
593
|
+
// Check for failed transaction
|
|
594
|
+
if (!!inspectResults.FailedTransaction)
|
|
595
|
+
throw new Error((_g = (_f = (_e = (_d = inspectResults.FailedTransaction.effects) === null || _d === void 0 ? void 0 : _d.status) === null || _e === void 0 ? void 0 : _e.error) === null || _f === void 0 ? void 0 : _f.message) !== null && _g !== void 0 ? _g : "Failed to inspect transaction");
|
|
598
596
|
return [2 /*return*/, inspectResults];
|
|
599
|
-
case
|
|
600
|
-
|
|
597
|
+
case 4:
|
|
598
|
+
err_4 = _h.sent();
|
|
601
599
|
// _transaction.getData().inputs.filter(input=>!!input.Object).map(input=>input.)
|
|
602
|
-
console.error(
|
|
603
|
-
throw
|
|
604
|
-
case
|
|
600
|
+
console.error(err_4);
|
|
601
|
+
throw err_4;
|
|
602
|
+
case 5: return [2 /*return*/];
|
|
605
603
|
}
|
|
606
604
|
});
|
|
607
605
|
});
|
|
608
606
|
}, [impersonatedAddress, account === null || account === void 0 ? void 0 : account.address, gasBudget, suiClient]);
|
|
609
607
|
var signExecuteAndWaitForTransaction = useCallback(function (transaction, options, onSetGasBudget, onSign, onExecute) { return __awaiter(_this, void 0, void 0, function () {
|
|
610
|
-
var _address, signedTransaction, txBytes, res,
|
|
611
|
-
var
|
|
612
|
-
|
|
613
|
-
|
|
608
|
+
var _address, signedTransaction, txBytes, res, err_5, res1, _a, _b, txResult1, res2, txResult2, err_6;
|
|
609
|
+
var _c;
|
|
610
|
+
var _d, _e, _f, _g;
|
|
611
|
+
return __generator(this, function (_h) {
|
|
612
|
+
switch (_h.label) {
|
|
614
613
|
case 0:
|
|
615
614
|
_address = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
616
615
|
if (_address) {
|
|
@@ -619,9 +618,9 @@ function Inner(_a) {
|
|
|
619
618
|
}
|
|
620
619
|
catch (err) { }
|
|
621
620
|
}
|
|
622
|
-
|
|
621
|
+
_h.label = 1;
|
|
623
622
|
case 1:
|
|
624
|
-
|
|
623
|
+
_h.trys.push([1, 14, , 15]);
|
|
625
624
|
// Gas budget
|
|
626
625
|
if (gasBudget !== "")
|
|
627
626
|
transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
@@ -635,7 +634,7 @@ function Inner(_a) {
|
|
|
635
634
|
transaction.setSender(sessionAddress);
|
|
636
635
|
return [4 /*yield*/, transaction.build({ client: suiClient })];
|
|
637
636
|
case 2:
|
|
638
|
-
txBytes =
|
|
637
|
+
txBytes = _h.sent();
|
|
639
638
|
return [4 /*yield*/, universalConnector.request({
|
|
640
639
|
method: "sui_signTransaction",
|
|
641
640
|
params: {
|
|
@@ -644,74 +643,79 @@ function Inner(_a) {
|
|
|
644
643
|
},
|
|
645
644
|
}, "sui:mainnet")];
|
|
646
645
|
case 3:
|
|
647
|
-
res =
|
|
646
|
+
res = _h.sent();
|
|
648
647
|
signedTransaction = {
|
|
649
648
|
bytes: res.transactionBytes,
|
|
650
649
|
signature: res.signature,
|
|
651
650
|
};
|
|
652
651
|
return [3 /*break*/, 6];
|
|
653
|
-
case 4: return [4 /*yield*/, signTransaction({
|
|
652
|
+
case 4: return [4 /*yield*/, dAppKit.signTransaction({
|
|
654
653
|
transaction: transaction,
|
|
655
|
-
chain: "sui:mainnet",
|
|
656
654
|
})];
|
|
657
655
|
case 5:
|
|
658
656
|
// Sign
|
|
659
|
-
signedTransaction =
|
|
660
|
-
|
|
657
|
+
signedTransaction = _h.sent();
|
|
658
|
+
_h.label = 6;
|
|
661
659
|
case 6:
|
|
662
660
|
onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction);
|
|
663
661
|
if (!(options === null || options === void 0 ? void 0 : options.auction)) return [3 /*break*/, 10];
|
|
664
|
-
|
|
662
|
+
_h.label = 7;
|
|
665
663
|
case 7:
|
|
666
|
-
|
|
664
|
+
_h.trys.push([7, 9, , 10]);
|
|
667
665
|
return [4 /*yield*/, executeAuction(signedTransaction.bytes, signedTransaction.signature)];
|
|
668
666
|
case 8:
|
|
669
|
-
|
|
667
|
+
_h.sent();
|
|
670
668
|
return [3 /*break*/, 10];
|
|
671
669
|
case 9:
|
|
672
|
-
|
|
670
|
+
err_5 = _h.sent();
|
|
673
671
|
return [3 /*break*/, 10];
|
|
674
|
-
case 10:
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
})];
|
|
678
|
-
case 11:
|
|
679
|
-
|
|
672
|
+
case 10:
|
|
673
|
+
_b = (_a = suiClient).executeTransaction;
|
|
674
|
+
_c = {};
|
|
675
|
+
return [4 /*yield*/, transaction.build({ client: suiClient })];
|
|
676
|
+
case 11: return [4 /*yield*/, _b.apply(_a, [(_c.transaction = _h.sent(),
|
|
677
|
+
_c.signatures = [signedTransaction.signature],
|
|
678
|
+
_c)])];
|
|
679
|
+
case 12:
|
|
680
|
+
res1 = _h.sent();
|
|
681
|
+
txResult1 = (_d = res1.Transaction) !== null && _d !== void 0 ? _d : res1.FailedTransaction;
|
|
682
|
+
if (!(txResult1 === null || txResult1 === void 0 ? void 0 : txResult1.digest))
|
|
683
|
+
throw new Error("Failed to get transaction digest");
|
|
680
684
|
onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1);
|
|
681
685
|
return [4 /*yield*/, suiClient.waitForTransaction({
|
|
682
|
-
digest:
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
686
|
+
digest: txResult1.digest,
|
|
687
|
+
include: {
|
|
688
|
+
balanceChanges: true,
|
|
689
|
+
effects: true,
|
|
690
|
+
events: true,
|
|
691
|
+
objectChanges: true,
|
|
688
692
|
},
|
|
689
693
|
})];
|
|
690
|
-
case 12:
|
|
691
|
-
res2 = _c.sent();
|
|
692
|
-
if (((_a = res2.effects) === null || _a === void 0 ? void 0 : _a.status) !== undefined &&
|
|
693
|
-
res2.effects.status.status === "failure")
|
|
694
|
-
throw new Error((_b = res2.effects.status.error) !== null && _b !== void 0 ? _b : "Transaction failed");
|
|
695
|
-
return [2 /*return*/, res2];
|
|
696
694
|
case 13:
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
695
|
+
res2 = _h.sent();
|
|
696
|
+
txResult2 = (_e = res2.Transaction) !== null && _e !== void 0 ? _e : res2.FailedTransaction;
|
|
697
|
+
if ((txResult2 === null || txResult2 === void 0 ? void 0 : txResult2.effects) && !txResult2.effects.status.success)
|
|
698
|
+
throw new Error((_g = (_f = txResult2.effects.status.error) === null || _f === void 0 ? void 0 : _f.message) !== null && _g !== void 0 ? _g : "Transaction failed");
|
|
699
|
+
return [2 /*return*/, res2];
|
|
700
|
+
case 14:
|
|
701
|
+
err_6 = _h.sent();
|
|
702
|
+
console.error(err_6);
|
|
703
|
+
throw err_6;
|
|
704
|
+
case 15: return [2 /*return*/];
|
|
701
705
|
}
|
|
702
706
|
});
|
|
703
707
|
}); }, [
|
|
704
|
-
universalConnector,
|
|
705
|
-
sessionAddress,
|
|
706
|
-
gasBudget,
|
|
707
708
|
impersonatedAddress,
|
|
708
709
|
account === null || account === void 0 ? void 0 : account.address,
|
|
709
710
|
dryRunTransaction,
|
|
711
|
+
gasBudget,
|
|
712
|
+
sessionAddress,
|
|
713
|
+
universalConnector,
|
|
710
714
|
suiClient,
|
|
711
|
-
|
|
715
|
+
dAppKit,
|
|
712
716
|
]);
|
|
713
717
|
// Using Ledger
|
|
714
|
-
var
|
|
718
|
+
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];
|
|
715
719
|
// Context
|
|
716
720
|
var contextValue = useMemo(function () {
|
|
717
721
|
return {
|
|
@@ -755,15 +759,24 @@ function Inner(_a) {
|
|
|
755
759
|
export function WalletContextProvider(_a) {
|
|
756
760
|
var appName = _a.appName, children = _a.children;
|
|
757
761
|
var rpc = useSettingsContext().rpc;
|
|
758
|
-
var
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
+
var queryClient = useMemo(function () { return new QueryClient(); }, []);
|
|
763
|
+
var dAppKit = useMemo(function () {
|
|
764
|
+
return createDAppKit({
|
|
765
|
+
networks: ["mainnet"],
|
|
766
|
+
defaultNetwork: "mainnet",
|
|
767
|
+
createClient: function (network) {
|
|
768
|
+
return new SuiGrpcClient({
|
|
769
|
+
baseUrl: rpc.url,
|
|
770
|
+
network: network,
|
|
771
|
+
});
|
|
772
|
+
},
|
|
773
|
+
autoConnect: true,
|
|
774
|
+
slushWalletConfig: { appName: appName },
|
|
775
|
+
});
|
|
776
|
+
}, [rpc.url, appName]);
|
|
762
777
|
return (<QueryClientProvider client={queryClient}>
|
|
763
|
-
<
|
|
764
|
-
<
|
|
765
|
-
|
|
766
|
-
</MystenWalletProvider>
|
|
767
|
-
</SuiClientProvider>
|
|
778
|
+
<DAppKitProvider dAppKit={dAppKit}>
|
|
779
|
+
<Inner appName={appName}>{children}</Inner>
|
|
780
|
+
</DAppKitProvider>
|
|
768
781
|
</QueryClientProvider>);
|
|
769
782
|
}
|