@luno-kit/react 0.0.10 → 0.0.11

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/dist/index.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  export * from '@luno-kit/core';
2
2
  import React, { ReactNode } from 'react';
3
- import { Config, Account, HexString, Connector, AccountBalance, Chain, PapiSigner, Signer } from '@luno-kit/core/types';
3
+ import { Config, Optional, Account, HexString, Connector, AccountBalance, Chain, PapiSigner, Signer } from '@luno-kit/core/types';
4
4
  import { LegacyClient, SubstrateRuntimeVersion } from 'dedot';
5
- import { GenericStorageQuery, Callback, TxPaymentInfo, ISubmittableExtrinsic, IEventRecord } from 'dedot/types';
5
+ import { GenericStorageQuery, Callback, TxPaymentInfo, ISubmittableExtrinsic, IEventRecord, ISubmittableResult } from 'dedot/types';
6
6
  import { ConnectionStatus, TxStatus } from './types/index.cjs';
7
7
  import { MutateOptions, UseQueryResult } from '@tanstack/react-query';
8
8
  import { DispatchError, DispatchInfo } from 'dedot/codecs';
@@ -14,31 +14,31 @@ interface LunoProviderProps {
14
14
  declare const LunoProvider: React.FC<LunoProviderProps>;
15
15
 
16
16
  interface UseAccountResult {
17
- account?: Account;
18
- address?: string;
17
+ account?: Optional<Account>;
18
+ address?: Optional<string>;
19
19
  }
20
20
  declare const useAccount: () => UseAccountResult;
21
21
 
22
22
  interface UseAccountsResult {
23
23
  accounts: Account[];
24
- selectAccount: (accountOrPublicKey?: Account | HexString) => void;
24
+ selectAccount: (accountOrPublicKey?: Optional<Account | HexString>) => void;
25
25
  }
26
26
  declare const useAccounts: () => UseAccountsResult;
27
27
 
28
28
  declare const useActiveConnector: () => Connector | undefined;
29
29
 
30
- interface UseApiResult {
31
- api?: LegacyClient;
30
+ interface UseApiResult<T extends LegacyClient = LegacyClient> {
31
+ api?: Optional<T>;
32
32
  isApiReady: boolean;
33
33
  apiError: Error | null;
34
34
  }
35
- declare const useApi: () => UseApiResult;
35
+ declare const useApi: <T extends LegacyClient = LegacyClient>() => UseApiResult<T>;
36
36
 
37
37
  type SubscriptionFn<TArgs extends any[], TData> = (...params: [...TArgs, Callback<TData>]) => Promise<() => Promise<void>>;
38
38
  interface UseSubscriptionOptions<TData, TTransformed = TData> {
39
- enabled?: boolean;
40
- transform?: (data: TData) => TTransformed;
41
- defaultValue?: TTransformed;
39
+ enabled?: Optional<boolean>;
40
+ transform?: Optional<(data: TData) => TTransformed>;
41
+ defaultValue?: Optional<TTransformed>;
42
42
  }
43
43
  type ApiBoundSubscriptionFactory<TArgs extends any[], TData> = (api: LegacyClient) => SubscriptionFn<TArgs, TData>;
44
44
  interface QueryMultiItem {
@@ -64,7 +64,7 @@ interface ChainProperties {
64
64
  tokenSymbol?: string;
65
65
  }
66
66
  interface UseBalanceProps {
67
- address?: string;
67
+ address?: Optional<string>;
68
68
  }
69
69
  type UseBalanceResult = UseSubscriptionResult<AccountBalance>;
70
70
  declare const useBalance: ({ address }: UseBalanceProps) => UseBalanceResult;
@@ -86,12 +86,12 @@ type LunoMutationOptions<TData = unknown, TError = Error, TVariables = void, TCo
86
86
 
87
87
  interface ConnectVariables {
88
88
  connectorId: string;
89
- targetChainId?: string;
89
+ targetChainId?: Optional<string>;
90
90
  }
91
91
  type UseConnectOptions = LunoMutationOptions<void, Error, ConnectVariables, unknown>;
92
92
  interface UseConnectResult {
93
- connect: (variables: ConnectVariables, options?: UseConnectOptions) => void;
94
- connectAsync: (variables: ConnectVariables, options?: UseConnectOptions) => Promise<void>;
93
+ connect: (variables: ConnectVariables, options?: Optional<UseConnectOptions>) => void;
94
+ connectAsync: (variables: ConnectVariables, options?: Optional<UseConnectOptions>) => Promise<void>;
95
95
  connectors: Connector[];
96
96
  activeConnector?: Connector;
97
97
  status: ConnectionStatus;
@@ -104,14 +104,14 @@ interface UseConnectResult {
104
104
  reset: () => void;
105
105
  variables: ConnectVariables | undefined;
106
106
  }
107
- declare const useConnect: (hookLevelConfig?: UseConnectOptions) => UseConnectResult;
107
+ declare const useConnect: (hookLevelConfig?: Optional<UseConnectOptions>) => UseConnectResult;
108
108
 
109
109
  declare const useConnectors: () => Connector[];
110
110
 
111
111
  type UseDisconnectOptions = LunoMutationOptions<void, Error, void, unknown>;
112
112
  interface UseDisconnectResult {
113
- disconnect: (options?: UseDisconnectOptions) => void;
114
- disconnectAsync: (options?: UseDisconnectOptions) => Promise<void>;
113
+ disconnect: (options?: Optional<UseDisconnectOptions>) => void;
114
+ disconnectAsync: (options?: Optional<UseDisconnectOptions>) => Promise<void>;
115
115
  status: ConnectionStatus;
116
116
  data: undefined;
117
117
  error: Error | null;
@@ -121,7 +121,7 @@ interface UseDisconnectResult {
121
121
  isSuccess: boolean;
122
122
  reset: () => void;
123
123
  }
124
- declare const useDisconnect: (hookLevelConfig?: UseDisconnectOptions) => UseDisconnectResult;
124
+ declare const useDisconnect: (hookLevelConfig?: Optional<UseDisconnectOptions>) => UseDisconnectResult;
125
125
 
126
126
  interface PaymentInfo extends TxPaymentInfo {
127
127
  partialFeeFormatted: string;
@@ -130,7 +130,7 @@ declare function useEstimatePaymentInfo(): {
130
130
  data: PaymentInfo | null;
131
131
  isLoading: boolean;
132
132
  error: Error | null;
133
- estimate: (extrinsic: ISubmittableExtrinsic, senderAddress?: string) => Promise<PaymentInfo | undefined>;
133
+ estimate: (extrinsic: ISubmittableExtrinsic, senderAddress?: Optional<string>) => Promise<PaymentInfo | undefined>;
134
134
  };
135
135
 
136
136
  interface UseGenesisHashResult {
@@ -159,14 +159,18 @@ interface TransactionReceipt {
159
159
  dispatchError?: DispatchError;
160
160
  errorMessage?: string;
161
161
  dispatchInfo?: DispatchInfo;
162
+ rawReceipt: ISubmittableResult;
162
163
  }
163
164
  interface SendTransactionVariables {
164
165
  extrinsic: ISubmittableExtrinsic;
165
166
  }
166
- type UseSendTransactionOptions = LunoMutationOptions<TransactionReceipt, Error, SendTransactionVariables, unknown>;
167
+ interface UseSendTransactionConfig {
168
+ waitFor?: Optional<'inBlock' | 'finalized'>;
169
+ }
170
+ type UseSendTransactionOptions = LunoMutationOptions<TransactionReceipt, Error, SendTransactionVariables, unknown> & UseSendTransactionConfig;
167
171
  interface UseSendTransactionResult {
168
- sendTransaction: (variables: SendTransactionVariables, options?: UseSendTransactionOptions) => void;
169
- sendTransactionAsync: (variables: SendTransactionVariables, options?: UseSendTransactionOptions) => Promise<TransactionReceipt>;
172
+ sendTransaction: (variables: SendTransactionVariables, options?: Optional<UseSendTransactionOptions>) => void;
173
+ sendTransactionAsync: (variables: SendTransactionVariables, options?: Optional<UseSendTransactionOptions>) => Promise<TransactionReceipt>;
170
174
  data: TransactionReceipt | undefined;
171
175
  error: Error | null;
172
176
  isError: boolean;
@@ -179,7 +183,7 @@ interface UseSendTransactionResult {
179
183
  txStatus: TxStatus;
180
184
  detailedStatus: DetailedTxStatus;
181
185
  }
182
- declare function useSendTransaction(hookLevelConfig?: UseSendTransactionOptions): UseSendTransactionResult;
186
+ declare function useSendTransaction(hookLevelConfig?: Optional<UseSendTransactionOptions>): UseSendTransactionResult;
183
187
 
184
188
  interface SendTransactionHashVariables {
185
189
  extrinsic: ISubmittableExtrinsic;
@@ -216,8 +220,8 @@ interface SignMessageData {
216
220
  }
217
221
  type UseSignMessageOptions = LunoMutationOptions<SignMessageData, Error, SignMessageVariables, unknown>;
218
222
  interface UseSignMessageResult {
219
- signMessage: (variables: SignMessageVariables, options?: UseSignMessageOptions) => void;
220
- signMessageAsync: (variables: SignMessageVariables, options?: UseSignMessageOptions) => Promise<SignMessageData>;
223
+ signMessage: (variables: SignMessageVariables, options?: Optional<UseSignMessageOptions>) => void;
224
+ signMessageAsync: (variables: SignMessageVariables, options?: Optional<UseSignMessageOptions>) => Promise<SignMessageData>;
221
225
  data: SignMessageData | undefined;
222
226
  error: Error | null;
223
227
  isError: boolean;
@@ -228,7 +232,7 @@ interface UseSignMessageResult {
228
232
  reset: () => void;
229
233
  variables: SignMessageVariables | undefined;
230
234
  }
231
- declare function useSignMessage(hookLevelConfig?: UseSignMessageOptions): UseSignMessageResult;
235
+ declare function useSignMessage(hookLevelConfig?: Optional<UseSignMessageOptions>): UseSignMessageResult;
232
236
 
233
237
  interface UseSs58FormatResult {
234
238
  data?: number;
@@ -243,8 +247,8 @@ interface SwitchChainVariables {
243
247
  }
244
248
  type UseSwitchChainOptions = LunoMutationOptions<void, Error, SwitchChainVariables, unknown>;
245
249
  interface UseSwitchChainResult {
246
- switchChain: (variables: SwitchChainVariables, options?: UseSwitchChainOptions) => void;
247
- switchChainAsync: (variables: SwitchChainVariables, options?: UseSwitchChainOptions) => Promise<void>;
250
+ switchChain: (variables: SwitchChainVariables, options?: Optional<UseSwitchChainOptions>) => void;
251
+ switchChainAsync: (variables: SwitchChainVariables, options?: Optional<UseSwitchChainOptions>) => Promise<void>;
248
252
  chains: Chain[];
249
253
  currentChain?: Chain;
250
254
  currentChainId?: string;
@@ -257,6 +261,6 @@ interface UseSwitchChainResult {
257
261
  reset: () => void;
258
262
  variables: SwitchChainVariables | undefined;
259
263
  }
260
- declare const useSwitchChain: (hookLevelConfig?: UseSwitchChainOptions) => UseSwitchChainResult;
264
+ declare const useSwitchChain: (hookLevelConfig?: Optional<UseSwitchChainOptions>) => UseSwitchChainResult;
261
265
 
262
- 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 UsePapiSignerResult, 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, useEstimatePaymentInfo, useGenesisHash, usePapiSigner, useRuntimeVersion, useSendTransaction, useSendTransactionHash, useSignMessage, useSigner, useSs58Format, useStatus, useSubscription, useSwitchChain };
266
+ 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 UsePapiSignerResult, type UseRuntimeVersionResult, type UseSendTransactionConfig, 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, useEstimatePaymentInfo, useGenesisHash, usePapiSigner, useRuntimeVersion, useSendTransaction, useSendTransactionHash, useSignMessage, useSigner, useSs58Format, useStatus, useSubscription, useSwitchChain };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export * from '@luno-kit/core';
2
2
  import React, { ReactNode } from 'react';
3
- import { Config, Account, HexString, Connector, AccountBalance, Chain, PapiSigner, Signer } from '@luno-kit/core/types';
3
+ import { Config, Optional, Account, HexString, Connector, AccountBalance, Chain, PapiSigner, Signer } from '@luno-kit/core/types';
4
4
  import { LegacyClient, SubstrateRuntimeVersion } from 'dedot';
5
- import { GenericStorageQuery, Callback, TxPaymentInfo, ISubmittableExtrinsic, IEventRecord } from 'dedot/types';
5
+ import { GenericStorageQuery, Callback, TxPaymentInfo, ISubmittableExtrinsic, IEventRecord, ISubmittableResult } from 'dedot/types';
6
6
  import { ConnectionStatus, TxStatus } from './types/index.js';
7
7
  import { MutateOptions, UseQueryResult } from '@tanstack/react-query';
8
8
  import { DispatchError, DispatchInfo } from 'dedot/codecs';
@@ -14,31 +14,31 @@ interface LunoProviderProps {
14
14
  declare const LunoProvider: React.FC<LunoProviderProps>;
15
15
 
16
16
  interface UseAccountResult {
17
- account?: Account;
18
- address?: string;
17
+ account?: Optional<Account>;
18
+ address?: Optional<string>;
19
19
  }
20
20
  declare const useAccount: () => UseAccountResult;
21
21
 
22
22
  interface UseAccountsResult {
23
23
  accounts: Account[];
24
- selectAccount: (accountOrPublicKey?: Account | HexString) => void;
24
+ selectAccount: (accountOrPublicKey?: Optional<Account | HexString>) => void;
25
25
  }
26
26
  declare const useAccounts: () => UseAccountsResult;
27
27
 
28
28
  declare const useActiveConnector: () => Connector | undefined;
29
29
 
30
- interface UseApiResult {
31
- api?: LegacyClient;
30
+ interface UseApiResult<T extends LegacyClient = LegacyClient> {
31
+ api?: Optional<T>;
32
32
  isApiReady: boolean;
33
33
  apiError: Error | null;
34
34
  }
35
- declare const useApi: () => UseApiResult;
35
+ declare const useApi: <T extends LegacyClient = LegacyClient>() => UseApiResult<T>;
36
36
 
37
37
  type SubscriptionFn<TArgs extends any[], TData> = (...params: [...TArgs, Callback<TData>]) => Promise<() => Promise<void>>;
38
38
  interface UseSubscriptionOptions<TData, TTransformed = TData> {
39
- enabled?: boolean;
40
- transform?: (data: TData) => TTransformed;
41
- defaultValue?: TTransformed;
39
+ enabled?: Optional<boolean>;
40
+ transform?: Optional<(data: TData) => TTransformed>;
41
+ defaultValue?: Optional<TTransformed>;
42
42
  }
43
43
  type ApiBoundSubscriptionFactory<TArgs extends any[], TData> = (api: LegacyClient) => SubscriptionFn<TArgs, TData>;
44
44
  interface QueryMultiItem {
@@ -64,7 +64,7 @@ interface ChainProperties {
64
64
  tokenSymbol?: string;
65
65
  }
66
66
  interface UseBalanceProps {
67
- address?: string;
67
+ address?: Optional<string>;
68
68
  }
69
69
  type UseBalanceResult = UseSubscriptionResult<AccountBalance>;
70
70
  declare const useBalance: ({ address }: UseBalanceProps) => UseBalanceResult;
@@ -86,12 +86,12 @@ type LunoMutationOptions<TData = unknown, TError = Error, TVariables = void, TCo
86
86
 
87
87
  interface ConnectVariables {
88
88
  connectorId: string;
89
- targetChainId?: string;
89
+ targetChainId?: Optional<string>;
90
90
  }
91
91
  type UseConnectOptions = LunoMutationOptions<void, Error, ConnectVariables, unknown>;
92
92
  interface UseConnectResult {
93
- connect: (variables: ConnectVariables, options?: UseConnectOptions) => void;
94
- connectAsync: (variables: ConnectVariables, options?: UseConnectOptions) => Promise<void>;
93
+ connect: (variables: ConnectVariables, options?: Optional<UseConnectOptions>) => void;
94
+ connectAsync: (variables: ConnectVariables, options?: Optional<UseConnectOptions>) => Promise<void>;
95
95
  connectors: Connector[];
96
96
  activeConnector?: Connector;
97
97
  status: ConnectionStatus;
@@ -104,14 +104,14 @@ interface UseConnectResult {
104
104
  reset: () => void;
105
105
  variables: ConnectVariables | undefined;
106
106
  }
107
- declare const useConnect: (hookLevelConfig?: UseConnectOptions) => UseConnectResult;
107
+ declare const useConnect: (hookLevelConfig?: Optional<UseConnectOptions>) => UseConnectResult;
108
108
 
109
109
  declare const useConnectors: () => Connector[];
110
110
 
111
111
  type UseDisconnectOptions = LunoMutationOptions<void, Error, void, unknown>;
112
112
  interface UseDisconnectResult {
113
- disconnect: (options?: UseDisconnectOptions) => void;
114
- disconnectAsync: (options?: UseDisconnectOptions) => Promise<void>;
113
+ disconnect: (options?: Optional<UseDisconnectOptions>) => void;
114
+ disconnectAsync: (options?: Optional<UseDisconnectOptions>) => Promise<void>;
115
115
  status: ConnectionStatus;
116
116
  data: undefined;
117
117
  error: Error | null;
@@ -121,7 +121,7 @@ interface UseDisconnectResult {
121
121
  isSuccess: boolean;
122
122
  reset: () => void;
123
123
  }
124
- declare const useDisconnect: (hookLevelConfig?: UseDisconnectOptions) => UseDisconnectResult;
124
+ declare const useDisconnect: (hookLevelConfig?: Optional<UseDisconnectOptions>) => UseDisconnectResult;
125
125
 
126
126
  interface PaymentInfo extends TxPaymentInfo {
127
127
  partialFeeFormatted: string;
@@ -130,7 +130,7 @@ declare function useEstimatePaymentInfo(): {
130
130
  data: PaymentInfo | null;
131
131
  isLoading: boolean;
132
132
  error: Error | null;
133
- estimate: (extrinsic: ISubmittableExtrinsic, senderAddress?: string) => Promise<PaymentInfo | undefined>;
133
+ estimate: (extrinsic: ISubmittableExtrinsic, senderAddress?: Optional<string>) => Promise<PaymentInfo | undefined>;
134
134
  };
135
135
 
136
136
  interface UseGenesisHashResult {
@@ -159,14 +159,18 @@ interface TransactionReceipt {
159
159
  dispatchError?: DispatchError;
160
160
  errorMessage?: string;
161
161
  dispatchInfo?: DispatchInfo;
162
+ rawReceipt: ISubmittableResult;
162
163
  }
163
164
  interface SendTransactionVariables {
164
165
  extrinsic: ISubmittableExtrinsic;
165
166
  }
166
- type UseSendTransactionOptions = LunoMutationOptions<TransactionReceipt, Error, SendTransactionVariables, unknown>;
167
+ interface UseSendTransactionConfig {
168
+ waitFor?: Optional<'inBlock' | 'finalized'>;
169
+ }
170
+ type UseSendTransactionOptions = LunoMutationOptions<TransactionReceipt, Error, SendTransactionVariables, unknown> & UseSendTransactionConfig;
167
171
  interface UseSendTransactionResult {
168
- sendTransaction: (variables: SendTransactionVariables, options?: UseSendTransactionOptions) => void;
169
- sendTransactionAsync: (variables: SendTransactionVariables, options?: UseSendTransactionOptions) => Promise<TransactionReceipt>;
172
+ sendTransaction: (variables: SendTransactionVariables, options?: Optional<UseSendTransactionOptions>) => void;
173
+ sendTransactionAsync: (variables: SendTransactionVariables, options?: Optional<UseSendTransactionOptions>) => Promise<TransactionReceipt>;
170
174
  data: TransactionReceipt | undefined;
171
175
  error: Error | null;
172
176
  isError: boolean;
@@ -179,7 +183,7 @@ interface UseSendTransactionResult {
179
183
  txStatus: TxStatus;
180
184
  detailedStatus: DetailedTxStatus;
181
185
  }
182
- declare function useSendTransaction(hookLevelConfig?: UseSendTransactionOptions): UseSendTransactionResult;
186
+ declare function useSendTransaction(hookLevelConfig?: Optional<UseSendTransactionOptions>): UseSendTransactionResult;
183
187
 
184
188
  interface SendTransactionHashVariables {
185
189
  extrinsic: ISubmittableExtrinsic;
@@ -216,8 +220,8 @@ interface SignMessageData {
216
220
  }
217
221
  type UseSignMessageOptions = LunoMutationOptions<SignMessageData, Error, SignMessageVariables, unknown>;
218
222
  interface UseSignMessageResult {
219
- signMessage: (variables: SignMessageVariables, options?: UseSignMessageOptions) => void;
220
- signMessageAsync: (variables: SignMessageVariables, options?: UseSignMessageOptions) => Promise<SignMessageData>;
223
+ signMessage: (variables: SignMessageVariables, options?: Optional<UseSignMessageOptions>) => void;
224
+ signMessageAsync: (variables: SignMessageVariables, options?: Optional<UseSignMessageOptions>) => Promise<SignMessageData>;
221
225
  data: SignMessageData | undefined;
222
226
  error: Error | null;
223
227
  isError: boolean;
@@ -228,7 +232,7 @@ interface UseSignMessageResult {
228
232
  reset: () => void;
229
233
  variables: SignMessageVariables | undefined;
230
234
  }
231
- declare function useSignMessage(hookLevelConfig?: UseSignMessageOptions): UseSignMessageResult;
235
+ declare function useSignMessage(hookLevelConfig?: Optional<UseSignMessageOptions>): UseSignMessageResult;
232
236
 
233
237
  interface UseSs58FormatResult {
234
238
  data?: number;
@@ -243,8 +247,8 @@ interface SwitchChainVariables {
243
247
  }
244
248
  type UseSwitchChainOptions = LunoMutationOptions<void, Error, SwitchChainVariables, unknown>;
245
249
  interface UseSwitchChainResult {
246
- switchChain: (variables: SwitchChainVariables, options?: UseSwitchChainOptions) => void;
247
- switchChainAsync: (variables: SwitchChainVariables, options?: UseSwitchChainOptions) => Promise<void>;
250
+ switchChain: (variables: SwitchChainVariables, options?: Optional<UseSwitchChainOptions>) => void;
251
+ switchChainAsync: (variables: SwitchChainVariables, options?: Optional<UseSwitchChainOptions>) => Promise<void>;
248
252
  chains: Chain[];
249
253
  currentChain?: Chain;
250
254
  currentChainId?: string;
@@ -257,6 +261,6 @@ interface UseSwitchChainResult {
257
261
  reset: () => void;
258
262
  variables: SwitchChainVariables | undefined;
259
263
  }
260
- declare const useSwitchChain: (hookLevelConfig?: UseSwitchChainOptions) => UseSwitchChainResult;
264
+ declare const useSwitchChain: (hookLevelConfig?: Optional<UseSwitchChainOptions>) => UseSwitchChainResult;
261
265
 
262
- 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 UsePapiSignerResult, 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, useEstimatePaymentInfo, useGenesisHash, usePapiSigner, useRuntimeVersion, useSendTransaction, useSendTransactionHash, useSignMessage, useSigner, useSs58Format, useStatus, useSubscription, useSwitchChain };
266
+ 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 UsePapiSignerResult, type UseRuntimeVersionResult, type UseSendTransactionConfig, 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, useEstimatePaymentInfo, useGenesisHash, usePapiSigner, useRuntimeVersion, useSendTransaction, useSendTransactionHash, useSignMessage, useSigner, useSs58Format, useStatus, useSubscription, useSwitchChain };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export{a as ConnectionStatus}from'./chunk-62JXEP3B.js';import {a,c as c$1,b}from'./chunk-A6LYVRYZ.js';export*from'@luno-kit/core';import Z,{useCallback,useEffect,useMemo,useState,useRef,useContext}from'react';import {isSameAddress,convertAddress,formatBalance,createPapiSigner}from'@luno-kit/core/utils';import {create}from'zustand';import {jsx}from'react/jsx-runtime';import {useQueryClient,useQuery,useMutation}from'@tanstack/react-query';import {isNumber}from'dedot/utils';var S={LAST_CONNECTOR_ID:"lastConnectorId",LAST_CHAIN_ID:"lastChainId",LAST_SELECTED_ACCOUNT_INFO:"lastSelectedAccountInfo",RECENT_SELECTED_ACCOUNT_INFO:"recentSelectedAccountInfo",RECENT_CONNECTOR_ID:"recentConnectorId"};var K=()=>{let e=useRef(false);return {isInitialized:e.current,markAsInitialized:()=>{e.current=true;}}};var N=[],R=()=>{N.forEach(e=>{try{e();}catch(r){console.warn("[LunoStore] Error during listener cleanup:",r);}}),N=[];},z=create((e,r)=>({config:void 0,status:"disconnected",activeConnector:void 0,accounts:[],account:void 0,currentChainId:void 0,currentChain:void 0,currentApi:void 0,isApiReady:false,apiError:null,_setConfig:async n=>{R();let s=null;try{s=await n.storage.getItem(S.LAST_CHAIN_ID);}catch(a){console.warn("[LunoStore] Failed to read stored chain ID from storage:",a);}let t=s?.toLowerCase(),o=t&&n.chains.some(a=>a.genesisHash.toLowerCase()===t)?t:n.chains[0]?.genesisHash,i=o?n.chains.find(a=>a.genesisHash.toLowerCase()===o):void 0;e({config:n,status:"disconnected",activeConnector:void 0,accounts:[],currentChainId:o,currentChain:i});},_setApi:n=>{e({currentApi:n});},_setIsApiReady:n=>{e({isApiReady:n});},setAccount:async n=>{if(!n)return;let{accounts:s,config:t}=r(),o=typeof n=="string"?n.toLowerCase():n.publicKey?.toLowerCase(),i=s.find(a=>a.publicKey?.toLowerCase()===o);if(!i)throw new Error("[LunoStore] setAccount: The provided account or address is not in the current accounts list. Ignored.");if(e({account:i}),t)try{let a={publicKey:i.publicKey,address:i.address,name:i.name,source:i.meta?.source};await t.storage.setItem(S.LAST_SELECTED_ACCOUNT_INFO,JSON.stringify(a)),await t.storage.setItem(S.RECENT_SELECTED_ACCOUNT_INFO,JSON.stringify(a)),console.log(`[LunoStore] Persisted selected account: ${i.address}`);}catch(a){console.error("[LunoStore] Failed to persist selected account:",a);}},connect:async(n,s)=>{let t=r().config;if(!t)throw e({status:"disconnected"}),new Error("[LunoStore] LunoConfig has not been initialized. Cannot connect.");let o=t.connectors.find(a=>a.id===n);if(!o)throw e({status:"disconnected"}),new Error(`[LunoStore] Connector with ID "${n}" not found in LunoConfig.`);e({status:"connecting"});let i=r().activeConnector;i&&i.id!==o.id?(console.log(`[LunoStore] Switching connector. Cleaning up listeners for old connector: ${i.id}`),R()):i&&i.id===o.id&&(console.log(`[LunoStore] Attempting to reconnect with the same connector: ${o.id}. Cleaning up existing listeners.`),R());try{let a=async l=>{if(console.log(`[LunoStore] accountsChanged event from ${o.name}:`,l),l.length===0){await r().disconnect();return}l.forEach(g=>{g.publicKey||console.warn(`[LunoStore] Account ${g.address} (from ${o.name}) is missing publicKey.`);});let b=l[0];try{let g=await t.storage.getItem(S.LAST_SELECTED_ACCOUNT_INFO),h=await t.storage.getItem(S.RECENT_SELECTED_ACCOUNT_INFO),T=g||h;if(T){let E=JSON.parse(T),I=l.find(v=>isSameAddress(v.address,E.address));I&&(b=I);}}catch(g){console.warn("[LunoStore] Failed to restore account during accountsChanged:",g);}e({accounts:l,account:b});},d=()=>{if(console.log(`[LunoStore] disconnect event from ${o.name}`),r().activeConnector?.id===o.id){R();try{t.storage.removeItem(S.LAST_CONNECTOR_ID),t.storage.removeItem(S.LAST_CHAIN_ID),console.log("[LunoStore] Removed persisted connection info from storage due to disconnect event.");}catch(l){console.error("[LunoStore] Failed to remove connection info from storage:",l);}e({status:"disconnected",activeConnector:void 0,accounts:[]});}else console.warn(`[LunoStore] Received disconnect event from an inactive connector ${o.name}. Ignored.`);};o.on("accountsChanged",a),N.push(()=>o.off("accountsChanged",a)),o.on("disconnect",d),N.push(()=>o.off("disconnect",d));let u=s||r().currentChainId||t.chains[0]?.genesisHash,m=await o.connect(t.appName,t.chains,u);if(!m||m?.length===0)throw new Error("[LunoStore] No accounts found from wallet");let f=m[0];try{let l=await t.storage.getItem(S.LAST_SELECTED_ACCOUNT_INFO),b=await t.storage.getItem(S.RECENT_SELECTED_ACCOUNT_INFO),g=l||b;if(g){let h=JSON.parse(g),T=m.find(E=>isSameAddress(E.address,h.address));T?(f=T,console.log(`[LunoStore] Restored previously selected account: ${f.address}`)):console.log("[LunoStore] Previously selected account not found in current accounts list, using first account");}}catch(l){console.warn("[LunoStore] Failed to restore selected account from storage:",l);}e({activeConnector:o,accounts:m,status:"connected",account:f});let p={publicKey:f.publicKey,address:f.address,name:f.name,source:f.meta?.source};try{t.storage.setItem(S.LAST_CONNECTOR_ID,o.id),t.storage.setItem(S.RECENT_CONNECTOR_ID,o.id),t.storage.setItem(S.LAST_SELECTED_ACCOUNT_INFO,JSON.stringify(p)),t.storage.setItem(S.RECENT_SELECTED_ACCOUNT_INFO,JSON.stringify(p)),console.log(`[LunoStore] Persisted connectorId: ${o.id}`);}catch(l){console.error("[LunoStore] Failed to persist connectorId to storage:",l);}let y=r().currentChainId,C=s||y||t.chains[0]?.genesisHash;if(C){let l=t.chains.find(b=>b.genesisHash===C);if(l){(C!==y||!r().currentApi)&&e({currentChainId:C,currentChain:l,currentApi:void 0});try{t.storage.setItem(S.LAST_CHAIN_ID,C),console.log(`[LunoStore] Persisted chainId: ${C}`);}catch(b){console.error("[LunoStore] Failed to persist chainId to storage:",b);}}else console.warn(`[LunoStore] After connection, target chain ID "${C}" was not found in config. Current chain state might not have changed. Not persisting chainId.`);}}catch(a){throw R(),e({status:"disconnected",activeConnector:void 0,accounts:[]}),new Error(`[LunoStore] Error connecting with ${o.name}: ${a?.message||a}`)}},disconnect:async()=>{let{activeConnector:n,status:s,config:t}=r();if(!n||s==="disconnecting"||s==="disconnected"){console.log("[LunoStore] No active connector or already disconnected/disconnecting. Disconnect action aborted.");return}e({status:"disconnecting"});try{if(await n.disconnect(),t)try{console.log("[LunoStore] Attempting to remove persisted connection info due to user disconnect action..."),await t.storage.removeItem(S.LAST_CONNECTOR_ID),await t.storage.removeItem(S.LAST_CHAIN_ID),await t.storage.removeItem(S.LAST_SELECTED_ACCOUNT_INFO),console.log("[LunoStore] Removed persisted connection info from storage.");}catch(o){console.error("[LunoStore] Failed to remove connection info from storage during disconnect action:",o);}R(),e({status:"disconnected",activeConnector:void 0,accounts:[],account:void 0}),r().status!=="disconnected"&&console.warn("[LunoStore] disconnect method called, but status is not yet 'disconnected' (event handler might be delayed or did not fire). Check connector events.");}catch(o){throw e({status:"connected"}),new Error(`[LunoStore] Error disconnecting from ${n.name}: ${o?.message||o}`)}},switchChain:async n=>{let{config:s,currentChainId:t,currentApi:o,activeConnector:i,account:a$1,accounts:d}=r();if(!s)throw new Error("[LunoStore] LunoConfig has not been initialized. Cannot switch chain.");if(n===t){console.log(`[LunoStore] Already on chain ${n}. No switch needed.`);return}let u=s.chains.find(m=>m.genesisHash===n);if(!u)throw new Error(`[LunoStore] Chain with ID "${n}" not found in LunoConfig.`);try{try{o&&o.status==="connected"&&await o.disconnect();}catch(f){console.warn("[LunoStore] Failed to disconnect from previous chain:",f);}console.log(`[LunoStore] Attempting to switch chain to ${u.name} (ID: ${n})`),e({currentChainId:n,currentChain:u,currentApi:void 0,isApiReady:!1,apiError:null});let m=await a({config:s,chainId:n});e({currentApi:m,isApiReady:!0}),await s.storage.setItem(S.LAST_CHAIN_ID,n);}catch(m){e({apiError:m,isApiReady:false});}},_setApiError:n=>{e({apiError:n});}}));var M=Z.createContext({});var te=({config:e,children:r})=>{let{_setConfig:n,_setApi:s,_setIsApiReady:t,_setApiError:o,setAccount:i,currentChainId:a$1,config:d,currentApi:u,connect:m,status:f,activeConnector:p,accounts:y,account:C,currentChain:l,isApiReady:b,apiError:g,disconnect:h,switchChain:T}=z(),{markAsInitialized:E,isInitialized:I}=K(),v=useCallback(()=>{s(void 0),t(false);},[s,t]);useEffect(()=>{e&&(console.log("[LunoProvider] Setting config to store:",e),n(e));},[e]),useEffect(()=>{if(I)return;if(!e||!a$1){u&&u.status==="connected"&&u.disconnect().catch(console.error),v();return}let A=e.chains.find(w=>w.genesisHash===a$1),L=e.transports[a$1];if(!A||!L){u&&u.status==="connected"&&u.disconnect().catch(console.error),v();return}u&&u.status==="connected"&&(console.log("[LunoProvider]: Disconnecting API from previous render cycle:",u.runtimeVersion.specName),u.disconnect().catch(w=>console.error("[LunoProvider] Error disconnecting previous API:",w))),v(),a({config:e,chainId:a$1}).then(w=>{s(w),t(true);}).catch(w=>{v(),o(w);}).finally(()=>E());},[e,a$1]),useEffect(()=>{e&&(async()=>{if(await c$1(500),!e.autoConnect){console.log("[LunoProvider]: AutoConnect disabled or config not set.");return}if(!e.storage){console.warn("[LunoProvider]: AutoConnect Storage not available, cannot auto-connect.");return}try{let L=await e.storage.getItem(S.LAST_CONNECTOR_ID),w=await e.storage.getItem(S.LAST_CHAIN_ID);L?(console.log(`[LunoProvider]: AutoConnect Found persisted session: Connector ID "${L}", Chain ID "${w}"`),await m(L,w||void 0)):console.log("[LunoProvider]: AutoConnect No persisted session found or missing data.");}catch(L){console.error("[LunoProvider]: AutoConnect Error during auto-connect process:",L);}})();},[e]),useEffect(()=>{if(b&&u&&l&&l.ss58Format!==void 0&&l.ss58Format!==null)try{let A=u.consts.system.ss58Prefix;A!=null&&A!==l.ss58Format?console.error(`[LunoProvider]: SS58 Format Mismatch for chain "${l.name}" (genesisHash: ${l.genesisHash}):
1
+ export{a as ConnectionStatus}from'./chunk-62JXEP3B.js';import {a,c as c$1,b}from'./chunk-A6LYVRYZ.js';export*from'@luno-kit/core';import oe,{useCallback,useEffect,useMemo,useState,useRef,useContext}from'react';import {isSameAddress,convertAddress,formatBalance,createPapiSigner}from'@luno-kit/core/utils';import {create}from'zustand';import {jsx}from'react/jsx-runtime';import {useQueryClient,useQuery,useMutation}from'@tanstack/react-query';import {isNumber}from'dedot/utils';var y={LAST_CONNECTOR_ID:"lastConnectorId",LAST_CHAIN_ID:"lastChainId",LAST_SELECTED_ACCOUNT_INFO:"lastSelectedAccountInfo",RECENT_SELECTED_ACCOUNT_INFO:"recentSelectedAccountInfo",RECENT_CONNECTOR_ID:"recentConnectorId"};var Q=()=>{let e=useRef(false);return {isInitialized:e.current,markAsInitialized:()=>{e.current=true;}}};var _=[],D=()=>{_.forEach(e=>{try{e();}catch(r){console.warn("[LunoStore] Error during listener cleanup:",r);}}),_=[];},G=create((e,r)=>({config:void 0,status:"disconnected",activeConnector:void 0,accounts:[],account:void 0,currentChainId:void 0,currentChain:void 0,currentApi:void 0,isApiReady:false,apiError:null,_setConfig:async n=>{D();let s=null;try{s=await n.storage.getItem(y.LAST_CHAIN_ID);}catch(a){console.warn("[LunoStore] Failed to read stored chain ID from storage:",a);}let t=s?.toLowerCase(),o=t&&n.chains.some(a=>a.genesisHash.toLowerCase()===t)?t:n.chains[0]?.genesisHash,i=o?n.chains.find(a=>a.genesisHash.toLowerCase()===o):void 0;e({config:n,status:"disconnected",activeConnector:void 0,accounts:[],currentChainId:o,currentChain:i});},_setApi:n=>{e({currentApi:n});},_setIsApiReady:n=>{e({isApiReady:n});},setAccount:async n=>{if(!n)return;let{accounts:s,config:t}=r(),o=typeof n=="string"?n.toLowerCase():n.publicKey?.toLowerCase(),i=s.find(a=>a.publicKey?.toLowerCase()===o);if(!i)throw new Error("[LunoStore] setAccount: The provided account or address is not in the current accounts list. Ignored.");if(e({account:i}),t)try{let a={publicKey:i.publicKey,address:i.address,name:i.name,source:i.meta?.source};await t.storage.setItem(y.LAST_SELECTED_ACCOUNT_INFO,JSON.stringify(a)),await t.storage.setItem(y.RECENT_SELECTED_ACCOUNT_INFO,JSON.stringify(a));}catch(a){console.error("[LunoStore] Failed to persist selected account:",a);}},connect:async(n,s)=>{let t=r().config;if(!t)throw e({status:"disconnected"}),new Error("[LunoStore] LunoConfig has not been initialized. Cannot connect.");let o=t.connectors.find(a=>a.id===n);if(!o)throw e({status:"disconnected"}),new Error(`[LunoStore] Connector with ID "${n}" not found in LunoConfig.`);e({status:"connecting"});let i=r().activeConnector;(i&&i.id!==o.id||i&&i.id===o.id)&&D();try{let a=async l=>{if(l.length===0){await r().disconnect();return}l.forEach(C=>{C.publicKey||console.warn(`[LunoStore] Account ${C.address} (from ${o.name}) is missing publicKey.`);});let b=l[0];try{let C=await t.storage.getItem(y.LAST_SELECTED_ACCOUNT_INFO),E=await t.storage.getItem(y.RECENT_SELECTED_ACCOUNT_INFO),g=C||E;if(g){let T=JSON.parse(g),L=l.find(w=>isSameAddress(w.address,T.address));L&&(b=L);}}catch(C){console.warn("[LunoStore] Failed to restore account during accountsChanged:",C);}e({accounts:l,account:b});},d=()=>{if(r().activeConnector?.id===o.id){D();try{t.storage.removeItem(y.LAST_CONNECTOR_ID),t.storage.removeItem(y.LAST_CHAIN_ID);}catch(l){console.error("[LunoStore] Failed to remove connection info from storage:",l);}e({status:"disconnected",activeConnector:void 0,accounts:[]});}else console.warn(`[LunoStore] Received disconnect event from an inactive connector ${o.name}. Ignored.`);};o.on("accountsChanged",a),_.push(()=>o.off("accountsChanged",a)),o.on("disconnect",d),_.push(()=>o.off("disconnect",d));let u=s||r().currentChainId||t.chains[0]?.genesisHash,f=await o.connect(t.appName,t.chains,u);if(!f||f?.length===0)throw new Error("[LunoStore] No accounts found from wallet");let m=f[0];try{let l=await t.storage.getItem(y.LAST_SELECTED_ACCOUNT_INFO),b=await t.storage.getItem(y.RECENT_SELECTED_ACCOUNT_INFO),C=l||b;if(C){let E=JSON.parse(C),g=f.find(T=>isSameAddress(T.address,E.address));g&&(m=g);}}catch(l){console.warn("[LunoStore] Failed to restore selected account from storage:",l);}e({activeConnector:o,accounts:f,status:"connected",account:m});let S={publicKey:m.publicKey,address:m.address,name:m.name,source:m.meta?.source};try{t.storage.setItem(y.LAST_CONNECTOR_ID,o.id),t.storage.setItem(y.RECENT_CONNECTOR_ID,o.id),t.storage.setItem(y.LAST_SELECTED_ACCOUNT_INFO,JSON.stringify(S)),t.storage.setItem(y.RECENT_SELECTED_ACCOUNT_INFO,JSON.stringify(S));}catch(l){console.error("[LunoStore] Failed to persist connectorId to storage:",l);}let p=r().currentChainId,h=s||p||t.chains[0]?.genesisHash;if(h){let l=t.chains.find(b=>b.genesisHash===h);if(l){(h!==p||!r().currentApi)&&e({currentChainId:h,currentChain:l,currentApi:void 0});try{t.storage.setItem(y.LAST_CHAIN_ID,h);}catch(b){console.error("[LunoStore] Failed to persist chainId to storage:",b);}}else console.warn(`[LunoStore] After connection, target chain ID "${h}" was not found in config. Current chain state might not have changed. Not persisting chainId.`);}}catch(a){throw D(),e({status:"disconnected",activeConnector:void 0,accounts:[]}),new Error(`${o.name}: ${a?.message||a}`)}},disconnect:async()=>{let{activeConnector:n,status:s,config:t}=r();if(!(!n||s==="disconnecting"||s==="disconnected")){e({status:"disconnecting"});try{if(await n.disconnect(),t)try{await t.storage.removeItem(y.LAST_CONNECTOR_ID),await t.storage.removeItem(y.LAST_CHAIN_ID),await t.storage.removeItem(y.LAST_SELECTED_ACCOUNT_INFO);}catch(o){console.error("[LunoStore] Failed to remove connection info from storage during disconnect action:",o);}D(),e({status:"disconnected",activeConnector:void 0,accounts:[],account:void 0}),r().status!=="disconnected"&&console.warn("[LunoStore] disconnect method called, but status is not yet 'disconnected' (event handler might be delayed or did not fire). Check connector events.");}catch(o){throw e({status:"connected"}),new Error(`[LunoStore] Error disconnecting from ${n.name}: ${o?.message||o}`)}}},switchChain:async n=>{let{config:s,currentChainId:t,currentApi:o,activeConnector:i,account:a$1,accounts:d}=r();if(!s)throw new Error("[LunoStore] LunoConfig has not been initialized. Cannot switch chain.");if(n===t)return;let u=s.chains.find(f=>f.genesisHash===n);if(!u)throw new Error(`[LunoStore] Chain with ID "${n}" not found in LunoConfig.`);try{try{o&&o.status==="connected"&&await o.disconnect();}catch(m){console.warn("[LunoStore] Failed to disconnect from previous chain:",m);}e({currentChainId:n,currentChain:u,currentApi:void 0,isApiReady:!1,apiError:null});let f=await a({config:s,chainId:n});e({currentApi:f,isApiReady:!0}),await s.storage.setItem(y.LAST_CHAIN_ID,n);}catch(f){e({apiError:f,isApiReady:false});}},_setApiError:n=>{e({apiError:n});}}));var k=oe.createContext({});var ie=({config:e,children:r})=>{let{_setConfig:n,_setApi:s,_setIsApiReady:t,_setApiError:o,setAccount:i,currentChainId:a$1,config:d,currentApi:u,connect:f,status:m,activeConnector:S,accounts:p,account:h,currentChain:l,isApiReady:b,apiError:C,disconnect:E,switchChain:g}=G(),{markAsInitialized:T,isInitialized:L}=Q(),w=useCallback(()=>{s(void 0),t(false);},[s,t]);useEffect(()=>{e&&n(e);},[e]),useEffect(()=>{if(L)return;if(!e||!a$1){u&&u.status==="connected"&&u.disconnect().catch(console.error),w();return}let A=e.chains.find(x=>x.genesisHash===a$1),v=e.transports[a$1];if(!A||!v){u&&u.status==="connected"&&u.disconnect().catch(console.error),w();return}u&&u.status==="connected"&&u.disconnect().catch(x=>console.error("[LunoProvider] Error disconnecting previous API:",x)),w(),a({config:e,chainId:a$1}).then(x=>{s(x),t(true);}).catch(x=>{w(),o(x);}).finally(()=>T());},[e,a$1]),useEffect(()=>{e&&(async()=>{if(await c$1(500),!!e.autoConnect){if(!e.storage){console.warn("[LunoProvider]: AutoConnect Storage not available, cannot auto-connect.");return}try{let v=await e.storage.getItem(y.LAST_CONNECTOR_ID),x=await e.storage.getItem(y.LAST_CHAIN_ID);v?await f(v,x||void 0):console.warn("[LunoProvider]: AutoConnect No persisted session found or missing data.");}catch(v){console.error("[LunoProvider]: AutoConnect Error during auto-connect process:",v);}}})();},[e]),useEffect(()=>{if(b&&u&&l&&l.ss58Format!==void 0&&l.ss58Format!==null)try{let A=u.consts.system.ss58Prefix;A!=null&&A!==l.ss58Format?console.error(`[LunoProvider]: SS58 Format Mismatch for chain "${l.name}" (genesisHash: ${l.genesisHash}):
2
2
  - Configured SS58Format: ${l.ss58Format}
3
3
  - Node Runtime SS58Format: ${A}
4
- Please verify your Luno configuration for this chain to ensure correct address display and interaction.`):A==null&&console.warn(`[LunoProvider]: Could not determine SS58 format from the API for chain "${l.name}". Cannot validate configured SS58Format (${l.ss58Format}). The application will use the configured value.`);}catch(A){console.error(`[LunoProvider]: Error retrieving SS58 format from API for chain "${l.name}" while attempting validation:`,A);}},[b,u,l]);let U=useMemo(()=>({config:d,status:f,activeConnector:p,accounts:y,account:C,setAccount:i,currentChainId:a$1,currentChain:l,currentApi:u,isApiReady:b,connect:m,disconnect:h,switchChain:T,apiError:g}),[d,f,p,y,C,a$1,l,u,b,g,m,h,T,i]);return jsx(M.Provider,{value:U,children:r})};var c=()=>{let e=useContext(M);if(e===void 0)throw new Error("useLuno must be used within a LunoProvider");return e};var D=()=>{let{account:e,currentChain:r}=c(),n=useMemo(()=>{if(e){if(!r||r?.ss58Format===void 0)return e;try{let s=convertAddress(e.address,r.ss58Format);return {...e,address:s}}catch(s){return console.error(`[useAccount]: Failed to re-format address for account ${e.address}:`,s),{...e}}}},[e,r,r?.ss58Format]);return {account:n,address:n?.address}};var ln=()=>{let{accounts:e,setAccount:r,currentChain:n}=c();return {accounts:useMemo(()=>!n||n?.ss58Format===void 0?e??[]:(e||[]).map(t=>{try{let o=convertAddress(t.address,n.ss58Format);return {...t,address:o}}catch(o){return console.error(`[useAccounts]: Failed to re-format address for account ${t.address}:`,o),{...t}}}),[e,n,n?.ss58Format]),selectAccount:r}};var fn=()=>{let{activeConnector:e}=c();return e};var hn=()=>{let{currentApi:e,isApiReady:r,apiError:n}=c();return {api:e,isApiReady:r,apiError:n}};var fe=e=>e,_=({queryKey:e,factory:r,params:n,options:s={}})=>{let[t,o]=useState(void 0),{currentApi:i,isApiReady:a}=c(),d=useQueryClient(),{enabled:u=true,transform:m=fe,defaultValue:f}=s,p=useRef(null),y=useMemo(()=>{if(!(!n||!i||!a))return typeof n=="function"?[n(i)]:n},[n,i,a]),C=useMemo(()=>[e,y,i?.genesisHash],[e,y,i?.genesisHash]);useEffect(()=>{if(p.current&&(p.current(),p.current=null),!(!u||!r||!i||!y||!a)){try{let g=r(i),h=typeof g=="function"?g.bind(i):g,T=E=>{try{let I=m(E);d.setQueryData(C,I),o(void 0);}catch(I){o(new Error(`[useSubscription]: ${I}`));}};h(...y,T).then(E=>{p.current=E;}).catch(E=>{o(new Error(`[useSubscription]: ${E}`));});}catch(g){o(new Error(`[useSubscription]: ${g}`));}return ()=>{p.current&&(p.current(),p.current=null,o(void 0));}}},[JSON.stringify(C),u,d]);let{data:l,isLoading:b}=useQuery({queryKey:C,queryFn:()=>Promise.resolve(f),enabled:false,initialData:f});return {data:l,error:t,isLoading:!!(u&&a&&!l)}};var ge=10,Se=(e,r)=>{let n=e[0],s=e[1],t=n.data.free,o=n.data.reserved,i=n.data.frozen,a=BigInt(t)+BigInt(o),d=t>i?BigInt(t)-BigInt(i):0n;return {free:t,total:a,reserved:o,transferable:d,formattedTransferable:formatBalance(d,r.tokenDecimals),formattedTotal:formatBalance(a,r.tokenDecimals),locks:s.map(u=>({id:u.id,amount:u.amount,reason:u.reasons,lockHuman:formatBalance(u.amount,r.tokenDecimals)}))}},In=({address:e})=>{let{currentApi:r,isApiReady:n,currentChain:s}=c();return _({queryKey:"/native-balance",factory:t=>t.queryMulti,params:t=>[{fn:t.query.system.account,args:[e]},{fn:t.query.balances.locks,args:[e]}],options:{enabled:!!r&&n&&!!e,transform:t=>{let o={tokenDecimals:s?.nativeCurrency?.decimals??ge,tokenSymbol:s?.nativeCurrency?.symbol,ss58Format:s?.ss58Format};return Se(t,o)}}})};var Dn=()=>{let{currentApi:e,isApiReady:r}=c();return _({queryKey:"/block-number",factory:s=>s.query.system.number,params:[],options:{enabled:!!e&&r,transform:s=>s}})};var On=()=>{let{currentChain:e,currentChainId:r}=c();return {chain:e,chainId:r}};var kn=()=>{let{config:e}=c();return e?.chains?[...e.chains]:[]};var Hn=()=>{let{config:e}=c();return e};function x(e,r){let n={};r?.onSuccess&&(n.onSuccess=r.onSuccess),r?.onError&&(n.onError=r.onError),r?.onSettled&&(n.onSettled=r.onSettled);let s=useMutation({mutationFn:e,retry:false,throwOnError:false,...n});return {mutate:(t,o)=>{s.mutate(t,o);},mutateAsync:(t,o)=>s.mutateAsync(t,o),data:s.data,error:s.error,isError:s.isError,isIdle:s.isIdle,isPending:s.isPending,isSuccess:s.isSuccess,reset:s.reset,status:s.status,variables:s.variables}}var Qn=e=>{let{connect:r,config:n,activeConnector:s,status:t}=c(),i=x(async a=>{await r(a.connectorId,a.targetChainId),await c$1();},e);return {connect:i.mutate,connectAsync:i.mutateAsync,connectors:n?.connectors?[...n.connectors]:[],activeConnector:s,status:t,data:i.data,error:i.error,isError:i.isError,isIdle:i.isIdle,isPending:i.isPending,isSuccess:i.isSuccess,reset:i.reset,variables:i.variables}};var Yn=()=>{let{config:e}=c();return e?.connectors?[...e.connectors]:[]};var Zn=e=>{let{disconnect:r,status:n}=c(),t=x(async()=>{await r();},e);return {disconnect:o=>t.mutate(void 0,o),disconnectAsync:o=>t.mutateAsync(void 0,o),status:n,data:t.data,error:t.error,isError:t.isError,isIdle:t.isIdle,isPending:t.isPending,isSuccess:t.isSuccess,reset:t.reset}};function rt(){let{account:e,currentChain:r}=c(),[n,s]=useState(null),[t,o]=useState(false),[i,a]=useState(null),d=useCallback(async(u,m)=>{let f=m||e?.address;if(!(!u||!f||!r)){o(true),a(null);try{let p=await u.paymentInfo(f),y=r.nativeCurrency.decimals,C={...p,partialFeeFormatted:formatBalance(p.partialFee,y)};return s(C),C}catch(p){let y=p instanceof Error?p:new Error("Failed to estimate payment info");a(y);}finally{o(false);}}},[e?.address,r]);return {data:n,isLoading:t,error:i,estimate:d}}var ct=()=>{let{currentApi:e,currentChainId:r,isApiReady:n}=c(),{data:s,isLoading:t,error:o}=useQuery({queryKey:["/genesis-hash",r],queryFn:async()=>await e.rpc.chain_getBlockHash(0),enabled:!!e&&n&&!!r,staleTime:1/0,gcTime:1/0,retry:false});return {data:s,isLoading:t,error:o}};var G=()=>{let{activeConnector:e}=c(),{account:r}=D(),[n,s]=useState(void 0),[t,o]=useState(false);return useEffect(()=>{if(!e||!r?.address){s(void 0),o(false);return}o(true),e.getSigner().then(i=>s(i)).catch(()=>s(void 0)).finally(()=>o(false));},[e,r?.address]),{data:n,isLoading:t}};function Ct(){let{data:e}=G(),{address:r}=D(),[n,s]=useState(false),[t,o]=useState(void 0);return useEffect(()=>{if(!e||!r){o(void 0),s(false);return}s(true),createPapiSigner(r,e).then(i=>o(i)).catch(()=>o(void 0)).finally(()=>s(false));},[e,r]),{data:t,isLoading:n}}var Et=()=>{let{currentApi:e,isApiReady:r,currentChainId:n}=c();return useQuery({queryKey:["luno","runtimeVersion",n],queryFn:async()=>await e.getRuntimeVersion(),enabled:!!e&&r&&!!n})};function Rt(e){let{activeConnector:r,currentApi:n,isApiReady:s}=c(),{account:t}=D(),[o,i]=useState("idle"),[a,d]=useState("idle"),[u,m]=useState(null),f=useCallback(async y=>{if(!n||!s)throw new Error("[useSendTransaction]: Polkadot API is not ready.");if(!r)throw new Error("[useSendTransaction]: No active connector found.");if(!t||!t.address||!t.meta?.source)throw new Error("[useSendTransaction]: No active account, address, or account metadata (source) found.");if(!y.extrinsic)throw new Error("[useSendTransaction]: No extrinsic provided to send.");let C=await r.getSigner();if(!C)throw new Error("[useSendTransaction]: Could not retrieve signer from the injector.");return i("signing"),d("idle"),new Promise((l,b$1)=>{let g;y.extrinsic.signAndSend(t.address,{signer:C},({status:h,dispatchError:T,events:E,dispatchInfo:I,txHash:v})=>{let U=L=>{g&&g(),l(L);},A=L=>{g&&g(),m(L),b$1(L);};switch(h.type){case "Broadcasting":d("broadcasting");break;case "BestChainBlockIncluded":d("inBlock");break;case "Finalized":i("success"),d("finalized"),U(T?{transactionHash:v,blockHash:h.value?.blockHash,blockNumber:h.value?.blockNumber,events:E,status:"failed",dispatchError:T,errorMessage:b(n,T),dispatchInfo:I}:{transactionHash:v,blockHash:h.value?.blockHash,blockNumber:h.value?.blockNumber,events:E,status:"success",dispatchError:void 0,errorMessage:void 0,dispatchInfo:I});break;case "Invalid":i("failed"),d("invalid"),A(new Error(`Transaction invalid: ${v}`));break;case "Drop":i("failed"),d("dropped"),A(new Error(`Transaction dropped: ${v}`));break}}).then(h=>{g=h;}).catch(h=>{i("failed"),console.error("[useSendTransaction]: Error in signAndSend promise:",h?.message||h),m(h),b$1(h);});})},[n,s,r,t,i,d]),p=x(f,e);return {sendTransaction:p.mutate,sendTransactionAsync:p.mutateAsync,data:p.data,error:u||p.error,isError:!!u||p.isError,isIdle:p.isIdle,isPending:p.isPending,isSuccess:p.isSuccess,reset:p.reset,status:p.status,variables:p.variables,txStatus:o,detailedStatus:a}}function Nt(e){let{account:r,activeConnector:n,currentApi:s,isApiReady:t}=c(),[o,i]=useState(null),a=useCallback(async u=>{if(!s||!t)throw new Error("[useSendTransactionHash]: Polkadot API is not ready.");if(!n)throw new Error("[useSendTransactionHash]: No active connector found.");if(!r||!r.address||!r.meta?.source)throw new Error("[useSendTransactionHash]: No active account, address, or account metadata (source) found.");if(!u.extrinsic)throw new Error("[useSendTransactionHash]: No extrinsic provided to send.");let m=await n.getSigner();if(!m)throw new Error("[useSendTransactionHash]: Could not retrieve signer from the injector.");try{return await u.extrinsic.signAndSend(r.address,{signer:m}).catch(p=>{throw p})}catch(f){throw i(f),f}},[s,t,n,r]),d=x(a,e);return {sendTransaction:d.mutate,sendTransactionAsync:d.mutateAsync,data:d.data,error:o||d.error,isError:!!o||d.isError,isIdle:d.isIdle,isPending:d.isPending,isSuccess:d.isSuccess,reset:d.reset,status:d.status,variables:d.variables}}function Ht(e){let{activeConnector:r,account:n,accounts:s}=c(),o=x(async i=>{if(!r)throw new Error("[useSignMessage]: No active connector found to sign the message.");if(!n||!n.address||!n.meta?.source)throw new Error("[useSignMessage]: No address provided for signing.");if(!s.some(u=>u.address===n.address))throw new Error(`[useSignMessage]: Address ${n.address} is not managed by ${r.id}.`);if(!i.message)throw new Error("[useSignMessage]: No message provided for signing.");let a=s.find(u=>isSameAddress(u.address,n.address));if(!a)throw new Error("[useSignMessage]: Invalid account address.");let d=await r.signMessage(i.message,a.address);if(!d)throw new Error("[useSignMessage]: Signature was not obtained. The user may have cancelled the request or the connector failed.");return {signature:d,rawMessage:i.message,addressUsed:n.address}},e);return {signMessage:o.mutate,signMessageAsync:o.mutateAsync,data:o.data,error:o.error,isError:o.isError,isIdle:o.isIdle,isPending:o.isPending,isSuccess:o.isSuccess,reset:o.reset,status:o.status,variables:o.variables}}var j=42,qt=()=>{let{currentApi:e,isApiReady:r,currentChain:n}=c(),s=n?.ss58Format!==void 0?n.ss58Format:j;return useMemo(()=>{if(e&&r){let t;try{let o=e.consts.system.ss58Prefix;t=isNumber(o)?o:j;}catch(o){console.error("[useSs58Format] Error fetching chainSS58:",o),t=s;}return {data:t,isLoading:false}}else return {data:void 0,isLoading:true}},[e,r,s])};var Jt=()=>{let{status:e}=c();return e};var Wt=e=>{let{switchChain:r,config:n,currentChain:s,currentChainId:t}=c(),i=x(async a=>{await r(a.chainId);},e);return {switchChain:i.mutate,switchChainAsync:i.mutateAsync,chains:n?.chains?[...n.chains]:[],currentChain:s,currentChainId:t,data:i.data,error:i.error,isError:i.isError,isIdle:i.isIdle,isPending:i.isPending,isSuccess:i.isSuccess,reset:i.reset,variables:i.variables}};export{te as LunoProvider,D as useAccount,ln as useAccounts,fn as useActiveConnector,hn as useApi,In as useBalance,Dn as useBlockNumber,On as useChain,kn as useChains,Hn as useConfig,Qn as useConnect,Yn as useConnectors,Zn as useDisconnect,rt as useEstimatePaymentInfo,ct as useGenesisHash,Ct as usePapiSigner,Et as useRuntimeVersion,Rt as useSendTransaction,Nt as useSendTransactionHash,Ht as useSignMessage,G as useSigner,qt as useSs58Format,Jt as useStatus,_ as useSubscription,Wt as useSwitchChain};//# sourceMappingURL=index.js.map
4
+ Please verify your Luno configuration for this chain to ensure correct address display and interaction.`):A==null&&console.warn(`[LunoProvider]: Could not determine SS58 format from the API for chain "${l.name}". Cannot validate configured SS58Format (${l.ss58Format}). The application will use the configured value.`);}catch(A){console.error(`[LunoProvider]: Error retrieving SS58 format from API for chain "${l.name}" while attempting validation:`,A);}},[b,u,l]);let O=useMemo(()=>({config:d,status:m,activeConnector:S,accounts:p,account:h,setAccount:i,currentChainId:a$1,currentChain:l,currentApi:u,isApiReady:b,connect:f,disconnect:E,switchChain:g,apiError:C}),[d,m,S,p,h,a$1,l,u,b,C,f,E,g,i]);return jsx(k.Provider,{value:O,children:r})};var c=()=>{let e=useContext(k);if(e===void 0)throw new Error("useLuno must be used within a LunoProvider");return e};var U=()=>{let{account:e,currentChain:r}=c(),n=useMemo(()=>{if(e){if(!r||r?.ss58Format===void 0)return e;try{let s=convertAddress(e.address,r.ss58Format);return {...e,address:s}}catch(s){return console.error(`[useAccount]: Failed to re-format address for account ${e.address}:`,s),{...e}}}},[e,r,r?.ss58Format]);return {account:n,address:n?.address}};var Sn=()=>{let{accounts:e,setAccount:r,currentChain:n}=c();return {accounts:useMemo(()=>!n||n?.ss58Format===void 0?e??[]:(e||[]).map(t=>{try{let o=convertAddress(t.address,n.ss58Format);return {...t,address:o}}catch(o){return console.error(`[useAccounts]: Failed to re-format address for account ${t.address}:`,o),{...t}}}),[e,n,n?.ss58Format]),selectAccount:r}};var hn=()=>{let{activeConnector:e}=c();return e};var En=()=>{let{currentApi:e,isApiReady:r,apiError:n}=c();return {api:e,isApiReady:r,apiError:n}};var Ce=e=>e,V=({queryKey:e,factory:r,params:n,options:s={}})=>{let[t,o]=useState(void 0),{currentApi:i,isApiReady:a}=c(),d=useQueryClient(),{enabled:u=true,transform:f=Ce,defaultValue:m}=s,S=useRef(null),p=useMemo(()=>{if(!(!n||!i||!a))return typeof n=="function"?[n(i)]:n},[n,i,a]),h=useMemo(()=>[e,p,i?.genesisHash],[e,p,i?.genesisHash]);useEffect(()=>{if(S.current&&(S.current(),S.current=null),!(!u||!r||!i||!p||!a)){try{let C=r(i),E=typeof C=="function"?C.bind(i):C,g=T=>{try{let L=f(T);d.setQueryData(h,L),o(void 0);}catch(L){o(new Error(`[useSubscription]: ${L}`));}};E(...p,g).then(T=>{S.current=T;}).catch(T=>{o(new Error(`[useSubscription]: ${T}`));});}catch(C){o(new Error(`[useSubscription]: ${C}`));}return ()=>{S.current&&(S.current(),S.current=null,o(void 0));}}},[JSON.stringify(h),u,d]);let{data:l,isLoading:b}=useQuery({queryKey:h,queryFn:()=>Promise.resolve(m),enabled:false,initialData:m});return {data:l,error:t,isLoading:!!(u&&a&&!l)}};var he=10,Te=(e,r)=>{let n=e[0],s=e[1],t=n.data.free,o=n.data.reserved,i=n.data.frozen,a=BigInt(t)+BigInt(o),d=t>i?BigInt(t)-BigInt(i):0n;return {free:t,total:a,reserved:o,transferable:d,formattedTransferable:formatBalance(d,r.tokenDecimals),formattedTotal:formatBalance(a,r.tokenDecimals),locks:s.map(u=>({id:u.id,amount:u.amount,reason:u.reasons,lockHuman:formatBalance(u.amount,r.tokenDecimals)}))}},Dn=({address:e})=>{let{currentApi:r,isApiReady:n,currentChain:s}=c();return V({queryKey:"/native-balance",factory:t=>t.queryMulti,params:t=>[{fn:t.query.system.account,args:[e]},{fn:t.query.balances.locks,args:[e]}],options:{enabled:!!r&&n&&!!e,transform:t=>{let o={tokenDecimals:s?.nativeCurrency?.decimals??he,tokenSymbol:s?.nativeCurrency?.symbol,ss58Format:s?.ss58Format};return Te(t,o)}}})};var Mn=()=>{let{currentApi:e,isApiReady:r}=c();return V({queryKey:"/block-number",factory:s=>s.query.system.number,params:[],options:{enabled:!!e&&r,transform:s=>s}})};var Fn=()=>{let{currentChain:e,currentChainId:r}=c();return {chain:e,chainId:r}};var Bn=()=>{let{config:e}=c();return e?.chains?[...e.chains]:[]};var Kn=()=>{let{config:e}=c();return e};function I(e,r){let n={};r?.onSuccess&&(n.onSuccess=r.onSuccess),r?.onError&&(n.onError=r.onError),r?.onSettled&&(n.onSettled=r.onSettled);let s=useMutation({mutationFn:e,retry:false,throwOnError:false,...n});return {mutate:(t,o)=>{s.mutate(t,o);},mutateAsync:(t,o)=>s.mutateAsync(t,o),data:s.data,error:s.error,isError:s.isError,isIdle:s.isIdle,isPending:s.isPending,isSuccess:s.isSuccess,reset:s.reset,status:s.status,variables:s.variables}}var Wn=e=>{let{connect:r,config:n,activeConnector:s,status:t}=c(),i=I(async a=>{await r(a.connectorId,a.targetChainId),await c$1();},e);return {connect:i.mutate,connectAsync:i.mutateAsync,connectors:n?.connectors?[...n.connectors]:[],activeConnector:s,status:t,data:i.data,error:i.error,isError:i.isError,isIdle:i.isIdle,isPending:i.isPending,isSuccess:i.isSuccess,reset:i.reset,variables:i.variables}};var et=()=>{let{config:e}=c();return e?.connectors?[...e.connectors]:[]};var rt=e=>{let{disconnect:r,status:n}=c(),t=I(async()=>{await r();},e);return {disconnect:o=>t.mutate(void 0,o),disconnectAsync:o=>t.mutateAsync(void 0,o),status:n,data:t.data,error:t.error,isError:t.isError,isIdle:t.isIdle,isPending:t.isPending,isSuccess:t.isSuccess,reset:t.reset}};function ut(){let{account:e,currentChain:r}=c(),[n,s]=useState(null),[t,o]=useState(false),[i,a]=useState(null),d=useCallback(async(u,f)=>{let m=f||e?.address;if(!(!u||!m||!r)){o(true),a(null);try{let S=await u.paymentInfo(m),p=r.nativeCurrency.decimals,h={...S,partialFeeFormatted:formatBalance(S.partialFee,p)};return s(h),h}catch(S){let p=S instanceof Error?S:new Error("Failed to estimate payment info");a(p);}finally{o(false);}}},[e?.address,r]);return {data:n,isLoading:t,error:i,estimate:d}}var ft=()=>{let{currentApi:e,currentChainId:r,isApiReady:n}=c(),{data:s,isLoading:t,error:o}=useQuery({queryKey:["/genesis-hash",r],queryFn:async()=>await e.rpc.chain_getBlockHash(0),enabled:!!e&&n&&!!r,staleTime:1/0,gcTime:1/0,retry:false});return {data:s,isLoading:t,error:o}};var W=()=>{let{activeConnector:e}=c(),{account:r}=U(),[n,s]=useState(void 0),[t,o]=useState(false);return useEffect(()=>{if(!e||!r?.address){s(void 0),o(false);return}o(true),e.getSigner().then(i=>s(i)).catch(()=>s(void 0)).finally(()=>o(false));},[e,r?.address]),{data:n,isLoading:t}};function At(){let{data:e}=W(),{address:r}=U(),[n,s]=useState(false),[t,o]=useState(void 0);return useEffect(()=>{if(!e||!r){o(void 0),s(false);return}s(true),createPapiSigner(r,e).then(i=>o(i)).catch(()=>o(void 0)).finally(()=>s(false));},[e,r]),{data:t,isLoading:n}}var wt=()=>{let{currentApi:e,isApiReady:r,currentChainId:n}=c();return useQuery({queryKey:["luno","runtimeVersion",n],queryFn:async()=>await e.getRuntimeVersion(),enabled:!!e&&r&&!!n})};function Nt(e){let{activeConnector:r,currentApi:n,isApiReady:s}=c(),{account:t}=U(),[o,i]=useState("idle"),[a,d]=useState("idle"),[u,f]=useState(null),m=e?.waitFor??"finalized",S=useCallback(async h=>{if(i("idle"),d("idle"),!n||!s)throw new Error("[useSendTransaction]: Polkadot API is not ready.");if(!r)throw new Error("[useSendTransaction]: No active connector found.");if(!t||!t.address||!t.meta?.source)throw new Error("[useSendTransaction]: No active account, address, or account metadata (source) found.");if(!h.extrinsic)throw new Error("[useSendTransaction]: No extrinsic provided to send.");let l=await r.getSigner();if(!l)throw new Error("[useSendTransaction]: Could not retrieve signer from the injector.");return i("signing"),new Promise((b$1,C)=>{let E;h.extrinsic.signAndSend(t.address,{signer:l},({status:g,dispatchError:T,events:L,dispatchInfo:w,txHash:O,...A})=>{let v=R=>{E&&E(),b$1(R);},x=R=>{E&&E(),f(R),C(R);},z=(R,ee,P)=>({transactionHash:O,blockHash:R,blockNumber:ee,events:L,status:!!P?"failed":"success",dispatchError:P||void 0,errorMessage:P?b(n,P):void 0,dispatchInfo:w,rawReceipt:{status:g,dispatchError:T,events:L,dispatchInfo:w,txHash:O,...A}});switch(g.type){case "Broadcasting":i("pending"),d("broadcasting");break;case "BestChainBlockIncluded":i("pending"),d("inBlock"),m==="inBlock"&&(i(T?"failed":"success"),v(z(g.value?.blockHash,g.value?.blockNumber,T)));break;case "Finalized":d("finalized"),m==="finalized"&&(i(T?"failed":"success"),v(z(g.value?.blockHash,g.value?.blockNumber,T)));break;case "Invalid":i("failed"),d("invalid"),x(new Error(`Transaction invalid: ${O}`));break;case "Drop":i("failed"),d("dropped"),x(new Error(`Transaction dropped: ${O}`));break}}).then(g=>{E=g;}).catch(g=>{i("failed"),console.error("[useSendTransaction]: Error in signAndSend promise:",g?.message||g),f(g),C(g);});})},[n,s,r,t,i,d,m]),p=I(S,e);return {sendTransaction:p.mutate,sendTransactionAsync:p.mutateAsync,data:p.data,error:u||p.error,isError:!!u||p.isError,isIdle:p.isIdle,isPending:p.isPending,isSuccess:p.isSuccess,reset:p.reset,status:p.status,variables:p.variables,txStatus:o,detailedStatus:a}}function Vt(e){let{account:r,activeConnector:n,currentApi:s,isApiReady:t}=c(),[o,i]=useState(null),a=useCallback(async u=>{if(!s||!t)throw new Error("[useSendTransactionHash]: Polkadot API is not ready.");if(!n)throw new Error("[useSendTransactionHash]: No active connector found.");if(!r||!r.address||!r.meta?.source)throw new Error("[useSendTransactionHash]: No active account, address, or account metadata (source) found.");if(!u.extrinsic)throw new Error("[useSendTransactionHash]: No extrinsic provided to send.");let f=await n.getSigner();if(!f)throw new Error("[useSendTransactionHash]: Could not retrieve signer from the injector.");try{return await u.extrinsic.signAndSend(r.address,{signer:f}).catch(S=>{throw S})}catch(m){throw i(m),m}},[s,t,n,r]),d=I(a,e);return {sendTransaction:d.mutate,sendTransactionAsync:d.mutateAsync,data:d.data,error:o||d.error,isError:!!o||d.isError,isIdle:d.isIdle,isPending:d.isPending,isSuccess:d.isSuccess,reset:d.reset,status:d.status,variables:d.variables}}function Kt(e){let{activeConnector:r,account:n,accounts:s}=c(),o=I(async i=>{if(!r)throw new Error("[useSignMessage]: No active connector found to sign the message.");if(!n||!n.address||!n.meta?.source)throw new Error("[useSignMessage]: No address provided for signing.");if(!s.some(u=>u.address===n.address))throw new Error(`[useSignMessage]: Address ${n.address} is not managed by ${r.id}.`);if(!i.message)throw new Error("[useSignMessage]: No message provided for signing.");let a=s.find(u=>isSameAddress(u.address,n.address));if(!a)throw new Error("[useSignMessage]: Invalid account address.");let d=await r.signMessage(i.message,a.address);if(!d)throw new Error("[useSignMessage]: Signature was not obtained. The user may have cancelled the request or the connector failed.");return {signature:d,rawMessage:i.message,addressUsed:n.address}},e);return {signMessage:o.mutate,signMessageAsync:o.mutateAsync,data:o.data,error:o.error,isError:o.isError,isIdle:o.isIdle,isPending:o.isPending,isSuccess:o.isSuccess,reset:o.reset,status:o.status,variables:o.variables}}var Z=42,Yt=()=>{let{currentApi:e,isApiReady:r,currentChain:n}=c(),s=n?.ss58Format!==void 0?n.ss58Format:Z;return useMemo(()=>{if(e&&r){let t;try{let o=e.consts.system.ss58Prefix;t=isNumber(o)?o:Z;}catch(o){console.error("[useSs58Format] Error fetching chainSS58:",o),t=s;}return {data:t,isLoading:false}}else return {data:void 0,isLoading:true}},[e,r,s])};var Xt=()=>{let{status:e}=c();return e};var to=e=>{let{switchChain:r,config:n,currentChain:s,currentChainId:t}=c(),i=I(async a=>{await r(a.chainId);},e);return {switchChain:i.mutate,switchChainAsync:i.mutateAsync,chains:n?.chains?[...n.chains]:[],currentChain:s,currentChainId:t,data:i.data,error:i.error,isError:i.isError,isIdle:i.isIdle,isPending:i.isPending,isSuccess:i.isSuccess,reset:i.reset,variables:i.variables}};export{ie as LunoProvider,U as useAccount,Sn as useAccounts,hn as useActiveConnector,En as useApi,Dn as useBalance,Mn as useBlockNumber,Fn as useChain,Bn as useChains,Kn as useConfig,Wn as useConnect,et as useConnectors,rt as useDisconnect,ut as useEstimatePaymentInfo,ft as useGenesisHash,At as usePapiSigner,wt as useRuntimeVersion,Nt as useSendTransaction,Vt as useSendTransactionHash,Kt as useSignMessage,W as useSigner,Yt as useSs58Format,Xt as useStatus,V as useSubscription,to as useSwitchChain};//# sourceMappingURL=index.js.map
5
5
  //# sourceMappingURL=index.js.map