@tuwaio/pulsar-core 1.0.0-alpha.5.815bc21.acc55b8.6f58c3c → 1.0.0-alpha.7.815bc21.acc55b8.3307a45
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 +74 -34
- package/dist/index.d.mts +222 -169
- package/dist/index.d.ts +222 -169
- 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 +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -9,108 +9,107 @@ import { PersistOptions } from 'zustand/middleware';
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* A utility type for creating modular Zustand store slices.
|
|
13
|
-
* @template T The state slice
|
|
14
|
-
* @template
|
|
12
|
+
* A utility type for creating modular Zustand store slices, enabling composable state management.
|
|
13
|
+
* @template T - The type of the state slice.
|
|
14
|
+
* @template S - The type of the full store state, defaulting to T.
|
|
15
15
|
*/
|
|
16
|
-
type StoreSlice<T extends object,
|
|
16
|
+
type StoreSlice<T extends object, S extends object = T> = (set: StoreApi<S extends T ? S : S & T>['setState'], get: StoreApi<S extends T ? S : S & T>['getState']) => T;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* Defines the supported blockchain adapters. Each adapter corresponds to a specific chain architecture.
|
|
19
19
|
*/
|
|
20
20
|
declare enum TransactionAdapter {
|
|
21
|
-
/** EVM
|
|
21
|
+
/** For Ethereum Virtual Machine (EVM) compatible chains like Ethereum, Polygon, etc. */
|
|
22
22
|
EVM = "evm",
|
|
23
|
-
/** Solana
|
|
23
|
+
/** For the Solana blockchain. */
|
|
24
24
|
SOLANA = "solana",
|
|
25
|
-
/** Starknet
|
|
26
|
-
Starknet = "
|
|
25
|
+
/** For the Starknet L2 network. */
|
|
26
|
+
Starknet = "starknet"
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* Represents the
|
|
29
|
+
* Represents the terminal status of a transaction after it has been processed.
|
|
30
30
|
*/
|
|
31
31
|
declare enum TransactionStatus {
|
|
32
|
-
/** The transaction failed to execute. */
|
|
32
|
+
/** The transaction failed to execute due to an on-chain error or rejection. */
|
|
33
33
|
Failed = "Failed",
|
|
34
34
|
/** The transaction was successfully mined and executed. */
|
|
35
35
|
Success = "Success",
|
|
36
|
-
/** The transaction was replaced by another (e.g., speed-up). */
|
|
36
|
+
/** The transaction was replaced by another with the same nonce (e.g., a speed-up or cancel). */
|
|
37
37
|
Replaced = "Replaced"
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
|
-
* The
|
|
41
|
-
*
|
|
40
|
+
* The fundamental structure for any transaction being tracked by Pulsar.
|
|
41
|
+
* This forms the base upon which chain-specific transaction types are built.
|
|
42
|
+
* @template T - The type of the tracker identifier (e.g., 'ethereum', 'gelato', 'safe').
|
|
42
43
|
*/
|
|
43
44
|
type BaseTransaction<T> = {
|
|
44
|
-
/** A key identifying
|
|
45
|
+
/** A unique key identifying a re-executable action from the `TxActions` registry. */
|
|
45
46
|
actionKey?: string;
|
|
46
47
|
/** The chain identifier (e.g., 1 for Ethereum Mainnet, 'SN_MAIN' for Starknet). */
|
|
47
48
|
chainId: number | string;
|
|
48
|
-
/** A description
|
|
49
|
+
/** A user-facing description. Can be a single string or an array for [pending, success, error, replaced] states. */
|
|
49
50
|
description?: string | [string, string, string, string];
|
|
50
|
-
/**
|
|
51
|
+
/** The error message if the transaction failed. */
|
|
51
52
|
errorMessage?: string;
|
|
52
|
-
/** The timestamp (in seconds) when the transaction was finalized
|
|
53
|
+
/** The on-chain timestamp (in seconds) when the transaction was finalized. */
|
|
53
54
|
finishedTimestamp?: number;
|
|
54
|
-
/** The sender's address. */
|
|
55
|
+
/** The sender's wallet address. */
|
|
55
56
|
from: string;
|
|
56
57
|
/** A flag indicating if the transaction is in a failed state. */
|
|
57
58
|
isError?: boolean;
|
|
58
|
-
/** A flag
|
|
59
|
+
/** A UI flag to control the visibility of a detailed tracking modal for this transaction. */
|
|
59
60
|
isTrackedModalOpen?: boolean;
|
|
60
|
-
/** The local timestamp (in seconds) when the transaction was initiated. */
|
|
61
|
+
/** The local timestamp (in seconds) when the transaction was initiated by the user. */
|
|
61
62
|
localTimestamp: number;
|
|
62
|
-
/** Any additional data associated with the transaction. */
|
|
63
|
+
/** Any additional, custom data associated with the transaction. */
|
|
63
64
|
payload?: object;
|
|
64
|
-
/**
|
|
65
|
+
/** A flag indicating if the transaction is still awaiting on-chain confirmation. */
|
|
65
66
|
pending: boolean;
|
|
66
|
-
/** The final status of the transaction. */
|
|
67
|
+
/** The final on-chain status of the transaction. */
|
|
67
68
|
status?: TransactionStatus;
|
|
68
|
-
/** A title
|
|
69
|
+
/** A user-facing title. Can be a single string or an array for [pending, success, error, replaced] states. */
|
|
69
70
|
title?: string | [string, string, string, string];
|
|
70
|
-
/** The specific tracker responsible for monitoring this transaction
|
|
71
|
+
/** The specific tracker responsible for monitoring this transaction's status. */
|
|
71
72
|
tracker: T;
|
|
72
|
-
/** The unique
|
|
73
|
+
/** The unique identifier for the transaction (e.g., EVM hash, Gelato task ID). */
|
|
73
74
|
txKey: string;
|
|
74
|
-
/** The type or category of the transaction (e.g., '
|
|
75
|
+
/** The application-specific type or category of the transaction (e.g., 'SWAP', 'APPROVE'). */
|
|
75
76
|
type: string;
|
|
76
|
-
/** The type of wallet used
|
|
77
|
+
/** The type of wallet used to sign the transaction (e.g., 'injected', 'walletConnect'). */
|
|
77
78
|
walletType: string;
|
|
78
79
|
};
|
|
79
80
|
/**
|
|
80
|
-
* Represents an EVM-specific transaction, extending the base properties.
|
|
81
|
-
* @template T The type of the tracker identifier.
|
|
81
|
+
* Represents an EVM-specific transaction, extending the base properties with EVM fields.
|
|
82
|
+
* @template T - The type of the tracker identifier.
|
|
82
83
|
*/
|
|
83
84
|
type EvmTransaction<T> = BaseTransaction<T> & {
|
|
84
|
-
/** The transaction adapter type. */
|
|
85
85
|
adapter: TransactionAdapter.EVM;
|
|
86
86
|
/** The on-chain transaction hash, available after submission. */
|
|
87
|
-
hash?: string
|
|
88
|
-
/** The data payload for the transaction, typically for contract interactions. */
|
|
89
|
-
input?: string
|
|
90
|
-
/** The maximum fee per gas for
|
|
87
|
+
hash?: `0x${string}`;
|
|
88
|
+
/** The data payload for the transaction, typically for smart contract interactions. */
|
|
89
|
+
input?: `0x${string}`;
|
|
90
|
+
/** The maximum fee per gas for an EIP-1559 transaction (in wei). */
|
|
91
91
|
maxFeePerGas?: string;
|
|
92
|
-
/** The maximum priority fee per gas for
|
|
92
|
+
/** The maximum priority fee per gas for an EIP-1559 transaction (in wei). */
|
|
93
93
|
maxPriorityFeePerGas?: string;
|
|
94
|
-
/** The transaction nonce. */
|
|
94
|
+
/** The transaction nonce, a sequential number for the sender's account. */
|
|
95
95
|
nonce?: number;
|
|
96
|
-
/** The hash of a transaction that this one replaced
|
|
97
|
-
replacedTxHash?: string
|
|
98
|
-
/** The recipient's address. */
|
|
99
|
-
to?: string
|
|
100
|
-
/** The
|
|
96
|
+
/** The hash of a transaction that this one replaced. */
|
|
97
|
+
replacedTxHash?: `0x${string}`;
|
|
98
|
+
/** The recipient's address or contract address. */
|
|
99
|
+
to?: `0x${string}`;
|
|
100
|
+
/** The amount of native currency (in wei) being sent. */
|
|
101
101
|
value?: string;
|
|
102
102
|
};
|
|
103
103
|
/**
|
|
104
104
|
* Represents a Solana-specific transaction, extending the base properties.
|
|
105
|
-
* @template T The type of the tracker identifier.
|
|
105
|
+
* @template T - The type of the tracker identifier.
|
|
106
106
|
*/
|
|
107
107
|
type SolanaTransaction<T> = BaseTransaction<T> & {
|
|
108
|
-
/** The transaction adapter type. */
|
|
109
108
|
adapter: TransactionAdapter.SOLANA;
|
|
110
|
-
/** The transaction fee. */
|
|
109
|
+
/** The transaction fee in lamports. */
|
|
111
110
|
fee?: number;
|
|
112
111
|
/** The instructions included in the transaction. */
|
|
113
|
-
instructions?:
|
|
112
|
+
instructions?: unknown[];
|
|
114
113
|
/** The recent blockhash used for the transaction. */
|
|
115
114
|
recentBlockhash?: string;
|
|
116
115
|
/** The slot in which the transaction was processed. */
|
|
@@ -118,9 +117,10 @@ type SolanaTransaction<T> = BaseTransaction<T> & {
|
|
|
118
117
|
};
|
|
119
118
|
/**
|
|
120
119
|
* Represents a Starknet-specific transaction, extending the base properties.
|
|
121
|
-
* @template T The type of the tracker identifier.
|
|
120
|
+
* @template T - The type of the tracker identifier.
|
|
122
121
|
*/
|
|
123
122
|
type StarknetTransaction<T> = BaseTransaction<T> & {
|
|
123
|
+
adapter: TransactionAdapter.Starknet;
|
|
124
124
|
/** The actual fee paid for the transaction. */
|
|
125
125
|
actualFee?: {
|
|
126
126
|
amount: string;
|
|
@@ -128,107 +128,118 @@ type StarknetTransaction<T> = BaseTransaction<T> & {
|
|
|
128
128
|
};
|
|
129
129
|
/** The address of the contract being interacted with. */
|
|
130
130
|
contractAddress?: string;
|
|
131
|
-
/** The transaction adapter type. */
|
|
132
|
-
adapter: TransactionAdapter.Starknet;
|
|
133
131
|
/** The reason for transaction failure, if applicable. */
|
|
134
132
|
revertReason?: string;
|
|
135
133
|
};
|
|
136
|
-
/** A union type representing any possible transaction structure. */
|
|
134
|
+
/** A union type representing any possible transaction structure that Pulsar can handle. */
|
|
137
135
|
type Transaction<T> = EvmTransaction<T> | SolanaTransaction<T> | StarknetTransaction<T>;
|
|
138
|
-
/**
|
|
136
|
+
/**
|
|
137
|
+
* A registry of functions that can be re-executed, keyed by `actionKey`.
|
|
138
|
+
* Used for implementing "Retry" functionality.
|
|
139
|
+
*/
|
|
139
140
|
type TxActions = Record<string, (...args: any[]) => Promise<unknown>>;
|
|
140
141
|
/**
|
|
141
|
-
* Represents the parameters required to initiate a new transaction.
|
|
142
|
+
* Represents the parameters required to initiate a new transaction tracking flow.
|
|
142
143
|
*/
|
|
143
144
|
type InitialTransactionParams = {
|
|
144
|
-
/** The transaction adapter type. */
|
|
145
145
|
adapter: TransactionAdapter;
|
|
146
|
-
/** A key
|
|
146
|
+
/** A key to identify the re-executable action from the `TxActions` registry. */
|
|
147
147
|
actionKey?: string;
|
|
148
|
-
/** A description for the transaction
|
|
148
|
+
/** A user-facing description for the transaction. */
|
|
149
149
|
description?: string | [string, string, string, string];
|
|
150
|
-
/** The ID
|
|
150
|
+
/** The target chain ID for the transaction. */
|
|
151
151
|
desiredChainID: number | string;
|
|
152
|
-
/** Any
|
|
152
|
+
/** Any custom data to associate with the transaction. */
|
|
153
153
|
payload?: object;
|
|
154
|
-
/** A title for the transaction
|
|
154
|
+
/** A user-facing title for the transaction. */
|
|
155
155
|
title?: string | [string, string, string, string];
|
|
156
|
-
/** The type
|
|
156
|
+
/** The application-specific type of the transaction. */
|
|
157
157
|
type: string;
|
|
158
|
-
/** If true, the detailed tracking modal will open automatically
|
|
158
|
+
/** If true, the detailed tracking modal will open automatically upon initiation. */
|
|
159
159
|
withTrackedModal?: boolean;
|
|
160
160
|
};
|
|
161
161
|
/**
|
|
162
|
-
* Represents a transaction in its
|
|
162
|
+
* Represents a transaction in its temporary, pre-submission state.
|
|
163
163
|
* This is used for UI feedback while the transaction is being signed and sent.
|
|
164
164
|
*/
|
|
165
165
|
type InitialTransaction = InitialTransactionParams & {
|
|
166
|
-
/** An error message if the initialization
|
|
166
|
+
/** An error message if the initialization fails (e.g., user rejects signature). */
|
|
167
167
|
errorMessage?: string;
|
|
168
|
-
/**
|
|
168
|
+
/** A flag indicating if the transaction is being processed (e.g., waiting for signature). */
|
|
169
169
|
isInitializing: boolean;
|
|
170
|
-
/** The
|
|
170
|
+
/** The `txKey` of the on-chain transaction that this action produced, used for linking the states. */
|
|
171
171
|
lastTxKey?: string;
|
|
172
172
|
/** The local timestamp when the user initiated the action. */
|
|
173
173
|
localTimestamp: number;
|
|
174
174
|
};
|
|
175
175
|
/**
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
* @template
|
|
179
|
-
* @template
|
|
180
|
-
* @template A - Represents the type for the action transaction key.
|
|
176
|
+
* Defines the interface for a transaction adapter, which provides chain-specific logic and utilities.
|
|
177
|
+
* @template TR - The type of the tracker identifier (e.g., a string enum).
|
|
178
|
+
* @template T - The specific transaction type, extending `Transaction<TR>`.
|
|
179
|
+
* @template A - The type of the key returned by the `actionFunction` (e.g., a transaction hash).
|
|
181
180
|
*/
|
|
182
181
|
type TxAdapter<TR, T extends Transaction<TR>, A> = {
|
|
182
|
+
/** The unique key identifying this adapter. */
|
|
183
183
|
key: TransactionAdapter;
|
|
184
|
+
/** Returns information about the currently connected wallet. */
|
|
184
185
|
getWalletInfo: () => {
|
|
185
|
-
/** Wallet address. */
|
|
186
186
|
walletAddress: string;
|
|
187
|
-
/** Type of the wallet. (injected, wallet connect, etc.) */
|
|
188
187
|
walletType: string;
|
|
189
188
|
};
|
|
189
|
+
/** Ensures the connected wallet is on the correct network for the transaction. */
|
|
190
190
|
checkChainForTx: (chainId: string | number) => Promise<void>;
|
|
191
|
+
/** Determines the appropriate tracker and final `txKey` based on the result of an action. */
|
|
191
192
|
checkTransactionsTracker: (actionTxKey: A, walletType: string) => {
|
|
192
193
|
txKey: string;
|
|
193
194
|
tracker: TR;
|
|
194
195
|
};
|
|
195
|
-
|
|
196
|
+
/** Initializes the correct background tracker for a given transaction. */
|
|
197
|
+
checkAndInitializeTrackerInStore: (params: {
|
|
196
198
|
tx: T;
|
|
197
199
|
} & Pick<ITxTrackingStore<TR, T, A>, 'transactionsPool' | 'updateTxParams' | 'onSucceedCallbacks' | 'removeTxFromPool'>) => Promise<void>;
|
|
200
|
+
/** Returns the base URL for the blockchain explorer. */
|
|
198
201
|
getExplorerUrl: () => string | undefined;
|
|
202
|
+
/** Optional: Fetches a name from a chain-specific name service (e.g., ENS). */
|
|
203
|
+
getName?: (address: string) => Promise<string | null>;
|
|
204
|
+
/** Optional: Fetches an avatar URL from a chain-specific name service. */
|
|
205
|
+
getAvatar?: (name: string) => Promise<string | null>;
|
|
206
|
+
/** Optional: Logic to cancel a pending EVM transaction. */
|
|
199
207
|
cancelTxAction?: (tx: T) => Promise<string>;
|
|
208
|
+
/** Optional: Logic to speed up a pending EVM transaction. */
|
|
200
209
|
speedUpTxAction?: (tx: T) => Promise<string>;
|
|
201
|
-
|
|
210
|
+
/** Optional: Logic to retry a failed transaction. */
|
|
211
|
+
retryTxAction?: (params: {
|
|
202
212
|
txKey: string;
|
|
203
213
|
tx: InitialTransactionParams;
|
|
204
214
|
actions?: TxActions;
|
|
205
215
|
onClose: (txKey?: string) => void;
|
|
206
216
|
} & Partial<Pick<ITxTrackingStore<TR, T, A>, 'handleTransaction'>>) => Promise<void>;
|
|
217
|
+
/** Optional: Constructs a full explorer URL for a specific transaction. */
|
|
207
218
|
getExplorerTxUrl?: (transactionsPool: TransactionPool<TR, T>, txKey: string, replacedTxHash?: string) => string;
|
|
208
219
|
};
|
|
209
220
|
/**
|
|
210
|
-
*
|
|
211
|
-
* @template TR The type of the tracker identifier.
|
|
212
|
-
* @template T The transaction type.
|
|
213
|
-
* @template
|
|
214
|
-
* @template A The return type of the action function being wrapped.
|
|
221
|
+
* The complete interface for the Pulsar transaction tracking store.
|
|
222
|
+
* @template TR - The type of the tracker identifier.
|
|
223
|
+
* @template T - The transaction type.
|
|
224
|
+
* @template A - The return type of the `actionFunction`.
|
|
215
225
|
*/
|
|
216
226
|
type ITxTrackingStore<TR, T extends Transaction<TR>, A> = IInitializeTxTrackingStore<TR, T> & {
|
|
217
227
|
/**
|
|
218
|
-
*
|
|
219
|
-
* It
|
|
228
|
+
* The core function that handles the entire lifecycle of a new transaction.
|
|
229
|
+
* It manages UI state, executes the on-chain action, and initiates background tracking.
|
|
220
230
|
* @param params - The parameters for handling the transaction.
|
|
221
231
|
*/
|
|
222
232
|
handleTransaction: (params: {
|
|
223
|
-
/** The async function to execute (e.g., a smart contract write call). */
|
|
233
|
+
/** The async function to execute (e.g., a smart contract write call). Must return a unique key or undefined. */
|
|
224
234
|
actionFunction: () => Promise<A | undefined>;
|
|
225
|
-
/** The metadata for the transaction
|
|
235
|
+
/** The metadata for the transaction. */
|
|
226
236
|
params: InitialTransactionParams;
|
|
237
|
+
/** The default tracker to use if it cannot be determined automatically. */
|
|
227
238
|
defaultTracker?: TR;
|
|
228
239
|
}) => Promise<void>;
|
|
229
240
|
/**
|
|
230
|
-
* Initializes
|
|
231
|
-
* This is
|
|
241
|
+
* Initializes trackers for all pending transactions in the pool.
|
|
242
|
+
* This is essential for resuming tracking after a page reload.
|
|
232
243
|
*/
|
|
233
244
|
initializeTransactionsPool: () => Promise<void>;
|
|
234
245
|
};
|
|
@@ -249,14 +260,14 @@ type TransactionPool<TR, T extends Transaction<TR>> = Record<string, T>;
|
|
|
249
260
|
* that are updatable via the `updateTxParams` action.
|
|
250
261
|
* @template TR - The type of the tracker identifier.
|
|
251
262
|
*/
|
|
252
|
-
type
|
|
263
|
+
type UpdatableTransactionFields<TR> = Partial<Pick<EvmTransaction<TR>, 'to' | 'nonce' | 'txKey' | 'pending' | 'hash' | 'status' | 'replacedTxHash' | 'errorMessage' | 'finishedTimestamp' | 'isTrackedModalOpen' | 'isError' | 'maxPriorityFeePerGas' | 'maxFeePerGas' | 'input' | 'value'>>;
|
|
253
264
|
/**
|
|
254
265
|
* Defines the interface for the base transaction tracking store slice.
|
|
255
266
|
* It includes the state and actions for managing transactions.
|
|
256
267
|
* @template TR - The type of the tracker identifier.
|
|
257
268
|
* @template T - The transaction type.
|
|
258
269
|
*/
|
|
259
|
-
|
|
270
|
+
interface IInitializeTxTrackingStore<TR, T extends Transaction<TR>> {
|
|
260
271
|
/** An optional callback function to be executed when a transaction successfully completes. */
|
|
261
272
|
onSucceedCallbacks?: (tx: T) => Promise<void> | void;
|
|
262
273
|
/** A pool of all transactions currently being tracked, indexed by their `txKey`. */
|
|
@@ -266,18 +277,16 @@ type IInitializeTxTrackingStore<TR, T extends Transaction<TR>> = {
|
|
|
266
277
|
/** The state of a transaction that is currently being initiated but not yet submitted. */
|
|
267
278
|
initialTx?: InitialTransaction;
|
|
268
279
|
/** Adds a new transaction to the tracking pool. */
|
|
269
|
-
addTxToPool: (
|
|
270
|
-
tx: T;
|
|
271
|
-
}) => void;
|
|
280
|
+
addTxToPool: (tx: T) => void;
|
|
272
281
|
/** Updates one or more parameters of an existing transaction in the pool. */
|
|
273
|
-
updateTxParams: (fields:
|
|
282
|
+
updateTxParams: (txKey: string, fields: UpdatableTransactionFields<TR>) => void;
|
|
274
283
|
/** Removes a transaction from the tracking pool using its key. */
|
|
275
284
|
removeTxFromPool: (txKey: string) => void;
|
|
276
285
|
/** Closes the tracking modal for a specific transaction. */
|
|
277
286
|
closeTxTrackedModal: (txKey?: string) => void;
|
|
278
287
|
/** Returns the key of the last transaction that was added to the pool. */
|
|
279
288
|
getLastTxKey: () => string | undefined;
|
|
280
|
-
}
|
|
289
|
+
}
|
|
281
290
|
/**
|
|
282
291
|
* Creates a Zustand store slice containing the core logic for transaction tracking.
|
|
283
292
|
* This function is a slice creator and is meant to be used within `createStore` from Zustand.
|
|
@@ -291,91 +300,118 @@ declare function initializeTxTrackingStore<TR, T extends Transaction<TR>>({ onSu
|
|
|
291
300
|
|
|
292
301
|
/**
|
|
293
302
|
* @file This file contains selector functions for deriving state from the transaction tracking store.
|
|
294
|
-
* Selectors help abstract
|
|
303
|
+
* Selectors help abstract the state's shape and provide efficient, memoized access to computed data.
|
|
295
304
|
*/
|
|
296
305
|
|
|
297
306
|
/**
|
|
298
|
-
* Selects all transactions from the pool and sorts them by their creation timestamp.
|
|
307
|
+
* Selects all transactions from the pool and sorts them by their creation timestamp in ascending order.
|
|
299
308
|
* @template TR - The type of the tracker identifier.
|
|
300
309
|
* @template T - The transaction type.
|
|
301
|
-
* @param {TransactionPool<TR, T>} transactionsPool - The entire pool
|
|
310
|
+
* @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
|
|
302
311
|
* @returns {T[]} An array of all transactions, sorted chronologically.
|
|
303
312
|
*/
|
|
304
313
|
declare const selectAllTransactions: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>) => T[];
|
|
305
314
|
/**
|
|
306
|
-
* Selects all transactions that are currently in a pending state.
|
|
315
|
+
* Selects all transactions that are currently in a pending state, sorted chronologically.
|
|
307
316
|
* @template TR - The type of the tracker identifier.
|
|
308
317
|
* @template T - The transaction type.
|
|
309
|
-
* @param {TransactionPool<TR, T>} transactionsPool - The entire pool
|
|
318
|
+
* @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
|
|
310
319
|
* @returns {T[]} An array of pending transactions.
|
|
311
320
|
*/
|
|
312
321
|
declare const selectPendingTransactions: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>) => T[];
|
|
313
322
|
/**
|
|
314
|
-
* Selects a single transaction from the pool by its unique
|
|
315
|
-
* This is the most direct way to retrieve a transaction.
|
|
323
|
+
* Selects a single transaction from the pool by its unique key (`txKey`).
|
|
316
324
|
* @template TR - The type of the tracker identifier.
|
|
317
325
|
* @template T - The transaction type.
|
|
318
|
-
* @param {TransactionPool<TR, T>} transactionsPool - The entire pool
|
|
326
|
+
* @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
|
|
319
327
|
* @param {string} key - The `txKey` of the transaction to retrieve.
|
|
320
328
|
* @returns {T | undefined} The transaction object if found, otherwise undefined.
|
|
321
329
|
*/
|
|
322
|
-
declare const
|
|
330
|
+
declare const selectTxByKey: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>, key: string) => T | undefined;
|
|
323
331
|
/**
|
|
324
|
-
* Selects all transactions initiated by a specific wallet address.
|
|
332
|
+
* Selects all transactions initiated by a specific wallet address, sorted chronologically.
|
|
325
333
|
* @template TR - The type of the tracker identifier.
|
|
326
334
|
* @template T - The transaction type.
|
|
327
|
-
* @param {TransactionPool<TR, T>} transactionsPool - The entire pool
|
|
335
|
+
* @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
|
|
328
336
|
* @param {string} from - The wallet address (`from` address) to filter transactions by.
|
|
329
337
|
* @returns {T[]} An array of transactions associated with the given wallet.
|
|
330
338
|
*/
|
|
331
339
|
declare const selectAllTransactionsByActiveWallet: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>, from: string) => T[];
|
|
332
340
|
/**
|
|
333
|
-
* Selects all pending transactions
|
|
341
|
+
* Selects all pending transactions for a specific wallet address, sorted chronologically.
|
|
334
342
|
* @template TR - The type of the tracker identifier.
|
|
335
343
|
* @template T - The transaction type.
|
|
336
|
-
* @param {TransactionPool<TR, T>} transactionsPool - The entire pool
|
|
344
|
+
* @param {TransactionPool<TR, T>} transactionsPool - The entire transaction pool from the store.
|
|
337
345
|
* @param {string} from - The wallet address (`from` address) to filter transactions by.
|
|
338
|
-
* @returns {T[]} An array of pending transactions
|
|
346
|
+
* @returns {T[]} An array of pending transactions for the given wallet.
|
|
339
347
|
*/
|
|
340
348
|
declare const selectPendingTransactionsByActiveWallet: <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>, from: string) => T[];
|
|
341
349
|
|
|
350
|
+
/**
|
|
351
|
+
* Creates the main Pulsar store for transaction tracking.
|
|
352
|
+
*
|
|
353
|
+
* This function sets up a Zustand store with persistence, combining the core
|
|
354
|
+
* transaction slice with adapter-specific logic to handle the entire lifecycle
|
|
355
|
+
* of a transaction.
|
|
356
|
+
*
|
|
357
|
+
* @template TR - The type of the tracker identifier (e.g., a string enum).
|
|
358
|
+
* @template T - The specific transaction type, extending the base `Transaction`.
|
|
359
|
+
* @template A - The type for the adapter-specific context or API.
|
|
360
|
+
*
|
|
361
|
+
* @param {object} config - Configuration object for creating the store.
|
|
362
|
+
* @param {function} [config.onSucceedCallbacks] - Optional async callback executed on transaction success.
|
|
363
|
+
* @param {TxAdapter<TR, T, A>[]} config.adapters - An array of adapters for different transaction types or chains.
|
|
364
|
+
* @param {PersistOptions<ITxTrackingStore<TR, T, A>>} [options] - Configuration for the Zustand persist middleware.
|
|
365
|
+
* @returns A fully configured Zustand store instance.
|
|
366
|
+
*/
|
|
342
367
|
declare function createPulsarStore<TR, T extends Transaction<TR>, A>({ onSucceedCallbacks, adapters, ...options }: {
|
|
343
368
|
onSucceedCallbacks?: (tx: T) => Promise<void> | void;
|
|
344
369
|
adapters: TxAdapter<TR, T, A>[];
|
|
345
|
-
} & PersistOptions<ITxTrackingStore<TR, T, A>>): Omit<zustand.StoreApi<ITxTrackingStore<TR, T, A>>, "persist"> & {
|
|
370
|
+
} & PersistOptions<ITxTrackingStore<TR, T, A>>): Omit<zustand.StoreApi<ITxTrackingStore<TR, T, A>>, "setState" | "persist"> & {
|
|
371
|
+
setState(partial: ITxTrackingStore<TR, T, A> | Partial<ITxTrackingStore<TR, T, A>> | ((state: ITxTrackingStore<TR, T, A>) => ITxTrackingStore<TR, T, A> | Partial<ITxTrackingStore<TR, T, A>>), replace?: false | undefined): unknown;
|
|
372
|
+
setState(state: ITxTrackingStore<TR, T, A> | ((state: ITxTrackingStore<TR, T, A>) => ITxTrackingStore<TR, T, A>), replace: true): unknown;
|
|
346
373
|
persist: {
|
|
347
|
-
setOptions: (options: Partial<PersistOptions<ITxTrackingStore<TR, T, A>, ITxTrackingStore<TR, T, A
|
|
374
|
+
setOptions: (options: Partial<PersistOptions<ITxTrackingStore<TR, T, A>, ITxTrackingStore<TR, T, A>, unknown>>) => void;
|
|
348
375
|
clearStorage: () => void;
|
|
349
376
|
rehydrate: () => Promise<void> | void;
|
|
350
377
|
hasHydrated: () => boolean;
|
|
351
378
|
onHydrate: (fn: (state: ITxTrackingStore<TR, T, A>) => void) => () => void;
|
|
352
379
|
onFinishHydration: (fn: (state: ITxTrackingStore<TR, T, A>) => void) => () => void;
|
|
353
|
-
getOptions: () => Partial<PersistOptions<ITxTrackingStore<TR, T, A>, ITxTrackingStore<TR, T, A
|
|
380
|
+
getOptions: () => Partial<PersistOptions<ITxTrackingStore<TR, T, A>, ITxTrackingStore<TR, T, A>, unknown>>;
|
|
354
381
|
};
|
|
355
382
|
};
|
|
356
383
|
|
|
357
384
|
/**
|
|
358
|
-
* @file This file provides a utility for creating a bounded Zustand hook from a vanilla store.
|
|
359
|
-
* This is
|
|
385
|
+
* @file This file provides a utility for creating a type-safe, bounded Zustand hook from a vanilla store.
|
|
386
|
+
* This pattern is recommended by the official Zustand documentation to ensure full type
|
|
387
|
+
* safety when integrating vanilla stores with React.
|
|
360
388
|
*
|
|
361
|
-
* @see https://
|
|
389
|
+
* @see https://docs.pmnd.rs/zustand/guides/typescript#bounded-usestore-hook-for-vanilla-stores
|
|
362
390
|
*/
|
|
363
391
|
|
|
364
392
|
/**
|
|
365
|
-
* A utility type
|
|
366
|
-
*
|
|
393
|
+
* A utility type that infers the state shape from a Zustand `StoreApi`.
|
|
394
|
+
* It extracts the return type of the `getState` method.
|
|
395
|
+
* @template S - The type of the Zustand store (`StoreApi`).
|
|
367
396
|
*/
|
|
368
397
|
type ExtractState<S> = S extends {
|
|
369
|
-
getState: () => infer
|
|
370
|
-
} ?
|
|
398
|
+
getState: () => infer T;
|
|
399
|
+
} ? T : never;
|
|
371
400
|
/**
|
|
372
|
-
* Creates a bounded `useStore` hook from a vanilla Zustand store
|
|
373
|
-
*
|
|
401
|
+
* Creates a bounded `useStore` hook from a vanilla Zustand store.
|
|
402
|
+
*
|
|
403
|
+
* This function takes a vanilla Zustand store instance and returns a React hook
|
|
404
|
+
* that is pre-bound to that store. This approach provides a cleaner API and
|
|
405
|
+
* enhances type inference, eliminating the need to pass the store instance
|
|
406
|
+
* on every use.
|
|
374
407
|
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
408
|
+
* The returned hook supports two signatures:
|
|
409
|
+
* 1. `useBoundedStore()`: Selects the entire state.
|
|
410
|
+
* 2. `useBoundedStore(selector)`: Selects a slice of the state, returning only what the selector function specifies.
|
|
411
|
+
*
|
|
412
|
+
* @template S - The type of the Zustand store (`StoreApi`).
|
|
413
|
+
* @param {S} store - The vanilla Zustand store instance to bind the hook to.
|
|
414
|
+
* @returns {function} A fully typed React hook for accessing the store's state.
|
|
379
415
|
*/
|
|
380
416
|
declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) => {
|
|
381
417
|
(): ExtractState<S>;
|
|
@@ -383,82 +419,99 @@ declare const createBoundedUseStore: <S extends StoreApi<unknown>>(store: S) =>
|
|
|
383
419
|
};
|
|
384
420
|
|
|
385
421
|
/**
|
|
386
|
-
* @file This file
|
|
387
|
-
* such as API-based transaction status checks (e.g., for Gelato or Safe).
|
|
422
|
+
* @file This file provides a generic utility for creating a polling mechanism to track
|
|
423
|
+
* asynchronous tasks, such as API-based transaction status checks (e.g., for Gelato or Safe).
|
|
388
424
|
*/
|
|
389
425
|
|
|
426
|
+
/**
|
|
427
|
+
* Defines the parameters for the fetcher function used within the polling tracker.
|
|
428
|
+
* The fetcher is the core logic that performs the actual API call.
|
|
429
|
+
* @template R - The expected type of the successful API response.
|
|
430
|
+
* @template T - The type of the transaction object being tracked.
|
|
431
|
+
*/
|
|
432
|
+
type PollingFetcherParams<R, T> = {
|
|
433
|
+
/** The transaction object being tracked. */
|
|
434
|
+
tx: T;
|
|
435
|
+
/** A callback to stop the polling mechanism, typically called on success or terminal failure. */
|
|
436
|
+
stopPolling: (options?: {
|
|
437
|
+
withoutRemoving?: boolean;
|
|
438
|
+
}) => void;
|
|
439
|
+
/** Callback to be invoked when the fetcher determines the transaction has succeeded. */
|
|
440
|
+
onSuccess: (response: R) => void;
|
|
441
|
+
/** Callback to be invoked when the fetcher determines the transaction has failed. */
|
|
442
|
+
onFailure: (response?: R) => void;
|
|
443
|
+
/** Optional callback for each successful poll, useful for updating UI with intermediate states. */
|
|
444
|
+
onIntervalTick?: (response: R) => void;
|
|
445
|
+
/** Optional callback for when a transaction is replaced (e.g., speed-up). */
|
|
446
|
+
onReplaced?: (response: R) => void;
|
|
447
|
+
};
|
|
390
448
|
/**
|
|
391
449
|
* Defines the configuration object for the `initializePollingTracker` function.
|
|
392
|
-
* @template R The expected type of the successful API response
|
|
393
|
-
* @template T The type of the transaction object
|
|
394
|
-
* @template TR The type of the tracker identifier
|
|
395
|
-
*/
|
|
396
|
-
type
|
|
397
|
-
/** The transaction object to be tracked. It must include `txKey` and
|
|
398
|
-
tx: T & Pick<Transaction<TR>, 'txKey'
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
/** A callback to stop the polling mechanism, typically called on success or terminal failure. */
|
|
406
|
-
clearWatch: (withoutRemoving?: boolean) => void;
|
|
407
|
-
/** Callback to be invoked when the fetcher determines the transaction has succeeded. */
|
|
408
|
-
onSucceed: (response: R) => void;
|
|
409
|
-
/** Callback to be invoked when the fetcher determines the transaction has failed. */
|
|
410
|
-
onFailed: (response: R) => void;
|
|
411
|
-
/** Optional callback for each successful poll, useful for updating UI with intermediate states. */
|
|
412
|
-
onIntervalTick?: (response: R) => void;
|
|
413
|
-
/** Optional callback for when a transaction is replaced by another. */
|
|
414
|
-
onReplaced?: (response: R) => void;
|
|
415
|
-
}) => Promise<Response>;
|
|
450
|
+
* @template R - The expected type of the successful API response.
|
|
451
|
+
* @template T - The type of the transaction object.
|
|
452
|
+
* @template TR - The type of the tracker identifier.
|
|
453
|
+
*/
|
|
454
|
+
type PollingTrackerConfig<R, T, TR> = {
|
|
455
|
+
/** The transaction object to be tracked. It must include `txKey` and `pending` status. */
|
|
456
|
+
tx: T & Pick<Transaction<TR>, 'txKey' | 'pending'>;
|
|
457
|
+
/** The function that performs the data fetching (e.g., an API call) on each interval. */
|
|
458
|
+
fetcher: (params: PollingFetcherParams<R, T>) => Promise<void>;
|
|
459
|
+
/** Callback to be invoked when the transaction successfully completes. */
|
|
460
|
+
onSuccess: (response: R) => void;
|
|
461
|
+
/** Callback to be invoked when the transaction fails. */
|
|
462
|
+
onFailure: (response?: R) => void;
|
|
416
463
|
/** Optional callback executed once when the tracker is initialized. */
|
|
417
464
|
onInitialize?: () => void;
|
|
418
|
-
/** Callback to be invoked when the transaction has succeeded. */
|
|
419
|
-
onSucceed: (response: R) => void;
|
|
420
|
-
/** Callback to be invoked when the transaction has failed. */
|
|
421
|
-
onFailed: (response: R) => void;
|
|
422
465
|
/** Optional callback for each successful poll. */
|
|
423
466
|
onIntervalTick?: (response: R) => void;
|
|
424
467
|
/** Optional callback for when a transaction is replaced. */
|
|
425
468
|
onReplaced?: (response: R) => void;
|
|
426
469
|
/** Optional function to remove the transaction from the main pool, typically after polling stops. */
|
|
427
|
-
removeTxFromPool?: (
|
|
470
|
+
removeTxFromPool?: (txKey: string) => void;
|
|
428
471
|
/** The interval (in milliseconds) between polling attempts. Defaults to 5000ms. */
|
|
429
472
|
pollingInterval?: number;
|
|
430
473
|
/** The number of consecutive failed fetches before stopping the tracker. Defaults to 10. */
|
|
431
|
-
|
|
474
|
+
maxRetries?: number;
|
|
432
475
|
};
|
|
433
476
|
/**
|
|
434
477
|
* Initializes a generic polling tracker that repeatedly calls a fetcher function
|
|
435
|
-
* to monitor the status of
|
|
478
|
+
* to monitor the status of an asynchronous task.
|
|
436
479
|
*
|
|
437
|
-
*
|
|
480
|
+
* This function handles the lifecycle of polling, including starting, stopping,
|
|
481
|
+
* and automatic termination after a certain number of failed attempts.
|
|
482
|
+
*
|
|
483
|
+
* @template R The expected type of the API response.
|
|
438
484
|
* @template T The type of the transaction object.
|
|
439
485
|
* @template TR The type of the tracker identifier.
|
|
440
|
-
* @param {
|
|
441
|
-
|
|
486
|
+
* @param {PollingTrackerConfig<R, T, TR>} config - The configuration for the tracker.
|
|
487
|
+
*/
|
|
488
|
+
declare function initializePollingTracker<R, T, TR>(config: PollingTrackerConfig<R, T, TR>): void;
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* @file This file contains a utility function for selecting a specific transaction adapter from a list.
|
|
442
492
|
*/
|
|
443
|
-
declare function initializePollingTracker<R, T, TR>({ onInitialize, tx, removeTxFromPool, fetcher, onFailed, onIntervalTick, onSucceed, pollingInterval, retryCount, onReplaced, }: InitializePollingTracker<R, T, TR>): Promise<void>;
|
|
444
493
|
|
|
445
494
|
/**
|
|
446
|
-
* Selects
|
|
447
|
-
* If no matching adapter is found, the first adapter in the list is returned as a fallback.
|
|
495
|
+
* Selects a transaction adapter from a list based on a provided key.
|
|
448
496
|
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
*
|
|
497
|
+
* This function searches through an array of `TxAdapter` instances and returns the one
|
|
498
|
+
* that matches the given `adapterKey`. If no specific adapter is found, it logs a warning
|
|
499
|
+
* and returns the first adapter in the array as a fallback. This fallback mechanism
|
|
500
|
+
* ensures that the system can still function, but it highlights a potential configuration issue.
|
|
501
|
+
*
|
|
502
|
+
* @template TR - The type of the tracker identifier.
|
|
503
|
+
* @template T - The transaction type, extending the base `Transaction`.
|
|
504
|
+
* @template A - The type for the adapter-specific context or API.
|
|
452
505
|
*
|
|
453
|
-
* @param {
|
|
454
|
-
* @param {TransactionAdapter} params.adapterKey - The key
|
|
506
|
+
* @param {object} params - The parameters for the selection.
|
|
507
|
+
* @param {TransactionAdapter} params.adapterKey - The key of the desired adapter.
|
|
455
508
|
* @param {TxAdapter<TR, T, A>[]} params.adapters - An array of available transaction adapters.
|
|
456
509
|
*
|
|
457
|
-
* @returns {TxAdapter<TR, T, A>} The transaction adapter
|
|
510
|
+
* @returns {TxAdapter<TR, T, A> | undefined} The found transaction adapter, the fallback adapter, or undefined if the adapters array is empty.
|
|
458
511
|
*/
|
|
459
512
|
declare const selectAdapterByKey: <TR, T extends Transaction<TR>, A>({ adapterKey, adapters, }: {
|
|
460
513
|
adapterKey: TransactionAdapter;
|
|
461
514
|
adapters: TxAdapter<TR, T, A>[];
|
|
462
|
-
}) => TxAdapter<TR, T, A
|
|
515
|
+
}) => TxAdapter<TR, T, A> | undefined;
|
|
463
516
|
|
|
464
|
-
export { type BaseTransaction, type EvmTransaction, type IInitializeTxTrackingStore, type ITxTrackingStore, type InitialTransaction, type InitialTransactionParams, type
|
|
517
|
+
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 TxActions, type TxAdapter, createBoundedUseStore, createPulsarStore, initializePollingTracker, initializeTxTrackingStore, selectAdapterByKey, selectAllTransactions, selectAllTransactionsByActiveWallet, selectPendingTransactions, selectPendingTransactionsByActiveWallet, selectTxByKey };
|