@suilend/sui-fe-next 2.0.30 → 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 +13 -6
- package/contexts/WalletContext.jsx +126 -139
- 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,14 +1,15 @@
|
|
|
1
1
|
import { Dispatch, PropsWithChildren, SetStateAction } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { UiWallet } from "@mysten/dapp-kit-core";
|
|
3
|
+
import { SuiClientTypes } from "@mysten/sui/client";
|
|
4
|
+
import { SignatureWithBytes } from "@mysten/sui/cryptography";
|
|
4
5
|
import { Transaction } from "@mysten/sui/transactions";
|
|
5
|
-
import {
|
|
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"
|
|
9
10
|
}
|
|
10
11
|
export type WalletAccount = Omit<WalletStandardWalletAccount, "publicKey"> & {
|
|
11
|
-
publicKey?:
|
|
12
|
+
publicKey?: ReadonlyUint8Array;
|
|
12
13
|
};
|
|
13
14
|
type WalletPlatform = "iOS" | "android" | "extension";
|
|
14
15
|
export type Wallet = {
|
|
@@ -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,12 +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 { createDAppKit,
|
|
60
|
+
import { createDAppKit, } from "@mysten/dapp-kit-core";
|
|
61
61
|
import { DAppKitProvider, useCurrentAccount, useCurrentWallet, useDAppKit, useWalletConnection, useWallets, } from "@mysten/dapp-kit-react";
|
|
62
|
-
import {
|
|
62
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
63
63
|
import { Transaction } from "@mysten/sui/transactions";
|
|
64
|
-
import { SUI_DECIMALS, toBase64 } from "@mysten/sui/utils";
|
|
65
|
-
import { getWallets } from "@wallet-standard/app";
|
|
64
|
+
import { SUI_DECIMALS, fromBase64, toBase64 } from "@mysten/sui/utils";
|
|
66
65
|
import BigNumber from "bignumber.js";
|
|
67
66
|
import { useLDClient } from "launchdarkly-react-client-sdk";
|
|
68
67
|
import { useLocalStorage } from "usehooks-ts";
|
|
@@ -218,7 +217,7 @@ function Inner(_a) {
|
|
|
218
217
|
var queryParams = (_b = {},
|
|
219
218
|
_b[WalletContextQueryParams.WALLET] = router.query[WalletContextQueryParams.WALLET],
|
|
220
219
|
_b);
|
|
221
|
-
var _h = useSettingsContext(), rpc = _h.rpc,
|
|
220
|
+
var _h = useSettingsContext(), rpc = _h.rpc, suiGrpcClient = _h.suiGrpcClient;
|
|
222
221
|
// Only used for wallet connect
|
|
223
222
|
var _j = useState(), universalConnector = _j[0], setUniversalConnector = _j[1];
|
|
224
223
|
var _k = useState(), session = _k[0], setSession = _k[1];
|
|
@@ -243,7 +242,6 @@ function Inner(_a) {
|
|
|
243
242
|
// Impersonated address
|
|
244
243
|
var impersonatedAddress = queryParams[WalletContextQueryParams.WALLET];
|
|
245
244
|
// Wallets
|
|
246
|
-
var dAppKit = useDAppKit();
|
|
247
245
|
var wallets__installed = useWallets();
|
|
248
246
|
var getInstalledWallet = useCallback(function (name) { return wallets__installed.find(function (w) { return w.name === name; }); }, [wallets__installed]);
|
|
249
247
|
var wallets__extension_default = useMemo(function () {
|
|
@@ -354,6 +352,7 @@ function Inner(_a) {
|
|
|
354
352
|
]);
|
|
355
353
|
// Wallet
|
|
356
354
|
var _l = useState(false), isConnectWalletDropdownOpen = _l[0], setIsConnectWalletDropdownOpen = _l[1];
|
|
355
|
+
var dAppKit = useDAppKit();
|
|
357
356
|
var rawWallet = useCurrentWallet();
|
|
358
357
|
var wallet = useMemo(function () {
|
|
359
358
|
if (sessionAddress) {
|
|
@@ -363,9 +362,6 @@ function Inner(_a) {
|
|
|
363
362
|
? wallets.find(function (w) { return w.name === rawWallet.name; })
|
|
364
363
|
: undefined;
|
|
365
364
|
}, [rawWallet, wallets, sessionAddress]);
|
|
366
|
-
var connectWallet = dAppKit.connectWallet;
|
|
367
|
-
var disconnectWallet = dAppKit.disconnectWallet;
|
|
368
|
-
var signPersonalMessageRaw = dAppKit.signPersonalMessage;
|
|
369
365
|
var walletConnectSignPersonalMessage = useCallback(function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
370
366
|
var res;
|
|
371
367
|
return __generator(this, function (_a) {
|
|
@@ -390,24 +386,38 @@ function Inner(_a) {
|
|
|
390
386
|
try {
|
|
391
387
|
if (_wallet === null || _wallet === void 0 ? void 0 : _wallet.walletConnect) {
|
|
392
388
|
universalConnector.connect().then(function (res) {
|
|
393
|
-
|
|
394
|
-
|
|
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
|
+
});
|
|
395
398
|
});
|
|
396
399
|
return;
|
|
397
400
|
}
|
|
398
401
|
if (!_wallet.raw)
|
|
399
402
|
throw new Error("Missing wallet");
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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);
|
|
414
|
+
});
|
|
405
415
|
}
|
|
406
416
|
catch (err) {
|
|
407
417
|
showErrorToast("Failed to connect ".concat(_wallet.name), err);
|
|
408
418
|
console.error(err);
|
|
409
419
|
}
|
|
410
|
-
}, [
|
|
420
|
+
}, [universalConnector, dAppKit]);
|
|
411
421
|
var disconnectWalletWrapper = useCallback(function () {
|
|
412
422
|
try {
|
|
413
423
|
if (sessionAddress) {
|
|
@@ -415,20 +425,27 @@ function Inner(_a) {
|
|
|
415
425
|
setSession(null);
|
|
416
426
|
}
|
|
417
427
|
else {
|
|
418
|
-
|
|
419
|
-
|
|
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);
|
|
436
|
+
});
|
|
420
437
|
}
|
|
421
438
|
}
|
|
422
439
|
catch (err) {
|
|
423
440
|
showErrorToast("Failed to disconnect wallet", err);
|
|
424
441
|
console.error(err);
|
|
425
442
|
}
|
|
426
|
-
}, [sessionAddress, universalConnector,
|
|
443
|
+
}, [sessionAddress, universalConnector, dAppKit]);
|
|
427
444
|
// Accounts
|
|
428
|
-
var
|
|
429
|
-
var accountsRes = useMemo(function () { var _a, _b; return (_b = (_a =
|
|
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]);
|
|
430
447
|
var accountRes = (_g = useCurrentAccount()) !== null && _g !== void 0 ? _g : undefined;
|
|
431
|
-
var
|
|
448
|
+
var account = useMemo(function () {
|
|
432
449
|
return sessionAddress
|
|
433
450
|
? {
|
|
434
451
|
address: sessionAddress,
|
|
@@ -436,33 +453,32 @@ function Inner(_a) {
|
|
|
436
453
|
chains: ["sui:mainnet"],
|
|
437
454
|
features: [],
|
|
438
455
|
}
|
|
439
|
-
:
|
|
440
|
-
}, [sessionAddress]);
|
|
441
|
-
var
|
|
442
|
-
|
|
456
|
+
: accountRes;
|
|
457
|
+
}, [sessionAddress, accountRes]);
|
|
458
|
+
var accounts = useMemo(function () {
|
|
459
|
+
return sessionAddress
|
|
460
|
+
? [
|
|
461
|
+
{
|
|
462
|
+
address: sessionAddress,
|
|
463
|
+
publicKey: new Uint8Array(),
|
|
464
|
+
chains: ["sui:mainnet"],
|
|
465
|
+
features: [],
|
|
466
|
+
},
|
|
467
|
+
]
|
|
468
|
+
: accountsRes;
|
|
469
|
+
}, [sessionAddress, accountsRes]);
|
|
443
470
|
var signPersonalMessage = useMemo(function () {
|
|
444
471
|
return sessionAddress
|
|
445
472
|
? walletConnectSignPersonalMessage
|
|
446
|
-
: function (message) { return
|
|
447
|
-
}, [sessionAddress, walletConnectSignPersonalMessage,
|
|
448
|
-
var DAPP_KIT_STORAGE_KEY = "mysten-dapp-kit:selected-wallet-and-address";
|
|
473
|
+
: function (message) { return dAppKit.signPersonalMessage({ message: message }); };
|
|
474
|
+
}, [sessionAddress, walletConnectSignPersonalMessage, dAppKit]);
|
|
449
475
|
var switchAccountWrapper = useCallback(function (_account, addressNameServiceName) {
|
|
450
|
-
var _a, _b
|
|
476
|
+
var _a, _b;
|
|
451
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);
|
|
452
478
|
try {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
dAppKit.switchAccount({ account: matchingAccount });
|
|
457
|
-
// Persist to dapp-kit's own storage key so autoconnect restores
|
|
458
|
-
// the correct account on page reload.
|
|
459
|
-
try {
|
|
460
|
-
var walletId = getWalletUniqueIdentifier(matchingAccount);
|
|
461
|
-
var intents = (_d = walletConnection.supportedIntents) !== null && _d !== void 0 ? _d : [];
|
|
462
|
-
var storageValue = "".concat(walletId.replace(":", "_"), ":").concat(matchingAccount.address, ":").concat(intents.join(","), ":");
|
|
463
|
-
localStorage.setItem(DAPP_KIT_STORAGE_KEY, storageValue);
|
|
464
|
-
}
|
|
465
|
-
catch (_e) { }
|
|
479
|
+
dAppKit.switchAccount({
|
|
480
|
+
account: _account,
|
|
481
|
+
});
|
|
466
482
|
showInfoToast("Switched to ".concat(accountLabel), {
|
|
467
483
|
description: (_account === null || _account === void 0 ? void 0 : _account.label)
|
|
468
484
|
? (addressNameServiceName !== null && addressNameServiceName !== void 0 ? addressNameServiceName : formatAddress(_account.address))
|
|
@@ -473,7 +489,7 @@ function Inner(_a) {
|
|
|
473
489
|
showErrorToast("Failed to switch to ".concat(accountLabel), err);
|
|
474
490
|
console.error(err);
|
|
475
491
|
}
|
|
476
|
-
}, [dAppKit
|
|
492
|
+
}, [dAppKit]);
|
|
477
493
|
// LaunchDarkly
|
|
478
494
|
var ldClient = useLDClient();
|
|
479
495
|
var ldKeyRef = useRef(undefined);
|
|
@@ -538,43 +554,46 @@ function Inner(_a) {
|
|
|
538
554
|
args_1[_i - 1] = arguments[_i];
|
|
539
555
|
}
|
|
540
556
|
return __awaiter(_this, __spreadArray([transaction_1], args_1, true), void 0, function (transaction, setGasBudget) {
|
|
541
|
-
var _address, _transaction,
|
|
557
|
+
var _address, _transaction, simResult, err_2;
|
|
558
|
+
var _a, _b;
|
|
542
559
|
if (setGasBudget === void 0) { setGasBudget = true; }
|
|
543
|
-
return __generator(this, function (
|
|
544
|
-
switch (
|
|
560
|
+
return __generator(this, function (_c) {
|
|
561
|
+
switch (_c.label) {
|
|
545
562
|
case 0:
|
|
546
563
|
_address = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
547
564
|
_transaction = Transaction.from(transaction);
|
|
548
|
-
|
|
565
|
+
_c.label = 1;
|
|
549
566
|
case 1:
|
|
550
|
-
|
|
567
|
+
_c.trys.push([1, 3, , 4]);
|
|
551
568
|
// Gas budget
|
|
552
569
|
if (setGasBudget && gasBudget !== "")
|
|
553
570
|
_transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
554
571
|
.times(Math.pow(10, SUI_DECIMALS))
|
|
555
572
|
.integerValue(BigNumber.ROUND_DOWN));
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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 },
|
|
559
579
|
})];
|
|
560
580
|
case 2:
|
|
561
|
-
|
|
562
|
-
console.log("[WalletContext] dryRunTransaction -
|
|
563
|
-
if (
|
|
564
|
-
throw new Error(
|
|
565
|
-
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];
|
|
566
586
|
case 3:
|
|
567
|
-
err_2 =
|
|
568
|
-
// _transaction.getData().inputs.filter(input=>!!input.Object).map(input=>input.)
|
|
587
|
+
err_2 = _c.sent();
|
|
569
588
|
console.error(err_2);
|
|
570
589
|
throw err_2;
|
|
571
590
|
case 4: return [2 /*return*/];
|
|
572
591
|
}
|
|
573
592
|
});
|
|
574
593
|
});
|
|
575
|
-
}, [impersonatedAddress, account === null || account === void 0 ? void 0 : account.address, gasBudget,
|
|
594
|
+
}, [impersonatedAddress, account === null || account === void 0 ? void 0 : account.address, gasBudget, suiGrpcClient]);
|
|
576
595
|
var signExecuteAndWaitForTransaction = useCallback(function (transaction, onSetGasBudget, onSign, onExecute) { return __awaiter(_this, void 0, void 0, function () {
|
|
577
|
-
var _address, txBytes, res,
|
|
596
|
+
var _address, signedTransaction, txBytes, res, execResult, execTx, waitResult, tx, err_3;
|
|
578
597
|
var _a, _b, _c, _d;
|
|
579
598
|
return __generator(this, function (_e) {
|
|
580
599
|
switch (_e.label) {
|
|
@@ -588,7 +607,7 @@ function Inner(_a) {
|
|
|
588
607
|
}
|
|
589
608
|
_e.label = 1;
|
|
590
609
|
case 1:
|
|
591
|
-
_e.trys.push([1,
|
|
610
|
+
_e.trys.push([1, 9, , 10]);
|
|
592
611
|
// Gas budget
|
|
593
612
|
if (gasBudget !== "")
|
|
594
613
|
transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
@@ -597,9 +616,10 @@ function Inner(_a) {
|
|
|
597
616
|
onSetGasBudget === null || onSetGasBudget === void 0 ? void 0 : onSetGasBudget(transaction);
|
|
598
617
|
// Log
|
|
599
618
|
console.log("[WalletContext] signExecuteAndWaitForTransaction - transaction.getData():", transaction.getData());
|
|
600
|
-
|
|
619
|
+
signedTransaction = void 0;
|
|
620
|
+
if (!(sessionAddress && universalConnector)) return [3 /*break*/, 4];
|
|
601
621
|
transaction.setSender(sessionAddress);
|
|
602
|
-
return [4 /*yield*/, transaction.build({ client:
|
|
622
|
+
return [4 /*yield*/, transaction.build({ client: suiGrpcClient })];
|
|
603
623
|
case 2:
|
|
604
624
|
txBytes = _e.sent();
|
|
605
625
|
return [4 /*yield*/, universalConnector.request({
|
|
@@ -611,95 +631,63 @@ function Inner(_a) {
|
|
|
611
631
|
}, "sui:mainnet")];
|
|
612
632
|
case 3:
|
|
613
633
|
res = _e.sent();
|
|
614
|
-
|
|
634
|
+
signedTransaction = {
|
|
615
635
|
bytes: res.transactionBytes,
|
|
616
636
|
signature: res.signature,
|
|
617
637
|
};
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
transactionBlock: signedTransaction_1.bytes,
|
|
621
|
-
signature: signedTransaction_1.signature,
|
|
622
|
-
})];
|
|
623
|
-
case 4:
|
|
624
|
-
res1_1 = _e.sent();
|
|
625
|
-
onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1_1);
|
|
626
|
-
return [4 /*yield*/, suiClient.waitForTransaction({
|
|
627
|
-
digest: res1_1.digest,
|
|
628
|
-
options: {
|
|
629
|
-
showBalanceChanges: true,
|
|
630
|
-
showEffects: true,
|
|
631
|
-
showEvents: true,
|
|
632
|
-
showObjectChanges: true,
|
|
633
|
-
},
|
|
634
|
-
})];
|
|
635
|
-
case 5:
|
|
636
|
-
res2_1 = _e.sent();
|
|
637
|
-
if (((_a = res2_1.effects) === null || _a === void 0 ? void 0 : _a.status) !== undefined &&
|
|
638
|
-
res2_1.effects.status.status === "failure")
|
|
639
|
-
throw new Error((_b = res2_1.effects.status.error) !== null && _b !== void 0 ? _b : "Transaction failed");
|
|
640
|
-
return [2 /*return*/, res2_1];
|
|
641
|
-
case 6:
|
|
642
|
-
if (!isInMsafeApp()) return [3 /*break*/, 9];
|
|
643
|
-
msafeWallet = getWallets()
|
|
644
|
-
.get()
|
|
645
|
-
.find(function (w) { return w.name === WalletName.MSAFE_WALLET; });
|
|
646
|
-
msafeFeature = msafeWallet === null || msafeWallet === void 0 ? void 0 : msafeWallet.features["sui:signAndExecuteTransactionBlock"];
|
|
647
|
-
if (!(msafeFeature && account)) return [3 /*break*/, 8];
|
|
648
|
-
msafeAccount = msafeWallet.accounts.find(function (a) { return a.address === account.address; });
|
|
649
|
-
if (!msafeAccount)
|
|
650
|
-
throw new Error("MSafe account not found");
|
|
651
|
-
return [4 /*yield*/, msafeFeature.signAndExecuteTransactionBlock({
|
|
652
|
-
transactionBlock: transaction,
|
|
653
|
-
account: msafeAccount,
|
|
654
|
-
chain: "sui:mainnet",
|
|
655
|
-
})];
|
|
656
|
-
case 7:
|
|
657
|
-
_e.sent();
|
|
658
|
-
throw new Error("Unreachable");
|
|
659
|
-
case 8: throw new Error("MSafe wallet not found. Please reload the page inside MSafe.");
|
|
660
|
-
case 9: return [4 /*yield*/, dAppKit.signTransaction({
|
|
638
|
+
return [3 /*break*/, 6];
|
|
639
|
+
case 4: return [4 /*yield*/, dAppKit.signTransaction({
|
|
661
640
|
transaction: transaction,
|
|
662
641
|
})];
|
|
663
|
-
case
|
|
642
|
+
case 5:
|
|
643
|
+
// Sign
|
|
664
644
|
signedTransaction = _e.sent();
|
|
645
|
+
_e.label = 6;
|
|
646
|
+
case 6:
|
|
647
|
+
if (!signedTransaction)
|
|
648
|
+
throw new Error("Failed to sign transaction");
|
|
665
649
|
onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction);
|
|
666
|
-
return [4 /*yield*/,
|
|
667
|
-
|
|
668
|
-
|
|
650
|
+
return [4 /*yield*/, suiGrpcClient.executeTransaction({
|
|
651
|
+
transaction: fromBase64(signedTransaction.bytes),
|
|
652
|
+
signatures: [signedTransaction.signature],
|
|
669
653
|
})];
|
|
670
|
-
case
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
654
|
+
case 7:
|
|
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,
|
|
680
666
|
},
|
|
681
667
|
})];
|
|
682
|
-
case
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
throw new Error(
|
|
687
|
-
|
|
688
|
-
|
|
668
|
+
case 8:
|
|
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];
|
|
676
|
+
case 9:
|
|
689
677
|
err_3 = _e.sent();
|
|
690
678
|
console.error(err_3);
|
|
691
679
|
throw err_3;
|
|
692
|
-
case
|
|
680
|
+
case 10: return [2 /*return*/];
|
|
693
681
|
}
|
|
694
682
|
});
|
|
695
683
|
}); }, [
|
|
696
|
-
universalConnector,
|
|
697
|
-
sessionAddress,
|
|
698
|
-
gasBudget,
|
|
699
684
|
impersonatedAddress,
|
|
700
|
-
account,
|
|
685
|
+
account === null || account === void 0 ? void 0 : account.address,
|
|
701
686
|
dryRunTransaction,
|
|
702
|
-
|
|
687
|
+
gasBudget,
|
|
688
|
+
sessionAddress,
|
|
689
|
+
universalConnector,
|
|
690
|
+
suiGrpcClient,
|
|
703
691
|
dAppKit,
|
|
704
692
|
]);
|
|
705
693
|
// Using Ledger
|
|
@@ -750,10 +738,9 @@ export function WalletContextProvider(_a) {
|
|
|
750
738
|
var dAppKitInstance = useMemo(function () {
|
|
751
739
|
return createDAppKit({
|
|
752
740
|
networks: ["mainnet"],
|
|
753
|
-
createClient: function () {
|
|
754
|
-
return new
|
|
741
|
+
createClient: function (network) {
|
|
742
|
+
return new SuiGrpcClient({ network: network, baseUrl: rpc.url });
|
|
755
743
|
},
|
|
756
|
-
defaultNetwork: "mainnet",
|
|
757
744
|
autoConnect: true,
|
|
758
745
|
slushWalletConfig: { appName: appName },
|
|
759
746
|
});
|
|
@@ -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
|
}, []);
|
|
@@ -39,7 +39,7 @@ import { isEqual } from "lodash";
|
|
|
39
39
|
import { useSettingsContext } from "../contexts/SettingsContext";
|
|
40
40
|
import { useWalletContext } from "../contexts/WalletContext";
|
|
41
41
|
var useRefreshOnBalancesChange = function (refresh) {
|
|
42
|
-
var
|
|
42
|
+
var suiGrpcClient = useSettingsContext().suiGrpcClient;
|
|
43
43
|
var address = useWalletContext().address;
|
|
44
44
|
var previousBalancesRef = useRef(undefined);
|
|
45
45
|
useEffect(function () {
|
|
@@ -52,11 +52,11 @@ var useRefreshOnBalancesChange = function (refresh) {
|
|
|
52
52
|
switch (_a.label) {
|
|
53
53
|
case 0:
|
|
54
54
|
_a.trys.push([0, 4, , 5]);
|
|
55
|
-
return [4 /*yield*/,
|
|
55
|
+
return [4 /*yield*/, suiGrpcClient.listBalances({
|
|
56
56
|
owner: address,
|
|
57
57
|
})];
|
|
58
58
|
case 1:
|
|
59
|
-
balances = _a.sent();
|
|
59
|
+
balances = (_a.sent()).balances;
|
|
60
60
|
if (!(previousBalancesRef.current !== undefined &&
|
|
61
61
|
!isEqual(balances, previousBalancesRef.current))) return [3 /*break*/, 3];
|
|
62
62
|
return [4 /*yield*/, refresh()];
|
|
@@ -78,6 +78,6 @@ var useRefreshOnBalancesChange = function (refresh) {
|
|
|
78
78
|
if (interval !== undefined)
|
|
79
79
|
clearInterval(interval);
|
|
80
80
|
};
|
|
81
|
-
}, [address,
|
|
81
|
+
}, [address, suiGrpcClient, refresh]);
|
|
82
82
|
};
|
|
83
83
|
export default useRefreshOnBalancesChange;
|