@luno-kit/react 0.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.
@@ -0,0 +1,256 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { Config, Account, Connector, AccountBalance, Chain, Signer } from '@luno-kit/core';
3
+ export * from '@luno-kit/core';
4
+ import { LegacyClient, SubstrateRuntimeVersion } from 'dedot';
5
+ import { HexString } from 'dedot/utils';
6
+ import { Callback, IEventRecord, ISubmittableExtrinsic } from 'dedot/types';
7
+ import { MutateOptions, UseQueryResult } from '@tanstack/react-query';
8
+ import { DispatchError, DispatchInfo } from 'dedot/codecs';
9
+
10
+ interface LunoProviderProps {
11
+ config: Config;
12
+ children: ReactNode;
13
+ }
14
+ declare const LunoProvider: React.FC<LunoProviderProps>;
15
+
16
+ declare enum ConnectionStatus {
17
+ Disconnected = "disconnected",
18
+ Connecting = "connecting",
19
+ Disconnecting = "disconnecting",
20
+ Connected = "connected"
21
+ }
22
+
23
+ type TxStatus = 'idle' | 'signing' | 'pending' | 'success' | 'failed';
24
+
25
+ interface UseApiResult {
26
+ api?: LegacyClient;
27
+ isApiReady: boolean;
28
+ apiError: Error | null;
29
+ }
30
+ declare const useApi: () => UseApiResult;
31
+
32
+ interface UseAccountResult {
33
+ account?: Account;
34
+ address?: string;
35
+ }
36
+ declare const useAccount: () => UseAccountResult;
37
+
38
+ interface UseAccountsResult {
39
+ accounts: Account[];
40
+ selectAccount: (accountOrAddress?: Account | HexString) => void;
41
+ }
42
+ declare const useAccounts: () => UseAccountsResult;
43
+
44
+ declare const useActiveConnector: () => Connector | undefined;
45
+
46
+ type SubscriptionFn<TArgs extends any[], TData> = (...params: [...TArgs, Callback<TData>]) => Promise<() => Promise<void>>;
47
+ interface UseSubscriptionOptions<TData, TTransformed = TData> {
48
+ enabled?: boolean;
49
+ transform?: (data: TData) => TTransformed;
50
+ defaultValue?: TTransformed;
51
+ }
52
+ type ApiBoundSubscriptionFactory<TArgs extends any[], TData> = (api: LegacyClient) => SubscriptionFn<TArgs, TData>;
53
+ interface QueryMultiItem {
54
+ fn: any;
55
+ args: any[];
56
+ }
57
+ interface UseSubscriptionProps<TArgs extends any[], TData, TTransformed = TData> {
58
+ queryKey: string | number;
59
+ factory: ApiBoundSubscriptionFactory<TArgs, TData> | ((api: LegacyClient) => any);
60
+ params: TArgs | ((api: LegacyClient) => QueryMultiItem[]);
61
+ options?: UseSubscriptionOptions<TData, TTransformed>;
62
+ }
63
+ interface UseSubscriptionResult<TTransformed> {
64
+ data?: TTransformed;
65
+ error?: Error;
66
+ isLoading: boolean;
67
+ }
68
+ declare const useSubscription: <TArgs extends any[], TData, TTransformed = TData>({ queryKey: userQueryKey, factory, params, options }: UseSubscriptionProps<TArgs, TData, TTransformed>) => UseSubscriptionResult<TTransformed>;
69
+
70
+ interface ChainProperties {
71
+ ss58Format?: number;
72
+ tokenDecimals?: number;
73
+ tokenSymbol?: string;
74
+ }
75
+ interface UseBalanceProps {
76
+ address?: string;
77
+ }
78
+ type UseBalanceResult = UseSubscriptionResult<AccountBalance>;
79
+ declare const useBalance: ({ address }: UseBalanceProps) => UseBalanceResult;
80
+
81
+ type UseBlockNumberResult = UseSubscriptionResult<number>;
82
+ declare const useBlockNumber: () => UseBlockNumberResult;
83
+
84
+ interface UseChainResult {
85
+ chain?: Chain;
86
+ chainId?: string;
87
+ }
88
+ declare const useChain: () => UseChainResult;
89
+
90
+ declare const useChains: () => Chain[];
91
+
92
+ declare const useConnectors: () => Connector[];
93
+
94
+ declare const useConfig: () => Config | undefined;
95
+
96
+ type LunoMutationOptions<TData = unknown, TError = Error, TVariables = void, TContext = unknown> = Partial<Pick<MutateOptions<TData, TError, TVariables, TContext>, 'onSuccess' | 'onError' | 'onSettled'>>;
97
+
98
+ interface ConnectVariables {
99
+ connectorId: string;
100
+ targetChainId?: string;
101
+ }
102
+ type UseConnectOptions = LunoMutationOptions<void, Error, ConnectVariables, unknown>;
103
+ interface UseConnectResult {
104
+ connect: (variables: ConnectVariables, options?: UseConnectOptions) => void;
105
+ connectAsync: (variables: ConnectVariables, options?: UseConnectOptions) => Promise<void>;
106
+ connectors: Connector[];
107
+ activeConnector?: Connector;
108
+ status: ConnectionStatus;
109
+ data: void | undefined;
110
+ error: Error | null;
111
+ isError: boolean;
112
+ isIdle: boolean;
113
+ isPending: boolean;
114
+ isSuccess: boolean;
115
+ reset: () => void;
116
+ variables: ConnectVariables | undefined;
117
+ }
118
+ declare const useConnect: (hookLevelConfig?: UseConnectOptions) => UseConnectResult;
119
+
120
+ type UseDisconnectOptions = LunoMutationOptions<void, Error, void, unknown>;
121
+ interface UseDisconnectResult {
122
+ disconnect: (options?: UseDisconnectOptions) => void;
123
+ disconnectAsync: (options?: UseDisconnectOptions) => Promise<void>;
124
+ status: ConnectionStatus;
125
+ data: void | undefined;
126
+ error: Error | null;
127
+ isError: boolean;
128
+ isIdle: boolean;
129
+ isPending: boolean;
130
+ isSuccess: boolean;
131
+ reset: () => void;
132
+ variables: void | undefined;
133
+ }
134
+ declare const useDisconnect: (hookLevelConfig?: UseDisconnectOptions) => UseDisconnectResult;
135
+
136
+ interface UseGenesisHashResult {
137
+ data?: HexString;
138
+ error: Error | null;
139
+ isLoading: boolean;
140
+ }
141
+ declare const useGenesisHash: () => UseGenesisHashResult;
142
+
143
+ type UseRuntimeVersionResult = UseQueryResult<SubstrateRuntimeVersion, Error>;
144
+ declare const useRuntimeVersion: () => UseRuntimeVersionResult;
145
+
146
+ type DetailedTxStatus = 'idle' | 'broadcasting' | 'inBlock' | 'finalized' | 'invalid' | 'dropped';
147
+ interface TransactionReceipt {
148
+ transactionHash: HexString;
149
+ blockHash: HexString;
150
+ blockNumber?: number;
151
+ readonly events: IEventRecord[];
152
+ status: 'failed' | 'success';
153
+ dispatchError?: DispatchError;
154
+ errorMessage?: string;
155
+ dispatchInfo?: DispatchInfo;
156
+ }
157
+ interface SendTransactionVariables {
158
+ extrinsic: ISubmittableExtrinsic;
159
+ }
160
+ type UseSendTransactionOptions = LunoMutationOptions<TransactionReceipt, Error, SendTransactionVariables, unknown>;
161
+ interface UseSendTransactionResult {
162
+ sendTransaction: (variables: SendTransactionVariables, options?: UseSendTransactionOptions) => void;
163
+ sendTransactionAsync: (variables: SendTransactionVariables, options?: UseSendTransactionOptions) => Promise<TransactionReceipt>;
164
+ data: TransactionReceipt | undefined;
165
+ error: Error | null;
166
+ isError: boolean;
167
+ isIdle: boolean;
168
+ isPending: boolean;
169
+ isSuccess: boolean;
170
+ status: 'idle' | 'pending' | 'error' | 'success';
171
+ reset: () => void;
172
+ variables: SendTransactionVariables | undefined;
173
+ txStatus: TxStatus;
174
+ detailedStatus: DetailedTxStatus;
175
+ }
176
+ declare function useSendTransaction(hookLevelConfig?: UseSendTransactionOptions): UseSendTransactionResult;
177
+
178
+ interface SendTransactionHashVariables {
179
+ extrinsic: ISubmittableExtrinsic;
180
+ }
181
+ type UseSendTransactionHashOptions = LunoMutationOptions<HexString, Error, SendTransactionHashVariables, unknown>;
182
+ interface UseSendTransactionHashResult {
183
+ sendTransaction: (variables: SendTransactionHashVariables, options?: UseSendTransactionHashOptions) => void;
184
+ sendTransactionAsync: (variables: SendTransactionHashVariables, options?: UseSendTransactionHashOptions) => Promise<HexString>;
185
+ data: HexString | undefined;
186
+ error: Error | null;
187
+ isError: boolean;
188
+ isIdle: boolean;
189
+ isPending: boolean;
190
+ isSuccess: boolean;
191
+ status: 'idle' | 'pending' | 'error' | 'success';
192
+ reset: () => void;
193
+ variables: SendTransactionHashVariables | undefined;
194
+ }
195
+ declare function useSendTransactionHash(hookLevelConfig?: UseSendTransactionHashOptions): UseSendTransactionHashResult;
196
+
197
+ interface SignMessageVariables {
198
+ message: string;
199
+ }
200
+ interface SignMessageData {
201
+ signature: string;
202
+ rawMessage: string;
203
+ addressUsed: string;
204
+ }
205
+ type UseSignMessageOptions = LunoMutationOptions<SignMessageData, Error, SignMessageVariables, unknown>;
206
+ interface UseSignMessageResult {
207
+ signMessage: (variables: SignMessageVariables, options?: UseSignMessageOptions) => void;
208
+ signMessageAsync: (variables: SignMessageVariables, options?: UseSignMessageOptions) => Promise<SignMessageData>;
209
+ data: SignMessageData | undefined;
210
+ error: Error | null;
211
+ isError: boolean;
212
+ isIdle: boolean;
213
+ isPending: boolean;
214
+ isSuccess: boolean;
215
+ status: 'idle' | 'pending' | 'error' | 'success';
216
+ reset: () => void;
217
+ variables: SignMessageVariables | undefined;
218
+ }
219
+ declare function useSignMessage(hookLevelConfig?: UseSignMessageOptions): UseSignMessageResult;
220
+
221
+ interface UseSs58FormatResult {
222
+ data?: number;
223
+ isLoading: boolean;
224
+ }
225
+ declare const useSs58Format: () => UseSs58FormatResult;
226
+
227
+ declare const useStatus: () => ConnectionStatus;
228
+
229
+ interface SwitchChainVariables {
230
+ chainId: string;
231
+ }
232
+ type UseSwitchChainOptions = LunoMutationOptions<void, Error, SwitchChainVariables, unknown>;
233
+ interface UseSwitchChainResult {
234
+ switchChain: (variables: SwitchChainVariables, options?: UseSwitchChainOptions) => void;
235
+ switchChainAsync: (variables: SwitchChainVariables, options?: UseSwitchChainOptions) => Promise<void>;
236
+ chains: Chain[];
237
+ currentChain?: Chain;
238
+ currentChainId?: string;
239
+ data: void | undefined;
240
+ error: Error | null;
241
+ isError: boolean;
242
+ isIdle: boolean;
243
+ isPending: boolean;
244
+ isSuccess: boolean;
245
+ reset: () => void;
246
+ variables: SwitchChainVariables | undefined;
247
+ }
248
+ declare const useSwitchChain: (hookLevelConfig?: UseSwitchChainOptions) => UseSwitchChainResult;
249
+
250
+ interface UseSignerResult {
251
+ signer?: Signer;
252
+ isLoading: boolean;
253
+ }
254
+ declare const useSigner: () => UseSignerResult;
255
+
256
+ export { type ChainProperties, type ConnectVariables, ConnectionStatus, type DetailedTxStatus, LunoProvider, type QueryMultiItem, type SendTransactionHashVariables, type SendTransactionVariables, type SignMessageData, type SignMessageVariables, type SwitchChainVariables, type TransactionReceipt, type UseAccountResult, type UseAccountsResult, type UseApiResult, type UseBalanceProps, type UseBalanceResult, type UseBlockNumberResult, type UseChainResult, type UseConnectOptions, type UseConnectResult, type UseDisconnectOptions, type UseDisconnectResult, type UseGenesisHashResult, type UseRuntimeVersionResult, type UseSendTransactionHashOptions, type UseSendTransactionHashResult, type UseSendTransactionOptions, type UseSendTransactionResult, type UseSignMessageOptions, type UseSignMessageResult, type UseSignerResult, type UseSs58FormatResult, type UseSubscriptionOptions, type UseSubscriptionProps, type UseSubscriptionResult, type UseSwitchChainOptions, type UseSwitchChainResult, useAccount, useAccounts, useActiveConnector, useApi, useBalance, useBlockNumber, useChain, useChains, useConfig, useConnect, useConnectors, useDisconnect, useGenesisHash, useRuntimeVersion, useSendTransaction, useSendTransactionHash, useSignMessage, useSigner, useSs58Format, useStatus, useSubscription, useSwitchChain };