@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 +8 -0
- package/contexts/SettingsContext.d.ts +17 -0
- package/contexts/SettingsContext.jsx +79 -0
- package/contexts/WalletContext.d.ts +55 -0
- package/contexts/WalletContext.jsx +616 -0
- package/contexts/index.d.ts +2 -0
- package/contexts/index.js +2 -0
- package/fetchers/index.d.ts +1 -0
- package/fetchers/index.js +1 -0
- package/fetchers/useFetchBalances.d.ts +5 -0
- package/fetchers/useFetchBalances.js +94 -0
- package/hooks/index.d.ts +5 -0
- package/hooks/index.js +5 -0
- package/hooks/useCoinMetadataMap.d.ts +3 -0
- package/hooks/useCoinMetadataMap.js +76 -0
- package/hooks/useIsAndroid.d.ts +2 -0
- package/hooks/useIsAndroid.jsx +2 -0
- package/hooks/useIsTouchscreen.d.ts +2 -0
- package/hooks/useIsTouchscreen.jsx +7 -0
- package/hooks/useIsiOS.d.ts +2 -0
- package/hooks/useIsiOS.jsx +7 -0
- package/hooks/useRefreshOnBalancesChange.d.ts +2 -0
- package/hooks/useRefreshOnBalancesChange.js +82 -0
- package/index.d.ts +4 -0
- package/index.js +4 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/router.d.ts +4 -0
- package/lib/router.js +2 -0
- package/lib/toasts.d.ts +5 -0
- package/lib/toasts.jsx +55 -0
- package/package.json +1 -0
- package/tsconfig.tsbuildinfo +1 -0
package/README.md
ADDED
|
@@ -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 {};
|