@suilend/sui-fe-next 0.1.63 → 0.1.65
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/WalletContext.d.ts +7 -2
- package/contexts/WalletContext.jsx +133 -48
- package/lib/connector.d.ts +3 -0
- package/lib/connector.js +78 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -2,11 +2,14 @@ import { Dispatch, PropsWithChildren, SetStateAction } from "react";
|
|
|
2
2
|
import { DevInspectResults, SuiTransactionBlockResponse } from "@mysten/sui/client";
|
|
3
3
|
import { SignatureWithBytes } from "@mysten/sui/cryptography";
|
|
4
4
|
import { Transaction } from "@mysten/sui/transactions";
|
|
5
|
-
import {
|
|
5
|
+
import { ReadonlyUint8Array, WalletIcon, WalletAccount as WalletStandardWalletAccount, WalletWithRequiredFeatures } from "@mysten/wallet-standard";
|
|
6
6
|
export declare enum WalletType {
|
|
7
7
|
EXTENSION = "extension",
|
|
8
8
|
WEB = "web"
|
|
9
9
|
}
|
|
10
|
+
export type WalletAccount = Omit<WalletStandardWalletAccount, 'publicKey'> & {
|
|
11
|
+
publicKey?: ReadonlyUint8Array;
|
|
12
|
+
};
|
|
10
13
|
type WalletPlatform = "iOS" | "android" | "extension";
|
|
11
14
|
export type Wallet = {
|
|
12
15
|
name: string;
|
|
@@ -37,7 +40,9 @@ export interface WalletContext {
|
|
|
37
40
|
setIsConnectWalletDropdownOpen: Dispatch<SetStateAction<boolean>>;
|
|
38
41
|
wallets: Wallet[];
|
|
39
42
|
wallet?: Wallet;
|
|
40
|
-
connectWallet: (wallet: Wallet
|
|
43
|
+
connectWallet: (wallet: Wallet & {
|
|
44
|
+
walletConnect: boolean;
|
|
45
|
+
}) => void;
|
|
41
46
|
disconnectWallet: () => void;
|
|
42
47
|
accounts: readonly WalletAccount[];
|
|
43
48
|
account?: WalletAccount;
|
|
@@ -57,10 +57,10 @@ 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 { WalletProvider as MystenWalletProvider, SuiClientProvider, createNetworkConfig, } from "@mysten/dapp-kit";
|
|
60
|
+
import { WalletProvider as MystenWalletProvider, SuiClientProvider, createNetworkConfig, useSignPersonalMessage, } from "@mysten/dapp-kit";
|
|
61
61
|
import { useAccounts, useConnectWallet, useCurrentAccount, useCurrentWallet, useDisconnectWallet, useSignTransaction, useSwitchAccount, useWallets, } from "@mysten/dapp-kit";
|
|
62
62
|
import { Transaction } from "@mysten/sui/transactions";
|
|
63
|
-
import { SUI_DECIMALS } from "@mysten/sui/utils";
|
|
63
|
+
import { SUI_DECIMALS, toBase64 } from "@mysten/sui/utils";
|
|
64
64
|
import * as Sentry from "@sentry/nextjs";
|
|
65
65
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
66
66
|
import BigNumber from "bignumber.js";
|
|
@@ -70,6 +70,7 @@ import { useLocalStorage } from "usehooks-ts";
|
|
|
70
70
|
import { API_URL, formatAddress, isInMsafeApp } from "@suilend/sui-fe";
|
|
71
71
|
import { showErrorToast, showInfoToast } from "../lib";
|
|
72
72
|
import { useSettingsContext } from "./SettingsContext";
|
|
73
|
+
import { getUniversalConnector } from "../lib/connector";
|
|
73
74
|
export var WalletType;
|
|
74
75
|
(function (WalletType) {
|
|
75
76
|
WalletType["EXTENSION"] = "extension";
|
|
@@ -200,13 +201,32 @@ export var useWalletContext = function () { return useContext(WalletContext); };
|
|
|
200
201
|
function Inner(_a) {
|
|
201
202
|
var _b;
|
|
202
203
|
var _this = this;
|
|
203
|
-
var _c;
|
|
204
|
+
var _c, _d, _e, _f;
|
|
204
205
|
var appName = _a.appName, children = _a.children;
|
|
205
206
|
var router = useRouter();
|
|
206
207
|
var queryParams = (_b = {},
|
|
207
208
|
_b[WalletContextQueryParams.WALLET] = router.query[WalletContextQueryParams.WALLET],
|
|
208
209
|
_b);
|
|
209
|
-
var
|
|
210
|
+
var _g = useSettingsContext(), suiClient = _g.suiClient, rpc = _g.rpc;
|
|
211
|
+
// Only used for wallet connect
|
|
212
|
+
var _h = useState(), universalConnector = _h[0], setUniversalConnector = _h[1];
|
|
213
|
+
var _j = useState(), session = _j[0], setSession = _j[1];
|
|
214
|
+
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];
|
|
215
|
+
var sessionAddress = sessionAddressWithout0x ? sessionAddressWithout0x.split(":").pop() : undefined;
|
|
216
|
+
useEffect(function () {
|
|
217
|
+
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
218
|
+
var connector;
|
|
219
|
+
return __generator(this, function (_a) {
|
|
220
|
+
switch (_a.label) {
|
|
221
|
+
case 0: return [4 /*yield*/, getUniversalConnector(rpc.url)];
|
|
222
|
+
case 1:
|
|
223
|
+
connector = _a.sent();
|
|
224
|
+
setUniversalConnector(connector);
|
|
225
|
+
return [2 /*return*/];
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}); })();
|
|
229
|
+
}, [rpc.url]);
|
|
210
230
|
// Impersonated address
|
|
211
231
|
var impersonatedAddress = queryParams[WalletContextQueryParams.WALLET];
|
|
212
232
|
// Wallets
|
|
@@ -318,18 +338,50 @@ function Inner(_a) {
|
|
|
318
338
|
wallets__web,
|
|
319
339
|
]);
|
|
320
340
|
// Wallet
|
|
321
|
-
var
|
|
341
|
+
var _k = useState(false), isConnectWalletDropdownOpen = _k[0], setIsConnectWalletDropdownOpen = _k[1];
|
|
322
342
|
var rawWallet = useCurrentWallet().currentWallet;
|
|
323
343
|
var wallet = useMemo(function () {
|
|
324
344
|
return rawWallet ? wallets.find(function (w) { return w.name === rawWallet.name; }) : undefined;
|
|
325
345
|
}, [rawWallet, wallets]);
|
|
326
346
|
var connectWallet = useConnectWallet().mutate;
|
|
347
|
+
var disconnectWallet = useDisconnectWallet().mutate;
|
|
348
|
+
var signPersonalMessageRaw = useSignPersonalMessage().mutateAsync;
|
|
349
|
+
var walletConnectSignPersonalMessage = useCallback(function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
350
|
+
var res;
|
|
351
|
+
return __generator(this, function (_a) {
|
|
352
|
+
switch (_a.label) {
|
|
353
|
+
case 0:
|
|
354
|
+
if (!sessionAddress || !universalConnector)
|
|
355
|
+
throw new Error("Wallet not connected");
|
|
356
|
+
return [4 /*yield*/, universalConnector.request({
|
|
357
|
+
method: "sui_signPersonalMessage",
|
|
358
|
+
params: { message: message.toString() },
|
|
359
|
+
}, "sui:mainnet")];
|
|
360
|
+
case 1:
|
|
361
|
+
res = _a.sent();
|
|
362
|
+
return [2 /*return*/, {
|
|
363
|
+
signature: res.signature,
|
|
364
|
+
bytes: res.transactionBytes,
|
|
365
|
+
}];
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
}); }, [sessionAddress, universalConnector]);
|
|
369
|
+
var signPersonalMessage = sessionAddress ? walletConnectSignPersonalMessage : signPersonalMessageRaw;
|
|
327
370
|
var connectWalletWrapper = useCallback(function (_wallet) {
|
|
328
371
|
try {
|
|
329
372
|
if (!_wallet.raw)
|
|
330
373
|
throw new Error("Missing wallet");
|
|
374
|
+
if (_wallet === null || _wallet === void 0 ? void 0 : _wallet.walletConnect) {
|
|
375
|
+
universalConnector.connect().then(function (res) {
|
|
376
|
+
disconnectWallet();
|
|
377
|
+
setSession(res.session);
|
|
378
|
+
});
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
331
381
|
connectWallet({ wallet: _wallet.raw }, {
|
|
332
382
|
onSuccess: function () {
|
|
383
|
+
universalConnector.disconnect();
|
|
384
|
+
setSession(null);
|
|
333
385
|
showInfoToast("Connected ".concat(_wallet.name));
|
|
334
386
|
setIsConnectWalletDropdownOpen(false);
|
|
335
387
|
},
|
|
@@ -343,8 +395,7 @@ function Inner(_a) {
|
|
|
343
395
|
showErrorToast("Failed to connect ".concat(_wallet.name), err);
|
|
344
396
|
console.error(err);
|
|
345
397
|
}
|
|
346
|
-
}, [connectWallet]);
|
|
347
|
-
var disconnectWallet = useDisconnectWallet().mutate;
|
|
398
|
+
}, [connectWallet, disconnectWallet]);
|
|
348
399
|
var disconnectWalletWrapper = useCallback(function () {
|
|
349
400
|
try {
|
|
350
401
|
disconnectWallet(undefined, {
|
|
@@ -363,14 +414,18 @@ function Inner(_a) {
|
|
|
363
414
|
}
|
|
364
415
|
}, [disconnectWallet]);
|
|
365
416
|
// Accounts
|
|
366
|
-
var
|
|
367
|
-
var
|
|
417
|
+
var accountsRes = useAccounts();
|
|
418
|
+
var accountRes = (_f = useCurrentAccount()) !== null && _f !== void 0 ? _f : undefined;
|
|
368
419
|
var switchAccount = useSwitchAccount().mutate;
|
|
420
|
+
var account = sessionAddress ? { address: sessionAddress, publicKey: new Uint8Array(), chains: ['sui:mainnet'], features: [] } : accountRes;
|
|
421
|
+
var accounts = sessionAddress ? [{ address: sessionAddress, publicKey: new Uint8Array(), chains: ['sui:mainnet'], features: [] }] : accountsRes;
|
|
369
422
|
var switchAccountWrapper = useCallback(function (_account, addressNameServiceName) {
|
|
370
|
-
var _a, _b;
|
|
423
|
+
var _a, _b, _c;
|
|
371
424
|
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);
|
|
372
425
|
try {
|
|
373
|
-
switchAccount(
|
|
426
|
+
switchAccount(
|
|
427
|
+
// only address needed here. rest for type compatibility
|
|
428
|
+
{ account: __assign(__assign({}, _account), { publicKey: (_c = _account.publicKey) !== null && _c !== void 0 ? _c : new Uint8Array() }) }, {
|
|
374
429
|
onSuccess: function () {
|
|
375
430
|
showInfoToast("Switched to ".concat(accountLabel), {
|
|
376
431
|
description: (_account === null || _account === void 0 ? void 0 : _account.label)
|
|
@@ -506,7 +561,7 @@ function Inner(_a) {
|
|
|
506
561
|
});
|
|
507
562
|
}, [impersonatedAddress, account === null || account === void 0 ? void 0 : account.address, gasBudget, suiClient]);
|
|
508
563
|
var signExecuteAndWaitForTransaction = useCallback(function (transaction, options, onSetGasBudget, onSign, onExecute) { return __awaiter(_this, void 0, void 0, function () {
|
|
509
|
-
var _address, signedTransaction, err_3, res1, res2, err_4;
|
|
564
|
+
var _address, signedTransaction, txBytes, res, err_3, res1, res2, err_4;
|
|
510
565
|
var _a, _b;
|
|
511
566
|
return __generator(this, function (_c) {
|
|
512
567
|
switch (_c.label) {
|
|
@@ -520,7 +575,7 @@ function Inner(_a) {
|
|
|
520
575
|
}
|
|
521
576
|
_c.label = 1;
|
|
522
577
|
case 1:
|
|
523
|
-
_c.trys.push([1,
|
|
578
|
+
_c.trys.push([1, 13, , 14]);
|
|
524
579
|
// Gas budget
|
|
525
580
|
if (gasBudget !== "")
|
|
526
581
|
transaction.setGasBudget(+new BigNumber(gasBudget)
|
|
@@ -529,29 +584,52 @@ function Inner(_a) {
|
|
|
529
584
|
onSetGasBudget === null || onSetGasBudget === void 0 ? void 0 : onSetGasBudget(transaction);
|
|
530
585
|
// Log
|
|
531
586
|
console.log("[WalletContext] signExecuteAndWaitForTransaction - transaction.getData():", transaction.getData());
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
587
|
+
signedTransaction = void 0;
|
|
588
|
+
if (!(sessionAddress && universalConnector)) return [3 /*break*/, 4];
|
|
589
|
+
transaction.setSender(sessionAddress);
|
|
590
|
+
return [4 /*yield*/, transaction.build({ client: suiClient })];
|
|
536
591
|
case 2:
|
|
592
|
+
txBytes = _c.sent();
|
|
593
|
+
return [4 /*yield*/, universalConnector.request({
|
|
594
|
+
method: "sui_signTransaction",
|
|
595
|
+
params: {
|
|
596
|
+
transaction: toBase64(txBytes),
|
|
597
|
+
address: sessionAddress,
|
|
598
|
+
},
|
|
599
|
+
}, "sui:mainnet")];
|
|
600
|
+
case 3:
|
|
601
|
+
res = _c.sent();
|
|
602
|
+
signedTransaction = {
|
|
603
|
+
bytes: res.transactionBytes,
|
|
604
|
+
signature: res.signature,
|
|
605
|
+
};
|
|
606
|
+
return [3 /*break*/, 6];
|
|
607
|
+
case 4: return [4 /*yield*/, signTransaction({
|
|
608
|
+
transaction: transaction,
|
|
609
|
+
chain: "sui:mainnet",
|
|
610
|
+
})];
|
|
611
|
+
case 5:
|
|
612
|
+
// Sign
|
|
537
613
|
signedTransaction = _c.sent();
|
|
614
|
+
_c.label = 6;
|
|
615
|
+
case 6:
|
|
538
616
|
onSign === null || onSign === void 0 ? void 0 : onSign(signedTransaction);
|
|
539
|
-
if (!(options === null || options === void 0 ? void 0 : options.auction)) return [3 /*break*/,
|
|
540
|
-
_c.label =
|
|
541
|
-
case
|
|
542
|
-
_c.trys.push([
|
|
617
|
+
if (!(options === null || options === void 0 ? void 0 : options.auction)) return [3 /*break*/, 10];
|
|
618
|
+
_c.label = 7;
|
|
619
|
+
case 7:
|
|
620
|
+
_c.trys.push([7, 9, , 10]);
|
|
543
621
|
return [4 /*yield*/, executeAuction(signedTransaction.bytes, signedTransaction.signature)];
|
|
544
|
-
case
|
|
622
|
+
case 8:
|
|
545
623
|
_c.sent();
|
|
546
|
-
return [3 /*break*/,
|
|
547
|
-
case
|
|
624
|
+
return [3 /*break*/, 10];
|
|
625
|
+
case 9:
|
|
548
626
|
err_3 = _c.sent();
|
|
549
|
-
return [3 /*break*/,
|
|
550
|
-
case
|
|
627
|
+
return [3 /*break*/, 10];
|
|
628
|
+
case 10: return [4 /*yield*/, suiClient.executeTransactionBlock({
|
|
551
629
|
transactionBlock: signedTransaction.bytes,
|
|
552
630
|
signature: signedTransaction.signature,
|
|
553
631
|
})];
|
|
554
|
-
case
|
|
632
|
+
case 11:
|
|
555
633
|
res1 = _c.sent();
|
|
556
634
|
onExecute === null || onExecute === void 0 ? void 0 : onExecute(res1);
|
|
557
635
|
return [4 /*yield*/, suiClient.waitForTransaction({
|
|
@@ -563,21 +641,23 @@ function Inner(_a) {
|
|
|
563
641
|
showObjectChanges: true,
|
|
564
642
|
},
|
|
565
643
|
})];
|
|
566
|
-
case
|
|
644
|
+
case 12:
|
|
567
645
|
res2 = _c.sent();
|
|
568
646
|
if (((_a = res2.effects) === null || _a === void 0 ? void 0 : _a.status) !== undefined &&
|
|
569
647
|
res2.effects.status.status === "failure")
|
|
570
648
|
throw new Error((_b = res2.effects.status.error) !== null && _b !== void 0 ? _b : "Transaction failed");
|
|
571
649
|
return [2 /*return*/, res2];
|
|
572
|
-
case
|
|
650
|
+
case 13:
|
|
573
651
|
err_4 = _c.sent();
|
|
574
652
|
Sentry.captureException(err_4);
|
|
575
653
|
console.error(err_4);
|
|
576
654
|
throw err_4;
|
|
577
|
-
case
|
|
655
|
+
case 14: return [2 /*return*/];
|
|
578
656
|
}
|
|
579
657
|
});
|
|
580
658
|
}); }, [
|
|
659
|
+
universalConnector,
|
|
660
|
+
sessionAddress,
|
|
581
661
|
gasBudget,
|
|
582
662
|
impersonatedAddress,
|
|
583
663
|
account === null || account === void 0 ? void 0 : account.address,
|
|
@@ -586,25 +666,29 @@ function Inner(_a) {
|
|
|
586
666
|
signTransaction,
|
|
587
667
|
]);
|
|
588
668
|
// Using Ledger
|
|
589
|
-
var
|
|
669
|
+
var _l = useLocalStorage("isUsingLedger-".concat(impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address), false), isUsingLedger = _l[0], setIsUsingLedger = _l[1];
|
|
590
670
|
// Context
|
|
591
|
-
var contextValue = useMemo(function () {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
671
|
+
var contextValue = useMemo(function () {
|
|
672
|
+
return ({
|
|
673
|
+
isImpersonating: !!impersonatedAddress,
|
|
674
|
+
isConnectWalletDropdownOpen: isConnectWalletDropdownOpen,
|
|
675
|
+
setIsConnectWalletDropdownOpen: setIsConnectWalletDropdownOpen,
|
|
676
|
+
wallets: wallets,
|
|
677
|
+
wallet: wallet,
|
|
678
|
+
connectWallet: connectWalletWrapper,
|
|
679
|
+
disconnectWallet: disconnectWalletWrapper,
|
|
680
|
+
accounts: accounts,
|
|
681
|
+
account: account,
|
|
682
|
+
switchAccount: switchAccountWrapper,
|
|
683
|
+
address: impersonatedAddress !== null && impersonatedAddress !== void 0 ? impersonatedAddress : account === null || account === void 0 ? void 0 : account.address,
|
|
684
|
+
dryRunTransaction: dryRunTransaction,
|
|
685
|
+
signExecuteAndWaitForTransaction: signExecuteAndWaitForTransaction,
|
|
686
|
+
isUsingLedger: isUsingLedger,
|
|
687
|
+
setIsUsingLedger: setIsUsingLedger,
|
|
688
|
+
signPersonalMessage: signPersonalMessage
|
|
689
|
+
});
|
|
690
|
+
}, [
|
|
691
|
+
session,
|
|
608
692
|
impersonatedAddress,
|
|
609
693
|
isConnectWalletDropdownOpen,
|
|
610
694
|
wallets,
|
|
@@ -618,6 +702,7 @@ function Inner(_a) {
|
|
|
618
702
|
signExecuteAndWaitForTransaction,
|
|
619
703
|
isUsingLedger,
|
|
620
704
|
setIsUsingLedger,
|
|
705
|
+
signPersonalMessage
|
|
621
706
|
]);
|
|
622
707
|
return (<WalletContext.Provider value={contextValue}>
|
|
623
708
|
{children}
|
package/lib/connector.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { UniversalConnector } from '@reown/appkit-universal-connector';
|
|
38
|
+
// Get projectId from https://dashboard.reown.com
|
|
39
|
+
export var projectId = "8bd21cb34c6a79f37b99768f8f607a99";
|
|
40
|
+
if (!projectId) {
|
|
41
|
+
throw new Error('Project ID is not defined');
|
|
42
|
+
}
|
|
43
|
+
export function getUniversalConnector(rpcUrl) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
+
var universalConnector;
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
switch (_a.label) {
|
|
48
|
+
case 0: return [4 /*yield*/, UniversalConnector.init({
|
|
49
|
+
projectId: projectId,
|
|
50
|
+
metadata: {
|
|
51
|
+
name: 'Universal Connector',
|
|
52
|
+
description: 'Universal Connector',
|
|
53
|
+
url: 'http://localhost:3000',
|
|
54
|
+
icons: ['https://appkit.reown.com/icon.png']
|
|
55
|
+
},
|
|
56
|
+
networks: [
|
|
57
|
+
{
|
|
58
|
+
methods: ['sui_signPersonalMessage', 'sui_signTransaction', 'sui_signAndExecuteTransaction'],
|
|
59
|
+
chains: [{
|
|
60
|
+
id: 784,
|
|
61
|
+
chainNamespace: 'sui',
|
|
62
|
+
caipNetworkId: 'sui:mainnet',
|
|
63
|
+
name: 'Sui',
|
|
64
|
+
nativeCurrency: { name: 'SUI', symbol: 'SUI', decimals: 9 },
|
|
65
|
+
rpcUrls: { default: { http: [rpcUrl] } }
|
|
66
|
+
}],
|
|
67
|
+
events: [],
|
|
68
|
+
namespace: 'sui'
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
})];
|
|
72
|
+
case 1:
|
|
73
|
+
universalConnector = _a.sent();
|
|
74
|
+
return [2 /*return*/, universalConnector];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@suilend/sui-fe-next","version":"0.1.
|
|
1
|
+
{"name":"@suilend/sui-fe-next","version":"0.1.65","private":false,"description":"A collection of TypeScript frontend components and hooks","author":"Suilend","license":"MIT","main":"./index.js","exports":{".":"./index.js","./contexts/SettingsContext":"./contexts/SettingsContext.jsx","./contexts/WalletContext":"./contexts/WalletContext.jsx","./contexts":"./contexts/index.js","./fetchers":"./fetchers/index.js","./fetchers/useFetchBalances":"./fetchers/useFetchBalances.js","./hooks":"./hooks/index.js","./hooks/keypair":"./hooks/keypair.js","./hooks/useCoinMetadataMap":"./hooks/useCoinMetadataMap.js","./hooks/useIsAndroid":"./hooks/useIsAndroid.jsx","./hooks/useIsTouchscreen":"./hooks/useIsTouchscreen.jsx","./hooks/useIsiOS":"./hooks/useIsiOS.jsx","./hooks/useLedgerHashDialog":"./hooks/useLedgerHashDialog.js","./hooks/useRefreshOnBalancesChange":"./hooks/useRefreshOnBalancesChange.js","./lib/connector":"./lib/connector.js","./lib":"./lib/index.js","./lib/router":"./lib/router.js","./lib/toasts":"./lib/toasts.jsx"},"types":"./index.js","scripts":{"build":"rm -rf ./dist && bun tsc","eslint":"eslint --fix \"./src/**/*.ts\"","prettier":"prettier --write \"./src/**/*\"","lint":"bun eslint && bun prettier && bun tsc --noEmit","release":"bun run build && bun ts-node ./release.ts && cd ./dist && npm publish --access public"},"repository":{"type":"git","url":"git+https://github.com/suilend/sui-fe.git"},"bugs":{"url":"https://github.com/suilend/sui-fe/issues"},"dependencies":{"@sentry/nextjs":"^8.38.0","@tanstack/react-query":"^5.60.2","bignumber.js":"^9.1.2","launchdarkly-react-client-sdk":"^3.6.0","lodash":"^4.17.21","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":"0.16.0","@mysten/sui":"1.28.2","@mysten/wallet-standard":"0.14.7","@suilend/sui-fe":"^0.3.31"}}
|