@suilend/sui-fe-next 2.0.31 → 3.0.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 -8
- package/contexts/WalletContext.d.ts +12 -5
- package/contexts/WalletContext.jsx +129 -135
- package/fetchers/useFetchBalances.js +7 -6
- package/hooks/useCoinMetadataMap.d.ts +2 -2
- package/hooks/useLedgerHashDialog.js +3 -3
- package/hooks/useRefreshOnBalancesChange.js +4 -4
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { SuiGraphQLClient } from "@mysten/sui/graphql";
|
|
3
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
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
|
-
|
|
13
|
+
suiGrpcClient: SuiGrpcClient;
|
|
14
|
+
suiGraphQLClient: SuiGraphQLClient;
|
|
13
15
|
}
|
|
14
16
|
declare const SettingsContext: import("react").Context<SettingsContext>;
|
|
15
17
|
export declare const useSettingsContext: () => SettingsContext;
|
|
@@ -10,9 +10,10 @@ 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 { SuiGraphQLClient } from "@mysten/sui/graphql";
|
|
14
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
14
15
|
import { useLocalStorage } from "usehooks-ts";
|
|
15
|
-
import { EXPLORERS, RPCS, RpcId, } from "@suilend/sui-fe";
|
|
16
|
+
import { EXPLORERS, RPCS, RPC_GRAPHQL_URL, RpcId, } from "@suilend/sui-fe";
|
|
16
17
|
var defaultContextValue = {
|
|
17
18
|
rpc: RPCS[0],
|
|
18
19
|
setRpcId: function () {
|
|
@@ -29,8 +30,12 @@ var defaultContextValue = {
|
|
|
29
30
|
setGasBudget: function () {
|
|
30
31
|
throw Error("SettingsContextProvider not initialized");
|
|
31
32
|
},
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
suiGrpcClient: new SuiGrpcClient({
|
|
34
|
+
baseUrl: "https://fullnode.mainnet.sui.io:443",
|
|
35
|
+
network: "mainnet",
|
|
36
|
+
}),
|
|
37
|
+
suiGraphQLClient: new SuiGraphQLClient({
|
|
38
|
+
url: RPC_GRAPHQL_URL,
|
|
34
39
|
network: "mainnet",
|
|
35
40
|
}),
|
|
36
41
|
};
|
|
@@ -54,8 +59,9 @@ export function SettingsContextProvider(_a) {
|
|
|
54
59
|
}, [explorerId]);
|
|
55
60
|
// Gas budget
|
|
56
61
|
var _e = useLocalStorage("gasBudget", defaultContextValue.gasBudget), gasBudget = _e[0], setGasBudget = _e[1];
|
|
57
|
-
// Sui
|
|
58
|
-
var
|
|
62
|
+
// Sui clients
|
|
63
|
+
var suiGrpcClient = useMemo(function () { return new SuiGrpcClient({ baseUrl: rpc.url, network: "mainnet" }); }, [rpc.url]);
|
|
64
|
+
var suiGraphQLClient = useMemo(function () { return new SuiGraphQLClient({ url: RPC_GRAPHQL_URL, network: "mainnet" }); }, []);
|
|
59
65
|
// Context
|
|
60
66
|
var contextValue = useMemo(function () { return ({
|
|
61
67
|
rpc: rpc,
|
|
@@ -65,7 +71,8 @@ export function SettingsContextProvider(_a) {
|
|
|
65
71
|
setExplorerId: setExplorerId,
|
|
66
72
|
gasBudget: gasBudget,
|
|
67
73
|
setGasBudget: setGasBudget,
|
|
68
|
-
|
|
74
|
+
suiGrpcClient: suiGrpcClient,
|
|
75
|
+
suiGraphQLClient: suiGraphQLClient,
|
|
69
76
|
}); }, [
|
|
70
77
|
rpc,
|
|
71
78
|
setRpcId,
|
|
@@ -74,7 +81,8 @@ export function SettingsContextProvider(_a) {
|
|
|
74
81
|
setExplorerId,
|
|
75
82
|
gasBudget,
|
|
76
83
|
setGasBudget,
|
|
77
|
-
|
|
84
|
+
suiGrpcClient,
|
|
85
|
+
suiGraphQLClient,
|
|
78
86
|
]);
|
|
79
87
|
return (<SettingsContext.Provider value={contextValue}>
|
|
80
88
|
{children}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Dispatch, PropsWithChildren, SetStateAction } from "react";
|
|
2
|
+
import { UiWallet } from "@mysten/dapp-kit-core";
|
|
3
|
+
import { SuiClientTypes } from "@mysten/sui/client";
|
|
2
4
|
import { SignatureWithBytes } from "@mysten/sui/cryptography";
|
|
3
|
-
import { DevInspectResults, SuiTransactionBlockResponse } from "@mysten/sui/jsonRpc";
|
|
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,8 +51,14 @@ 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
|
-
|
|
54
|
+
dryRunTransaction: (transaction: Transaction, setGasBudget?: boolean) => Promise<SuiClientTypes.SimulateTransactionResult<{
|
|
55
|
+
commandResults: true;
|
|
56
|
+
}>>;
|
|
57
|
+
signExecuteAndWaitForTransaction: (transaction: Transaction, onSetGasBudget?: (transaction: Transaction) => void, onSign?: (signedTransaction: SignatureWithBytes) => void, onExecute?: (res: SuiClientTypes.Transaction) => void) => Promise<SuiClientTypes.Transaction<{
|
|
58
|
+
effects: true;
|
|
59
|
+
events: true;
|
|
60
|
+
balanceChanges: true;
|
|
61
|
+
}>>;
|
|
55
62
|
isUsingLedger: boolean;
|
|
56
63
|
setIsUsingLedger: (isUsingLedger: boolean) => void;
|
|
57
64
|
signPersonalMessage: (message: Uint8Array) => Promise<{
|
|
@@ -57,11 +57,11 @@ 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 { createDAppKit, } from "@mysten/dapp-kit-core";
|
|
61
|
+
import { DAppKitProvider, useCurrentAccount, useCurrentWallet, useDAppKit, useWalletConnection, useWallets, } from "@mysten/dapp-kit-react";
|
|
62
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
62
63
|
import { Transaction } from "@mysten/sui/transactions";
|
|
63
|
-
import { SUI_DECIMALS, toBase64 } from "@mysten/sui/utils";
|
|
64
|
-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
64
|
+
import { SUI_DECIMALS, fromBase64, toBase64 } from "@mysten/sui/utils";
|
|
65
65
|
import BigNumber from "bignumber.js";
|
|
66
66
|
import { useLDClient } from "launchdarkly-react-client-sdk";
|
|
67
67
|
import { useLocalStorage } from "usehooks-ts";
|
|
@@ -211,16 +211,16 @@ export var useWalletContext = function () { return useContext(WalletContext); };
|
|
|
211
211
|
function Inner(_a) {
|
|
212
212
|
var _b;
|
|
213
213
|
var _this = this;
|
|
214
|
-
var _c, _d, _e, _f;
|
|
214
|
+
var _c, _d, _e, _f, _g;
|
|
215
215
|
var appName = _a.appName, children = _a.children;
|
|
216
216
|
var router = useRouter();
|
|
217
217
|
var queryParams = (_b = {},
|
|
218
218
|
_b[WalletContextQueryParams.WALLET] = router.query[WalletContextQueryParams.WALLET],
|
|
219
219
|
_b);
|
|
220
|
-
var
|
|
220
|
+
var _h = useSettingsContext(), rpc = _h.rpc, suiGrpcClient = _h.suiGrpcClient;
|
|
221
221
|
// Only used for wallet connect
|
|
222
|
-
var
|
|
223
|
-
var
|
|
222
|
+
var _j = useState(), universalConnector = _j[0], setUniversalConnector = _j[1];
|
|
223
|
+
var _k = useState(), session = _k[0], setSession = _k[1];
|
|
224
224
|
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];
|
|
225
225
|
var sessionAddress = sessionAddressWithout0x
|
|
226
226
|
? sessionAddressWithout0x.split(":").pop()
|
|
@@ -351,8 +351,9 @@ function Inner(_a) {
|
|
|
351
351
|
wallets__web,
|
|
352
352
|
]);
|
|
353
353
|
// Wallet
|
|
354
|
-
var
|
|
355
|
-
var
|
|
354
|
+
var _l = useState(false), isConnectWalletDropdownOpen = _l[0], setIsConnectWalletDropdownOpen = _l[1];
|
|
355
|
+
var dAppKit = useDAppKit();
|
|
356
|
+
var rawWallet = useCurrentWallet();
|
|
356
357
|
var wallet = useMemo(function () {
|
|
357
358
|
if (sessionAddress) {
|
|
358
359
|
return WALLET_CONNECT_WALLET;
|
|
@@ -361,9 +362,6 @@ function Inner(_a) {
|
|
|
361
362
|
? wallets.find(function (w) { return w.name === rawWallet.name; })
|
|
362
363
|
: undefined;
|
|
363
364
|
}, [rawWallet, wallets, sessionAddress]);
|
|
364
|
-
var connectWallet = useConnectWallet().mutate;
|
|
365
|
-
var disconnectWallet = useDisconnectWallet().mutate;
|
|
366
|
-
var signPersonalMessageRaw = useSignPersonalMessage().mutateAsync;
|
|
367
365
|
var walletConnectSignPersonalMessage = useCallback(function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
368
366
|
var res;
|
|
369
367
|
return __generator(this, function (_a) {
|
|
@@ -388,31 +386,38 @@ function Inner(_a) {
|
|
|
388
386
|
try {
|
|
389
387
|
if (_wallet === null || _wallet === void 0 ? void 0 : _wallet.walletConnect) {
|
|
390
388
|
universalConnector.connect().then(function (res) {
|
|
391
|
-
|
|
392
|
-
|
|
389
|
+
dAppKit
|
|
390
|
+
.disconnectWallet()
|
|
391
|
+
.then(function () {
|
|
392
|
+
setSession(res.session);
|
|
393
|
+
})
|
|
394
|
+
.catch(function (err) {
|
|
395
|
+
showErrorToast("Failed to connect ".concat(_wallet.name), err);
|
|
396
|
+
console.error(err);
|
|
397
|
+
});
|
|
393
398
|
});
|
|
394
399
|
return;
|
|
395
400
|
}
|
|
396
401
|
if (!_wallet.raw)
|
|
397
402
|
throw new Error("Missing wallet");
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
403
|
+
dAppKit
|
|
404
|
+
.connectWallet({ wallet: _wallet.raw })
|
|
405
|
+
.then(function (res) {
|
|
406
|
+
universalConnector.disconnect();
|
|
407
|
+
setSession(null);
|
|
408
|
+
showInfoToast("Connected ".concat(_wallet.name));
|
|
409
|
+
setIsConnectWalletDropdownOpen(false);
|
|
410
|
+
})
|
|
411
|
+
.catch(function (err) {
|
|
412
|
+
showErrorToast("Failed to connect ".concat(_wallet.name), err);
|
|
413
|
+
console.error(err);
|
|
409
414
|
});
|
|
410
415
|
}
|
|
411
416
|
catch (err) {
|
|
412
417
|
showErrorToast("Failed to connect ".concat(_wallet.name), err);
|
|
413
418
|
console.error(err);
|
|
414
419
|
}
|
|
415
|
-
}, [
|
|
420
|
+
}, [universalConnector, dAppKit]);
|
|
416
421
|
var disconnectWalletWrapper = useCallback(function () {
|
|
417
422
|
try {
|
|
418
423
|
if (sessionAddress) {
|
|
@@ -420,14 +425,14 @@ function Inner(_a) {
|
|
|
420
425
|
setSession(null);
|
|
421
426
|
}
|
|
422
427
|
else {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
428
|
+
dAppKit
|
|
429
|
+
.disconnectWallet()
|
|
430
|
+
.then(function () {
|
|
431
|
+
showInfoToast("Disconnected wallet");
|
|
432
|
+
})
|
|
433
|
+
.catch(function (err) {
|
|
434
|
+
showErrorToast("Failed to disconnect wallet", err);
|
|
435
|
+
console.error(err);
|
|
431
436
|
});
|
|
432
437
|
}
|
|
433
438
|
}
|
|
@@ -435,11 +440,11 @@ function Inner(_a) {
|
|
|
435
440
|
showErrorToast("Failed to disconnect wallet", err);
|
|
436
441
|
console.error(err);
|
|
437
442
|
}
|
|
438
|
-
}, [sessionAddress, universalConnector,
|
|
443
|
+
}, [sessionAddress, universalConnector, dAppKit]);
|
|
439
444
|
// Accounts
|
|
440
|
-
var
|
|
441
|
-
var
|
|
442
|
-
var
|
|
445
|
+
var connection = useWalletConnection();
|
|
446
|
+
var accountsRes = useMemo(function () { var _a, _b; return (_b = (_a = connection === null || connection === void 0 ? void 0 : connection.wallet) === null || _a === void 0 ? void 0 : _a.accounts) !== null && _b !== void 0 ? _b : []; }, [(_f = connection === null || connection === void 0 ? void 0 : connection.wallet) === null || _f === void 0 ? void 0 : _f.accounts]);
|
|
447
|
+
var accountRes = (_g = useCurrentAccount()) !== null && _g !== void 0 ? _g : undefined;
|
|
443
448
|
var account = useMemo(function () {
|
|
444
449
|
return sessionAddress
|
|
445
450
|
? {
|
|
@@ -465,46 +470,26 @@ function Inner(_a) {
|
|
|
465
470
|
var signPersonalMessage = useMemo(function () {
|
|
466
471
|
return sessionAddress
|
|
467
472
|
? walletConnectSignPersonalMessage
|
|
468
|
-
: function (message) { return
|
|
469
|
-
}, [
|
|
470
|
-
sessionAddress,
|
|
471
|
-
walletConnectSignPersonalMessage,
|
|
472
|
-
signPersonalMessageRaw,
|
|
473
|
-
account,
|
|
474
|
-
]);
|
|
473
|
+
: function (message) { return dAppKit.signPersonalMessage({ message: message }); };
|
|
474
|
+
}, [sessionAddress, walletConnectSignPersonalMessage, dAppKit]);
|
|
475
475
|
var switchAccountWrapper = useCallback(function (_account, addressNameServiceName) {
|
|
476
|
-
var _a, _b
|
|
476
|
+
var _a, _b;
|
|
477
477
|
var 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);
|
|
478
478
|
try {
|
|
479
|
-
switchAccount(
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
icon: _account.icon,
|
|
487
|
-
label: _account.label,
|
|
488
|
-
publicKey: (_c = _account.publicKey) !== null && _c !== void 0 ? _c : new Uint8Array(),
|
|
489
|
-
},
|
|
490
|
-
}, {
|
|
491
|
-
onSuccess: function () {
|
|
492
|
-
showInfoToast("Switched to ".concat(accountLabel), {
|
|
493
|
-
description: (_account === null || _account === void 0 ? void 0 : _account.label)
|
|
494
|
-
? (addressNameServiceName !== null && addressNameServiceName !== void 0 ? addressNameServiceName : formatAddress(_account.address))
|
|
495
|
-
: undefined,
|
|
496
|
-
});
|
|
497
|
-
},
|
|
498
|
-
onError: function (err) {
|
|
499
|
-
showErrorToast("Failed to switch to ".concat(accountLabel), err);
|
|
500
|
-
},
|
|
479
|
+
dAppKit.switchAccount({
|
|
480
|
+
account: _account,
|
|
481
|
+
});
|
|
482
|
+
showInfoToast("Switched to ".concat(accountLabel), {
|
|
483
|
+
description: (_account === null || _account === void 0 ? void 0 : _account.label)
|
|
484
|
+
? (addressNameServiceName !== null && addressNameServiceName !== void 0 ? addressNameServiceName : formatAddress(_account.address))
|
|
485
|
+
: undefined,
|
|
501
486
|
});
|
|
502
487
|
}
|
|
503
488
|
catch (err) {
|
|
504
489
|
showErrorToast("Failed to switch to ".concat(accountLabel), err);
|
|
505
490
|
console.error(err);
|
|
506
491
|
}
|
|
507
|
-
}, [
|
|
492
|
+
}, [dAppKit]);
|
|
508
493
|
// LaunchDarkly
|
|
509
494
|
var ldClient = useLDClient();
|
|
510
495
|
var ldKeyRef = useRef(undefined);
|
|
@@ -563,53 +548,55 @@ function Inner(_a) {
|
|
|
563
548
|
}, [impersonatedAddress, account === null || account === void 0 ? void 0 : account.address, wallet === null || wallet === void 0 ? void 0 : wallet.name, appName]);
|
|
564
549
|
// Tx
|
|
565
550
|
var gasBudget = useSettingsContext().gasBudget;
|
|
566
|
-
var signTransaction = useSignTransaction().mutateAsync;
|
|
567
551
|
var dryRunTransaction = useCallback(function (transaction_1) {
|
|
568
552
|
var args_1 = [];
|
|
569
553
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
570
554
|
args_1[_i - 1] = arguments[_i];
|
|
571
555
|
}
|
|
572
556
|
return __awaiter(_this, __spreadArray([transaction_1], args_1, true), void 0, function (transaction, setGasBudget) {
|
|
573
|
-
var _address, _transaction,
|
|
557
|
+
var _address, _transaction, simResult, err_2;
|
|
558
|
+
var _a, _b;
|
|
574
559
|
if (setGasBudget === void 0) { setGasBudget = true; }
|
|
575
|
-
return __generator(this, function (
|
|
576
|
-
switch (
|
|
560
|
+
return __generator(this, function (_c) {
|
|
561
|
+
switch (_c.label) {
|
|
577
562
|
case 0:
|
|
578
563
|
_address = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
579
564
|
_transaction = Transaction.from(transaction);
|
|
580
|
-
|
|
565
|
+
_c.label = 1;
|
|
581
566
|
case 1:
|
|
582
|
-
|
|
567
|
+
_c.trys.push([1, 3, , 4]);
|
|
583
568
|
// Gas budget
|
|
584
569
|
if (setGasBudget && gasBudget !== "")
|
|
585
570
|
_transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
586
571
|
.times(Math.pow(10, SUI_DECIMALS))
|
|
587
572
|
.integerValue(BigNumber.ROUND_DOWN));
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
573
|
+
// Set sender for simulation
|
|
574
|
+
_transaction.setSender(_address !== null && _address !== void 0 ? _address : "0x0000000000000000000000000000000000000000000000000000000000000000");
|
|
575
|
+
return [4 /*yield*/, suiGrpcClient.simulateTransaction({
|
|
576
|
+
transaction: _transaction,
|
|
577
|
+
checksEnabled: false,
|
|
578
|
+
include: { commandResults: true },
|
|
591
579
|
})];
|
|
592
580
|
case 2:
|
|
593
|
-
|
|
594
|
-
console.log("[WalletContext] dryRunTransaction -
|
|
595
|
-
if (
|
|
596
|
-
throw new Error(
|
|
597
|
-
return [2 /*return*/,
|
|
581
|
+
simResult = _c.sent();
|
|
582
|
+
console.log("[WalletContext] dryRunTransaction - simResult:", simResult);
|
|
583
|
+
if (simResult.FailedTransaction)
|
|
584
|
+
throw new Error((_b = (_a = simResult.FailedTransaction.status.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "Simulation failed");
|
|
585
|
+
return [2 /*return*/, simResult];
|
|
598
586
|
case 3:
|
|
599
|
-
err_2 =
|
|
600
|
-
// _transaction.getData().inputs.filter(input=>!!input.Object).map(input=>input.)
|
|
587
|
+
err_2 = _c.sent();
|
|
601
588
|
console.error(err_2);
|
|
602
589
|
throw err_2;
|
|
603
590
|
case 4: return [2 /*return*/];
|
|
604
591
|
}
|
|
605
592
|
});
|
|
606
593
|
});
|
|
607
|
-
}, [impersonatedAddress, account === null || account === void 0 ? void 0 : account.address, gasBudget,
|
|
594
|
+
}, [impersonatedAddress, account === null || account === void 0 ? void 0 : account.address, gasBudget, suiGrpcClient]);
|
|
608
595
|
var signExecuteAndWaitForTransaction = useCallback(function (transaction, onSetGasBudget, onSign, onExecute) { return __awaiter(_this, void 0, void 0, function () {
|
|
609
|
-
var _address, signedTransaction, txBytes, res,
|
|
610
|
-
var _a, _b;
|
|
611
|
-
return __generator(this, function (
|
|
612
|
-
switch (
|
|
596
|
+
var _address, signedTransaction, txBytes, res, execResult, execTx, waitResult, tx, err_3;
|
|
597
|
+
var _a, _b, _c, _d;
|
|
598
|
+
return __generator(this, function (_e) {
|
|
599
|
+
switch (_e.label) {
|
|
613
600
|
case 0:
|
|
614
601
|
_address = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
615
602
|
if (_address) {
|
|
@@ -618,9 +605,9 @@ function Inner(_a) {
|
|
|
618
605
|
}
|
|
619
606
|
catch (err) { }
|
|
620
607
|
}
|
|
621
|
-
|
|
608
|
+
_e.label = 1;
|
|
622
609
|
case 1:
|
|
623
|
-
|
|
610
|
+
_e.trys.push([1, 9, , 10]);
|
|
624
611
|
// Gas budget
|
|
625
612
|
if (gasBudget !== "")
|
|
626
613
|
transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
@@ -632,9 +619,9 @@ function Inner(_a) {
|
|
|
632
619
|
signedTransaction = void 0;
|
|
633
620
|
if (!(sessionAddress && universalConnector)) return [3 /*break*/, 4];
|
|
634
621
|
transaction.setSender(sessionAddress);
|
|
635
|
-
return [4 /*yield*/, transaction.build({ client:
|
|
622
|
+
return [4 /*yield*/, transaction.build({ client: suiGrpcClient })];
|
|
636
623
|
case 2:
|
|
637
|
-
txBytes =
|
|
624
|
+
txBytes = _e.sent();
|
|
638
625
|
return [4 /*yield*/, universalConnector.request({
|
|
639
626
|
method: "sui_signTransaction",
|
|
640
627
|
params: {
|
|
@@ -643,63 +630,68 @@ function Inner(_a) {
|
|
|
643
630
|
},
|
|
644
631
|
}, "sui:mainnet")];
|
|
645
632
|
case 3:
|
|
646
|
-
res =
|
|
633
|
+
res = _e.sent();
|
|
647
634
|
signedTransaction = {
|
|
648
635
|
bytes: res.transactionBytes,
|
|
649
636
|
signature: res.signature,
|
|
650
637
|
};
|
|
651
638
|
return [3 /*break*/, 6];
|
|
652
|
-
case 4: return [4 /*yield*/, signTransaction({
|
|
639
|
+
case 4: return [4 /*yield*/, dAppKit.signTransaction({
|
|
653
640
|
transaction: transaction,
|
|
654
|
-
chain: "sui:mainnet",
|
|
655
641
|
})];
|
|
656
642
|
case 5:
|
|
657
643
|
// Sign
|
|
658
|
-
signedTransaction =
|
|
659
|
-
|
|
644
|
+
signedTransaction = _e.sent();
|
|
645
|
+
_e.label = 6;
|
|
660
646
|
case 6:
|
|
647
|
+
if (!signedTransaction)
|
|
648
|
+
throw new Error("Failed to sign transaction");
|
|
661
649
|
onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction);
|
|
662
|
-
return [4 /*yield*/,
|
|
663
|
-
|
|
664
|
-
|
|
650
|
+
return [4 /*yield*/, suiGrpcClient.executeTransaction({
|
|
651
|
+
transaction: fromBase64(signedTransaction.bytes),
|
|
652
|
+
signatures: [signedTransaction.signature],
|
|
665
653
|
})];
|
|
666
654
|
case 7:
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
655
|
+
execResult = _e.sent();
|
|
656
|
+
execTx = (_a = execResult.Transaction) !== null && _a !== void 0 ? _a : execResult.FailedTransaction;
|
|
657
|
+
if (!execTx)
|
|
658
|
+
throw new Error("Transaction not found");
|
|
659
|
+
onExecute === null || onExecute === void 0 ? void 0 : onExecute(execTx);
|
|
660
|
+
return [4 /*yield*/, suiGrpcClient.waitForTransaction({
|
|
661
|
+
digest: execTx.digest,
|
|
662
|
+
include: {
|
|
663
|
+
effects: true,
|
|
664
|
+
events: true,
|
|
665
|
+
balanceChanges: true,
|
|
676
666
|
},
|
|
677
667
|
})];
|
|
678
668
|
case 8:
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
throw new Error(
|
|
683
|
-
|
|
669
|
+
waitResult = _e.sent();
|
|
670
|
+
tx = (_b = waitResult.Transaction) !== null && _b !== void 0 ? _b : waitResult.FailedTransaction;
|
|
671
|
+
if (!tx)
|
|
672
|
+
throw new Error("Transaction not found");
|
|
673
|
+
if (!tx.status.success)
|
|
674
|
+
throw new Error((_d = (_c = tx.status.error) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : "Transaction failed");
|
|
675
|
+
return [2 /*return*/, tx];
|
|
684
676
|
case 9:
|
|
685
|
-
err_3 =
|
|
677
|
+
err_3 = _e.sent();
|
|
686
678
|
console.error(err_3);
|
|
687
679
|
throw err_3;
|
|
688
680
|
case 10: return [2 /*return*/];
|
|
689
681
|
}
|
|
690
682
|
});
|
|
691
683
|
}); }, [
|
|
692
|
-
universalConnector,
|
|
693
|
-
sessionAddress,
|
|
694
|
-
gasBudget,
|
|
695
684
|
impersonatedAddress,
|
|
696
685
|
account === null || account === void 0 ? void 0 : account.address,
|
|
697
686
|
dryRunTransaction,
|
|
698
|
-
|
|
699
|
-
|
|
687
|
+
gasBudget,
|
|
688
|
+
sessionAddress,
|
|
689
|
+
universalConnector,
|
|
690
|
+
suiGrpcClient,
|
|
691
|
+
dAppKit,
|
|
700
692
|
]);
|
|
701
693
|
// Using Ledger
|
|
702
|
-
var
|
|
694
|
+
var _m = useLocalStorage("isUsingLedger-".concat(impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address), false), isUsingLedger = _m[0], setIsUsingLedger = _m[1];
|
|
703
695
|
// Context
|
|
704
696
|
var contextValue = useMemo(function () {
|
|
705
697
|
return {
|
|
@@ -743,15 +735,17 @@ function Inner(_a) {
|
|
|
743
735
|
export function WalletContextProvider(_a) {
|
|
744
736
|
var appName = _a.appName, children = _a.children;
|
|
745
737
|
var rpc = useSettingsContext().rpc;
|
|
746
|
-
var
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
738
|
+
var dAppKitInstance = useMemo(function () {
|
|
739
|
+
return createDAppKit({
|
|
740
|
+
networks: ["mainnet"],
|
|
741
|
+
createClient: function (network) {
|
|
742
|
+
return new SuiGrpcClient({ network: network, baseUrl: rpc.url });
|
|
743
|
+
},
|
|
744
|
+
autoConnect: true,
|
|
745
|
+
slushWalletConfig: { appName: appName },
|
|
746
|
+
});
|
|
747
|
+
}, [rpc.url, appName]);
|
|
748
|
+
return (<DAppKitProvider dAppKit={dAppKitInstance}>
|
|
749
|
+
<Inner appName={appName}>{children}</Inner>
|
|
750
|
+
</DAppKitProvider>);
|
|
757
751
|
}
|
|
@@ -53,25 +53,26 @@ import { useWalletContext } from "../contexts/WalletContext";
|
|
|
53
53
|
import { showErrorToast } from "../lib/toasts";
|
|
54
54
|
export default function useFetchBalances() {
|
|
55
55
|
var _this = this;
|
|
56
|
-
var
|
|
56
|
+
var suiGrpcClient = useSettingsContext().suiGrpcClient;
|
|
57
57
|
var address = useWalletContext().address;
|
|
58
58
|
var dataFetcher = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
59
|
-
var balancesMap, rawBalances, _i, rawBalances_1, rawBalance, totalBalance;
|
|
59
|
+
var balancesMap, balances, rawBalances, _i, rawBalances_1, rawBalance, totalBalance;
|
|
60
60
|
return __generator(this, function (_a) {
|
|
61
61
|
switch (_a.label) {
|
|
62
62
|
case 0:
|
|
63
63
|
balancesMap = {};
|
|
64
64
|
if (!address) return [3 /*break*/, 2];
|
|
65
|
-
return [4 /*yield*/,
|
|
65
|
+
return [4 /*yield*/, suiGrpcClient.listBalances({
|
|
66
66
|
owner: address,
|
|
67
67
|
})];
|
|
68
68
|
case 1:
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
balances = (_a.sent()).balances;
|
|
70
|
+
rawBalances = balances
|
|
71
|
+
.map(function (b) { return (__assign(__assign({}, b), { coinType: normalizeStructTag(b.coinType) })); })
|
|
71
72
|
.sort(function (a, b) { return (a.coinType < b.coinType ? -1 : 1); });
|
|
72
73
|
for (_i = 0, rawBalances_1 = rawBalances; _i < rawBalances_1.length; _i++) {
|
|
73
74
|
rawBalance = rawBalances_1[_i];
|
|
74
|
-
totalBalance = new BigNumber(rawBalance.
|
|
75
|
+
totalBalance = new BigNumber(rawBalance.balance);
|
|
75
76
|
if (totalBalance.gt(0))
|
|
76
77
|
balancesMap[rawBalance.coinType] = totalBalance;
|
|
77
78
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const useCoinMetadataMap: (coinTypes: string[]) => Record<string, CoinMetadata> | undefined;
|
|
1
|
+
import { SuiClientTypes } from "@mysten/sui/client";
|
|
2
|
+
declare const useCoinMetadataMap: (coinTypes: string[]) => Record<string, SuiClientTypes.CoinMetadata> | undefined;
|
|
3
3
|
export default useCoinMetadataMap;
|
|
@@ -39,7 +39,7 @@ import { getLedgerHash } from "@suilend/sui-fe";
|
|
|
39
39
|
import { useSettingsContext } from "../contexts/SettingsContext";
|
|
40
40
|
import { useWalletContext } from "../contexts/WalletContext";
|
|
41
41
|
var useLedgerHashDialog = function () {
|
|
42
|
-
var
|
|
42
|
+
var suiGrpcClient = useSettingsContext().suiGrpcClient;
|
|
43
43
|
var _a = useWalletContext(), address = _a.address, isUsingLedger = _a.isUsingLedger;
|
|
44
44
|
var _b = useState(undefined), ledgerHash = _b[0], setLedgerHash = _b[1];
|
|
45
45
|
var _c = useState(false), isOpen = _c[0], setIsOpen = _c[1];
|
|
@@ -52,7 +52,7 @@ var useLedgerHashDialog = function () {
|
|
|
52
52
|
return [2 /*return*/];
|
|
53
53
|
if (!isUsingLedger)
|
|
54
54
|
return [2 /*return*/];
|
|
55
|
-
return [4 /*yield*/, getLedgerHash(address, transaction,
|
|
55
|
+
return [4 /*yield*/, getLedgerHash(address, transaction, suiGrpcClient)];
|
|
56
56
|
case 1:
|
|
57
57
|
transactionLedgerHash = _a.sent();
|
|
58
58
|
setLedgerHash(transactionLedgerHash);
|
|
@@ -60,7 +60,7 @@ var useLedgerHashDialog = function () {
|
|
|
60
60
|
return [2 /*return*/];
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
|
-
}); }, [address, isUsingLedger,
|
|
63
|
+
}); }, [address, isUsingLedger, suiGrpcClient]);
|
|
64
64
|
var close = useCallback(function () {
|
|
65
65
|
setIsOpen(false);
|
|
66
66
|
}, []);
|