@tuwaio/pulsar-core 1.0.0-fix-retry-actions-alpha.3.fe1128f → 1.0.0-fix-callbacks-alpha.1.227594b
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 +1 -9
- package/dist/index.d.mts +101 -101
- package/dist/index.d.ts +101 -101
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,20 +62,12 @@ import { wagmiConfig, chains } from './path/to/your/wagmi/config';
|
|
|
62
62
|
const pulsarStore = createPulsarStore({
|
|
63
63
|
// A unique name for Zustand's persistence middleware. This will be the key in localStorage.
|
|
64
64
|
name: 'my-app-pulsar-storage',
|
|
65
|
-
|
|
66
65
|
// An array of adapters for different blockchain ecosystems.
|
|
67
66
|
// Each adapter provides chain-specific logic.
|
|
68
|
-
|
|
67
|
+
adapter: [
|
|
69
68
|
evmAdapter(wagmiConfig, chains),
|
|
70
69
|
// ... add other adapters like solanaAdapter here
|
|
71
70
|
],
|
|
72
|
-
|
|
73
|
-
// (Optional) A callback function to execute on every successful transaction.
|
|
74
|
-
// Ideal for global logic like showing a success notification.
|
|
75
|
-
onSucceedCallbacks: (tx) => {
|
|
76
|
-
console.log('Transaction succeeded!', tx);
|
|
77
|
-
// e.g., showToast('Success!', { type: 'success' });
|
|
78
|
-
},
|
|
79
71
|
});
|
|
80
72
|
|
|
81
73
|
export default pulsarStore;
|
package/dist/index.d.mts
CHANGED
|
@@ -25,6 +25,20 @@ declare enum TransactionAdapter {
|
|
|
25
25
|
/** For the Starknet L2 network. */
|
|
26
26
|
Starknet = "starknet"
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Enum representing the different tracking strategies available for EVM transactions.
|
|
30
|
+
* Each tracker corresponds to a specific method of monitoring a transaction's lifecycle.
|
|
31
|
+
*/
|
|
32
|
+
declare enum TransactionTracker {
|
|
33
|
+
/** For standard on-chain EVM transactions tracked by their hash. */
|
|
34
|
+
Ethereum = "ethereum",
|
|
35
|
+
/** For multi-signature transactions managed and executed via a Safe contract. */
|
|
36
|
+
Safe = "safe",
|
|
37
|
+
/** For meta-transactions relayed and executed by the Gelato Network. */
|
|
38
|
+
Gelato = "gelato",
|
|
39
|
+
/** The tracker for monitoring standard Solana transaction signatures. */
|
|
40
|
+
Solana = "solana"
|
|
41
|
+
}
|
|
28
42
|
/**
|
|
29
43
|
* Represents the terminal status of a transaction after it has been processed.
|
|
30
44
|
*/
|
|
@@ -36,12 +50,29 @@ declare enum TransactionStatus {
|
|
|
36
50
|
/** The transaction was replaced by another with the same nonce (e.g., a speed-up or cancel). */
|
|
37
51
|
Replaced = "Replaced"
|
|
38
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Defines the shape of the identifier for a Gelato transaction task.
|
|
55
|
+
*/
|
|
56
|
+
type GelatoTxKey = {
|
|
57
|
+
taskId: string;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* A union type representing the unique identifier returned by an `actionFunction`
|
|
61
|
+
* after a transaction is submitted to the network or a relay service.
|
|
62
|
+
*
|
|
63
|
+
* This key is crucial for the EVM adapter to determine which tracker should
|
|
64
|
+
* monitor the transaction.
|
|
65
|
+
*
|
|
66
|
+
* It can be one of the following:
|
|
67
|
+
* - A standard `0x...` transaction hash (`Hex`).
|
|
68
|
+
* - A structured object from a relay service like Gelato (`GelatoTxKey`).
|
|
69
|
+
*/
|
|
70
|
+
type ActionTxKey = `0x${string}` | GelatoTxKey | string;
|
|
39
71
|
/**
|
|
40
72
|
* The fundamental structure for any transaction being tracked by Pulsar.
|
|
41
73
|
* This serves as the base upon which chain-specific transaction types are built.
|
|
42
|
-
* @template T The type of the tracker identifier (e.g., 'ethereum', 'gelato').
|
|
43
74
|
*/
|
|
44
|
-
type BaseTransaction
|
|
75
|
+
type BaseTransaction = {
|
|
45
76
|
/** The chain identifier (e.g., 1 for Ethereum Mainnet, 'SN_MAIN' for Starknet). */
|
|
46
77
|
chainId: number | string;
|
|
47
78
|
/**
|
|
@@ -81,7 +112,7 @@ type BaseTransaction<T> = {
|
|
|
81
112
|
*/
|
|
82
113
|
title?: string | [string, string, string, string];
|
|
83
114
|
/** The specific tracker responsible for monitoring this transaction's status. */
|
|
84
|
-
tracker:
|
|
115
|
+
tracker: TransactionTracker;
|
|
85
116
|
/** The unique identifier for the transaction (e.g., EVM hash, Gelato task ID). */
|
|
86
117
|
txKey: string;
|
|
87
118
|
/** The application-specific type or category of the transaction (e.g., 'SWAP', 'APPROVE'). */
|
|
@@ -91,9 +122,8 @@ type BaseTransaction<T> = {
|
|
|
91
122
|
};
|
|
92
123
|
/**
|
|
93
124
|
* Represents an EVM-specific transaction, extending the base properties with EVM fields.
|
|
94
|
-
* @template T The type of the tracker identifier.
|
|
95
125
|
*/
|
|
96
|
-
type EvmTransaction
|
|
126
|
+
type EvmTransaction = BaseTransaction & {
|
|
97
127
|
adapter: TransactionAdapter.EVM;
|
|
98
128
|
/** The on-chain transaction hash, available after submission. */
|
|
99
129
|
hash?: `0x${string}`;
|
|
@@ -114,9 +144,8 @@ type EvmTransaction<T> = BaseTransaction<T> & {
|
|
|
114
144
|
};
|
|
115
145
|
/**
|
|
116
146
|
* Represents a Solana-specific transaction, extending the base properties.
|
|
117
|
-
* @template T The type of the tracker identifier.
|
|
118
147
|
*/
|
|
119
|
-
type SolanaTransaction
|
|
148
|
+
type SolanaTransaction = BaseTransaction & {
|
|
120
149
|
adapter: TransactionAdapter.SOLANA;
|
|
121
150
|
/** The transaction fee in lamports. */
|
|
122
151
|
fee?: number;
|
|
@@ -126,16 +155,15 @@ type SolanaTransaction<T> = BaseTransaction<T> & {
|
|
|
126
155
|
recentBlockhash?: string;
|
|
127
156
|
/** The slot in which the transaction was processed. */
|
|
128
157
|
slot?: number;
|
|
129
|
-
/** The number of confirmations received. `null` if the transaction is pending or unconfirmed. */
|
|
130
|
-
confirmations?: number | null;
|
|
158
|
+
/** The number of confirmations received. `string` when tx successed. `null` if the transaction is pending or unconfirmed. */
|
|
159
|
+
confirmations?: number | string | null;
|
|
131
160
|
/** The RPC URL used to submit and track this transaction. */
|
|
132
161
|
rpcUrl?: string;
|
|
133
162
|
};
|
|
134
163
|
/**
|
|
135
164
|
* Represents a Starknet-specific transaction, extending the base properties.
|
|
136
|
-
* @template T The type of the tracker identifier.
|
|
137
165
|
*/
|
|
138
|
-
type StarknetTransaction
|
|
166
|
+
type StarknetTransaction = BaseTransaction & {
|
|
139
167
|
adapter: TransactionAdapter.Starknet;
|
|
140
168
|
/** The actual fee paid for the transaction. */
|
|
141
169
|
actualFee?: {
|
|
@@ -144,18 +172,16 @@ type StarknetTransaction<T> = BaseTransaction<T> & {
|
|
|
144
172
|
};
|
|
145
173
|
/** The address of the contract being interacted with. */
|
|
146
174
|
contractAddress?: string;
|
|
147
|
-
/** The reason for transaction failure, if applicable. */
|
|
148
|
-
revertReason?: string;
|
|
149
175
|
};
|
|
150
176
|
/** A union type representing any possible transaction structure that Pulsar can handle. */
|
|
151
|
-
type Transaction
|
|
177
|
+
type Transaction = EvmTransaction | SolanaTransaction | StarknetTransaction;
|
|
152
178
|
/**
|
|
153
179
|
* Represents the parameters required to initiate a new transaction tracking flow.
|
|
154
180
|
*/
|
|
155
|
-
type InitialTransactionParams
|
|
181
|
+
type InitialTransactionParams = {
|
|
156
182
|
adapter: TransactionAdapter;
|
|
157
183
|
/** The function that executes the on-chain action (e.g., sending a transaction) and returns a preliminary identifier like a hash. */
|
|
158
|
-
actionFunction: (...args: any[]) => Promise<
|
|
184
|
+
actionFunction: (...args: any[]) => Promise<ActionTxKey | undefined>;
|
|
159
185
|
/** A user-facing description for the transaction. Supports state-specific descriptions. */
|
|
160
186
|
description?: string | [string, string, string, string];
|
|
161
187
|
/** The target chain ID for the transaction. */
|
|
@@ -175,7 +201,7 @@ type InitialTransactionParams<A> = {
|
|
|
175
201
|
* Represents a transaction in its temporary, pre-submission state.
|
|
176
202
|
* This is used for UI feedback while the transaction is being signed and sent.
|
|
177
203
|
*/
|
|
178
|
-
type InitialTransaction
|
|
204
|
+
type InitialTransaction = InitialTransactionParams & {
|
|
179
205
|
/** An error message if the initialization fails (e.g., user rejects signature). */
|
|
180
206
|
errorMessage?: string;
|
|
181
207
|
/** A flag indicating if the transaction is being processed (e.g., waiting for signature). */
|
|
@@ -187,11 +213,9 @@ type InitialTransaction<A> = InitialTransactionParams<A> & {
|
|
|
187
213
|
};
|
|
188
214
|
/**
|
|
189
215
|
* Defines the interface for a transaction adapter, which provides chain-specific logic and utilities.
|
|
190
|
-
* @template
|
|
191
|
-
* @template T The specific transaction type, extending `Transaction<TR>`.
|
|
192
|
-
* @template A The type of the key returned by the `actionFunction` (e.g., a transaction hash).
|
|
216
|
+
* @template T The specific transaction type, extending `Transaction`.
|
|
193
217
|
*/
|
|
194
|
-
type TxAdapter<
|
|
218
|
+
type TxAdapter<T extends Transaction> = {
|
|
195
219
|
/** The unique key identifying this adapter. */
|
|
196
220
|
key: TransactionAdapter;
|
|
197
221
|
/** Returns information about the currently connected wallet. */
|
|
@@ -202,16 +226,16 @@ type TxAdapter<TR, T extends Transaction<TR>, A> = {
|
|
|
202
226
|
/** Ensures the connected wallet is on the correct network for the transaction. Throws an error if the chain is mismatched. */
|
|
203
227
|
checkChainForTx: (chainId: string | number) => Promise<void>;
|
|
204
228
|
/** Determines the appropriate tracker and final `txKey` from the result of an action. */
|
|
205
|
-
checkTransactionsTracker: (actionTxKey:
|
|
229
|
+
checkTransactionsTracker: (actionTxKey: ActionTxKey, walletType: string) => {
|
|
206
230
|
txKey: string;
|
|
207
|
-
tracker:
|
|
231
|
+
tracker: TransactionTracker;
|
|
208
232
|
};
|
|
209
233
|
/** Selects and initializes the correct background tracker for a given transaction. */
|
|
210
234
|
checkAndInitializeTrackerInStore: (params: {
|
|
211
235
|
tx: T;
|
|
212
|
-
} & Pick<ITxTrackingStore<
|
|
236
|
+
} & Pick<ITxTrackingStore<T>, 'updateTxParams' | 'removeTxFromPool'>) => Promise<void>;
|
|
213
237
|
/** Returns the base URL for the blockchain explorer for the current network. */
|
|
214
|
-
getExplorerUrl: () => string | undefined;
|
|
238
|
+
getExplorerUrl: (url?: string) => string | undefined;
|
|
215
239
|
/** Optional: Fetches a name from a chain-specific name service (e.g., ENS). */
|
|
216
240
|
getName?: (address: string) => Promise<string | null>;
|
|
217
241
|
/** Optional: Fetches an avatar URL from a chain-specific name service. */
|
|
@@ -223,22 +247,20 @@ type TxAdapter<TR, T extends Transaction<TR>, A> = {
|
|
|
223
247
|
/** Optional: Logic to retry a failed transaction. */
|
|
224
248
|
retryTxAction?: (params: {
|
|
225
249
|
txKey: string;
|
|
226
|
-
tx: InitialTransactionParams
|
|
250
|
+
tx: InitialTransactionParams;
|
|
227
251
|
onClose: (txKey?: string) => void;
|
|
228
|
-
} & Partial<Pick<ITxTrackingStore<
|
|
252
|
+
} & Partial<Pick<ITxTrackingStore<T>, 'handleTransaction'>>) => Promise<void>;
|
|
229
253
|
/**
|
|
230
254
|
* Optional: Constructs a full explorer URL for a specific transaction.
|
|
231
255
|
* May require the full transaction pool to resolve details for replaced transactions.
|
|
232
256
|
*/
|
|
233
|
-
getExplorerTxUrl?: (
|
|
257
|
+
getExplorerTxUrl?: (tx: T) => string;
|
|
234
258
|
};
|
|
235
259
|
/**
|
|
236
260
|
* The complete interface for the Pulsar transaction tracking store.
|
|
237
|
-
* @template TR The type of the tracker identifier.
|
|
238
261
|
* @template T The transaction type.
|
|
239
|
-
* @template A The return type of the `actionFunction`.
|
|
240
262
|
*/
|
|
241
|
-
type ITxTrackingStore<
|
|
263
|
+
type ITxTrackingStore<T extends Transaction> = IInitializeTxTrackingStore<T> & {
|
|
242
264
|
/**
|
|
243
265
|
* The primary method for initiating and tracking a new transaction from start to finish.
|
|
244
266
|
* It manages UI state, executes the on-chain action, and initiates background tracking.
|
|
@@ -246,11 +268,13 @@ type ITxTrackingStore<TR, T extends Transaction<TR>, A> = IInitializeTxTrackingS
|
|
|
246
268
|
*/
|
|
247
269
|
handleTransaction: (params: {
|
|
248
270
|
/** The async function to execute (e.g., a smart contract write call). Must return a unique key or undefined. */
|
|
249
|
-
actionFunction: () => Promise<
|
|
271
|
+
actionFunction: () => Promise<ActionTxKey | undefined>;
|
|
250
272
|
/** The metadata for the transaction. */
|
|
251
|
-
params: Omit<InitialTransactionParams
|
|
273
|
+
params: Omit<InitialTransactionParams, 'actionFunction'>;
|
|
252
274
|
/** The default tracker to use if it cannot be determined automatically. */
|
|
253
|
-
defaultTracker?:
|
|
275
|
+
defaultTracker?: TransactionTracker;
|
|
276
|
+
/** Callback to execute when the transaction is successfully submitted. */
|
|
277
|
+
onSucceedCallback?: (tx: T) => Promise<void> | void;
|
|
254
278
|
}) => Promise<void>;
|
|
255
279
|
/**
|
|
256
280
|
* Initializes trackers for all pending transactions in the pool.
|
|
@@ -266,37 +290,31 @@ type ITxTrackingStore<TR, T extends Transaction<TR>, A> = IInitializeTxTrackingS
|
|
|
266
290
|
|
|
267
291
|
/**
|
|
268
292
|
* Defines the structure of the transaction pool, a key-value store of transactions indexed by their unique keys.
|
|
269
|
-
* @template
|
|
270
|
-
* @template T The transaction type.
|
|
293
|
+
* @template T The type of the transaction object being tracked.
|
|
271
294
|
*/
|
|
272
|
-
type TransactionPool<
|
|
295
|
+
type TransactionPool<T extends Transaction> = Record<string, T>;
|
|
273
296
|
/**
|
|
274
297
|
* A utility type that creates a union of all fields that can be safely updated
|
|
275
298
|
* on a transaction object via the `updateTxParams` action. This ensures type safety
|
|
276
299
|
* and prevents accidental modification of immutable properties.
|
|
277
|
-
* @template TR The type of the tracker identifier.
|
|
278
300
|
*/
|
|
279
|
-
type UpdatableTransactionFields
|
|
301
|
+
type UpdatableTransactionFields = Partial<Pick<EvmTransaction, 'to' | 'nonce' | 'txKey' | 'pending' | 'hash' | 'status' | 'replacedTxHash' | 'errorMessage' | 'finishedTimestamp' | 'isTrackedModalOpen' | 'isError' | 'maxPriorityFeePerGas' | 'maxFeePerGas' | 'input' | 'value'>> & Partial<Pick<SolanaTransaction, 'slot' | 'confirmations' | 'fee' | 'instructions' | 'recentBlockhash' | 'rpcUrl'>>;
|
|
280
302
|
/**
|
|
281
303
|
* The interface for the base transaction tracking store slice.
|
|
282
304
|
* It includes the state and actions for managing the transaction lifecycle.
|
|
283
|
-
* @template TR The type of the tracker identifier.
|
|
284
305
|
* @template T The specific transaction type.
|
|
285
|
-
* @template A The return type of the initial action function.
|
|
286
306
|
*/
|
|
287
|
-
interface IInitializeTxTrackingStore<
|
|
288
|
-
/** A callback function executed when any transaction successfully completes. */
|
|
289
|
-
onSucceedCallbacks?: (tx: T) => Promise<void> | void;
|
|
307
|
+
interface IInitializeTxTrackingStore<T extends Transaction> {
|
|
290
308
|
/** A pool of all transactions currently being tracked, indexed by `txKey`. */
|
|
291
|
-
transactionsPool: TransactionPool<
|
|
309
|
+
transactionsPool: TransactionPool<T>;
|
|
292
310
|
/** The `txKey` of the most recently added transaction. */
|
|
293
311
|
lastAddedTxKey?: string;
|
|
294
312
|
/** The state for a transaction being initiated, used for UI feedback before it's submitted to the chain. */
|
|
295
|
-
initialTx?: InitialTransaction
|
|
313
|
+
initialTx?: InitialTransaction;
|
|
296
314
|
/** Adds a new transaction to the tracking pool and marks it as pending. */
|
|
297
|
-
addTxToPool: (tx:
|
|
315
|
+
addTxToPool: (tx: T) => void;
|
|
298
316
|
/** Updates one or more properties of an existing transaction in the pool. */
|
|
299
|
-
updateTxParams: (txKey: string, fields: UpdatableTransactionFields
|
|
317
|
+
updateTxParams: (txKey: string, fields: UpdatableTransactionFields) => void;
|
|
300
318
|
/** Removes a transaction from the tracking pool by its key. */
|
|
301
319
|
removeTxFromPool: (txKey: string) => void;
|
|
302
320
|
/** Closes the tracking modal for a transaction and clears any initial transaction state. */
|
|
@@ -308,16 +326,11 @@ interface IInitializeTxTrackingStore<TR, T extends Transaction<TR>, A> {
|
|
|
308
326
|
* Creates a Zustand store slice with the core logic for transaction state management.
|
|
309
327
|
* This function is a slice creator intended for use with Zustand's `create` function.
|
|
310
328
|
*
|
|
311
|
-
* @template TR The type of the tracker identifier.
|
|
312
329
|
* @template T The specific transaction type.
|
|
313
|
-
* @template A The return type of the initial action function.
|
|
314
330
|
* @param options Configuration for the store slice.
|
|
315
|
-
* @param options.onSucceedCallbacks An optional async callback to run when a transaction succeeds.
|
|
316
331
|
* @returns A Zustand store slice implementing `IInitializeTxTrackingStore`.
|
|
317
332
|
*/
|
|
318
|
-
declare function initializeTxTrackingStore<
|
|
319
|
-
onSucceedCallbacks?: (tx: T) => Promise<void> | void;
|
|
320
|
-
}): StoreSlice<IInitializeTxTrackingStore<TR, T, A>>;
|
|
333
|
+
declare function initializeTxTrackingStore<T extends Transaction>(): StoreSlice<IInitializeTxTrackingStore<T>>;
|
|
321
334
|
|
|
322
335
|
/**
|
|
323
336
|
* @file This file contains selector functions for deriving state from the transaction tracking store.
|
|
@@ -326,47 +339,42 @@ declare function initializeTxTrackingStore<TR, T extends Transaction<TR>, A>({ o
|
|
|
326
339
|
|
|
327
340
|
/**
|
|
328
341
|
* Selects all transactions from the pool and sorts them by their creation timestamp in ascending order.
|
|
329
|
-
* @template TR - The type of the tracker identifier.
|
|
330
342
|
* @template T - The transaction type.
|
|
331
|
-
* @param {TransactionPool<
|
|
343
|
+
* @param {TransactionPool<T>} transactionsPool - The entire transaction pool from the store.
|
|
332
344
|
* @returns {T[]} An array of all transactions, sorted chronologically.
|
|
333
345
|
*/
|
|
334
|
-
declare const selectAllTransactions: <
|
|
346
|
+
declare const selectAllTransactions: <T extends Transaction>(transactionsPool: TransactionPool<T>) => T[];
|
|
335
347
|
/**
|
|
336
348
|
* Selects all transactions that are currently in a pending state, sorted chronologically.
|
|
337
|
-
* @template TR - The type of the tracker identifier.
|
|
338
349
|
* @template T - The transaction type.
|
|
339
|
-
* @param {TransactionPool<
|
|
350
|
+
* @param {TransactionPool<T>} transactionsPool - The entire transaction pool from the store.
|
|
340
351
|
* @returns {T[]} An array of pending transactions.
|
|
341
352
|
*/
|
|
342
|
-
declare const selectPendingTransactions: <
|
|
353
|
+
declare const selectPendingTransactions: <T extends Transaction>(transactionsPool: TransactionPool<T>) => T[];
|
|
343
354
|
/**
|
|
344
355
|
* Selects a single transaction from the pool by its unique key (`txKey`).
|
|
345
|
-
* @template TR - The type of the tracker identifier.
|
|
346
356
|
* @template T - The transaction type.
|
|
347
|
-
* @param {TransactionPool<
|
|
357
|
+
* @param {TransactionPool<T>} transactionsPool - The entire transaction pool from the store.
|
|
348
358
|
* @param {string} key - The `txKey` of the transaction to retrieve.
|
|
349
359
|
* @returns {T | undefined} The transaction object if found, otherwise undefined.
|
|
350
360
|
*/
|
|
351
|
-
declare const selectTxByKey: <
|
|
361
|
+
declare const selectTxByKey: <T extends Transaction>(transactionsPool: TransactionPool<T>, key: string) => T | undefined;
|
|
352
362
|
/**
|
|
353
363
|
* Selects all transactions initiated by a specific wallet address, sorted chronologically.
|
|
354
|
-
* @template TR - The type of the tracker identifier.
|
|
355
364
|
* @template T - The transaction type.
|
|
356
|
-
* @param {TransactionPool<
|
|
365
|
+
* @param {TransactionPool<T>} transactionsPool - The entire transaction pool from the store.
|
|
357
366
|
* @param {string} from - The wallet address (`from` address) to filter transactions by.
|
|
358
367
|
* @returns {T[]} An array of transactions associated with the given wallet.
|
|
359
368
|
*/
|
|
360
|
-
declare const selectAllTransactionsByActiveWallet: <
|
|
369
|
+
declare const selectAllTransactionsByActiveWallet: <T extends Transaction>(transactionsPool: TransactionPool<T>, from: string) => T[];
|
|
361
370
|
/**
|
|
362
371
|
* Selects all pending transactions for a specific wallet address, sorted chronologically.
|
|
363
|
-
* @template TR - The type of the tracker identifier.
|
|
364
372
|
* @template T - The transaction type.
|
|
365
|
-
* @param {TransactionPool<
|
|
373
|
+
* @param {TransactionPool<T>} transactionsPool - The entire transaction pool from the store.
|
|
366
374
|
* @param {string} from - The wallet address (`from` address) to filter transactions by.
|
|
367
375
|
* @returns {T[]} An array of pending transactions for the given wallet.
|
|
368
376
|
*/
|
|
369
|
-
declare const selectPendingTransactionsByActiveWallet: <
|
|
377
|
+
declare const selectPendingTransactionsByActiveWallet: <T extends Transaction>(transactionsPool: TransactionPool<T>, from: string) => T[];
|
|
370
378
|
|
|
371
379
|
/**
|
|
372
380
|
* Creates the main Pulsar store for transaction tracking.
|
|
@@ -375,30 +383,26 @@ declare const selectPendingTransactionsByActiveWallet: <TR, T extends Transactio
|
|
|
375
383
|
* slice with a powerful orchestration logic that leverages chain-specific adapters to handle the entire
|
|
376
384
|
* lifecycle of a transaction—from initiation and chain validation to execution and background status tracking.
|
|
377
385
|
*
|
|
378
|
-
* @template TR The type of the tracker identifier (e.g., a string enum).
|
|
379
386
|
* @template T The specific transaction type, extending the base `Transaction`.
|
|
380
|
-
* @template A The type of the key returned by the `actionFunction` (e.g., a transaction hash).
|
|
381
387
|
*
|
|
382
388
|
* @param config Configuration object for creating the store.
|
|
383
|
-
* @param config.
|
|
384
|
-
* @param config.adapters An array of adapters for different chains or transaction types.
|
|
389
|
+
* @param config.adapter Adapter or an array of adapters for different chains or transaction types.
|
|
385
390
|
* @param options Configuration for the Zustand `persist` middleware.
|
|
386
391
|
* @returns A fully configured Zustand store instance.
|
|
387
392
|
*/
|
|
388
|
-
declare function createPulsarStore<
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
setState(
|
|
393
|
-
setState(state: ITxTrackingStore<TR, T, A> | ((state: ITxTrackingStore<TR, T, A>) => ITxTrackingStore<TR, T, A>), replace: true): unknown;
|
|
393
|
+
declare function createPulsarStore<T extends Transaction>({ adapter, ...options }: {
|
|
394
|
+
adapter: TxAdapter<T> | TxAdapter<T>[];
|
|
395
|
+
} & PersistOptions<ITxTrackingStore<T>>): Omit<zustand.StoreApi<ITxTrackingStore<T>>, "setState" | "persist"> & {
|
|
396
|
+
setState(partial: ITxTrackingStore<T> | Partial<ITxTrackingStore<T>> | ((state: ITxTrackingStore<T>) => ITxTrackingStore<T> | Partial<ITxTrackingStore<T>>), replace?: false | undefined): unknown;
|
|
397
|
+
setState(state: ITxTrackingStore<T> | ((state: ITxTrackingStore<T>) => ITxTrackingStore<T>), replace: true): unknown;
|
|
394
398
|
persist: {
|
|
395
|
-
setOptions: (options: Partial<PersistOptions<ITxTrackingStore<
|
|
399
|
+
setOptions: (options: Partial<PersistOptions<ITxTrackingStore<T>, ITxTrackingStore<T>, unknown>>) => void;
|
|
396
400
|
clearStorage: () => void;
|
|
397
401
|
rehydrate: () => Promise<void> | void;
|
|
398
402
|
hasHydrated: () => boolean;
|
|
399
|
-
onHydrate: (fn: (state: ITxTrackingStore<
|
|
400
|
-
onFinishHydration: (fn: (state: ITxTrackingStore<
|
|
401
|
-
getOptions: () => Partial<PersistOptions<ITxTrackingStore<
|
|
403
|
+
onHydrate: (fn: (state: ITxTrackingStore<T>) => void) => () => void;
|
|
404
|
+
onFinishHydration: (fn: (state: ITxTrackingStore<T>) => void) => () => void;
|
|
405
|
+
getOptions: () => Partial<PersistOptions<ITxTrackingStore<T>, ITxTrackingStore<T>, unknown>>;
|
|
402
406
|
};
|
|
403
407
|
};
|
|
404
408
|
|
|
@@ -447,8 +451,8 @@ declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) =>
|
|
|
447
451
|
/**
|
|
448
452
|
* Defines the parameters for the fetcher function used within the polling tracker.
|
|
449
453
|
* The fetcher is the core logic that performs the actual API call.
|
|
450
|
-
* @template R
|
|
451
|
-
* @template T
|
|
454
|
+
* @template R The expected type of the successful API response.
|
|
455
|
+
* @template T The type of the transaction object being tracked.
|
|
452
456
|
*/
|
|
453
457
|
type PollingFetcherParams<R, T> = {
|
|
454
458
|
/** The transaction object being tracked. */
|
|
@@ -468,13 +472,12 @@ type PollingFetcherParams<R, T> = {
|
|
|
468
472
|
};
|
|
469
473
|
/**
|
|
470
474
|
* Defines the configuration object for the `initializePollingTracker` function.
|
|
471
|
-
* @template R
|
|
472
|
-
* @template T
|
|
473
|
-
* @template TR - The type of the tracker identifier.
|
|
475
|
+
* @template R The expected type of the successful API response.
|
|
476
|
+
* @template T The type of the transaction object.
|
|
474
477
|
*/
|
|
475
|
-
type PollingTrackerConfig<R, T
|
|
478
|
+
type PollingTrackerConfig<R, T extends Transaction> = {
|
|
476
479
|
/** The transaction object to be tracked. It must include `txKey` and `pending` status. */
|
|
477
|
-
tx: T & Pick<Transaction
|
|
480
|
+
tx: T & Pick<Transaction, 'txKey' | 'pending'>;
|
|
478
481
|
/** The function that performs the data fetching (e.g., an API call) on each interval. */
|
|
479
482
|
fetcher: (params: PollingFetcherParams<R, T>) => Promise<void>;
|
|
480
483
|
/** Callback to be invoked when the transaction successfully completes. */
|
|
@@ -503,10 +506,9 @@ type PollingTrackerConfig<R, T, TR> = {
|
|
|
503
506
|
*
|
|
504
507
|
* @template R The expected type of the API response.
|
|
505
508
|
* @template T The type of the transaction object.
|
|
506
|
-
* @
|
|
507
|
-
* @param {PollingTrackerConfig<R, T, TR>} config - The configuration for the tracker.
|
|
509
|
+
* @param {PollingTrackerConfig<R, T>} config - The configuration for the tracker.
|
|
508
510
|
*/
|
|
509
|
-
declare function initializePollingTracker<R, T
|
|
511
|
+
declare function initializePollingTracker<R, T extends Transaction>(config: PollingTrackerConfig<R, T>): void;
|
|
510
512
|
|
|
511
513
|
/**
|
|
512
514
|
* @file This file contains a utility function for selecting a specific transaction adapter from a list.
|
|
@@ -520,19 +522,17 @@ declare function initializePollingTracker<R, T, TR>(config: PollingTrackerConfig
|
|
|
520
522
|
* and returns the first adapter in the array as a fallback. This fallback mechanism
|
|
521
523
|
* ensures that the system can still function, but it highlights a potential configuration issue.
|
|
522
524
|
*
|
|
523
|
-
* @template TR - The type of the tracker identifier.
|
|
524
525
|
* @template T - The transaction type, extending the base `Transaction`.
|
|
525
|
-
* @template A - The type for the adapter-specific context or API.
|
|
526
526
|
*
|
|
527
527
|
* @param {object} params - The parameters for the selection.
|
|
528
528
|
* @param {TransactionAdapter} params.adapterKey - The key of the desired adapter.
|
|
529
|
-
* @param {TxAdapter<
|
|
529
|
+
* @param {TxAdapter<T> | TxAdapter<T>[]} params.adapter - Adapter or an array of adapters for different chains or transaction types.
|
|
530
530
|
*
|
|
531
|
-
* @returns {TxAdapter<
|
|
531
|
+
* @returns {TxAdapter<T> | undefined} The found transaction adapter, the fallback adapter, or undefined if the adapters array is empty.
|
|
532
532
|
*/
|
|
533
|
-
declare const selectAdapterByKey: <
|
|
533
|
+
declare const selectAdapterByKey: <T extends Transaction>({ adapterKey, adapter, }: {
|
|
534
534
|
adapterKey: TransactionAdapter;
|
|
535
|
-
|
|
536
|
-
}) => TxAdapter<
|
|
535
|
+
adapter: TxAdapter<T> | TxAdapter<T>[];
|
|
536
|
+
}) => TxAdapter<T> | undefined;
|
|
537
537
|
|
|
538
|
-
export { type BaseTransaction, type EvmTransaction, type IInitializeTxTrackingStore, type ITxTrackingStore, type InitialTransaction, type InitialTransactionParams, type PollingTrackerConfig, type SolanaTransaction, type StarknetTransaction, type StoreSlice, type Transaction, TransactionAdapter, type TransactionPool, TransactionStatus, type TxAdapter, createBoundedUseStore, createPulsarStore, initializePollingTracker, initializeTxTrackingStore, selectAdapterByKey, selectAllTransactions, selectAllTransactionsByActiveWallet, selectPendingTransactions, selectPendingTransactionsByActiveWallet, selectTxByKey };
|
|
538
|
+
export { type ActionTxKey, type BaseTransaction, type EvmTransaction, type GelatoTxKey, type IInitializeTxTrackingStore, type ITxTrackingStore, type InitialTransaction, type InitialTransactionParams, type PollingTrackerConfig, type SolanaTransaction, type StarknetTransaction, type StoreSlice, type Transaction, TransactionAdapter, type TransactionPool, TransactionStatus, TransactionTracker, type TxAdapter, createBoundedUseStore, createPulsarStore, initializePollingTracker, initializeTxTrackingStore, selectAdapterByKey, selectAllTransactions, selectAllTransactionsByActiveWallet, selectPendingTransactions, selectPendingTransactionsByActiveWallet, selectTxByKey };
|