@suilend/sui-fe-next 0.4.6 → 2.0.1
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 +1 -3
- package/contexts/SettingsContext.jsx +6 -16
- package/contexts/WalletContext.d.ts +10 -15
- package/contexts/WalletContext.jsx +100 -136
- package/fetchers/useFetchBalances.js +4 -5
- package/hooks/useCoinMetadataMap.d.ts +2 -2
- package/hooks/useRefreshOnBalancesChange.js +5 -5
- package/index.d.ts +4 -4
- package/index.js +4 -4
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
|
-
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
3
2
|
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
4
3
|
import { Explorer, ExplorerId, Rpc, RpcId } from "@suilend/sui-fe";
|
|
5
4
|
interface SettingsContext {
|
|
@@ -10,8 +9,7 @@ interface SettingsContext {
|
|
|
10
9
|
setExplorerId: (id: ExplorerId) => void;
|
|
11
10
|
gasBudget: string;
|
|
12
11
|
setGasBudget: (value: string) => void;
|
|
13
|
-
suiClient:
|
|
14
|
-
suiJsonRpcClient: SuiJsonRpcClient;
|
|
12
|
+
suiClient: SuiJsonRpcClient;
|
|
15
13
|
}
|
|
16
14
|
declare const SettingsContext: import("react").Context<SettingsContext>;
|
|
17
15
|
export declare const useSettingsContext: () => SettingsContext;
|
|
@@ -10,8 +10,7 @@ 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 {
|
|
14
|
-
import { SuiJsonRpcClient } from "@mysten/sui/jsonRpc";
|
|
13
|
+
import { SuiJsonRpcClient, getJsonRpcFullnodeUrl } from "@mysten/sui/jsonRpc";
|
|
15
14
|
import { useLocalStorage } from "usehooks-ts";
|
|
16
15
|
import { EXPLORERS, RPCS, RpcId, } from "@suilend/sui-fe";
|
|
17
16
|
var defaultContextValue = {
|
|
@@ -30,8 +29,10 @@ var defaultContextValue = {
|
|
|
30
29
|
setGasBudget: function () {
|
|
31
30
|
throw Error("SettingsContextProvider not initialized");
|
|
32
31
|
},
|
|
33
|
-
suiClient:
|
|
34
|
-
|
|
32
|
+
suiClient: new SuiJsonRpcClient({
|
|
33
|
+
url: getJsonRpcFullnodeUrl("mainnet"),
|
|
34
|
+
network: "mainnet",
|
|
35
|
+
}),
|
|
35
36
|
};
|
|
36
37
|
var SettingsContext = createContext(defaultContextValue);
|
|
37
38
|
export var useSettingsContext = function () { return useContext(SettingsContext); };
|
|
@@ -54,16 +55,7 @@ export function SettingsContextProvider(_a) {
|
|
|
54
55
|
// Gas budget
|
|
55
56
|
var _e = useLocalStorage("gasBudget", defaultContextValue.gasBudget), gasBudget = _e[0], setGasBudget = _e[1];
|
|
56
57
|
// Sui client
|
|
57
|
-
var
|
|
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];
|
|
58
|
+
var suiClient = useMemo(function () { return new SuiJsonRpcClient({ url: rpc.url, network: "mainnet" }); }, [rpc.url]);
|
|
67
59
|
// Context
|
|
68
60
|
var contextValue = useMemo(function () { return ({
|
|
69
61
|
rpc: rpc,
|
|
@@ -74,7 +66,6 @@ export function SettingsContextProvider(_a) {
|
|
|
74
66
|
gasBudget: gasBudget,
|
|
75
67
|
setGasBudget: setGasBudget,
|
|
76
68
|
suiClient: suiClient,
|
|
77
|
-
suiJsonRpcClient: suiJsonRpcClient,
|
|
78
69
|
}); }, [
|
|
79
70
|
rpc,
|
|
80
71
|
setRpcId,
|
|
@@ -84,7 +75,6 @@ export function SettingsContextProvider(_a) {
|
|
|
84
75
|
gasBudget,
|
|
85
76
|
setGasBudget,
|
|
86
77
|
suiClient,
|
|
87
|
-
suiJsonRpcClient,
|
|
88
78
|
]);
|
|
89
79
|
return (<SettingsContext.Provider value={contextValue}>
|
|
90
80
|
{children}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { Dispatch, PropsWithChildren, SetStateAction } from "react";
|
|
2
|
-
import { UiWallet } from "@mysten/dapp-kit-core";
|
|
3
|
-
import {
|
|
4
|
-
import { SignatureWithBytes } from "@mysten/sui/cryptography";
|
|
2
|
+
import { type UiWallet } from "@mysten/dapp-kit-core";
|
|
3
|
+
import { DevInspectResults, SuiTransactionBlockResponse } from "@mysten/sui/jsonRpc";
|
|
5
4
|
import { Transaction } from "@mysten/sui/transactions";
|
|
6
|
-
import {
|
|
5
|
+
import { type SignedTransaction, type WalletIcon, type WalletAccount as WalletStandardWalletAccount } from "@mysten/wallet-standard";
|
|
7
6
|
export declare enum WalletType {
|
|
8
7
|
EXTENSION = "extension",
|
|
9
8
|
WEB = "web"
|
|
10
9
|
}
|
|
11
10
|
export type WalletAccount = Omit<WalletStandardWalletAccount, "publicKey"> & {
|
|
12
|
-
publicKey?:
|
|
11
|
+
publicKey?: WalletStandardWalletAccount["publicKey"];
|
|
13
12
|
};
|
|
14
13
|
type WalletPlatform = "iOS" | "android" | "extension";
|
|
15
14
|
export type Wallet = {
|
|
@@ -51,20 +50,16 @@ export interface WalletContext {
|
|
|
51
50
|
account?: WalletAccount;
|
|
52
51
|
switchAccount: (account: WalletAccount, addressNameServiceName?: string) => void;
|
|
53
52
|
address?: string;
|
|
54
|
-
dryRunTransaction: (transaction: Transaction, setGasBudget?: boolean) => Promise<
|
|
55
|
-
commandResults: true;
|
|
56
|
-
}>>;
|
|
53
|
+
dryRunTransaction: (transaction: Transaction, setGasBudget?: boolean) => Promise<DevInspectResults>;
|
|
57
54
|
signExecuteAndWaitForTransaction: (transaction: Transaction, options?: {
|
|
58
55
|
auction?: boolean;
|
|
59
|
-
}, onSetGasBudget?: (transaction: Transaction) => void, onSign?: (signedTransaction:
|
|
60
|
-
balanceChanges: true;
|
|
61
|
-
effects: true;
|
|
62
|
-
events: true;
|
|
63
|
-
objectTypes: true;
|
|
64
|
-
}>>;
|
|
56
|
+
}, onSetGasBudget?: (transaction: Transaction) => void, onSign?: (signedTransaction: SignedTransaction) => void, onExecute?: (res: SuiTransactionBlockResponse) => void) => Promise<SuiTransactionBlockResponse>;
|
|
65
57
|
isUsingLedger: boolean;
|
|
66
58
|
setIsUsingLedger: (isUsingLedger: boolean) => void;
|
|
67
|
-
signPersonalMessage: (message: Uint8Array) => Promise<
|
|
59
|
+
signPersonalMessage: (message: Uint8Array) => Promise<{
|
|
60
|
+
bytes: string;
|
|
61
|
+
signature: string;
|
|
62
|
+
}>;
|
|
68
63
|
}
|
|
69
64
|
export declare const useWalletContext: () => WalletContext;
|
|
70
65
|
interface WalletContextProviderProps extends PropsWithChildren {
|
|
@@ -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 { SuiJsonRpcClient, } from "@mysten/sui/jsonRpc";
|
|
62
63
|
import { Transaction } from "@mysten/sui/transactions";
|
|
63
64
|
import { SUI_DECIMALS, toBase64 } from "@mysten/sui/utils";
|
|
64
|
-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
65
65
|
import BigNumber from "bignumber.js";
|
|
66
66
|
import { useLDClient } from "launchdarkly-react-client-sdk";
|
|
67
67
|
import { executeAuction } from "shio-sdk";
|
|
@@ -218,7 +218,7 @@ function Inner(_a) {
|
|
|
218
218
|
var queryParams = (_b = {},
|
|
219
219
|
_b[WalletContextQueryParams.WALLET] = router.query[WalletContextQueryParams.WALLET],
|
|
220
220
|
_b);
|
|
221
|
-
var _j = useSettingsContext(),
|
|
221
|
+
var _j = useSettingsContext(), suiClient = _j.suiClient, rpc = _j.rpc;
|
|
222
222
|
// Only used for wallet connect
|
|
223
223
|
var _k = useState(), universalConnector = _k[0], setUniversalConnector = _k[1];
|
|
224
224
|
var _l = useState(), session = _l[0], setSession = _l[1];
|
|
@@ -243,6 +243,7 @@ function Inner(_a) {
|
|
|
243
243
|
// Impersonated address
|
|
244
244
|
var impersonatedAddress = queryParams[WalletContextQueryParams.WALLET];
|
|
245
245
|
// Wallets
|
|
246
|
+
var dAppKit = useDAppKit();
|
|
246
247
|
var wallets__installed = useWallets();
|
|
247
248
|
var getInstalledWallet = useCallback(function (name) { return wallets__installed.find(function (w) { return w.name === name; }); }, [wallets__installed]);
|
|
248
249
|
var wallets__extension_default = useMemo(function () {
|
|
@@ -353,7 +354,6 @@ function Inner(_a) {
|
|
|
353
354
|
]);
|
|
354
355
|
// Wallet
|
|
355
356
|
var _m = useState(false), isConnectWalletDropdownOpen = _m[0], setIsConnectWalletDropdownOpen = _m[1];
|
|
356
|
-
var dAppKit = useDAppKit();
|
|
357
357
|
var rawWallet = useCurrentWallet();
|
|
358
358
|
var wallet = useMemo(function () {
|
|
359
359
|
if (sessionAddress) {
|
|
@@ -363,6 +363,9 @@ function Inner(_a) {
|
|
|
363
363
|
? wallets.find(function (w) { return w.name === rawWallet.name; })
|
|
364
364
|
: undefined;
|
|
365
365
|
}, [rawWallet, wallets, sessionAddress]);
|
|
366
|
+
var connectWallet = dAppKit.connectWallet;
|
|
367
|
+
var disconnectWallet = dAppKit.disconnectWallet;
|
|
368
|
+
var signPersonalMessageRaw = dAppKit.signPersonalMessage;
|
|
366
369
|
var walletConnectSignPersonalMessage = useCallback(function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
367
370
|
var res;
|
|
368
371
|
return __generator(this, function (_a) {
|
|
@@ -393,7 +396,7 @@ function Inner(_a) {
|
|
|
393
396
|
return [4 /*yield*/, universalConnector.connect()];
|
|
394
397
|
case 1:
|
|
395
398
|
res = _a.sent();
|
|
396
|
-
return [4 /*yield*/,
|
|
399
|
+
return [4 /*yield*/, disconnectWallet()];
|
|
397
400
|
case 2:
|
|
398
401
|
_a.sent();
|
|
399
402
|
setSession(res.session);
|
|
@@ -401,7 +404,7 @@ function Inner(_a) {
|
|
|
401
404
|
case 3:
|
|
402
405
|
if (!_wallet.raw)
|
|
403
406
|
throw new Error("Missing wallet");
|
|
404
|
-
return [4 /*yield*/,
|
|
407
|
+
return [4 /*yield*/, connectWallet({ wallet: _wallet.raw })];
|
|
405
408
|
case 4:
|
|
406
409
|
_a.sent();
|
|
407
410
|
universalConnector.disconnect();
|
|
@@ -417,7 +420,7 @@ function Inner(_a) {
|
|
|
417
420
|
case 6: return [2 /*return*/];
|
|
418
421
|
}
|
|
419
422
|
});
|
|
420
|
-
}); }, [
|
|
423
|
+
}); }, [connectWallet, disconnectWallet, universalConnector]);
|
|
421
424
|
var disconnectWalletWrapper = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
422
425
|
var err_2;
|
|
423
426
|
return __generator(this, function (_a) {
|
|
@@ -428,7 +431,7 @@ function Inner(_a) {
|
|
|
428
431
|
universalConnector.disconnect();
|
|
429
432
|
setSession(null);
|
|
430
433
|
return [3 /*break*/, 3];
|
|
431
|
-
case 1: return [4 /*yield*/,
|
|
434
|
+
case 1: return [4 /*yield*/, disconnectWallet()];
|
|
432
435
|
case 2:
|
|
433
436
|
_a.sent();
|
|
434
437
|
showInfoToast("Disconnected wallet");
|
|
@@ -442,12 +445,12 @@ function Inner(_a) {
|
|
|
442
445
|
case 5: return [2 /*return*/];
|
|
443
446
|
}
|
|
444
447
|
});
|
|
445
|
-
}); }, [sessionAddress, universalConnector,
|
|
448
|
+
}); }, [sessionAddress, universalConnector, disconnectWallet]);
|
|
446
449
|
// Accounts
|
|
447
450
|
var walletConnection = useWalletConnection();
|
|
448
451
|
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
452
|
var accountRes = (_g = useCurrentAccount()) !== null && _g !== void 0 ? _g : undefined;
|
|
450
|
-
var
|
|
453
|
+
var walletConnectAccount = useMemo(function () {
|
|
451
454
|
return sessionAddress
|
|
452
455
|
? {
|
|
453
456
|
address: sessionAddress,
|
|
@@ -455,50 +458,34 @@ function Inner(_a) {
|
|
|
455
458
|
chains: ["sui:mainnet"],
|
|
456
459
|
features: [],
|
|
457
460
|
}
|
|
458
|
-
:
|
|
459
|
-
}, [sessionAddress
|
|
460
|
-
var
|
|
461
|
+
: undefined;
|
|
462
|
+
}, [sessionAddress]);
|
|
463
|
+
var account = useMemo(function () { return walletConnectAccount !== null && walletConnectAccount !== void 0 ? walletConnectAccount : accountRes; }, [walletConnectAccount, accountRes]);
|
|
464
|
+
var accounts = useMemo(function () { return (walletConnectAccount ? [walletConnectAccount] : accountsRes); }, [walletConnectAccount, accountsRes]);
|
|
465
|
+
var signPersonalMessage = useMemo(function () {
|
|
461
466
|
return sessionAddress
|
|
462
|
-
?
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
chains: ["sui:mainnet"],
|
|
467
|
-
features: [],
|
|
468
|
-
},
|
|
469
|
-
]
|
|
470
|
-
: accountsRes;
|
|
471
|
-
}, [sessionAddress, accountsRes]);
|
|
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;
|
|
467
|
+
? walletConnectSignPersonalMessage
|
|
468
|
+
: function (message) { return signPersonalMessageRaw({ message: message }); };
|
|
469
|
+
}, [sessionAddress, walletConnectSignPersonalMessage, signPersonalMessageRaw]);
|
|
470
|
+
var switchAccountWrapper = useCallback(function (_account, addressNameServiceName) {
|
|
481
471
|
var _a, _b, _c;
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
return [2 /*return*/];
|
|
500
|
-
});
|
|
501
|
-
}); }, [(_h = walletConnection.wallet) === null || _h === void 0 ? void 0 : _h.accounts, dAppKit]);
|
|
472
|
+
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);
|
|
473
|
+
try {
|
|
474
|
+
var matchingAccount = (_c = walletConnection.wallet) === null || _c === void 0 ? void 0 : _c.accounts.find(function (a) { return a.address === _account.address; });
|
|
475
|
+
if (!matchingAccount)
|
|
476
|
+
throw new Error("Account not found");
|
|
477
|
+
dAppKit.switchAccount({ account: matchingAccount });
|
|
478
|
+
showInfoToast("Switched to ".concat(accountLabel), {
|
|
479
|
+
description: (_account === null || _account === void 0 ? void 0 : _account.label)
|
|
480
|
+
? (addressNameServiceName !== null && addressNameServiceName !== void 0 ? addressNameServiceName : formatAddress(_account.address))
|
|
481
|
+
: undefined,
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
catch (err) {
|
|
485
|
+
showErrorToast("Failed to switch to ".concat(accountLabel), err);
|
|
486
|
+
console.error(err);
|
|
487
|
+
}
|
|
488
|
+
}, [dAppKit, (_h = walletConnection.wallet) === null || _h === void 0 ? void 0 : _h.accounts]);
|
|
502
489
|
// LaunchDarkly
|
|
503
490
|
var ldClient = useLDClient();
|
|
504
491
|
var ldKeyRef = useRef(undefined);
|
|
@@ -563,56 +550,46 @@ function Inner(_a) {
|
|
|
563
550
|
args_1[_i - 1] = arguments[_i];
|
|
564
551
|
}
|
|
565
552
|
return __awaiter(_this, __spreadArray([transaction_1], args_1, true), void 0, function (transaction, setGasBudget) {
|
|
566
|
-
var _address, _transaction, inspectResults,
|
|
567
|
-
var _c;
|
|
568
|
-
var _d, _e, _f, _g;
|
|
553
|
+
var _address, _transaction, inspectResults, err_4;
|
|
569
554
|
if (setGasBudget === void 0) { setGasBudget = true; }
|
|
570
|
-
return __generator(this, function (
|
|
571
|
-
switch (
|
|
555
|
+
return __generator(this, function (_a) {
|
|
556
|
+
switch (_a.label) {
|
|
572
557
|
case 0:
|
|
573
558
|
_address = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
574
559
|
_transaction = Transaction.from(transaction);
|
|
575
|
-
|
|
560
|
+
_a.label = 1;
|
|
576
561
|
case 1:
|
|
577
|
-
|
|
562
|
+
_a.trys.push([1, 3, , 4]);
|
|
578
563
|
// Gas budget
|
|
579
564
|
if (setGasBudget && gasBudget !== "")
|
|
580
565
|
_transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
581
566
|
.times(Math.pow(10, SUI_DECIMALS))
|
|
582
567
|
.integerValue(BigNumber.ROUND_DOWN));
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
_c.include = {
|
|
590
|
-
commandResults: true,
|
|
591
|
-
},
|
|
592
|
-
_c)])];
|
|
593
|
-
case 3:
|
|
594
|
-
inspectResults = _h.sent();
|
|
568
|
+
return [4 /*yield*/, suiClient.devInspectTransactionBlock({
|
|
569
|
+
sender: _address !== null && _address !== void 0 ? _address : "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
570
|
+
transactionBlock: _transaction,
|
|
571
|
+
})];
|
|
572
|
+
case 2:
|
|
573
|
+
inspectResults = _a.sent();
|
|
595
574
|
console.log("[WalletContext] dryRunTransaction - inspectResults:", inspectResults);
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
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");
|
|
575
|
+
if (inspectResults.error)
|
|
576
|
+
throw new Error(inspectResults.error);
|
|
599
577
|
return [2 /*return*/, inspectResults];
|
|
600
|
-
case
|
|
601
|
-
err_4 =
|
|
578
|
+
case 3:
|
|
579
|
+
err_4 = _a.sent();
|
|
602
580
|
// _transaction.getData().inputs.filter(input=>!!input.Object).map(input=>input.)
|
|
603
581
|
console.error(err_4);
|
|
604
582
|
throw err_4;
|
|
605
|
-
case
|
|
583
|
+
case 4: return [2 /*return*/];
|
|
606
584
|
}
|
|
607
585
|
});
|
|
608
586
|
});
|
|
609
587
|
}, [impersonatedAddress, account === null || account === void 0 ? void 0 : account.address, gasBudget, suiClient]);
|
|
610
588
|
var signExecuteAndWaitForTransaction = useCallback(function (transaction, options, onSetGasBudget, onSign, onExecute) { return __awaiter(_this, void 0, void 0, function () {
|
|
611
|
-
var _address, signedTransaction, txBytes, res, err_5, res1,
|
|
612
|
-
var
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
switch (_h.label) {
|
|
589
|
+
var _address, signedTransaction, txBytes, res, err_5, res1, res2, err_6;
|
|
590
|
+
var _a, _b;
|
|
591
|
+
return __generator(this, function (_c) {
|
|
592
|
+
switch (_c.label) {
|
|
616
593
|
case 0:
|
|
617
594
|
_address = impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address;
|
|
618
595
|
if (_address) {
|
|
@@ -621,9 +598,9 @@ function Inner(_a) {
|
|
|
621
598
|
}
|
|
622
599
|
catch (err) { }
|
|
623
600
|
}
|
|
624
|
-
|
|
601
|
+
_c.label = 1;
|
|
625
602
|
case 1:
|
|
626
|
-
|
|
603
|
+
_c.trys.push([1, 13, , 14]);
|
|
627
604
|
// Gas budget
|
|
628
605
|
if (gasBudget !== "")
|
|
629
606
|
transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
@@ -637,7 +614,7 @@ function Inner(_a) {
|
|
|
637
614
|
transaction.setSender(sessionAddress);
|
|
638
615
|
return [4 /*yield*/, transaction.build({ client: suiClient })];
|
|
639
616
|
case 2:
|
|
640
|
-
txBytes =
|
|
617
|
+
txBytes = _c.sent();
|
|
641
618
|
return [4 /*yield*/, universalConnector.request({
|
|
642
619
|
method: "sui_signTransaction",
|
|
643
620
|
params: {
|
|
@@ -646,7 +623,7 @@ function Inner(_a) {
|
|
|
646
623
|
},
|
|
647
624
|
}, "sui:mainnet")];
|
|
648
625
|
case 3:
|
|
649
|
-
res =
|
|
626
|
+
res = _c.sent();
|
|
650
627
|
signedTransaction = {
|
|
651
628
|
bytes: res.transactionBytes,
|
|
652
629
|
signature: res.signature,
|
|
@@ -656,64 +633,57 @@ function Inner(_a) {
|
|
|
656
633
|
transaction: transaction,
|
|
657
634
|
})];
|
|
658
635
|
case 5:
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
_h.label = 6;
|
|
636
|
+
signedTransaction = _c.sent();
|
|
637
|
+
_c.label = 6;
|
|
662
638
|
case 6:
|
|
663
639
|
onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction);
|
|
664
640
|
if (!(options === null || options === void 0 ? void 0 : options.auction)) return [3 /*break*/, 10];
|
|
665
|
-
|
|
641
|
+
_c.label = 7;
|
|
666
642
|
case 7:
|
|
667
|
-
|
|
643
|
+
_c.trys.push([7, 9, , 10]);
|
|
668
644
|
return [4 /*yield*/, executeAuction(signedTransaction.bytes, signedTransaction.signature)];
|
|
669
645
|
case 8:
|
|
670
|
-
|
|
646
|
+
_c.sent();
|
|
671
647
|
return [3 /*break*/, 10];
|
|
672
648
|
case 9:
|
|
673
|
-
err_5 =
|
|
649
|
+
err_5 = _c.sent();
|
|
674
650
|
return [3 /*break*/, 10];
|
|
675
|
-
case 10:
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
case 11:
|
|
680
|
-
|
|
681
|
-
_c)])];
|
|
682
|
-
case 12:
|
|
683
|
-
res1 = _h.sent();
|
|
684
|
-
txResult1 = (_d = res1.Transaction) !== null && _d !== void 0 ? _d : res1.FailedTransaction;
|
|
685
|
-
if (!(txResult1 === null || txResult1 === void 0 ? void 0 : txResult1.digest))
|
|
686
|
-
throw new Error("Failed to get transaction digest");
|
|
651
|
+
case 10: return [4 /*yield*/, suiClient.executeTransactionBlock({
|
|
652
|
+
transactionBlock: signedTransaction.bytes,
|
|
653
|
+
signature: signedTransaction.signature,
|
|
654
|
+
})];
|
|
655
|
+
case 11:
|
|
656
|
+
res1 = _c.sent();
|
|
687
657
|
onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1);
|
|
688
658
|
return [4 /*yield*/, suiClient.waitForTransaction({
|
|
689
|
-
digest:
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
659
|
+
digest: res1.digest,
|
|
660
|
+
options: {
|
|
661
|
+
showBalanceChanges: true,
|
|
662
|
+
showEffects: true,
|
|
663
|
+
showEvents: true,
|
|
664
|
+
showObjectChanges: true,
|
|
695
665
|
},
|
|
696
666
|
})];
|
|
697
|
-
case
|
|
698
|
-
res2 =
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
throw new Error((
|
|
667
|
+
case 12:
|
|
668
|
+
res2 = _c.sent();
|
|
669
|
+
if (((_a = res2.effects) === null || _a === void 0 ? void 0 : _a.status) !== undefined &&
|
|
670
|
+
res2.effects.status.status === "failure")
|
|
671
|
+
throw new Error((_b = res2.effects.status.error) !== null && _b !== void 0 ? _b : "Transaction failed");
|
|
702
672
|
return [2 /*return*/, res2];
|
|
703
|
-
case
|
|
704
|
-
err_6 =
|
|
673
|
+
case 13:
|
|
674
|
+
err_6 = _c.sent();
|
|
705
675
|
console.error(err_6);
|
|
706
676
|
throw err_6;
|
|
707
|
-
case
|
|
677
|
+
case 14: return [2 /*return*/];
|
|
708
678
|
}
|
|
709
679
|
});
|
|
710
680
|
}); }, [
|
|
681
|
+
universalConnector,
|
|
682
|
+
sessionAddress,
|
|
683
|
+
gasBudget,
|
|
711
684
|
impersonatedAddress,
|
|
712
685
|
account === null || account === void 0 ? void 0 : account.address,
|
|
713
686
|
dryRunTransaction,
|
|
714
|
-
gasBudget,
|
|
715
|
-
sessionAddress,
|
|
716
|
-
universalConnector,
|
|
717
687
|
suiClient,
|
|
718
688
|
dAppKit,
|
|
719
689
|
]);
|
|
@@ -762,24 +732,18 @@ function Inner(_a) {
|
|
|
762
732
|
export function WalletContextProvider(_a) {
|
|
763
733
|
var appName = _a.appName, children = _a.children;
|
|
764
734
|
var rpc = useSettingsContext().rpc;
|
|
765
|
-
var
|
|
766
|
-
var dAppKit = useMemo(function () {
|
|
735
|
+
var dAppKitInstance = useMemo(function () {
|
|
767
736
|
return createDAppKit({
|
|
768
737
|
networks: ["mainnet"],
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
return new SuiGrpcClient({
|
|
772
|
-
baseUrl: rpc.url,
|
|
773
|
-
network: network,
|
|
774
|
-
});
|
|
738
|
+
createClient: function () {
|
|
739
|
+
return new SuiJsonRpcClient({ url: rpc.url, network: "mainnet" });
|
|
775
740
|
},
|
|
741
|
+
defaultNetwork: "mainnet",
|
|
776
742
|
autoConnect: true,
|
|
777
743
|
slushWalletConfig: { appName: appName },
|
|
778
744
|
});
|
|
779
745
|
}, [rpc.url, appName]);
|
|
780
|
-
return (<
|
|
781
|
-
<
|
|
782
|
-
|
|
783
|
-
</DAppKitProvider>
|
|
784
|
-
</QueryClientProvider>);
|
|
746
|
+
return (<DAppKitProvider dAppKit={dAppKitInstance}>
|
|
747
|
+
<Inner appName={appName}>{children}</Inner>
|
|
748
|
+
</DAppKitProvider>);
|
|
785
749
|
}
|
|
@@ -62,17 +62,16 @@ export default function useFetchBalances() {
|
|
|
62
62
|
case 0:
|
|
63
63
|
balancesMap = {};
|
|
64
64
|
if (!address) return [3 /*break*/, 2];
|
|
65
|
-
return [4 /*yield*/, suiClient.
|
|
65
|
+
return [4 /*yield*/, suiClient.getAllBalances({
|
|
66
66
|
owner: address,
|
|
67
67
|
})];
|
|
68
68
|
case 1:
|
|
69
|
-
rawBalances = (_a.sent())
|
|
70
|
-
.map(function (
|
|
69
|
+
rawBalances = (_a.sent())
|
|
70
|
+
.map(function (cb) { return (__assign(__assign({}, cb), { coinType: normalizeStructTag(cb.coinType) })); })
|
|
71
71
|
.sort(function (a, b) { return (a.coinType < b.coinType ? -1 : 1); });
|
|
72
|
-
console.log("XXXX rawBalances", rawBalances);
|
|
73
72
|
for (_i = 0, rawBalances_1 = rawBalances; _i < rawBalances_1.length; _i++) {
|
|
74
73
|
rawBalance = rawBalances_1[_i];
|
|
75
|
-
totalBalance = new BigNumber(rawBalance.
|
|
74
|
+
totalBalance = new BigNumber(rawBalance.totalBalance);
|
|
76
75
|
if (totalBalance.gt(0))
|
|
77
76
|
balancesMap[rawBalance.coinType] = totalBalance;
|
|
78
77
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const useCoinMetadataMap: (coinTypes: string[]) => Record<string,
|
|
1
|
+
import { CoinMetadata } from "@mysten/sui/jsonRpc";
|
|
2
|
+
declare const useCoinMetadataMap: (coinTypes: string[]) => Record<string, CoinMetadata> | undefined;
|
|
3
3
|
export default useCoinMetadataMap;
|
|
@@ -46,24 +46,24 @@ var useRefreshOnBalancesChange = function (refresh) {
|
|
|
46
46
|
return;
|
|
47
47
|
previousBalancesRef.current = undefined;
|
|
48
48
|
var interval = setInterval(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
-
var
|
|
49
|
+
var balances, err_1;
|
|
50
50
|
return __generator(this, function (_a) {
|
|
51
51
|
switch (_a.label) {
|
|
52
52
|
case 0:
|
|
53
53
|
_a.trys.push([0, 4, , 5]);
|
|
54
|
-
return [4 /*yield*/, suiClient.
|
|
54
|
+
return [4 /*yield*/, suiClient.getAllBalances({
|
|
55
55
|
owner: address,
|
|
56
56
|
})];
|
|
57
57
|
case 1:
|
|
58
|
-
|
|
58
|
+
balances = _a.sent();
|
|
59
59
|
if (!(previousBalancesRef.current !== undefined &&
|
|
60
|
-
!isEqual(
|
|
60
|
+
!isEqual(balances, previousBalancesRef.current))) return [3 /*break*/, 3];
|
|
61
61
|
return [4 /*yield*/, refresh()];
|
|
62
62
|
case 2:
|
|
63
63
|
_a.sent();
|
|
64
64
|
_a.label = 3;
|
|
65
65
|
case 3:
|
|
66
|
-
previousBalancesRef.current =
|
|
66
|
+
previousBalancesRef.current = balances;
|
|
67
67
|
return [3 /*break*/, 5];
|
|
68
68
|
case 4:
|
|
69
69
|
err_1 = _a.sent();
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./contexts
|
|
2
|
-
export * from "./fetchers
|
|
3
|
-
export * from "./hooks
|
|
4
|
-
export * from "./lib
|
|
1
|
+
export * from "./contexts";
|
|
2
|
+
export * from "./fetchers";
|
|
3
|
+
export * from "./hooks";
|
|
4
|
+
export * from "./lib";
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./contexts
|
|
2
|
-
export * from "./fetchers
|
|
3
|
-
export * from "./hooks
|
|
4
|
-
export * from "./lib
|
|
1
|
+
export * from "./contexts";
|
|
2
|
+
export * from "./fetchers";
|
|
3
|
+
export * from "./hooks";
|
|
4
|
+
export * from "./lib";
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sui-fe-next","version":"0.
|
|
1
|
+
{"name":"@suilend/sui-fe-next","version":"2.0.1","private":false,"description":"A collection of TypeScript frontend components and hooks","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./contexts/WalletContext":"./contexts/WalletContext.jsx","./contexts/SettingsContext":"./contexts/SettingsContext.jsx","./contexts":"./contexts/index.js","./fetchers":"./fetchers/index.js","./fetchers/useFetchBalances":"./fetchers/useFetchBalances.js","./hooks/useRefreshOnBalancesChange":"./hooks/useRefreshOnBalancesChange.js","./hooks/useLedgerHashDialog":"./hooks/useLedgerHashDialog.js","./hooks/useIsAndroid":"./hooks/useIsAndroid.jsx","./hooks/useCoinMetadataMap":"./hooks/useCoinMetadataMap.js","./hooks":"./hooks/index.js","./hooks/useIsTouchscreen":"./hooks/useIsTouchscreen.jsx","./hooks/useIsiOS":"./hooks/useIsiOS.jsx","./hooks/keypair":"./hooks/keypair.js","./lib/track":"./lib/track.js","./lib":"./lib/index.js","./lib/router":"./lib/router.js","./lib/toasts":"./lib/toasts.jsx","./lib/connector":"./lib/connector.js"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix \"./src/**/*.ts\"","prettier":"prettier --write \"./src/**/*\"","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ./release.js && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/suilend/sui-fe.git"},"bugs":{"url":"https://github.com/suilend/sui-fe/issues"},"dependencies":{"@reown/appkit":"^1.8.10","@reown/appkit-common":"^1.8.10","@reown/appkit-universal-connector":"^1.8.10","@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.72.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/node":"^22.9.0","@types/react":"^18.3.12","@types/react-dom":"^18.3.1","@typescript-eslint/eslint-plugin":"^8.14.0","@typescript-eslint/parser":"^8.14.0","eslint":"^9.14.0","eslint-config-next":"^15.0.3","eslint-config-prettier":"^9.1.0","eslint-plugin-import":"^2.31.0","eslint-plugin-prettier":"^5.2.1","prettier":"^3.3.3","ts-node":"^10.9.2","typescript":"^5.6.3"},"peerDependencies":{"@mysten/dapp-kit-core":"1.0.3","@mysten/dapp-kit-react":"1.0.1","@mysten/sui":"2.3.1","@mysten/wallet-standard":"0.20.0","@suilend/sui-fe":"^2.0.1"}}
|