@suilend/sui-fe-next 0.1.47

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/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # sui-fe-next
2
+
3
+ A collection of TypeScript frontend components and hooks.
4
+
5
+ ## Get started
6
+
7
+ 1. Install `bun` [https://bun.sh/](https://bun.sh/)
8
+ 2. Run `bun i`
@@ -0,0 +1,17 @@
1
+ import { PropsWithChildren } from "react";
2
+ import { SuiClient } from "@mysten/sui/client";
3
+ import { Explorer, ExplorerId, Rpc, RpcId } from "@suilend/sui-fe";
4
+ interface SettingsContext {
5
+ rpc: Rpc;
6
+ setRpcId: (id: RpcId) => void;
7
+ setRpcUrl: (url: string) => void;
8
+ explorer: Explorer;
9
+ setExplorerId: (id: ExplorerId) => void;
10
+ gasBudget: string;
11
+ setGasBudget: (value: string) => void;
12
+ suiClient: SuiClient;
13
+ }
14
+ declare const SettingsContext: import("react").Context<SettingsContext>;
15
+ export declare const useSettingsContext: () => SettingsContext;
16
+ export declare function SettingsContextProvider({ children }: PropsWithChildren): import("react").JSX.Element;
17
+ export {};
@@ -0,0 +1,79 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { createContext, useContext, useMemo } from "react";
13
+ import { SuiClient, getFullnodeUrl } from "@mysten/sui/client";
14
+ import { useLocalStorage } from "usehooks-ts";
15
+ import { EXPLORERS, RPCS, RpcId, } from "@suilend/sui-fe";
16
+ var defaultContextValue = {
17
+ rpc: RPCS[0],
18
+ setRpcId: function () {
19
+ throw Error("SettingsContextProvider not initialized");
20
+ },
21
+ setRpcUrl: function () {
22
+ throw Error("SettingsContextProvider not initialized");
23
+ },
24
+ explorer: EXPLORERS[0],
25
+ setExplorerId: function () {
26
+ throw Error("SettingsContextProvider not initialized");
27
+ },
28
+ gasBudget: "",
29
+ setGasBudget: function () {
30
+ throw Error("SettingsContextProvider not initialized");
31
+ },
32
+ suiClient: new SuiClient({ url: getFullnodeUrl("mainnet") }),
33
+ };
34
+ var SettingsContext = createContext(defaultContextValue);
35
+ export var useSettingsContext = function () { return useContext(SettingsContext); };
36
+ export function SettingsContextProvider(_a) {
37
+ var children = _a.children;
38
+ // RPC
39
+ var _b = useLocalStorage("rpcId", defaultContextValue.rpc.id), rpcId = _b[0], setRpcId = _b[1];
40
+ var _c = useLocalStorage("rpcUrl", ""), rpcUrl = _c[0], setRpcUrl = _c[1];
41
+ var rpc = useMemo(function () {
42
+ var _a;
43
+ return rpcId === RpcId.CUSTOM
44
+ ? __assign(__assign({}, RPCS.find(function (_rpc) { return _rpc.id === RpcId.CUSTOM; })), { url: rpcUrl }) : ((_a = RPCS.find(function (_rpc) { return _rpc.id === rpcId; })) !== null && _a !== void 0 ? _a : RPCS[0]);
45
+ }, [rpcId, rpcUrl]);
46
+ // Explorer
47
+ var _d = useLocalStorage("explorerId", defaultContextValue.explorer.id), explorerId = _d[0], setExplorerId = _d[1];
48
+ var explorer = useMemo(function () {
49
+ var _a;
50
+ return (_a = EXPLORERS.find(function (_explorer) { return _explorer.id === explorerId; })) !== null && _a !== void 0 ? _a : EXPLORERS[0];
51
+ }, [explorerId]);
52
+ // Gas budget
53
+ var _e = useLocalStorage("gasBudget", defaultContextValue.gasBudget), gasBudget = _e[0], setGasBudget = _e[1];
54
+ // Sui client
55
+ var suiClient = useMemo(function () { return new SuiClient({ url: rpc.url }); }, [rpc.url]);
56
+ // Context
57
+ var contextValue = useMemo(function () { return ({
58
+ rpc: rpc,
59
+ setRpcId: setRpcId,
60
+ setRpcUrl: setRpcUrl,
61
+ explorer: explorer,
62
+ setExplorerId: setExplorerId,
63
+ gasBudget: gasBudget,
64
+ setGasBudget: setGasBudget,
65
+ suiClient: suiClient,
66
+ }); }, [
67
+ rpc,
68
+ setRpcId,
69
+ setRpcUrl,
70
+ explorer,
71
+ setExplorerId,
72
+ gasBudget,
73
+ setGasBudget,
74
+ suiClient,
75
+ ]);
76
+ return (<SettingsContext.Provider value={contextValue}>
77
+ {children}
78
+ </SettingsContext.Provider>);
79
+ }
@@ -0,0 +1,55 @@
1
+ import { Dispatch, PropsWithChildren, SetStateAction } from "react";
2
+ import { DevInspectResults, SuiTransactionBlockResponse } from "@mysten/sui/client";
3
+ import { Transaction } from "@mysten/sui/transactions";
4
+ import { WalletAccount, WalletIcon, WalletWithRequiredFeatures } from "@mysten/wallet-standard";
5
+ export declare enum WalletType {
6
+ EXTENSION = "extension",
7
+ WEB = "web"
8
+ }
9
+ type WalletPlatform = "iOS" | "android" | "extension";
10
+ export type Wallet = {
11
+ name: string;
12
+ isInstalled?: boolean;
13
+ iconUrl?: WalletIcon;
14
+ type: WalletType;
15
+ downloadUrls?: Record<WalletPlatform, string | undefined>;
16
+ raw?: WalletWithRequiredFeatures;
17
+ };
18
+ declare enum WalletName {
19
+ SLUSH = "Slush",
20
+ BACKPACK = "Backpack",
21
+ PHANTOM = "Phantom",
22
+ NIGHTLY = "Nightly",
23
+ SUIET = "Suiet",
24
+ BYBIT_WALLET = "Bybit Wallet",
25
+ GATE_WALLET = "Gate Wallet",
26
+ OKX_WALLET = "OKX Wallet",
27
+ MSAFE_WALLET = "MSafe Wallet"
28
+ }
29
+ export declare const DEFAULT_EXTENSION_WALLET_NAMES: WalletName[];
30
+ export declare enum WalletContextQueryParams {
31
+ WALLET = "wallet"
32
+ }
33
+ export interface WalletContext {
34
+ isImpersonating?: boolean;
35
+ isConnectWalletDropdownOpen: boolean;
36
+ setIsConnectWalletDropdownOpen: Dispatch<SetStateAction<boolean>>;
37
+ wallets: Wallet[];
38
+ wallet?: Wallet;
39
+ connectWallet: (wallet: Wallet) => void;
40
+ disconnectWallet: () => void;
41
+ accounts: readonly WalletAccount[];
42
+ account?: WalletAccount;
43
+ switchAccount: (account: WalletAccount, addressNameServiceName?: string) => void;
44
+ address?: string;
45
+ dryRunTransaction: (transaction: Transaction, setGasBudget?: boolean) => Promise<DevInspectResults>;
46
+ signExecuteAndWaitForTransaction: (transaction: Transaction, options?: {
47
+ auction?: boolean;
48
+ }) => Promise<SuiTransactionBlockResponse>;
49
+ }
50
+ export declare const useWalletContext: () => WalletContext;
51
+ interface WalletContextProviderProps extends PropsWithChildren {
52
+ appName: string;
53
+ }
54
+ export declare function WalletContextProvider({ appName, children, }: WalletContextProviderProps): import("react").JSX.Element;
55
+ export {};