@tuwaio/pulsar-core 1.0.0-alpha.2 → 1.0.0-alpha.3.815bc21.acc55b8

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.mts CHANGED
@@ -135,6 +135,8 @@ type StarknetTransaction<T> = BaseTransaction<T> & {
135
135
  };
136
136
  /** A union type representing any possible transaction structure. */
137
137
  type Transaction<T> = EvmTransaction<T> | SolanaTransaction<T> | StarknetTransaction<T>;
138
+ /** A registry of functions that can be re-executed via the 'Retry' button. The key should match `actionKey` on a transaction. */
139
+ type TxActions = Record<string, (...args: any[]) => Promise<unknown>>;
138
140
  /**
139
141
  * Represents the parameters required to initiate a new transaction.
140
142
  */
@@ -170,6 +172,13 @@ type InitialTransaction = InitialTransactionParams & {
170
172
  /** The local timestamp when the user initiated the action. */
171
173
  localTimestamp: number;
172
174
  };
175
+ /**
176
+ * Represents the type for a transaction adapter which provides utilities for handling transaction-related operations.
177
+ *
178
+ * @template TR - Represents the transaction tracker type.
179
+ * @template T - Represents the type of the transaction, extending the base Transaction<TR>.
180
+ * @template A - Represents the type for the action transaction key.
181
+ */
173
182
  type TxAdapter<TR, T extends Transaction<TR>, A> = {
174
183
  key: TransactionAdapter;
175
184
  getWalletInfo: () => {
@@ -186,6 +195,15 @@ type TxAdapter<TR, T extends Transaction<TR>, A> = {
186
195
  checkAndInitializeTrackerInStore: ({ tx, ...rest }: {
187
196
  tx: T;
188
197
  } & Pick<ITxTrackingStore<TR, T, A>, 'transactionsPool' | 'updateTxParams' | 'onSucceedCallbacks' | 'removeTxFromPool'>) => Promise<void>;
198
+ cancelTxAction?: (tx: T) => Promise<string>;
199
+ speedUpTxAction?: (tx: T) => Promise<string>;
200
+ retryTxAction?: ({ tx, actions, onClose, handleTransaction, }: {
201
+ txKey: string;
202
+ tx: InitialTransactionParams;
203
+ actions?: TxActions;
204
+ onClose: (txKey?: string) => void;
205
+ } & Partial<Pick<ITxTrackingStore<TR, T, A>, 'handleTransaction'>>) => Promise<void>;
206
+ explorerLink: (transactionsPool: TransactionPool<TR, T>, txKey: string, replacedTxHash?: string) => string;
189
207
  };
190
208
  /**
191
209
  * Interface for the complete transaction tracking store.
@@ -423,4 +441,23 @@ type InitializePollingTracker<R, T, TR> = {
423
441
  */
424
442
  declare function initializePollingTracker<R, T, TR>({ onInitialize, tx, removeTxFromPool, fetcher, onFailed, onIntervalTick, onSucceed, pollingInterval, retryCount, onReplaced, }: InitializePollingTracker<R, T, TR>): Promise<void>;
425
443
 
426
- export { type BaseTransaction, type EvmTransaction, type IInitializeTxTrackingStore, type ITxTrackingStore, type InitialTransaction, type InitialTransactionParams, type InitializePollingTracker, type SolanaTransaction, type StarknetTransaction, type StoreSlice, type Transaction, TransactionAdapter, type TransactionPool, TransactionStatus, type TxAdapter, createBoundedUseStore, createPulsarStore, initializePollingTracker, initializeTxTrackingStore, selectAllTransactions, selectAllTransactionsByActiveWallet, selectPendingTransactions, selectPendingTransactionsByActiveWallet, selectTXByKey };
444
+ /**
445
+ * Selects and returns a transaction adapter from a list of adapters based on the provided adapter key.
446
+ * If no matching adapter is found, the first adapter in the list is returned as a fallback.
447
+ *
448
+ * @template TR - Represents the transaction response type.
449
+ * @template T - Extends the Transaction type and represents the transaction entity.
450
+ * @template A - Represents the adapter type.
451
+ *
452
+ * @param {Object} params - Configuration object for selecting the adapter.
453
+ * @param {TransactionAdapter} params.adapterKey - The key used to identify the desired transaction adapter.
454
+ * @param {TxAdapter<TR, T, A>[]} params.adapters - An array of available transaction adapters.
455
+ *
456
+ * @returns {TxAdapter<TR, T, A>} The transaction adapter corresponding to the provided key, or the first adapter in the list.
457
+ */
458
+ declare const selectAdapterByKey: <TR, T extends Transaction<TR>, A>({ adapterKey, adapters, }: {
459
+ adapterKey: TransactionAdapter;
460
+ adapters: TxAdapter<TR, T, A>[];
461
+ }) => TxAdapter<TR, T, A>;
462
+
463
+ export { type BaseTransaction, type EvmTransaction, type IInitializeTxTrackingStore, type ITxTrackingStore, type InitialTransaction, type InitialTransactionParams, type InitializePollingTracker, 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 };
package/dist/index.d.ts CHANGED
@@ -135,6 +135,8 @@ type StarknetTransaction<T> = BaseTransaction<T> & {
135
135
  };
136
136
  /** A union type representing any possible transaction structure. */
137
137
  type Transaction<T> = EvmTransaction<T> | SolanaTransaction<T> | StarknetTransaction<T>;
138
+ /** A registry of functions that can be re-executed via the 'Retry' button. The key should match `actionKey` on a transaction. */
139
+ type TxActions = Record<string, (...args: any[]) => Promise<unknown>>;
138
140
  /**
139
141
  * Represents the parameters required to initiate a new transaction.
140
142
  */
@@ -170,6 +172,13 @@ type InitialTransaction = InitialTransactionParams & {
170
172
  /** The local timestamp when the user initiated the action. */
171
173
  localTimestamp: number;
172
174
  };
175
+ /**
176
+ * Represents the type for a transaction adapter which provides utilities for handling transaction-related operations.
177
+ *
178
+ * @template TR - Represents the transaction tracker type.
179
+ * @template T - Represents the type of the transaction, extending the base Transaction<TR>.
180
+ * @template A - Represents the type for the action transaction key.
181
+ */
173
182
  type TxAdapter<TR, T extends Transaction<TR>, A> = {
174
183
  key: TransactionAdapter;
175
184
  getWalletInfo: () => {
@@ -186,6 +195,15 @@ type TxAdapter<TR, T extends Transaction<TR>, A> = {
186
195
  checkAndInitializeTrackerInStore: ({ tx, ...rest }: {
187
196
  tx: T;
188
197
  } & Pick<ITxTrackingStore<TR, T, A>, 'transactionsPool' | 'updateTxParams' | 'onSucceedCallbacks' | 'removeTxFromPool'>) => Promise<void>;
198
+ cancelTxAction?: (tx: T) => Promise<string>;
199
+ speedUpTxAction?: (tx: T) => Promise<string>;
200
+ retryTxAction?: ({ tx, actions, onClose, handleTransaction, }: {
201
+ txKey: string;
202
+ tx: InitialTransactionParams;
203
+ actions?: TxActions;
204
+ onClose: (txKey?: string) => void;
205
+ } & Partial<Pick<ITxTrackingStore<TR, T, A>, 'handleTransaction'>>) => Promise<void>;
206
+ explorerLink: (transactionsPool: TransactionPool<TR, T>, txKey: string, replacedTxHash?: string) => string;
189
207
  };
190
208
  /**
191
209
  * Interface for the complete transaction tracking store.
@@ -423,4 +441,23 @@ type InitializePollingTracker<R, T, TR> = {
423
441
  */
424
442
  declare function initializePollingTracker<R, T, TR>({ onInitialize, tx, removeTxFromPool, fetcher, onFailed, onIntervalTick, onSucceed, pollingInterval, retryCount, onReplaced, }: InitializePollingTracker<R, T, TR>): Promise<void>;
425
443
 
426
- export { type BaseTransaction, type EvmTransaction, type IInitializeTxTrackingStore, type ITxTrackingStore, type InitialTransaction, type InitialTransactionParams, type InitializePollingTracker, type SolanaTransaction, type StarknetTransaction, type StoreSlice, type Transaction, TransactionAdapter, type TransactionPool, TransactionStatus, type TxAdapter, createBoundedUseStore, createPulsarStore, initializePollingTracker, initializeTxTrackingStore, selectAllTransactions, selectAllTransactionsByActiveWallet, selectPendingTransactions, selectPendingTransactionsByActiveWallet, selectTXByKey };
444
+ /**
445
+ * Selects and returns a transaction adapter from a list of adapters based on the provided adapter key.
446
+ * If no matching adapter is found, the first adapter in the list is returned as a fallback.
447
+ *
448
+ * @template TR - Represents the transaction response type.
449
+ * @template T - Extends the Transaction type and represents the transaction entity.
450
+ * @template A - Represents the adapter type.
451
+ *
452
+ * @param {Object} params - Configuration object for selecting the adapter.
453
+ * @param {TransactionAdapter} params.adapterKey - The key used to identify the desired transaction adapter.
454
+ * @param {TxAdapter<TR, T, A>[]} params.adapters - An array of available transaction adapters.
455
+ *
456
+ * @returns {TxAdapter<TR, T, A>} The transaction adapter corresponding to the provided key, or the first adapter in the list.
457
+ */
458
+ declare const selectAdapterByKey: <TR, T extends Transaction<TR>, A>({ adapterKey, adapters, }: {
459
+ adapterKey: TransactionAdapter;
460
+ adapters: TxAdapter<TR, T, A>[];
461
+ }) => TxAdapter<TR, T, A>;
462
+
463
+ export { type BaseTransaction, type EvmTransaction, type IInitializeTxTrackingStore, type ITxTrackingStore, type InitialTransaction, type InitialTransactionParams, type InitializePollingTracker, 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 };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var immer=require('immer'),b=require('dayjs'),middleware=require('zustand/middleware'),vanilla=require('zustand/vanilla'),zustand=require('zustand');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var b__default=/*#__PURE__*/_interopDefault(b);function S({onSucceedCallbacks:n}){return (t,a)=>({onSucceedCallbacks:n,transactionsPool:{},lastAddedTxKey:void 0,initialTx:void 0,addTxToPool:({tx:e})=>{t({lastAddedTxKey:e.txKey}),t(i=>immer.produce(i,r=>{e.txKey&&(r.transactionsPool[e.txKey]={...e,pending:true});}));},updateTxParams:e=>{t(i=>immer.produce(i,r=>{r.transactionsPool[e.txKey]&&(r.transactionsPool[e.txKey]={...r.transactionsPool[e.txKey],...e});}));},removeTxFromPool:e=>{t(i=>immer.produce(i,r=>{delete r.transactionsPool[e];}));},closeTxTrackedModal:e=>{e&&t(i=>immer.produce(i,r=>{r.transactionsPool[e]&&(r.transactionsPool[e].isTrackedModalOpen=false);})),t({initialTx:void 0});},getLastTxKey:()=>a().lastAddedTxKey})}var v=n=>Object.values(n).sort((t,a)=>Number(t.localTimestamp)-Number(a.localTimestamp)),A=n=>v(n).filter(t=>t.pending),C=(n,t)=>n[t],j=(n,t)=>v(n).filter(a=>a.from===t),D=(n,t)=>A(n).filter(a=>a.from===t);function $({onSucceedCallbacks:n,adapters:t,...a}){return vanilla.createStore()(middleware.persist((e,i)=>({...S({onSucceedCallbacks:n})(e,i),initializeTransactionsPool:async()=>{await Promise.all(Object.values(i().transactionsPool).map(async r=>{r.pending&&t.find(T=>T.key===r.adapter)?.checkAndInitializeTrackerInStore({tx:r,...i()});}));},handleTransaction:async({defaultTracker:r,actionFunction:g,params:T})=>{e({initialTx:void 0});let{desiredChainID:u,...f}=T,l=b__default.default().unix(),s=t.find(o=>o.key===f.adapter),{walletType:d,walletAddress:c}=s?s.getWalletInfo():{},k={...f,walletType:d,from:c,tracker:r,chainId:u,localTimestamp:l,txKey:"",pending:false,isTrackedModalOpen:T.withTrackedModal},R=o=>{let p=o instanceof Error?o.message:String(o);throw e(x=>immer.produce(x,m=>{m.initialTx&&(m.initialTx.isInitializing=false,m.initialTx.errorMessage=p);})),new Error(`Transaction failed to initialize: ${p}`)};if(e({initialTx:{...T,localTimestamp:l,isInitializing:true}}),s)try{await s.checkChainForTx(u);let o=await g();if(o){let{tracker:p,txKey:x}=s.checkTransactionsTracker(o,k.walletType);i().addTxToPool({tx:{...k,tracker:p,txKey:x,hash:p==="ethereum"?o:void 0}}),e(h=>immer.produce(h,P=>{P.initialTx&&(P.initialTx.isInitializing=!1,P.initialTx.lastTxKey=x);}));let m=i().transactionsPool[x];await s.checkAndInitializeTrackerInStore({tx:m,...i()});}else e({initialTx:void 0});}catch(o){R(o);}else R("No adapter found for this transaction.");}}),{...a}))}var E=(e=>(e.EVM="evm",e.SOLANA="solana",e.Starknet="Starknet",e))(E||{}),z=(e=>(e.Failed="Failed",e.Success="Success",e.Replaced="Replaced",e))(z||{});var Z=(n=>t=>zustand.useStore(n,t));async function ee({onInitialize:n,tx:t,removeTxFromPool:a,fetcher:e,onFailed:i,onIntervalTick:r,onSucceed:g,pollingInterval:T,retryCount:u,onReplaced:f}){if(n&&n(),!t?.pending)return;let l,s=c=>{clearInterval(l),a&&!c&&a(t.txKey);},d=u??10;l=window.setInterval(async()=>{if(d<=0){s();return}try{(await e({tx:t,onSucceed:g,onFailed:i,onIntervalTick:r,onReplaced:f,clearWatch:s})).ok||d--;}catch(c){console.error("Polling fetcher function threw an error:",c),d--;}},T??5e3);}exports.TransactionAdapter=E;exports.TransactionStatus=z;exports.createBoundedUseStore=Z;exports.createPulsarStore=$;exports.initializePollingTracker=ee;exports.initializeTxTrackingStore=S;exports.selectAllTransactions=v;exports.selectAllTransactionsByActiveWallet=j;exports.selectPendingTransactions=A;exports.selectPendingTransactionsByActiveWallet=D;exports.selectTXByKey=C;//# sourceMappingURL=index.js.map
1
+ 'use strict';var immer=require('immer'),b=require('dayjs'),middleware=require('zustand/middleware'),vanilla=require('zustand/vanilla'),zustand=require('zustand');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var b__default=/*#__PURE__*/_interopDefault(b);function A({onSucceedCallbacks:n}){return (t,i)=>({onSucceedCallbacks:n,transactionsPool:{},lastAddedTxKey:void 0,initialTx:void 0,addTxToPool:({tx:e})=>{t({lastAddedTxKey:e.txKey}),t(a=>immer.produce(a,r=>{e.txKey&&(r.transactionsPool[e.txKey]={...e,pending:true});}));},updateTxParams:e=>{t(a=>immer.produce(a,r=>{r.transactionsPool[e.txKey]&&(r.transactionsPool[e.txKey]={...r.transactionsPool[e.txKey],...e});}));},removeTxFromPool:e=>{t(a=>immer.produce(a,r=>{delete r.transactionsPool[e];}));},closeTxTrackedModal:e=>{e&&t(a=>immer.produce(a,r=>{r.transactionsPool[e]&&(r.transactionsPool[e].isTrackedModalOpen=false);})),t({initialTx:void 0});},getLastTxKey:()=>i().lastAddedTxKey})}var v=n=>Object.values(n).sort((t,i)=>Number(t.localTimestamp)-Number(i.localTimestamp)),K=n=>v(n).filter(t=>t.pending),j=(n,t)=>n[t],D=(n,t)=>v(n).filter(i=>i.from===t),L=(n,t)=>K(n).filter(i=>i.from===t);var R=({adapterKey:n,adapters:t})=>{let i=t.find(e=>e.key===n);return i||t[0]};function Q({onSucceedCallbacks:n,adapters:t,...i}){return vanilla.createStore()(middleware.persist((e,a)=>({...A({onSucceedCallbacks:n})(e,a),initializeTransactionsPool:async()=>{await Promise.all(Object.values(a().transactionsPool).map(async r=>{r.pending&&R({adapterKey:r.adapter,adapters:t})?.checkAndInitializeTrackerInStore({tx:r,...a()});}));},handleTransaction:async({defaultTracker:r,actionFunction:g,params:c})=>{e({initialTx:void 0});let{desiredChainID:y,...u}=c,l=b__default.default().unix(),o=R({adapterKey:u.adapter,adapters:t}),{walletType:d,walletAddress:T}=o?o.getWalletInfo():{},k={...u,walletType:d,from:T,tracker:r,chainId:y,localTimestamp:l,txKey:"",pending:false,isTrackedModalOpen:c.withTrackedModal},S=s=>{let p=s instanceof Error?s.message:String(s);throw e(x=>immer.produce(x,m=>{m.initialTx&&(m.initialTx.isInitializing=false,m.initialTx.errorMessage=p);})),new Error(`Transaction failed to initialize: ${p}`)};if(e({initialTx:{...c,localTimestamp:l,isInitializing:true}}),o)try{await o.checkChainForTx(y);let s=await g();if(s){let{tracker:p,txKey:x}=o.checkTransactionsTracker(s,k.walletType);a().addTxToPool({tx:{...k,tracker:p,txKey:x,hash:p==="ethereum"?s:void 0}}),e(h=>immer.produce(h,P=>{P.initialTx&&(P.initialTx.isInitializing=!1,P.initialTx.lastTxKey=x);}));let m=a().transactionsPool[x];await o.checkAndInitializeTrackerInStore({tx:m,...a()});}else e({initialTx:void 0});}catch(s){S(s);}else S("No adapter found for this transaction.");}}),{...i}))}var z=(e=>(e.EVM="evm",e.SOLANA="solana",e.Starknet="Starknet",e))(z||{}),F=(e=>(e.Failed="Failed",e.Success="Success",e.Replaced="Replaced",e))(F||{});var te=(n=>t=>zustand.useStore(n,t));async function re({onInitialize:n,tx:t,removeTxFromPool:i,fetcher:e,onFailed:a,onIntervalTick:r,onSucceed:g,pollingInterval:c,retryCount:y,onReplaced:u}){if(n&&n(),!t?.pending)return;let l,o=T=>{clearInterval(l),i&&!T&&i(t.txKey);},d=y??10;l=window.setInterval(async()=>{if(d<=0){o();return}try{(await e({tx:t,onSucceed:g,onFailed:a,onIntervalTick:r,onReplaced:u,clearWatch:o})).ok||d--;}catch(T){console.error("Polling fetcher function threw an error:",T),d--;}},c??5e3);}exports.TransactionAdapter=z;exports.TransactionStatus=F;exports.createBoundedUseStore=te;exports.createPulsarStore=Q;exports.initializePollingTracker=re;exports.initializeTxTrackingStore=A;exports.selectAdapterByKey=R;exports.selectAllTransactions=v;exports.selectAllTransactionsByActiveWallet=D;exports.selectPendingTransactions=K;exports.selectPendingTransactionsByActiveWallet=L;exports.selectTXByKey=j;//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/store/initializeTxTrackingStore.ts","../src/store/transactionsSelectors.ts","../src/store/txTrackingStore.ts","../src/types.ts","../src/utils/createBoundedUseStore.ts","../src/utils/initializePollingTracker.ts"],"names":["initializeTxTrackingStore","onSucceedCallbacks","set","get","tx","state","produce","draft","txKey","selectAllTransactions","transactionsPool","a","b","selectPendingTransactions","selectTXByKey","key","selectAllTransactionsByActiveWallet","from","selectPendingTransactionsByActiveWallet","createPulsarStore","adapters","options","createStore","persist","adapter","defaultTracker","actionFunction","params","desiredChainID","restParams","localTimestamp","dayjs","walletType","walletAddress","txInitialParams","handleError","e","errorMessage","txKeyFromAction","updatedTracker","finalTxKey","TransactionAdapter","TransactionStatus","createBoundedUseStore","store","selector","useStore","initializePollingTracker","onInitialize","removeTxFromPool","fetcher","onFailed","onIntervalTick","onSucceed","pollingInterval","retryCount","onReplaced","pollingIntervalId","clearWatch","withoutRemoving","retriesLeft","error"],"mappings":"kRA2EO,SAASA,CAAAA,CAAyD,CACvE,kBAAA,CAAAC,CACF,CAAA,CAEkD,CAChD,OAAO,CAACC,CAAAA,CAAKC,KAAS,CACpB,kBAAA,CAAAF,EAEA,gBAAA,CAAkB,EAAC,CACnB,cAAA,CAAgB,OAChB,SAAA,CAAW,MAAA,CAEX,WAAA,CAAa,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AAAA,EAAmB,GAAI,EAC5B","file":"index.js","sourcesContent":["/**\n * @file This file provides the core slice for the Zustand store, responsible for managing the state of transactions.\n * It includes functions and types for initializing the store and performing basic CRUD operations on the transaction pool.\n */\n\nimport { Draft, produce } from 'immer';\n\nimport {EvmTransaction, InitialTransaction, StoreSlice, Transaction} from '../types';\n\n/**\n * Defines the structure of the transaction pool, which is a record of transactions indexed by their unique keys.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n */\nexport type TransactionPool<TR, T extends Transaction<TR>> = Record<string, T>;\n\n/**\n * A utility type that extracts a subset of fields from the `Transaction` type\n * that are updatable via the `updateTxParams` action.\n * @template TR - The type of the tracker identifier.\n */\ntype UpdatedParamsFields<TR> = Pick<\n EvmTransaction<TR>,\n | 'to'\n | 'nonce'\n | 'txKey'\n | 'pending'\n | 'hash'\n | 'status'\n | 'replacedTxHash'\n | 'errorMessage'\n | 'finishedTimestamp'\n | 'isTrackedModalOpen'\n | 'isError'\n | 'maxPriorityFeePerGas'\n | 'maxFeePerGas'\n | 'input'\n | 'value'\n>;\n\n/**\n * Defines the interface for the base transaction tracking store slice.\n * It includes the state and actions for managing transactions.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n */\nexport type IInitializeTxTrackingStore<TR, T extends Transaction<TR>> = {\n /** An optional callback function to be executed when a transaction successfully completes. */\n onSucceedCallbacks?: (tx: T) => Promise<void> | void;\n /** A pool of all transactions currently being tracked, indexed by their `txKey`. */\n transactionsPool: TransactionPool<TR, T>;\n /** The key of the most recently added transaction. */\n lastAddedTxKey?: string;\n /** The state of a transaction that is currently being initiated but not yet submitted. */\n initialTx?: InitialTransaction;\n\n /** Adds a new transaction to the tracking pool. */\n addTxToPool: ({ tx }: { tx: T }) => void;\n /** Updates one or more parameters of an existing transaction in the pool. */\n updateTxParams: (fields: UpdatedParamsFields<TR>) => void;\n /** Removes a transaction from the tracking pool using its key. */\n removeTxFromPool: (txKey: string) => void;\n /** Closes the tracking modal for a specific transaction. */\n closeTxTrackedModal: (txKey?: string) => void;\n /** Returns the key of the last transaction that was added to the pool. */\n getLastTxKey: () => string | undefined;\n};\n\n/**\n * Creates a Zustand store slice containing the core logic for transaction tracking.\n * This function is a slice creator and is meant to be used within `createStore` from Zustand.\n * @param {object} options - Configuration options for the store slice.\n * @param {function} [options.onSucceedCallbacks] - An optional async callback to run when a transaction succeeds.\n * @returns {StoreSlice<IInitializeTxTrackingStore<TR, T>>} A Zustand store slice.\n */\nexport function initializeTxTrackingStore<TR, T extends Transaction<TR>>({\n onSucceedCallbacks,\n}: {\n onSucceedCallbacks?: (tx: T) => Promise<void> | void;\n}): StoreSlice<IInitializeTxTrackingStore<TR, T>> {\n return (set, get) => ({\n onSucceedCallbacks,\n\n transactionsPool: {},\n lastAddedTxKey: undefined,\n initialTx: undefined,\n\n addTxToPool: ({ tx }) => {\n set({ lastAddedTxKey: tx.txKey });\n set((state) =>\n produce(state, (draft) => {\n if (tx.txKey) {\n draft.transactionsPool[tx.txKey] = {\n ...tx,\n pending: true,\n } as Draft<T>;\n }\n }),\n );\n },\n\n updateTxParams: (tx) => {\n set((state) =>\n produce(state, (draft) => {\n // Ensure the transaction exists before attempting to update\n if (draft.transactionsPool[tx.txKey]) {\n draft.transactionsPool[tx.txKey] = {\n ...draft.transactionsPool[tx.txKey],\n ...tx,\n };\n }\n }),\n );\n },\n\n removeTxFromPool: (txKey) => {\n set((state) =>\n produce(state, (draft) => {\n delete draft.transactionsPool[txKey];\n }),\n );\n },\n\n closeTxTrackedModal: (txKey) => {\n if (txKey) {\n set((state) =>\n produce(state, (draft) => {\n if (draft.transactionsPool[txKey]) {\n draft.transactionsPool[txKey].isTrackedModalOpen = false;\n }\n }),\n );\n }\n // Always clear the initial transaction state when a modal is closed\n set({ initialTx: undefined });\n },\n\n getLastTxKey: () => {\n return get().lastAddedTxKey;\n },\n });\n}\n","/**\n * @file This file contains selector functions for deriving state from the transaction tracking store.\n * Selectors help abstract away the shape of the state and provide memoized, efficient access to computed data.\n */\n\nimport { Transaction } from '../types';\nimport { TransactionPool } from './initializeTxTrackingStore';\n\n/**\n * Selects all transactions from the pool and sorts them by their creation timestamp.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @returns {T[]} An array of all transactions, sorted chronologically.\n */\nexport const selectAllTransactions = <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>): T[] => {\n return Object.values(transactionsPool).sort((a, b) => Number(a.localTimestamp) - Number(b.localTimestamp));\n};\n\n/**\n * Selects all transactions that are currently in a pending state.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @returns {T[]} An array of pending transactions.\n */\nexport const selectPendingTransactions = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n): T[] => {\n return selectAllTransactions(transactionsPool).filter((tx) => tx.pending);\n};\n\n/**\n * Selects a single transaction from the pool by its unique transaction key (`txKey`).\n * This is the most direct way to retrieve a transaction.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @param {string} key - The `txKey` of the transaction to retrieve.\n * @returns {T | undefined} The transaction object if found, otherwise undefined.\n */\nexport const selectTXByKey = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n key: string,\n): T | undefined => {\n return transactionsPool[key];\n};\n\n/**\n * Selects all transactions initiated by a specific wallet address.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @param {string} from - The wallet address (`from` address) to filter transactions by.\n * @returns {T[]} An array of transactions associated with the given wallet.\n */\nexport const selectAllTransactionsByActiveWallet = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n from: string,\n): T[] => {\n return selectAllTransactions(transactionsPool).filter((tx) => tx.from === from);\n};\n\n/**\n * Selects all pending transactions initiated by a specific wallet address.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @param {string} from - The wallet address (`from` address) to filter transactions by.\n * @returns {T[]} An array of pending transactions associated with the given wallet.\n */\nexport const selectPendingTransactionsByActiveWallet = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n from: string,\n): T[] => {\n return selectPendingTransactions(transactionsPool).filter((tx) => tx.from === from);\n};\n","import dayjs from 'dayjs';\nimport { Draft, produce } from 'immer';\nimport { persist, PersistOptions } from 'zustand/middleware';\nimport { createStore } from 'zustand/vanilla';\n\nimport { ITxTrackingStore, Transaction, TxAdapter } from '../types';\nimport { initializeTxTrackingStore } from './initializeTxTrackingStore';\n\nexport function createPulsarStore<TR, T extends Transaction<TR>, A>({\n onSucceedCallbacks,\n adapters,\n ...options\n}: {\n onSucceedCallbacks?: (tx: T) => Promise<void> | void;\n adapters: TxAdapter<TR, T, A>[];\n} & PersistOptions<ITxTrackingStore<TR, T, A>>) {\n return createStore<ITxTrackingStore<TR, T, A>>()(\n persist(\n (set, get) => ({\n ...initializeTxTrackingStore<TR, T>({ onSucceedCallbacks })(set, get),\n\n /**\n * Initializes trackers for all pending transactions in the pool.\n * This is essential for resuming tracking after a page reload.\n */\n initializeTransactionsPool: async () => {\n await Promise.all(\n Object.values(get().transactionsPool).map(async (tx) => {\n if (tx.pending) {\n const adapter = adapters.find((adapter) => adapter.key === tx.adapter);\n adapter?.checkAndInitializeTrackerInStore({ tx, ...get() });\n }\n }),\n );\n },\n\n /**\n * The main function to orchestrate sending and tracking a new transaction.\n * It handles chain switching, wallet interactions, state updates, and tracker initialization.\n */\n handleTransaction: async ({ defaultTracker, actionFunction, params }) => {\n set({ initialTx: undefined }); // Clear any previous initial state\n const { desiredChainID, ...restParams } = params;\n const localTimestamp = dayjs().unix();\n\n const adapter = adapters.find((adapter) => adapter.key === restParams.adapter);\n\n const { walletType, walletAddress } = adapter ? adapter.getWalletInfo() : {};\n\n const txInitialParams = {\n ...restParams,\n walletType,\n from: walletAddress,\n tracker: defaultTracker,\n chainId: desiredChainID,\n localTimestamp,\n txKey: '', // Will be populated after the action\n pending: false,\n isTrackedModalOpen: params.withTrackedModal,\n } as Draft<T>;\n\n const handleError = (e: unknown) => {\n const errorMessage = e instanceof Error ? e.message : String(e);\n set((state) =>\n produce(state, (draft) => {\n if (draft.initialTx) {\n draft.initialTx.isInitializing = false;\n draft.initialTx.errorMessage = errorMessage;\n }\n }),\n );\n // Re-throw to allow the caller to handle the error as well\n throw new Error(`Transaction failed to initialize: ${errorMessage}`);\n };\n\n // Set initial state for immediate UI feedback\n set({\n initialTx: {\n ...params,\n localTimestamp,\n isInitializing: true,\n },\n });\n\n if (adapter) {\n try {\n // 1. Ensure the wallet is on the correct chain\n await adapter.checkChainForTx(desiredChainID);\n\n // 2. Execute the action (e.g., wallet call) to get a transaction key (hash, taskId, etc.)\n const txKeyFromAction = await actionFunction();\n\n if (txKeyFromAction) {\n // 3. Determine the correct tracker and final txKey\n const { tracker: updatedTracker, txKey: finalTxKey } = adapter.checkTransactionsTracker(\n txKeyFromAction,\n txInitialParams.walletType,\n );\n\n // 4. Add the transaction to the pool\n get().addTxToPool({\n tx: {\n ...txInitialParams,\n tracker: updatedTracker,\n txKey: finalTxKey,\n hash: updatedTracker === 'ethereum' ? txKeyFromAction : undefined,\n } as T,\n });\n\n // Update initial state to reflect that initialization is complete\n set((state) =>\n produce(state, (draft) => {\n if (draft.initialTx) {\n draft.initialTx.isInitializing = false;\n draft.initialTx.lastTxKey = finalTxKey;\n }\n }),\n );\n\n // 5. Start the background tracking process for the new transaction\n const tx = get().transactionsPool[finalTxKey];\n await adapter.checkAndInitializeTrackerInStore({ tx, ...get() });\n } else {\n // Action was likely cancelled by the user, clear the initial state\n set({ initialTx: undefined });\n }\n } catch (e) {\n handleError(e);\n }\n } else {\n handleError('No adapter found for this transaction.');\n }\n },\n }),\n {\n ...options, // Zustand persist middleware options\n },\n ),\n );\n}\n","/**\n * @file This file defines the core data structures and TypeScript types for the Pulsar transaction tracking engine.\n * It includes types for transactions, their statuses, store interfaces, and utility types for Zustand slices.\n * These types are framework-agnostic and form the foundation of the entire tracking system.\n */\n\nimport { StoreApi } from 'zustand';\n\nimport { IInitializeTxTrackingStore } from './store/initializeTxTrackingStore';\n\n/**\n * A utility type for creating modular Zustand store slices.\n * @template T The state slice type.\n * @template E The full store state type, defaults to T.\n */\nexport type StoreSlice<T extends object, E extends object = T> = (\n set: StoreApi<E extends T ? E : E & T>['setState'],\n get: StoreApi<E extends T ? E : E & T>['getState'],\n) => T;\n\n/**\n * Represents the blockchain adapter for a transaction.\n */\nexport enum TransactionAdapter {\n /** EVM adapter. */\n EVM = 'evm',\n /** Solana adapter. */\n SOLANA = 'solana',\n /** Starknet adapter. */\n Starknet = 'Starknet',\n}\n\n/**\n * Represents the final status of a transaction.\n */\nexport enum TransactionStatus {\n /** The transaction failed to execute. */\n Failed = 'Failed',\n /** The transaction was successfully mined and executed. */\n Success = 'Success',\n /** The transaction was replaced by another (e.g., speed-up). */\n Replaced = 'Replaced',\n}\n\n/**\n * The base structure for any transaction being tracked.\n * @template T The type of the tracker identifier (e.g., 'evm', 'safe').\n */\nexport type BaseTransaction<T> = {\n /** A key identifying the retry logic for this transaction from the actions registry. */\n actionKey?: string;\n /** The chain identifier (e.g., 1 for Ethereum Mainnet, 'SN_MAIN' for Starknet). */\n chainId: number | string;\n /** A description for the transaction, with states for [pending, success, error, replaced]. */\n description?: string | [string, string, string, string];\n /** An error message if the transaction failed. */\n errorMessage?: string;\n /** The timestamp (in seconds) when the transaction was finalized on-chain. */\n finishedTimestamp?: number;\n /** The sender's address. */\n from: string;\n /** A flag indicating if the transaction is in a failed state. */\n isError?: boolean;\n /** A flag indicating if the detailed tracking modal should be open for this transaction. For UI purposes. */\n isTrackedModalOpen?: boolean;\n /** The local timestamp (in seconds) when the transaction was initiated. */\n localTimestamp: number;\n /** Any additional data associated with the transaction. */\n payload?: object;\n /** Indicates if the transaction is still pending confirmation. */\n pending: boolean;\n /** The final status of the transaction. */\n status?: TransactionStatus;\n /** A title for the transaction, with states for [pending, success, error, replaced]. */\n title?: string | [string, string, string, string];\n /** The specific tracker responsible for monitoring this transaction (e.g., 'evm', 'safe', 'gelato', etc.). */\n tracker: T;\n /** The unique key for the transaction within its tracker (e.g., EVM hash, Gelato task ID). */\n txKey: string;\n /** The type or category of the transaction (e.g., 'increment', 'approve'). */\n type: string;\n /** The type of wallet used for the transaction. */\n walletType: string;\n};\n\n/**\n * Represents an EVM-specific transaction, extending the base properties.\n * @template T The type of the tracker identifier.\n */\nexport type EvmTransaction<T> = BaseTransaction<T> & {\n /** The transaction adapter type. */\n adapter: TransactionAdapter.EVM;\n /** The on-chain transaction hash, available after submission. */\n hash?: string;\n /** The data payload for the transaction, typically for contract interactions. */\n input?: string;\n /** The maximum fee per gas for the transaction (EIP-1559). */\n maxFeePerGas?: string;\n /** The maximum priority fee per gas for the transaction (EIP-1559). */\n maxPriorityFeePerGas?: string;\n /** The transaction nonce. */\n nonce?: number;\n /** The hash of a transaction that this one replaced (e.g., for speed-up). */\n replacedTxHash?: string;\n /** The recipient's address. */\n to?: string;\n /** The value (in wei) being sent with the transaction. */\n value?: string;\n};\n\n/**\n * Represents a Solana-specific transaction, extending the base properties.\n * @template T The type of the tracker identifier.\n */\nexport type SolanaTransaction<T> = BaseTransaction<T> & {\n /** The transaction adapter type. */\n adapter: TransactionAdapter.SOLANA;\n /** The transaction fee. */\n fee?: number;\n /** The instructions included in the transaction. */\n instructions?: any[];\n /** The recent blockhash used for the transaction. */\n recentBlockhash?: string;\n /** The slot in which the transaction was processed. */\n slot?: number;\n};\n\n/**\n * Represents a Starknet-specific transaction, extending the base properties.\n * @template T The type of the tracker identifier.\n */\nexport type StarknetTransaction<T> = BaseTransaction<T> & {\n /** The actual fee paid for the transaction. */\n actualFee?: { amount: string; unit: string };\n /** The address of the contract being interacted with. */\n contractAddress?: string;\n /** The transaction adapter type. */\n adapter: TransactionAdapter.Starknet;\n /** The reason for transaction failure, if applicable. */\n revertReason?: string;\n};\n\n/** A union type representing any possible transaction structure. */\nexport type Transaction<T> = EvmTransaction<T> | SolanaTransaction<T> | StarknetTransaction<T>;\n\n/**\n * Represents the parameters required to initiate a new transaction.\n */\nexport type InitialTransactionParams = {\n /** The transaction adapter type. */\n adapter: TransactionAdapter;\n /** A key identifying the retry logic from the actions registry. */\n actionKey?: string;\n /** A description for the transaction, with states for [pending, success, error, replaced]. */\n description?: string | [string, string, string, string];\n /** The ID of the desired blockchain network. */\n desiredChainID: number | string;\n /** Any additional data to be associated with the transaction. */\n payload?: object;\n /** A title for the transaction, with states for [pending, success, error, replaced]. */\n title?: string | [string, string, string, string];\n /** The type or category of the transaction (e.g., 'increment', 'approve'). */\n type: string;\n /** If true, the detailed tracking modal will open automatically for this transaction. */\n withTrackedModal?: boolean;\n};\n\n/**\n * Represents a transaction in its initial, pre-submission state within the store.\n * This is used for UI feedback while the transaction is being signed and sent.\n */\nexport type InitialTransaction = InitialTransactionParams & {\n /** An error message if the initialization process fails (e.g., user rejects signature). */\n errorMessage?: string;\n /** True if the transaction is currently being processed (e.g., waiting for user signature). */\n isInitializing: boolean;\n /** The key of the on-chain transaction that this action produced, used for linking. */\n lastTxKey?: string;\n /** The local timestamp when the user initiated the action. */\n localTimestamp: number;\n};\n\nexport type TxAdapter<TR, T extends Transaction<TR>, A> = {\n key: TransactionAdapter;\n getWalletInfo: () => {\n /** Wallet address. */\n walletAddress: string;\n /** Type of the wallet. (injected, wallet connect, etc.) */\n walletType: string;\n };\n checkChainForTx: (chainId: string | number) => Promise<void>;\n checkTransactionsTracker: (actionTxKey: A, walletType: string) => { txKey: string; tracker: TR };\n checkAndInitializeTrackerInStore: ({\n tx,\n ...rest\n }: { tx: T } & Pick<\n ITxTrackingStore<TR, T, A>,\n 'transactionsPool' | 'updateTxParams' | 'onSucceedCallbacks' | 'removeTxFromPool'\n >) => Promise<void>;\n};\n\n/**\n * Interface for the complete transaction tracking store.\n * @template TR The type of the tracker identifier.\n * @template T The transaction type.\n * @template C The configuration object type (e.g., wagmi config).\n * @template A The return type of the action function being wrapped.\n */\nexport type ITxTrackingStore<TR, T extends Transaction<TR>, A> = IInitializeTxTrackingStore<TR, T> & {\n /**\n * A wrapper function that handles the entire lifecycle of a transaction.\n * It creates an `InitialTransaction`, executes the on-chain action, and tracks its status.\n * @param params - The parameters for handling the transaction.\n */\n handleTransaction: (params: {\n /** The async function to execute (e.g., a smart contract write call). */\n actionFunction: () => Promise<A | undefined>;\n /** The metadata for the transaction to be created, of type `InitialTransactionParams`. */\n params: InitialTransactionParams;\n\n defaultTracker?: TR;\n }) => Promise<void>;\n\n /**\n * Initializes all active trackers for pending transactions in the pool.\n * This is useful for resuming tracking after a page reload.\n */\n initializeTransactionsPool: () => Promise<void>;\n};\n","/**\n * @file This file provides a utility for creating a bounded Zustand hook from a vanilla store.\n * This is a recommended pattern for using vanilla stores with React to ensure full type safety.\n *\n * @see https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n */\n\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * A utility type to infer the state shape from a Zustand store type.\n * @template S The type of the Zustand store (`StoreApi`).\n */\ntype ExtractState<S> = S extends { getState: () => infer X } ? X : never;\n\n/**\n * Creates a bounded `useStore` hook from a vanilla Zustand store instance.\n * The returned hook is fully typed and can be used with or without a selector.\n *\n * @template S The type of the Zustand store (`StoreApi`).\n * @param {S} store - The vanilla Zustand store instance.\n * @returns {function} A hook that can be called with an optional selector function.\n * - When called with a selector (`useBoundedStore(state => state.someValue)`), it returns the selected slice of the state.\n */\nexport const createBoundedUseStore = ((store) => (selector) => useStore(store, selector)) as <\n S extends StoreApi<unknown>,\n>(\n store: S,\n) => {\n (): ExtractState<S>;\n <T>(selector: (state: ExtractState<S>) => T): T;\n};\n","/**\n * @file This file contains a generic utility for creating a polling mechanism to track asynchronous tasks,\n * such as API-based transaction status checks (e.g., for Gelato or Safe).\n */\n\nimport { Transaction } from '../types';\n\n/**\n * Defines the configuration object for the `initializePollingTracker` function.\n * @template R The expected type of the successful API response from the fetcher.\n * @template T The type of the transaction object being tracked.\n * @template TR The type of the tracker identifier used in the `Transaction` type.\n */\nexport type InitializePollingTracker<R, T, TR> = {\n /** The transaction object to be tracked. It must include `txKey` and an optional `pending` status. */\n tx: T & Pick<Transaction<TR>, 'txKey'> & { pending?: boolean };\n /** The function that performs the actual data fetching (e.g., an API call). */\n fetcher: (params: {\n /** The transaction object being tracked. */\n tx: T;\n /** A callback to stop the polling mechanism, typically called on success or terminal failure. */\n clearWatch: (withoutRemoving?: boolean) => void;\n /** Callback to be invoked when the fetcher determines the transaction has succeeded. */\n onSucceed: (response: R) => void;\n /** Callback to be invoked when the fetcher determines the transaction has failed. */\n onFailed: (response: R) => void;\n /** Optional callback for each successful poll, useful for updating UI with intermediate states. */\n onIntervalTick?: (response: R) => void;\n /** Optional callback for when a transaction is replaced by another. */\n onReplaced?: (response: R) => void;\n }) => Promise<Response>;\n\n /** Optional callback executed once when the tracker is initialized. */\n onInitialize?: () => void;\n /** Callback to be invoked when the transaction has succeeded. */\n onSucceed: (response: R) => void;\n /** Callback to be invoked when the transaction has failed. */\n onFailed: (response: R) => void;\n /** Optional callback for each successful poll. */\n onIntervalTick?: (response: R) => void;\n /** Optional callback for when a transaction is replaced. */\n onReplaced?: (response: R) => void;\n /** Optional function to remove the transaction from the main pool, typically after polling stops. */\n removeTxFromPool?: (taskId: string) => void;\n /** The interval (in milliseconds) between polling attempts. Defaults to 5000ms. */\n pollingInterval?: number;\n /** The number of consecutive failed fetches before stopping the tracker. Defaults to 10. */\n retryCount?: number;\n};\n\n/**\n * Initializes a generic polling tracker that repeatedly calls a fetcher function\n * to monitor the status of a transaction or any asynchronous task.\n *\n * @template R The expected type of the successful API response.\n * @template T The type of the transaction object.\n * @template TR The type of the tracker identifier.\n * @param {InitializePollingTracker<R, T, TR>} params - The configuration object for the tracker.\n * @returns {Promise<void>} A promise that resolves when the tracker is set up (note: polling happens asynchronously).\n */\nexport async function initializePollingTracker<R, T, TR>({\n onInitialize,\n tx,\n removeTxFromPool,\n fetcher,\n onFailed,\n onIntervalTick,\n onSucceed,\n pollingInterval,\n retryCount,\n onReplaced,\n}: InitializePollingTracker<R, T, TR>): Promise<void> {\n if (onInitialize) {\n onInitialize();\n }\n\n // Early exit if the transaction is not pending\n if (!tx?.pending) {\n return;\n }\n\n let pollingIntervalId: number | undefined;\n\n /**\n * Stops the polling interval and optionally removes the transaction from the pool.\n * @param {boolean} [withoutRemoving=false] - If true, the transaction will not be removed from the pool.\n */\n const clearWatch = (withoutRemoving?: boolean) => {\n clearInterval(pollingIntervalId);\n if (removeTxFromPool && !withoutRemoving) {\n removeTxFromPool(tx.txKey);\n }\n };\n\n let retriesLeft = retryCount ?? 10;\n\n pollingIntervalId = window.setInterval(async () => {\n if (retriesLeft <= 0) {\n clearWatch();\n return;\n }\n\n try {\n const response = await fetcher({\n tx,\n onSucceed,\n onFailed,\n onIntervalTick,\n onReplaced,\n clearWatch,\n });\n\n // If the API call fails (e.g., 404 Not Found), decrement the retry counter.\n // The fetcher itself is responsible for calling `clearWatch` on terminal statuses.\n if (!response.ok) {\n retriesLeft--;\n }\n } catch (error) {\n console.error('Polling fetcher function threw an error:', error);\n retriesLeft--;\n }\n }, pollingInterval ?? 5000);\n}\n"]}
1
+ {"version":3,"sources":["../src/store/initializeTxTrackingStore.ts","../src/store/transactionsSelectors.ts","../src/utils/selectAdapterByKey.ts","../src/store/txTrackingStore.ts","../src/types.ts","../src/utils/createBoundedUseStore.ts","../src/utils/initializePollingTracker.ts"],"names":["initializeTxTrackingStore","onSucceedCallbacks","set","get","tx","state","produce","draft","txKey","selectAllTransactions","transactionsPool","a","b","selectPendingTransactions","selectTXByKey","key","selectAllTransactionsByActiveWallet","from","selectPendingTransactionsByActiveWallet","selectAdapterByKey","adapterKey","adapters","adapter","createPulsarStore","options","createStore","persist","defaultTracker","actionFunction","params","desiredChainID","restParams","localTimestamp","dayjs","walletType","walletAddress","txInitialParams","handleError","e","errorMessage","txKeyFromAction","updatedTracker","finalTxKey","TransactionAdapter","TransactionStatus","createBoundedUseStore","store","selector","useStore","initializePollingTracker","onInitialize","removeTxFromPool","fetcher","onFailed","onIntervalTick","onSucceed","pollingInterval","retryCount","onReplaced","pollingIntervalId","clearWatch","withoutRemoving","retriesLeft","error"],"mappings":"kRA2EO,SAASA,CAAAA,CAAyD,CACvE,kBAAA,CAAAC,CACF,CAAA,CAEkD,CAChD,OAAO,CAACC,CAAAA,CAAKC,KAAS,CACpB,kBAAA,CAAAF,EAEA,gBAAA,CAAkB,EAAC,CACnB,cAAA,CAAgB,OAChB,SAAA,CAAW,MAAA,CAEX,YAAa,CAAC,CAAE,GAAAG,CAAG,CAAA,GAAM,CACvBF,CAAAA,CAAI,CAAE,cAAA,CAAgBE,CAAAA,CAAG,KAAM,CAAC,CAAA,CAChCF,EAAKG,CAAAA,EACHC,aAAAA,CAAQD,CAAAA,CAAQE,CAAAA,EAAU,CACpBH,CAAAA,CAAG,KAAA,GACLG,EAAM,gBAAA,CAAiBH,CAAAA,CAAG,KAAK,CAAA,CAAI,CACjC,GAAGA,CAAAA,CACH,QAAS,IACX,CAAA,EAEJ,CAAC,CACH,EACF,EAEA,cAAA,CAAiBA,CAAAA,EAAO,CACtBF,CAAAA,CAAKG,GACHC,aAAAA,CAAQD,CAAAA,CAAQE,GAAU,CAEpBA,CAAAA,CAAM,iBAAiBH,CAAAA,CAAG,KAAK,CAAA,GACjCG,CAAAA,CAAM,iBAAiBH,CAAAA,CAAG,KAAK,EAAI,CACjC,GAAGG,EAAM,gBAAA,CAAiBH,CAAAA,CAAG,KAAK,CAAA,CAClC,GAAGA,CACL,CAAA,EAEJ,CAAC,CACH,EACF,EAEA,gBAAA,CAAmBI,CAAAA,EAAU,CAC3B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AA,CAAsD,CAMpD,GALIR,GACFA,CAAAA,EAAa,CAIX,CAAC9C,CAAAA,EAAI,OAAA,CACP,OAGF,IAAIuD,CAAAA,CAMEC,CAAAA,CAAcC,CAAAA,EAA8B,CAChD,aAAA,CAAcF,CAAiB,EAC3BR,CAAAA,EAAoB,CAACU,GACvBV,CAAAA,CAAiB/C,CAAAA,CAAG,KAAK,EAE7B,EAEI0D,CAAAA,CAAcL,CAAAA,EAAc,GAEhCE,CAAAA,CAAoB,MAAA,CAAO,YAAY,SAAY,CACjD,GAAIG,CAAAA,EAAe,EAAG,CACpBF,CAAAA,GACA,MACF,CAEA,GAAI,CAAA,CACe,MAAMR,CAAAA,CAAQ,CAC7B,GAAAhD,CAAAA,CACA,SAAA,CAAAmD,EACA,QAAA,CAAAF,CAAAA,CACA,eAAAC,CAAAA,CACA,UAAA,CAAAI,CAAAA,CACA,UAAA,CAAAE,CACF,CAAC,CAAA,EAIa,IACZE,CAAAA,GAEJ,CAAA,MAASC,EAAO,CACd,OAAA,CAAQ,KAAA,CAAM,0CAAA,CAA4CA,CAAK,CAAA,CAC/DD,CAAAA,GACF,CACF,CAAA,CAAGN,CAAAA,EAAmB,GAAI,EAC5B","file":"index.js","sourcesContent":["/**\n * @file This file provides the core slice for the Zustand store, responsible for managing the state of transactions.\n * It includes functions and types for initializing the store and performing basic CRUD operations on the transaction pool.\n */\n\nimport { Draft, produce } from 'immer';\n\nimport { EvmTransaction, InitialTransaction, StoreSlice, Transaction } from '../types';\n\n/**\n * Defines the structure of the transaction pool, which is a record of transactions indexed by their unique keys.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n */\nexport type TransactionPool<TR, T extends Transaction<TR>> = Record<string, T>;\n\n/**\n * A utility type that extracts a subset of fields from the `Transaction` type\n * that are updatable via the `updateTxParams` action.\n * @template TR - The type of the tracker identifier.\n */\ntype UpdatedParamsFields<TR> = Pick<\n EvmTransaction<TR>,\n | 'to'\n | 'nonce'\n | 'txKey'\n | 'pending'\n | 'hash'\n | 'status'\n | 'replacedTxHash'\n | 'errorMessage'\n | 'finishedTimestamp'\n | 'isTrackedModalOpen'\n | 'isError'\n | 'maxPriorityFeePerGas'\n | 'maxFeePerGas'\n | 'input'\n | 'value'\n>;\n\n/**\n * Defines the interface for the base transaction tracking store slice.\n * It includes the state and actions for managing transactions.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n */\nexport type IInitializeTxTrackingStore<TR, T extends Transaction<TR>> = {\n /** An optional callback function to be executed when a transaction successfully completes. */\n onSucceedCallbacks?: (tx: T) => Promise<void> | void;\n /** A pool of all transactions currently being tracked, indexed by their `txKey`. */\n transactionsPool: TransactionPool<TR, T>;\n /** The key of the most recently added transaction. */\n lastAddedTxKey?: string;\n /** The state of a transaction that is currently being initiated but not yet submitted. */\n initialTx?: InitialTransaction;\n\n /** Adds a new transaction to the tracking pool. */\n addTxToPool: ({ tx }: { tx: T }) => void;\n /** Updates one or more parameters of an existing transaction in the pool. */\n updateTxParams: (fields: UpdatedParamsFields<TR>) => void;\n /** Removes a transaction from the tracking pool using its key. */\n removeTxFromPool: (txKey: string) => void;\n /** Closes the tracking modal for a specific transaction. */\n closeTxTrackedModal: (txKey?: string) => void;\n /** Returns the key of the last transaction that was added to the pool. */\n getLastTxKey: () => string | undefined;\n};\n\n/**\n * Creates a Zustand store slice containing the core logic for transaction tracking.\n * This function is a slice creator and is meant to be used within `createStore` from Zustand.\n * @param {object} options - Configuration options for the store slice.\n * @param {function} [options.onSucceedCallbacks] - An optional async callback to run when a transaction succeeds.\n * @returns {StoreSlice<IInitializeTxTrackingStore<TR, T>>} A Zustand store slice.\n */\nexport function initializeTxTrackingStore<TR, T extends Transaction<TR>>({\n onSucceedCallbacks,\n}: {\n onSucceedCallbacks?: (tx: T) => Promise<void> | void;\n}): StoreSlice<IInitializeTxTrackingStore<TR, T>> {\n return (set, get) => ({\n onSucceedCallbacks,\n\n transactionsPool: {},\n lastAddedTxKey: undefined,\n initialTx: undefined,\n\n addTxToPool: ({ tx }) => {\n set({ lastAddedTxKey: tx.txKey });\n set((state) =>\n produce(state, (draft) => {\n if (tx.txKey) {\n draft.transactionsPool[tx.txKey] = {\n ...tx,\n pending: true,\n } as Draft<T>;\n }\n }),\n );\n },\n\n updateTxParams: (tx) => {\n set((state) =>\n produce(state, (draft) => {\n // Ensure the transaction exists before attempting to update\n if (draft.transactionsPool[tx.txKey]) {\n draft.transactionsPool[tx.txKey] = {\n ...draft.transactionsPool[tx.txKey],\n ...tx,\n };\n }\n }),\n );\n },\n\n removeTxFromPool: (txKey) => {\n set((state) =>\n produce(state, (draft) => {\n delete draft.transactionsPool[txKey];\n }),\n );\n },\n\n closeTxTrackedModal: (txKey) => {\n if (txKey) {\n set((state) =>\n produce(state, (draft) => {\n if (draft.transactionsPool[txKey]) {\n draft.transactionsPool[txKey].isTrackedModalOpen = false;\n }\n }),\n );\n }\n // Always clear the initial transaction state when a modal is closed\n set({ initialTx: undefined });\n },\n\n getLastTxKey: () => {\n return get().lastAddedTxKey;\n },\n });\n}\n","/**\n * @file This file contains selector functions for deriving state from the transaction tracking store.\n * Selectors help abstract away the shape of the state and provide memoized, efficient access to computed data.\n */\n\nimport { Transaction } from '../types';\nimport { TransactionPool } from './initializeTxTrackingStore';\n\n/**\n * Selects all transactions from the pool and sorts them by their creation timestamp.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @returns {T[]} An array of all transactions, sorted chronologically.\n */\nexport const selectAllTransactions = <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>): T[] => {\n return Object.values(transactionsPool).sort((a, b) => Number(a.localTimestamp) - Number(b.localTimestamp));\n};\n\n/**\n * Selects all transactions that are currently in a pending state.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @returns {T[]} An array of pending transactions.\n */\nexport const selectPendingTransactions = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n): T[] => {\n return selectAllTransactions(transactionsPool).filter((tx) => tx.pending);\n};\n\n/**\n * Selects a single transaction from the pool by its unique transaction key (`txKey`).\n * This is the most direct way to retrieve a transaction.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @param {string} key - The `txKey` of the transaction to retrieve.\n * @returns {T | undefined} The transaction object if found, otherwise undefined.\n */\nexport const selectTXByKey = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n key: string,\n): T | undefined => {\n return transactionsPool[key];\n};\n\n/**\n * Selects all transactions initiated by a specific wallet address.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @param {string} from - The wallet address (`from` address) to filter transactions by.\n * @returns {T[]} An array of transactions associated with the given wallet.\n */\nexport const selectAllTransactionsByActiveWallet = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n from: string,\n): T[] => {\n return selectAllTransactions(transactionsPool).filter((tx) => tx.from === from);\n};\n\n/**\n * Selects all pending transactions initiated by a specific wallet address.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @param {string} from - The wallet address (`from` address) to filter transactions by.\n * @returns {T[]} An array of pending transactions associated with the given wallet.\n */\nexport const selectPendingTransactionsByActiveWallet = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n from: string,\n): T[] => {\n return selectPendingTransactions(transactionsPool).filter((tx) => tx.from === from);\n};\n","import { Transaction, TransactionAdapter, TxAdapter } from '../types';\n\n/**\n * Selects and returns a transaction adapter from a list of adapters based on the provided adapter key.\n * If no matching adapter is found, the first adapter in the list is returned as a fallback.\n *\n * @template TR - Represents the transaction response type.\n * @template T - Extends the Transaction type and represents the transaction entity.\n * @template A - Represents the adapter type.\n *\n * @param {Object} params - Configuration object for selecting the adapter.\n * @param {TransactionAdapter} params.adapterKey - The key used to identify the desired transaction adapter.\n * @param {TxAdapter<TR, T, A>[]} params.adapters - An array of available transaction adapters.\n *\n * @returns {TxAdapter<TR, T, A>} The transaction adapter corresponding to the provided key, or the first adapter in the list.\n */\nexport const selectAdapterByKey = <TR, T extends Transaction<TR>, A>({\n adapterKey,\n adapters,\n}: {\n adapterKey: TransactionAdapter;\n adapters: TxAdapter<TR, T, A>[];\n}): TxAdapter<TR, T, A> => {\n const adapter = adapters.find((adapter) => adapter.key === adapterKey);\n if (adapter) {\n return adapter;\n } else {\n return adapters[0];\n }\n};\n","import dayjs from 'dayjs';\nimport { Draft, produce } from 'immer';\nimport { persist, PersistOptions } from 'zustand/middleware';\nimport { createStore } from 'zustand/vanilla';\n\nimport { ITxTrackingStore, Transaction, TxAdapter } from '../types';\nimport { selectAdapterByKey } from '../utils/selectAdapterByKey';\nimport { initializeTxTrackingStore } from './initializeTxTrackingStore';\n\nexport function createPulsarStore<TR, T extends Transaction<TR>, A>({\n onSucceedCallbacks,\n adapters,\n ...options\n}: {\n onSucceedCallbacks?: (tx: T) => Promise<void> | void;\n adapters: TxAdapter<TR, T, A>[];\n} & PersistOptions<ITxTrackingStore<TR, T, A>>) {\n return createStore<ITxTrackingStore<TR, T, A>>()(\n persist(\n (set, get) => ({\n ...initializeTxTrackingStore<TR, T>({ onSucceedCallbacks })(set, get),\n\n /**\n * Initializes trackers for all pending transactions in the pool.\n * This is essential for resuming tracking after a page reload.\n */\n initializeTransactionsPool: async () => {\n await Promise.all(\n Object.values(get().transactionsPool).map(async (tx) => {\n if (tx.pending) {\n const adapter = selectAdapterByKey({ adapterKey: tx.adapter, adapters });\n adapter?.checkAndInitializeTrackerInStore({ tx, ...get() });\n }\n }),\n );\n },\n\n /**\n * The main function to orchestrate sending and tracking a new transaction.\n * It handles chain switching, wallet interactions, state updates, and tracker initialization.\n */\n handleTransaction: async ({ defaultTracker, actionFunction, params }) => {\n set({ initialTx: undefined }); // Clear any previous initial state\n const { desiredChainID, ...restParams } = params;\n const localTimestamp = dayjs().unix();\n\n const adapter = selectAdapterByKey({ adapterKey: restParams.adapter, adapters });\n\n const { walletType, walletAddress } = adapter ? adapter.getWalletInfo() : {};\n\n const txInitialParams = {\n ...restParams,\n walletType,\n from: walletAddress,\n tracker: defaultTracker,\n chainId: desiredChainID,\n localTimestamp,\n txKey: '', // Will be populated after the action\n pending: false,\n isTrackedModalOpen: params.withTrackedModal,\n } as Draft<T>;\n\n const handleError = (e: unknown) => {\n const errorMessage = e instanceof Error ? e.message : String(e);\n set((state) =>\n produce(state, (draft) => {\n if (draft.initialTx) {\n draft.initialTx.isInitializing = false;\n draft.initialTx.errorMessage = errorMessage;\n }\n }),\n );\n // Re-throw to allow the caller to handle the error as well\n throw new Error(`Transaction failed to initialize: ${errorMessage}`);\n };\n\n // Set initial state for immediate UI feedback\n set({\n initialTx: {\n ...params,\n localTimestamp,\n isInitializing: true,\n },\n });\n\n if (adapter) {\n try {\n // 1. Ensure the wallet is on the correct chain\n await adapter.checkChainForTx(desiredChainID);\n\n // 2. Execute the action (e.g., wallet call) to get a transaction key (hash, taskId, etc.)\n const txKeyFromAction = await actionFunction();\n\n if (txKeyFromAction) {\n // 3. Determine the correct tracker and final txKey\n const { tracker: updatedTracker, txKey: finalTxKey } = adapter.checkTransactionsTracker(\n txKeyFromAction,\n txInitialParams.walletType,\n );\n\n // 4. Add the transaction to the pool\n get().addTxToPool({\n tx: {\n ...txInitialParams,\n tracker: updatedTracker,\n txKey: finalTxKey,\n hash: updatedTracker === 'ethereum' ? txKeyFromAction : undefined,\n } as T,\n });\n\n // Update initial state to reflect that initialization is complete\n set((state) =>\n produce(state, (draft) => {\n if (draft.initialTx) {\n draft.initialTx.isInitializing = false;\n draft.initialTx.lastTxKey = finalTxKey;\n }\n }),\n );\n\n // 5. Start the background tracking process for the new transaction\n const tx = get().transactionsPool[finalTxKey];\n await adapter.checkAndInitializeTrackerInStore({ tx, ...get() });\n } else {\n // Action was likely cancelled by the user, clear the initial state\n set({ initialTx: undefined });\n }\n } catch (e) {\n handleError(e);\n }\n } else {\n handleError('No adapter found for this transaction.');\n }\n },\n }),\n {\n ...options, // Zustand persist middleware options\n },\n ),\n );\n}\n","/**\n * @file This file defines the core data structures and TypeScript types for the Pulsar transaction tracking engine.\n * It includes types for transactions, their statuses, store interfaces, and utility types for Zustand slices.\n * These types are framework-agnostic and form the foundation of the entire tracking system.\n */\n\nimport { StoreApi } from 'zustand';\n\nimport { IInitializeTxTrackingStore, TransactionPool } from './store/initializeTxTrackingStore';\n\n/**\n * A utility type for creating modular Zustand store slices.\n * @template T The state slice type.\n * @template E The full store state type, defaults to T.\n */\nexport type StoreSlice<T extends object, E extends object = T> = (\n set: StoreApi<E extends T ? E : E & T>['setState'],\n get: StoreApi<E extends T ? E : E & T>['getState'],\n) => T;\n\n/**\n * Represents the blockchain adapter for a transaction.\n */\nexport enum TransactionAdapter {\n /** EVM adapter. */\n EVM = 'evm',\n /** Solana adapter. */\n SOLANA = 'solana',\n /** Starknet adapter. */\n Starknet = 'Starknet',\n}\n\n/**\n * Represents the final status of a transaction.\n */\nexport enum TransactionStatus {\n /** The transaction failed to execute. */\n Failed = 'Failed',\n /** The transaction was successfully mined and executed. */\n Success = 'Success',\n /** The transaction was replaced by another (e.g., speed-up). */\n Replaced = 'Replaced',\n}\n\n/**\n * The base structure for any transaction being tracked.\n * @template T The type of the tracker identifier (e.g., 'evm', 'safe').\n */\nexport type BaseTransaction<T> = {\n /** A key identifying the retry logic for this transaction from the actions registry. */\n actionKey?: string;\n /** The chain identifier (e.g., 1 for Ethereum Mainnet, 'SN_MAIN' for Starknet). */\n chainId: number | string;\n /** A description for the transaction, with states for [pending, success, error, replaced]. */\n description?: string | [string, string, string, string];\n /** An error message if the transaction failed. */\n errorMessage?: string;\n /** The timestamp (in seconds) when the transaction was finalized on-chain. */\n finishedTimestamp?: number;\n /** The sender's address. */\n from: string;\n /** A flag indicating if the transaction is in a failed state. */\n isError?: boolean;\n /** A flag indicating if the detailed tracking modal should be open for this transaction. For UI purposes. */\n isTrackedModalOpen?: boolean;\n /** The local timestamp (in seconds) when the transaction was initiated. */\n localTimestamp: number;\n /** Any additional data associated with the transaction. */\n payload?: object;\n /** Indicates if the transaction is still pending confirmation. */\n pending: boolean;\n /** The final status of the transaction. */\n status?: TransactionStatus;\n /** A title for the transaction, with states for [pending, success, error, replaced]. */\n title?: string | [string, string, string, string];\n /** The specific tracker responsible for monitoring this transaction (e.g., 'evm', 'safe', 'gelato', etc.). */\n tracker: T;\n /** The unique key for the transaction within its tracker (e.g., EVM hash, Gelato task ID). */\n txKey: string;\n /** The type or category of the transaction (e.g., 'increment', 'approve'). */\n type: string;\n /** The type of wallet used for the transaction. */\n walletType: string;\n};\n\n/**\n * Represents an EVM-specific transaction, extending the base properties.\n * @template T The type of the tracker identifier.\n */\nexport type EvmTransaction<T> = BaseTransaction<T> & {\n /** The transaction adapter type. */\n adapter: TransactionAdapter.EVM;\n /** The on-chain transaction hash, available after submission. */\n hash?: string;\n /** The data payload for the transaction, typically for contract interactions. */\n input?: string;\n /** The maximum fee per gas for the transaction (EIP-1559). */\n maxFeePerGas?: string;\n /** The maximum priority fee per gas for the transaction (EIP-1559). */\n maxPriorityFeePerGas?: string;\n /** The transaction nonce. */\n nonce?: number;\n /** The hash of a transaction that this one replaced (e.g., for speed-up). */\n replacedTxHash?: string;\n /** The recipient's address. */\n to?: string;\n /** The value (in wei) being sent with the transaction. */\n value?: string;\n};\n\n/**\n * Represents a Solana-specific transaction, extending the base properties.\n * @template T The type of the tracker identifier.\n */\nexport type SolanaTransaction<T> = BaseTransaction<T> & {\n /** The transaction adapter type. */\n adapter: TransactionAdapter.SOLANA;\n /** The transaction fee. */\n fee?: number;\n /** The instructions included in the transaction. */\n instructions?: any[];\n /** The recent blockhash used for the transaction. */\n recentBlockhash?: string;\n /** The slot in which the transaction was processed. */\n slot?: number;\n};\n\n/**\n * Represents a Starknet-specific transaction, extending the base properties.\n * @template T The type of the tracker identifier.\n */\nexport type StarknetTransaction<T> = BaseTransaction<T> & {\n /** The actual fee paid for the transaction. */\n actualFee?: { amount: string; unit: string };\n /** The address of the contract being interacted with. */\n contractAddress?: string;\n /** The transaction adapter type. */\n adapter: TransactionAdapter.Starknet;\n /** The reason for transaction failure, if applicable. */\n revertReason?: string;\n};\n\n/** A union type representing any possible transaction structure. */\nexport type Transaction<T> = EvmTransaction<T> | SolanaTransaction<T> | StarknetTransaction<T>;\n\n/** A registry of functions that can be re-executed via the 'Retry' button. The key should match `actionKey` on a transaction. */\nexport type TxActions = Record<string, (...args: any[]) => Promise<unknown>>;\n\n/**\n * Represents the parameters required to initiate a new transaction.\n */\nexport type InitialTransactionParams = {\n /** The transaction adapter type. */\n adapter: TransactionAdapter;\n /** A key identifying the retry logic from the actions registry. */\n actionKey?: string;\n /** A description for the transaction, with states for [pending, success, error, replaced]. */\n description?: string | [string, string, string, string];\n /** The ID of the desired blockchain network. */\n desiredChainID: number | string;\n /** Any additional data to be associated with the transaction. */\n payload?: object;\n /** A title for the transaction, with states for [pending, success, error, replaced]. */\n title?: string | [string, string, string, string];\n /** The type or category of the transaction (e.g., 'increment', 'approve'). */\n type: string;\n /** If true, the detailed tracking modal will open automatically for this transaction. */\n withTrackedModal?: boolean;\n};\n\n/**\n * Represents a transaction in its initial, pre-submission state within the store.\n * This is used for UI feedback while the transaction is being signed and sent.\n */\nexport type InitialTransaction = InitialTransactionParams & {\n /** An error message if the initialization process fails (e.g., user rejects signature). */\n errorMessage?: string;\n /** True if the transaction is currently being processed (e.g., waiting for user signature). */\n isInitializing: boolean;\n /** The key of the on-chain transaction that this action produced, used for linking. */\n lastTxKey?: string;\n /** The local timestamp when the user initiated the action. */\n localTimestamp: number;\n};\n\n/**\n * Represents the type for a transaction adapter which provides utilities for handling transaction-related operations.\n *\n * @template TR - Represents the transaction tracker type.\n * @template T - Represents the type of the transaction, extending the base Transaction<TR>.\n * @template A - Represents the type for the action transaction key.\n */\nexport type TxAdapter<TR, T extends Transaction<TR>, A> = {\n key: TransactionAdapter;\n getWalletInfo: () => {\n /** Wallet address. */\n walletAddress: string;\n /** Type of the wallet. (injected, wallet connect, etc.) */\n walletType: string;\n };\n checkChainForTx: (chainId: string | number) => Promise<void>;\n checkTransactionsTracker: (actionTxKey: A, walletType: string) => { txKey: string; tracker: TR };\n checkAndInitializeTrackerInStore: ({\n tx,\n ...rest\n }: { tx: T } & Pick<\n ITxTrackingStore<TR, T, A>,\n 'transactionsPool' | 'updateTxParams' | 'onSucceedCallbacks' | 'removeTxFromPool'\n >) => Promise<void>;\n cancelTxAction?: (tx: T) => Promise<string>;\n speedUpTxAction?: (tx: T) => Promise<string>;\n retryTxAction?: ({\n tx,\n actions,\n onClose,\n handleTransaction,\n }: {\n txKey: string;\n tx: InitialTransactionParams;\n actions?: TxActions;\n onClose: (txKey?: string) => void;\n } & Partial<Pick<ITxTrackingStore<TR, T, A>, 'handleTransaction'>>) => Promise<void>;\n explorerLink: (transactionsPool: TransactionPool<TR, T>, txKey: string, replacedTxHash?: string) => string;\n};\n\n/**\n * Interface for the complete transaction tracking store.\n * @template TR The type of the tracker identifier.\n * @template T The transaction type.\n * @template C The configuration object type (e.g., wagmi config).\n * @template A The return type of the action function being wrapped.\n */\nexport type ITxTrackingStore<TR, T extends Transaction<TR>, A> = IInitializeTxTrackingStore<TR, T> & {\n /**\n * A wrapper function that handles the entire lifecycle of a transaction.\n * It creates an `InitialTransaction`, executes the on-chain action, and tracks its status.\n * @param params - The parameters for handling the transaction.\n */\n handleTransaction: (params: {\n /** The async function to execute (e.g., a smart contract write call). */\n actionFunction: () => Promise<A | undefined>;\n /** The metadata for the transaction to be created, of type `InitialTransactionParams`. */\n params: InitialTransactionParams;\n\n defaultTracker?: TR;\n }) => Promise<void>;\n\n /**\n * Initializes all active trackers for pending transactions in the pool.\n * This is useful for resuming tracking after a page reload.\n */\n initializeTransactionsPool: () => Promise<void>;\n};\n","/**\n * @file This file provides a utility for creating a bounded Zustand hook from a vanilla store.\n * This is a recommended pattern for using vanilla stores with React to ensure full type safety.\n *\n * @see https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n */\n\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * A utility type to infer the state shape from a Zustand store type.\n * @template S The type of the Zustand store (`StoreApi`).\n */\ntype ExtractState<S> = S extends { getState: () => infer X } ? X : never;\n\n/**\n * Creates a bounded `useStore` hook from a vanilla Zustand store instance.\n * The returned hook is fully typed and can be used with or without a selector.\n *\n * @template S The type of the Zustand store (`StoreApi`).\n * @param {S} store - The vanilla Zustand store instance.\n * @returns {function} A hook that can be called with an optional selector function.\n * - When called with a selector (`useBoundedStore(state => state.someValue)`), it returns the selected slice of the state.\n */\nexport const createBoundedUseStore = ((store) => (selector) => useStore(store, selector)) as <\n S extends StoreApi<unknown>,\n>(\n store: S,\n) => {\n (): ExtractState<S>;\n <T>(selector: (state: ExtractState<S>) => T): T;\n};\n","/**\n * @file This file contains a generic utility for creating a polling mechanism to track asynchronous tasks,\n * such as API-based transaction status checks (e.g., for Gelato or Safe).\n */\n\nimport { Transaction } from '../types';\n\n/**\n * Defines the configuration object for the `initializePollingTracker` function.\n * @template R The expected type of the successful API response from the fetcher.\n * @template T The type of the transaction object being tracked.\n * @template TR The type of the tracker identifier used in the `Transaction` type.\n */\nexport type InitializePollingTracker<R, T, TR> = {\n /** The transaction object to be tracked. It must include `txKey` and an optional `pending` status. */\n tx: T & Pick<Transaction<TR>, 'txKey'> & { pending?: boolean };\n /** The function that performs the actual data fetching (e.g., an API call). */\n fetcher: (params: {\n /** The transaction object being tracked. */\n tx: T;\n /** A callback to stop the polling mechanism, typically called on success or terminal failure. */\n clearWatch: (withoutRemoving?: boolean) => void;\n /** Callback to be invoked when the fetcher determines the transaction has succeeded. */\n onSucceed: (response: R) => void;\n /** Callback to be invoked when the fetcher determines the transaction has failed. */\n onFailed: (response: R) => void;\n /** Optional callback for each successful poll, useful for updating UI with intermediate states. */\n onIntervalTick?: (response: R) => void;\n /** Optional callback for when a transaction is replaced by another. */\n onReplaced?: (response: R) => void;\n }) => Promise<Response>;\n\n /** Optional callback executed once when the tracker is initialized. */\n onInitialize?: () => void;\n /** Callback to be invoked when the transaction has succeeded. */\n onSucceed: (response: R) => void;\n /** Callback to be invoked when the transaction has failed. */\n onFailed: (response: R) => void;\n /** Optional callback for each successful poll. */\n onIntervalTick?: (response: R) => void;\n /** Optional callback for when a transaction is replaced. */\n onReplaced?: (response: R) => void;\n /** Optional function to remove the transaction from the main pool, typically after polling stops. */\n removeTxFromPool?: (taskId: string) => void;\n /** The interval (in milliseconds) between polling attempts. Defaults to 5000ms. */\n pollingInterval?: number;\n /** The number of consecutive failed fetches before stopping the tracker. Defaults to 10. */\n retryCount?: number;\n};\n\n/**\n * Initializes a generic polling tracker that repeatedly calls a fetcher function\n * to monitor the status of a transaction or any asynchronous task.\n *\n * @template R The expected type of the successful API response.\n * @template T The type of the transaction object.\n * @template TR The type of the tracker identifier.\n * @param {InitializePollingTracker<R, T, TR>} params - The configuration object for the tracker.\n * @returns {Promise<void>} A promise that resolves when the tracker is set up (note: polling happens asynchronously).\n */\nexport async function initializePollingTracker<R, T, TR>({\n onInitialize,\n tx,\n removeTxFromPool,\n fetcher,\n onFailed,\n onIntervalTick,\n onSucceed,\n pollingInterval,\n retryCount,\n onReplaced,\n}: InitializePollingTracker<R, T, TR>): Promise<void> {\n if (onInitialize) {\n onInitialize();\n }\n\n // Early exit if the transaction is not pending\n if (!tx?.pending) {\n return;\n }\n\n let pollingIntervalId: number | undefined;\n\n /**\n * Stops the polling interval and optionally removes the transaction from the pool.\n * @param {boolean} [withoutRemoving=false] - If true, the transaction will not be removed from the pool.\n */\n const clearWatch = (withoutRemoving?: boolean) => {\n clearInterval(pollingIntervalId);\n if (removeTxFromPool && !withoutRemoving) {\n removeTxFromPool(tx.txKey);\n }\n };\n\n let retriesLeft = retryCount ?? 10;\n\n pollingIntervalId = window.setInterval(async () => {\n if (retriesLeft <= 0) {\n clearWatch();\n return;\n }\n\n try {\n const response = await fetcher({\n tx,\n onSucceed,\n onFailed,\n onIntervalTick,\n onReplaced,\n clearWatch,\n });\n\n // If the API call fails (e.g., 404 Not Found), decrement the retry counter.\n // The fetcher itself is responsible for calling `clearWatch` on terminal statuses.\n if (!response.ok) {\n retriesLeft--;\n }\n } catch (error) {\n console.error('Polling fetcher function threw an error:', error);\n retriesLeft--;\n }\n }, pollingInterval ?? 5000);\n}\n"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {produce}from'immer';import b from'dayjs';import {persist}from'zustand/middleware';import {createStore}from'zustand/vanilla';import {useStore}from'zustand';function S({onSucceedCallbacks:n}){return (t,a)=>({onSucceedCallbacks:n,transactionsPool:{},lastAddedTxKey:void 0,initialTx:void 0,addTxToPool:({tx:e})=>{t({lastAddedTxKey:e.txKey}),t(i=>produce(i,r=>{e.txKey&&(r.transactionsPool[e.txKey]={...e,pending:true});}));},updateTxParams:e=>{t(i=>produce(i,r=>{r.transactionsPool[e.txKey]&&(r.transactionsPool[e.txKey]={...r.transactionsPool[e.txKey],...e});}));},removeTxFromPool:e=>{t(i=>produce(i,r=>{delete r.transactionsPool[e];}));},closeTxTrackedModal:e=>{e&&t(i=>produce(i,r=>{r.transactionsPool[e]&&(r.transactionsPool[e].isTrackedModalOpen=false);})),t({initialTx:void 0});},getLastTxKey:()=>a().lastAddedTxKey})}var v=n=>Object.values(n).sort((t,a)=>Number(t.localTimestamp)-Number(a.localTimestamp)),A=n=>v(n).filter(t=>t.pending),C=(n,t)=>n[t],j=(n,t)=>v(n).filter(a=>a.from===t),D=(n,t)=>A(n).filter(a=>a.from===t);function $({onSucceedCallbacks:n,adapters:t,...a}){return createStore()(persist((e,i)=>({...S({onSucceedCallbacks:n})(e,i),initializeTransactionsPool:async()=>{await Promise.all(Object.values(i().transactionsPool).map(async r=>{r.pending&&t.find(T=>T.key===r.adapter)?.checkAndInitializeTrackerInStore({tx:r,...i()});}));},handleTransaction:async({defaultTracker:r,actionFunction:g,params:T})=>{e({initialTx:void 0});let{desiredChainID:u,...f}=T,l=b().unix(),s=t.find(o=>o.key===f.adapter),{walletType:d,walletAddress:c}=s?s.getWalletInfo():{},k={...f,walletType:d,from:c,tracker:r,chainId:u,localTimestamp:l,txKey:"",pending:false,isTrackedModalOpen:T.withTrackedModal},R=o=>{let p=o instanceof Error?o.message:String(o);throw e(x=>produce(x,m=>{m.initialTx&&(m.initialTx.isInitializing=false,m.initialTx.errorMessage=p);})),new Error(`Transaction failed to initialize: ${p}`)};if(e({initialTx:{...T,localTimestamp:l,isInitializing:true}}),s)try{await s.checkChainForTx(u);let o=await g();if(o){let{tracker:p,txKey:x}=s.checkTransactionsTracker(o,k.walletType);i().addTxToPool({tx:{...k,tracker:p,txKey:x,hash:p==="ethereum"?o:void 0}}),e(h=>produce(h,P=>{P.initialTx&&(P.initialTx.isInitializing=!1,P.initialTx.lastTxKey=x);}));let m=i().transactionsPool[x];await s.checkAndInitializeTrackerInStore({tx:m,...i()});}else e({initialTx:void 0});}catch(o){R(o);}else R("No adapter found for this transaction.");}}),{...a}))}var E=(e=>(e.EVM="evm",e.SOLANA="solana",e.Starknet="Starknet",e))(E||{}),z=(e=>(e.Failed="Failed",e.Success="Success",e.Replaced="Replaced",e))(z||{});var Z=(n=>t=>useStore(n,t));async function ee({onInitialize:n,tx:t,removeTxFromPool:a,fetcher:e,onFailed:i,onIntervalTick:r,onSucceed:g,pollingInterval:T,retryCount:u,onReplaced:f}){if(n&&n(),!t?.pending)return;let l,s=c=>{clearInterval(l),a&&!c&&a(t.txKey);},d=u??10;l=window.setInterval(async()=>{if(d<=0){s();return}try{(await e({tx:t,onSucceed:g,onFailed:i,onIntervalTick:r,onReplaced:f,clearWatch:s})).ok||d--;}catch(c){console.error("Polling fetcher function threw an error:",c),d--;}},T??5e3);}export{E as TransactionAdapter,z as TransactionStatus,Z as createBoundedUseStore,$ as createPulsarStore,ee as initializePollingTracker,S as initializeTxTrackingStore,v as selectAllTransactions,j as selectAllTransactionsByActiveWallet,A as selectPendingTransactions,D as selectPendingTransactionsByActiveWallet,C as selectTXByKey};//# sourceMappingURL=index.mjs.map
1
+ import {produce}from'immer';import b from'dayjs';import {persist}from'zustand/middleware';import {createStore}from'zustand/vanilla';import {useStore}from'zustand';function A({onSucceedCallbacks:n}){return (t,i)=>({onSucceedCallbacks:n,transactionsPool:{},lastAddedTxKey:void 0,initialTx:void 0,addTxToPool:({tx:e})=>{t({lastAddedTxKey:e.txKey}),t(a=>produce(a,r=>{e.txKey&&(r.transactionsPool[e.txKey]={...e,pending:true});}));},updateTxParams:e=>{t(a=>produce(a,r=>{r.transactionsPool[e.txKey]&&(r.transactionsPool[e.txKey]={...r.transactionsPool[e.txKey],...e});}));},removeTxFromPool:e=>{t(a=>produce(a,r=>{delete r.transactionsPool[e];}));},closeTxTrackedModal:e=>{e&&t(a=>produce(a,r=>{r.transactionsPool[e]&&(r.transactionsPool[e].isTrackedModalOpen=false);})),t({initialTx:void 0});},getLastTxKey:()=>i().lastAddedTxKey})}var v=n=>Object.values(n).sort((t,i)=>Number(t.localTimestamp)-Number(i.localTimestamp)),K=n=>v(n).filter(t=>t.pending),j=(n,t)=>n[t],D=(n,t)=>v(n).filter(i=>i.from===t),L=(n,t)=>K(n).filter(i=>i.from===t);var R=({adapterKey:n,adapters:t})=>{let i=t.find(e=>e.key===n);return i||t[0]};function Q({onSucceedCallbacks:n,adapters:t,...i}){return createStore()(persist((e,a)=>({...A({onSucceedCallbacks:n})(e,a),initializeTransactionsPool:async()=>{await Promise.all(Object.values(a().transactionsPool).map(async r=>{r.pending&&R({adapterKey:r.adapter,adapters:t})?.checkAndInitializeTrackerInStore({tx:r,...a()});}));},handleTransaction:async({defaultTracker:r,actionFunction:g,params:c})=>{e({initialTx:void 0});let{desiredChainID:y,...u}=c,l=b().unix(),o=R({adapterKey:u.adapter,adapters:t}),{walletType:d,walletAddress:T}=o?o.getWalletInfo():{},k={...u,walletType:d,from:T,tracker:r,chainId:y,localTimestamp:l,txKey:"",pending:false,isTrackedModalOpen:c.withTrackedModal},S=s=>{let p=s instanceof Error?s.message:String(s);throw e(x=>produce(x,m=>{m.initialTx&&(m.initialTx.isInitializing=false,m.initialTx.errorMessage=p);})),new Error(`Transaction failed to initialize: ${p}`)};if(e({initialTx:{...c,localTimestamp:l,isInitializing:true}}),o)try{await o.checkChainForTx(y);let s=await g();if(s){let{tracker:p,txKey:x}=o.checkTransactionsTracker(s,k.walletType);a().addTxToPool({tx:{...k,tracker:p,txKey:x,hash:p==="ethereum"?s:void 0}}),e(h=>produce(h,P=>{P.initialTx&&(P.initialTx.isInitializing=!1,P.initialTx.lastTxKey=x);}));let m=a().transactionsPool[x];await o.checkAndInitializeTrackerInStore({tx:m,...a()});}else e({initialTx:void 0});}catch(s){S(s);}else S("No adapter found for this transaction.");}}),{...i}))}var z=(e=>(e.EVM="evm",e.SOLANA="solana",e.Starknet="Starknet",e))(z||{}),F=(e=>(e.Failed="Failed",e.Success="Success",e.Replaced="Replaced",e))(F||{});var te=(n=>t=>useStore(n,t));async function re({onInitialize:n,tx:t,removeTxFromPool:i,fetcher:e,onFailed:a,onIntervalTick:r,onSucceed:g,pollingInterval:c,retryCount:y,onReplaced:u}){if(n&&n(),!t?.pending)return;let l,o=T=>{clearInterval(l),i&&!T&&i(t.txKey);},d=y??10;l=window.setInterval(async()=>{if(d<=0){o();return}try{(await e({tx:t,onSucceed:g,onFailed:a,onIntervalTick:r,onReplaced:u,clearWatch:o})).ok||d--;}catch(T){console.error("Polling fetcher function threw an error:",T),d--;}},c??5e3);}export{z as TransactionAdapter,F as TransactionStatus,te as createBoundedUseStore,Q as createPulsarStore,re as initializePollingTracker,A as initializeTxTrackingStore,R as selectAdapterByKey,v as selectAllTransactions,D as selectAllTransactionsByActiveWallet,K as selectPendingTransactions,L as selectPendingTransactionsByActiveWallet,j as selectTXByKey};//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/store/initializeTxTrackingStore.ts","../src/store/transactionsSelectors.ts","../src/store/txTrackingStore.ts","../src/types.ts","../src/utils/createBoundedUseStore.ts","../src/utils/initializePollingTracker.ts"],"names":["initializeTxTrackingStore","onSucceedCallbacks","set","get","tx","state","produce","draft","txKey","selectAllTransactions","transactionsPool","a","b","selectPendingTransactions","selectTXByKey","key","selectAllTransactionsByActiveWallet","from","selectPendingTransactionsByActiveWallet","createPulsarStore","adapters","options","createStore","persist","adapter","defaultTracker","actionFunction","params","desiredChainID","restParams","localTimestamp","dayjs","walletType","walletAddress","txInitialParams","handleError","e","errorMessage","txKeyFromAction","updatedTracker","finalTxKey","TransactionAdapter","TransactionStatus","createBoundedUseStore","store","selector","useStore","initializePollingTracker","onInitialize","removeTxFromPool","fetcher","onFailed","onIntervalTick","onSucceed","pollingInterval","retryCount","onReplaced","pollingIntervalId","clearWatch","withoutRemoving","retriesLeft","error"],"mappings":"mKA2EO,SAASA,CAAAA,CAAyD,CACvE,kBAAA,CAAAC,CACF,CAAA,CAEkD,CAChD,OAAO,CAACC,CAAAA,CAAKC,KAAS,CACpB,kBAAA,CAAAF,EAEA,gBAAA,CAAkB,EAAC,CACnB,cAAA,CAAgB,OAChB,SAAA,CAAW,MAAA,CAEX,WAAA,CAAa,CAAC,CAAE,EAAA,CAAAG,CAAG,CAAA,GAAM,CACvBF,EAAI,CAAE,cAAA,CAAgBE,EAAG,KAAM,CAAC,EAChCF,CAAAA,CAAKG,CAAAA,EACHC,OAAAA,CAAQD,CAAAA,CAAQE,GAAU,CACpBH,CAAAA,CAAG,KAAA,GACLG,CAAAA,CAAM,iBAAiBH,CAAAA,CAAG,KAAK,CAAA,CAAI,CACjC,GAAGA,CAAAA,CACH,OAAA,CAAS,IACX,CAAA,EAEJ,CAAC,CACH,EACF,CAAA,CAEA,cA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A6C,CAAAA,CACA,OAAA,CAAAC,EACA,QAAA,CAAAC,CAAAA,CACA,eAAAC,CAAAA,CACA,SAAA,CAAAC,CAAAA,CACA,eAAA,CAAAC,EACA,UAAA,CAAAC,CAAAA,CACA,UAAA,CAAAC,CACF,EAAsD,CAMpD,GALIR,CAAAA,EACFA,CAAAA,GAIE,CAAC5C,CAAAA,EAAI,QACP,OAGF,IAAIqD,EAMEC,CAAAA,CAAcC,CAAAA,EAA8B,CAChD,aAAA,CAAcF,CAAiB,CAAA,CAC3BR,CAAAA,EAAoB,CAACU,CAAAA,EACvBV,EAAiB7C,CAAAA,CAAG,KAAK,EAE7B,CAAA,CAEIwD,EAAcL,CAAAA,EAAc,EAAA,CAEhCE,EAAoB,MAAA,CAAO,WAAA,CAAY,SAAY,CACjD,GAAIG,CAAAA,EAAe,CAAA,CAAG,CACpBF,CAAAA,EAAW,CACX,MACF,CAEA,GAAI,CAAA,CACe,MAAMR,CAAAA,CAAQ,CAC7B,GAAA9C,CAAAA,CACA,SAAA,CAAAiD,EACA,QAAA,CAAAF,CAAAA,CACA,eAAAC,CAAAA,CACA,UAAA,CAAAI,CAAAA,CACA,UAAA,CAAAE,CACF,CAAC,CAAA,EAIa,IACZE,CAAAA,GAEJ,CAAA,MAASC,EAAO,CACd,OAAA,CAAQ,KAAA,CAAM,0CAAA,CAA4CA,CAAK,CAAA,CAC/DD,CAAAA,GACF,CACF,CAAA,CAAGN,CAAAA,EAAmB,GAAI,EAC5B","file":"index.mjs","sourcesContent":["/**\n * @file This file provides the core slice for the Zustand store, responsible for managing the state of transactions.\n * It includes functions and types for initializing the store and performing basic CRUD operations on the transaction pool.\n */\n\nimport { Draft, produce } from 'immer';\n\nimport {EvmTransaction, InitialTransaction, StoreSlice, Transaction} from '../types';\n\n/**\n * Defines the structure of the transaction pool, which is a record of transactions indexed by their unique keys.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n */\nexport type TransactionPool<TR, T extends Transaction<TR>> = Record<string, T>;\n\n/**\n * A utility type that extracts a subset of fields from the `Transaction` type\n * that are updatable via the `updateTxParams` action.\n * @template TR - The type of the tracker identifier.\n */\ntype UpdatedParamsFields<TR> = Pick<\n EvmTransaction<TR>,\n | 'to'\n | 'nonce'\n | 'txKey'\n | 'pending'\n | 'hash'\n | 'status'\n | 'replacedTxHash'\n | 'errorMessage'\n | 'finishedTimestamp'\n | 'isTrackedModalOpen'\n | 'isError'\n | 'maxPriorityFeePerGas'\n | 'maxFeePerGas'\n | 'input'\n | 'value'\n>;\n\n/**\n * Defines the interface for the base transaction tracking store slice.\n * It includes the state and actions for managing transactions.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n */\nexport type IInitializeTxTrackingStore<TR, T extends Transaction<TR>> = {\n /** An optional callback function to be executed when a transaction successfully completes. */\n onSucceedCallbacks?: (tx: T) => Promise<void> | void;\n /** A pool of all transactions currently being tracked, indexed by their `txKey`. */\n transactionsPool: TransactionPool<TR, T>;\n /** The key of the most recently added transaction. */\n lastAddedTxKey?: string;\n /** The state of a transaction that is currently being initiated but not yet submitted. */\n initialTx?: InitialTransaction;\n\n /** Adds a new transaction to the tracking pool. */\n addTxToPool: ({ tx }: { tx: T }) => void;\n /** Updates one or more parameters of an existing transaction in the pool. */\n updateTxParams: (fields: UpdatedParamsFields<TR>) => void;\n /** Removes a transaction from the tracking pool using its key. */\n removeTxFromPool: (txKey: string) => void;\n /** Closes the tracking modal for a specific transaction. */\n closeTxTrackedModal: (txKey?: string) => void;\n /** Returns the key of the last transaction that was added to the pool. */\n getLastTxKey: () => string | undefined;\n};\n\n/**\n * Creates a Zustand store slice containing the core logic for transaction tracking.\n * This function is a slice creator and is meant to be used within `createStore` from Zustand.\n * @param {object} options - Configuration options for the store slice.\n * @param {function} [options.onSucceedCallbacks] - An optional async callback to run when a transaction succeeds.\n * @returns {StoreSlice<IInitializeTxTrackingStore<TR, T>>} A Zustand store slice.\n */\nexport function initializeTxTrackingStore<TR, T extends Transaction<TR>>({\n onSucceedCallbacks,\n}: {\n onSucceedCallbacks?: (tx: T) => Promise<void> | void;\n}): StoreSlice<IInitializeTxTrackingStore<TR, T>> {\n return (set, get) => ({\n onSucceedCallbacks,\n\n transactionsPool: {},\n lastAddedTxKey: undefined,\n initialTx: undefined,\n\n addTxToPool: ({ tx }) => {\n set({ lastAddedTxKey: tx.txKey });\n set((state) =>\n produce(state, (draft) => {\n if (tx.txKey) {\n draft.transactionsPool[tx.txKey] = {\n ...tx,\n pending: true,\n } as Draft<T>;\n }\n }),\n );\n },\n\n updateTxParams: (tx) => {\n set((state) =>\n produce(state, (draft) => {\n // Ensure the transaction exists before attempting to update\n if (draft.transactionsPool[tx.txKey]) {\n draft.transactionsPool[tx.txKey] = {\n ...draft.transactionsPool[tx.txKey],\n ...tx,\n };\n }\n }),\n );\n },\n\n removeTxFromPool: (txKey) => {\n set((state) =>\n produce(state, (draft) => {\n delete draft.transactionsPool[txKey];\n }),\n );\n },\n\n closeTxTrackedModal: (txKey) => {\n if (txKey) {\n set((state) =>\n produce(state, (draft) => {\n if (draft.transactionsPool[txKey]) {\n draft.transactionsPool[txKey].isTrackedModalOpen = false;\n }\n }),\n );\n }\n // Always clear the initial transaction state when a modal is closed\n set({ initialTx: undefined });\n },\n\n getLastTxKey: () => {\n return get().lastAddedTxKey;\n },\n });\n}\n","/**\n * @file This file contains selector functions for deriving state from the transaction tracking store.\n * Selectors help abstract away the shape of the state and provide memoized, efficient access to computed data.\n */\n\nimport { Transaction } from '../types';\nimport { TransactionPool } from './initializeTxTrackingStore';\n\n/**\n * Selects all transactions from the pool and sorts them by their creation timestamp.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @returns {T[]} An array of all transactions, sorted chronologically.\n */\nexport const selectAllTransactions = <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>): T[] => {\n return Object.values(transactionsPool).sort((a, b) => Number(a.localTimestamp) - Number(b.localTimestamp));\n};\n\n/**\n * Selects all transactions that are currently in a pending state.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @returns {T[]} An array of pending transactions.\n */\nexport const selectPendingTransactions = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n): T[] => {\n return selectAllTransactions(transactionsPool).filter((tx) => tx.pending);\n};\n\n/**\n * Selects a single transaction from the pool by its unique transaction key (`txKey`).\n * This is the most direct way to retrieve a transaction.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @param {string} key - The `txKey` of the transaction to retrieve.\n * @returns {T | undefined} The transaction object if found, otherwise undefined.\n */\nexport const selectTXByKey = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n key: string,\n): T | undefined => {\n return transactionsPool[key];\n};\n\n/**\n * Selects all transactions initiated by a specific wallet address.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @param {string} from - The wallet address (`from` address) to filter transactions by.\n * @returns {T[]} An array of transactions associated with the given wallet.\n */\nexport const selectAllTransactionsByActiveWallet = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n from: string,\n): T[] => {\n return selectAllTransactions(transactionsPool).filter((tx) => tx.from === from);\n};\n\n/**\n * Selects all pending transactions initiated by a specific wallet address.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @param {string} from - The wallet address (`from` address) to filter transactions by.\n * @returns {T[]} An array of pending transactions associated with the given wallet.\n */\nexport const selectPendingTransactionsByActiveWallet = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n from: string,\n): T[] => {\n return selectPendingTransactions(transactionsPool).filter((tx) => tx.from === from);\n};\n","import dayjs from 'dayjs';\nimport { Draft, produce } from 'immer';\nimport { persist, PersistOptions } from 'zustand/middleware';\nimport { createStore } from 'zustand/vanilla';\n\nimport { ITxTrackingStore, Transaction, TxAdapter } from '../types';\nimport { initializeTxTrackingStore } from './initializeTxTrackingStore';\n\nexport function createPulsarStore<TR, T extends Transaction<TR>, A>({\n onSucceedCallbacks,\n adapters,\n ...options\n}: {\n onSucceedCallbacks?: (tx: T) => Promise<void> | void;\n adapters: TxAdapter<TR, T, A>[];\n} & PersistOptions<ITxTrackingStore<TR, T, A>>) {\n return createStore<ITxTrackingStore<TR, T, A>>()(\n persist(\n (set, get) => ({\n ...initializeTxTrackingStore<TR, T>({ onSucceedCallbacks })(set, get),\n\n /**\n * Initializes trackers for all pending transactions in the pool.\n * This is essential for resuming tracking after a page reload.\n */\n initializeTransactionsPool: async () => {\n await Promise.all(\n Object.values(get().transactionsPool).map(async (tx) => {\n if (tx.pending) {\n const adapter = adapters.find((adapter) => adapter.key === tx.adapter);\n adapter?.checkAndInitializeTrackerInStore({ tx, ...get() });\n }\n }),\n );\n },\n\n /**\n * The main function to orchestrate sending and tracking a new transaction.\n * It handles chain switching, wallet interactions, state updates, and tracker initialization.\n */\n handleTransaction: async ({ defaultTracker, actionFunction, params }) => {\n set({ initialTx: undefined }); // Clear any previous initial state\n const { desiredChainID, ...restParams } = params;\n const localTimestamp = dayjs().unix();\n\n const adapter = adapters.find((adapter) => adapter.key === restParams.adapter);\n\n const { walletType, walletAddress } = adapter ? adapter.getWalletInfo() : {};\n\n const txInitialParams = {\n ...restParams,\n walletType,\n from: walletAddress,\n tracker: defaultTracker,\n chainId: desiredChainID,\n localTimestamp,\n txKey: '', // Will be populated after the action\n pending: false,\n isTrackedModalOpen: params.withTrackedModal,\n } as Draft<T>;\n\n const handleError = (e: unknown) => {\n const errorMessage = e instanceof Error ? e.message : String(e);\n set((state) =>\n produce(state, (draft) => {\n if (draft.initialTx) {\n draft.initialTx.isInitializing = false;\n draft.initialTx.errorMessage = errorMessage;\n }\n }),\n );\n // Re-throw to allow the caller to handle the error as well\n throw new Error(`Transaction failed to initialize: ${errorMessage}`);\n };\n\n // Set initial state for immediate UI feedback\n set({\n initialTx: {\n ...params,\n localTimestamp,\n isInitializing: true,\n },\n });\n\n if (adapter) {\n try {\n // 1. Ensure the wallet is on the correct chain\n await adapter.checkChainForTx(desiredChainID);\n\n // 2. Execute the action (e.g., wallet call) to get a transaction key (hash, taskId, etc.)\n const txKeyFromAction = await actionFunction();\n\n if (txKeyFromAction) {\n // 3. Determine the correct tracker and final txKey\n const { tracker: updatedTracker, txKey: finalTxKey } = adapter.checkTransactionsTracker(\n txKeyFromAction,\n txInitialParams.walletType,\n );\n\n // 4. Add the transaction to the pool\n get().addTxToPool({\n tx: {\n ...txInitialParams,\n tracker: updatedTracker,\n txKey: finalTxKey,\n hash: updatedTracker === 'ethereum' ? txKeyFromAction : undefined,\n } as T,\n });\n\n // Update initial state to reflect that initialization is complete\n set((state) =>\n produce(state, (draft) => {\n if (draft.initialTx) {\n draft.initialTx.isInitializing = false;\n draft.initialTx.lastTxKey = finalTxKey;\n }\n }),\n );\n\n // 5. Start the background tracking process for the new transaction\n const tx = get().transactionsPool[finalTxKey];\n await adapter.checkAndInitializeTrackerInStore({ tx, ...get() });\n } else {\n // Action was likely cancelled by the user, clear the initial state\n set({ initialTx: undefined });\n }\n } catch (e) {\n handleError(e);\n }\n } else {\n handleError('No adapter found for this transaction.');\n }\n },\n }),\n {\n ...options, // Zustand persist middleware options\n },\n ),\n );\n}\n","/**\n * @file This file defines the core data structures and TypeScript types for the Pulsar transaction tracking engine.\n * It includes types for transactions, their statuses, store interfaces, and utility types for Zustand slices.\n * These types are framework-agnostic and form the foundation of the entire tracking system.\n */\n\nimport { StoreApi } from 'zustand';\n\nimport { IInitializeTxTrackingStore } from './store/initializeTxTrackingStore';\n\n/**\n * A utility type for creating modular Zustand store slices.\n * @template T The state slice type.\n * @template E The full store state type, defaults to T.\n */\nexport type StoreSlice<T extends object, E extends object = T> = (\n set: StoreApi<E extends T ? E : E & T>['setState'],\n get: StoreApi<E extends T ? E : E & T>['getState'],\n) => T;\n\n/**\n * Represents the blockchain adapter for a transaction.\n */\nexport enum TransactionAdapter {\n /** EVM adapter. */\n EVM = 'evm',\n /** Solana adapter. */\n SOLANA = 'solana',\n /** Starknet adapter. */\n Starknet = 'Starknet',\n}\n\n/**\n * Represents the final status of a transaction.\n */\nexport enum TransactionStatus {\n /** The transaction failed to execute. */\n Failed = 'Failed',\n /** The transaction was successfully mined and executed. */\n Success = 'Success',\n /** The transaction was replaced by another (e.g., speed-up). */\n Replaced = 'Replaced',\n}\n\n/**\n * The base structure for any transaction being tracked.\n * @template T The type of the tracker identifier (e.g., 'evm', 'safe').\n */\nexport type BaseTransaction<T> = {\n /** A key identifying the retry logic for this transaction from the actions registry. */\n actionKey?: string;\n /** The chain identifier (e.g., 1 for Ethereum Mainnet, 'SN_MAIN' for Starknet). */\n chainId: number | string;\n /** A description for the transaction, with states for [pending, success, error, replaced]. */\n description?: string | [string, string, string, string];\n /** An error message if the transaction failed. */\n errorMessage?: string;\n /** The timestamp (in seconds) when the transaction was finalized on-chain. */\n finishedTimestamp?: number;\n /** The sender's address. */\n from: string;\n /** A flag indicating if the transaction is in a failed state. */\n isError?: boolean;\n /** A flag indicating if the detailed tracking modal should be open for this transaction. For UI purposes. */\n isTrackedModalOpen?: boolean;\n /** The local timestamp (in seconds) when the transaction was initiated. */\n localTimestamp: number;\n /** Any additional data associated with the transaction. */\n payload?: object;\n /** Indicates if the transaction is still pending confirmation. */\n pending: boolean;\n /** The final status of the transaction. */\n status?: TransactionStatus;\n /** A title for the transaction, with states for [pending, success, error, replaced]. */\n title?: string | [string, string, string, string];\n /** The specific tracker responsible for monitoring this transaction (e.g., 'evm', 'safe', 'gelato', etc.). */\n tracker: T;\n /** The unique key for the transaction within its tracker (e.g., EVM hash, Gelato task ID). */\n txKey: string;\n /** The type or category of the transaction (e.g., 'increment', 'approve'). */\n type: string;\n /** The type of wallet used for the transaction. */\n walletType: string;\n};\n\n/**\n * Represents an EVM-specific transaction, extending the base properties.\n * @template T The type of the tracker identifier.\n */\nexport type EvmTransaction<T> = BaseTransaction<T> & {\n /** The transaction adapter type. */\n adapter: TransactionAdapter.EVM;\n /** The on-chain transaction hash, available after submission. */\n hash?: string;\n /** The data payload for the transaction, typically for contract interactions. */\n input?: string;\n /** The maximum fee per gas for the transaction (EIP-1559). */\n maxFeePerGas?: string;\n /** The maximum priority fee per gas for the transaction (EIP-1559). */\n maxPriorityFeePerGas?: string;\n /** The transaction nonce. */\n nonce?: number;\n /** The hash of a transaction that this one replaced (e.g., for speed-up). */\n replacedTxHash?: string;\n /** The recipient's address. */\n to?: string;\n /** The value (in wei) being sent with the transaction. */\n value?: string;\n};\n\n/**\n * Represents a Solana-specific transaction, extending the base properties.\n * @template T The type of the tracker identifier.\n */\nexport type SolanaTransaction<T> = BaseTransaction<T> & {\n /** The transaction adapter type. */\n adapter: TransactionAdapter.SOLANA;\n /** The transaction fee. */\n fee?: number;\n /** The instructions included in the transaction. */\n instructions?: any[];\n /** The recent blockhash used for the transaction. */\n recentBlockhash?: string;\n /** The slot in which the transaction was processed. */\n slot?: number;\n};\n\n/**\n * Represents a Starknet-specific transaction, extending the base properties.\n * @template T The type of the tracker identifier.\n */\nexport type StarknetTransaction<T> = BaseTransaction<T> & {\n /** The actual fee paid for the transaction. */\n actualFee?: { amount: string; unit: string };\n /** The address of the contract being interacted with. */\n contractAddress?: string;\n /** The transaction adapter type. */\n adapter: TransactionAdapter.Starknet;\n /** The reason for transaction failure, if applicable. */\n revertReason?: string;\n};\n\n/** A union type representing any possible transaction structure. */\nexport type Transaction<T> = EvmTransaction<T> | SolanaTransaction<T> | StarknetTransaction<T>;\n\n/**\n * Represents the parameters required to initiate a new transaction.\n */\nexport type InitialTransactionParams = {\n /** The transaction adapter type. */\n adapter: TransactionAdapter;\n /** A key identifying the retry logic from the actions registry. */\n actionKey?: string;\n /** A description for the transaction, with states for [pending, success, error, replaced]. */\n description?: string | [string, string, string, string];\n /** The ID of the desired blockchain network. */\n desiredChainID: number | string;\n /** Any additional data to be associated with the transaction. */\n payload?: object;\n /** A title for the transaction, with states for [pending, success, error, replaced]. */\n title?: string | [string, string, string, string];\n /** The type or category of the transaction (e.g., 'increment', 'approve'). */\n type: string;\n /** If true, the detailed tracking modal will open automatically for this transaction. */\n withTrackedModal?: boolean;\n};\n\n/**\n * Represents a transaction in its initial, pre-submission state within the store.\n * This is used for UI feedback while the transaction is being signed and sent.\n */\nexport type InitialTransaction = InitialTransactionParams & {\n /** An error message if the initialization process fails (e.g., user rejects signature). */\n errorMessage?: string;\n /** True if the transaction is currently being processed (e.g., waiting for user signature). */\n isInitializing: boolean;\n /** The key of the on-chain transaction that this action produced, used for linking. */\n lastTxKey?: string;\n /** The local timestamp when the user initiated the action. */\n localTimestamp: number;\n};\n\nexport type TxAdapter<TR, T extends Transaction<TR>, A> = {\n key: TransactionAdapter;\n getWalletInfo: () => {\n /** Wallet address. */\n walletAddress: string;\n /** Type of the wallet. (injected, wallet connect, etc.) */\n walletType: string;\n };\n checkChainForTx: (chainId: string | number) => Promise<void>;\n checkTransactionsTracker: (actionTxKey: A, walletType: string) => { txKey: string; tracker: TR };\n checkAndInitializeTrackerInStore: ({\n tx,\n ...rest\n }: { tx: T } & Pick<\n ITxTrackingStore<TR, T, A>,\n 'transactionsPool' | 'updateTxParams' | 'onSucceedCallbacks' | 'removeTxFromPool'\n >) => Promise<void>;\n};\n\n/**\n * Interface for the complete transaction tracking store.\n * @template TR The type of the tracker identifier.\n * @template T The transaction type.\n * @template C The configuration object type (e.g., wagmi config).\n * @template A The return type of the action function being wrapped.\n */\nexport type ITxTrackingStore<TR, T extends Transaction<TR>, A> = IInitializeTxTrackingStore<TR, T> & {\n /**\n * A wrapper function that handles the entire lifecycle of a transaction.\n * It creates an `InitialTransaction`, executes the on-chain action, and tracks its status.\n * @param params - The parameters for handling the transaction.\n */\n handleTransaction: (params: {\n /** The async function to execute (e.g., a smart contract write call). */\n actionFunction: () => Promise<A | undefined>;\n /** The metadata for the transaction to be created, of type `InitialTransactionParams`. */\n params: InitialTransactionParams;\n\n defaultTracker?: TR;\n }) => Promise<void>;\n\n /**\n * Initializes all active trackers for pending transactions in the pool.\n * This is useful for resuming tracking after a page reload.\n */\n initializeTransactionsPool: () => Promise<void>;\n};\n","/**\n * @file This file provides a utility for creating a bounded Zustand hook from a vanilla store.\n * This is a recommended pattern for using vanilla stores with React to ensure full type safety.\n *\n * @see https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n */\n\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * A utility type to infer the state shape from a Zustand store type.\n * @template S The type of the Zustand store (`StoreApi`).\n */\ntype ExtractState<S> = S extends { getState: () => infer X } ? X : never;\n\n/**\n * Creates a bounded `useStore` hook from a vanilla Zustand store instance.\n * The returned hook is fully typed and can be used with or without a selector.\n *\n * @template S The type of the Zustand store (`StoreApi`).\n * @param {S} store - The vanilla Zustand store instance.\n * @returns {function} A hook that can be called with an optional selector function.\n * - When called with a selector (`useBoundedStore(state => state.someValue)`), it returns the selected slice of the state.\n */\nexport const createBoundedUseStore = ((store) => (selector) => useStore(store, selector)) as <\n S extends StoreApi<unknown>,\n>(\n store: S,\n) => {\n (): ExtractState<S>;\n <T>(selector: (state: ExtractState<S>) => T): T;\n};\n","/**\n * @file This file contains a generic utility for creating a polling mechanism to track asynchronous tasks,\n * such as API-based transaction status checks (e.g., for Gelato or Safe).\n */\n\nimport { Transaction } from '../types';\n\n/**\n * Defines the configuration object for the `initializePollingTracker` function.\n * @template R The expected type of the successful API response from the fetcher.\n * @template T The type of the transaction object being tracked.\n * @template TR The type of the tracker identifier used in the `Transaction` type.\n */\nexport type InitializePollingTracker<R, T, TR> = {\n /** The transaction object to be tracked. It must include `txKey` and an optional `pending` status. */\n tx: T & Pick<Transaction<TR>, 'txKey'> & { pending?: boolean };\n /** The function that performs the actual data fetching (e.g., an API call). */\n fetcher: (params: {\n /** The transaction object being tracked. */\n tx: T;\n /** A callback to stop the polling mechanism, typically called on success or terminal failure. */\n clearWatch: (withoutRemoving?: boolean) => void;\n /** Callback to be invoked when the fetcher determines the transaction has succeeded. */\n onSucceed: (response: R) => void;\n /** Callback to be invoked when the fetcher determines the transaction has failed. */\n onFailed: (response: R) => void;\n /** Optional callback for each successful poll, useful for updating UI with intermediate states. */\n onIntervalTick?: (response: R) => void;\n /** Optional callback for when a transaction is replaced by another. */\n onReplaced?: (response: R) => void;\n }) => Promise<Response>;\n\n /** Optional callback executed once when the tracker is initialized. */\n onInitialize?: () => void;\n /** Callback to be invoked when the transaction has succeeded. */\n onSucceed: (response: R) => void;\n /** Callback to be invoked when the transaction has failed. */\n onFailed: (response: R) => void;\n /** Optional callback for each successful poll. */\n onIntervalTick?: (response: R) => void;\n /** Optional callback for when a transaction is replaced. */\n onReplaced?: (response: R) => void;\n /** Optional function to remove the transaction from the main pool, typically after polling stops. */\n removeTxFromPool?: (taskId: string) => void;\n /** The interval (in milliseconds) between polling attempts. Defaults to 5000ms. */\n pollingInterval?: number;\n /** The number of consecutive failed fetches before stopping the tracker. Defaults to 10. */\n retryCount?: number;\n};\n\n/**\n * Initializes a generic polling tracker that repeatedly calls a fetcher function\n * to monitor the status of a transaction or any asynchronous task.\n *\n * @template R The expected type of the successful API response.\n * @template T The type of the transaction object.\n * @template TR The type of the tracker identifier.\n * @param {InitializePollingTracker<R, T, TR>} params - The configuration object for the tracker.\n * @returns {Promise<void>} A promise that resolves when the tracker is set up (note: polling happens asynchronously).\n */\nexport async function initializePollingTracker<R, T, TR>({\n onInitialize,\n tx,\n removeTxFromPool,\n fetcher,\n onFailed,\n onIntervalTick,\n onSucceed,\n pollingInterval,\n retryCount,\n onReplaced,\n}: InitializePollingTracker<R, T, TR>): Promise<void> {\n if (onInitialize) {\n onInitialize();\n }\n\n // Early exit if the transaction is not pending\n if (!tx?.pending) {\n return;\n }\n\n let pollingIntervalId: number | undefined;\n\n /**\n * Stops the polling interval and optionally removes the transaction from the pool.\n * @param {boolean} [withoutRemoving=false] - If true, the transaction will not be removed from the pool.\n */\n const clearWatch = (withoutRemoving?: boolean) => {\n clearInterval(pollingIntervalId);\n if (removeTxFromPool && !withoutRemoving) {\n removeTxFromPool(tx.txKey);\n }\n };\n\n let retriesLeft = retryCount ?? 10;\n\n pollingIntervalId = window.setInterval(async () => {\n if (retriesLeft <= 0) {\n clearWatch();\n return;\n }\n\n try {\n const response = await fetcher({\n tx,\n onSucceed,\n onFailed,\n onIntervalTick,\n onReplaced,\n clearWatch,\n });\n\n // If the API call fails (e.g., 404 Not Found), decrement the retry counter.\n // The fetcher itself is responsible for calling `clearWatch` on terminal statuses.\n if (!response.ok) {\n retriesLeft--;\n }\n } catch (error) {\n console.error('Polling fetcher function threw an error:', error);\n retriesLeft--;\n }\n }, pollingInterval ?? 5000);\n}\n"]}
1
+ {"version":3,"sources":["../src/store/initializeTxTrackingStore.ts","../src/store/transactionsSelectors.ts","../src/utils/selectAdapterByKey.ts","../src/store/txTrackingStore.ts","../src/types.ts","../src/utils/createBoundedUseStore.ts","../src/utils/initializePollingTracker.ts"],"names":["initializeTxTrackingStore","onSucceedCallbacks","set","get","tx","state","produce","draft","txKey","selectAllTransactions","transactionsPool","a","b","selectPendingTransactions","selectTXByKey","key","selectAllTransactionsByActiveWallet","from","selectPendingTransactionsByActiveWallet","selectAdapterByKey","adapterKey","adapters","adapter","createPulsarStore","options","createStore","persist","defaultTracker","actionFunction","params","desiredChainID","restParams","localTimestamp","dayjs","walletType","walletAddress","txInitialParams","handleError","e","errorMessage","txKeyFromAction","updatedTracker","finalTxKey","TransactionAdapter","TransactionStatus","createBoundedUseStore","store","selector","useStore","initializePollingTracker","onInitialize","removeTxFromPool","fetcher","onFailed","onIntervalTick","onSucceed","pollingInterval","retryCount","onReplaced","pollingIntervalId","clearWatch","withoutRemoving","retriesLeft","error"],"mappings":"m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AAA,EAAe,EAAG,CACpBF,CAAAA,GACA,MACF,CAEA,GAAI,CAAA,CACe,MAAMR,CAAAA,CAAQ,CAC7B,GAAAhD,CAAAA,CACA,SAAA,CAAAmD,EACA,QAAA,CAAAF,CAAAA,CACA,eAAAC,CAAAA,CACA,UAAA,CAAAI,CAAAA,CACA,UAAA,CAAAE,CACF,CAAC,CAAA,EAIa,IACZE,CAAAA,GAEJ,CAAA,MAASC,EAAO,CACd,OAAA,CAAQ,KAAA,CAAM,0CAAA,CAA4CA,CAAK,CAAA,CAC/DD,CAAAA,GACF,CACF,CAAA,CAAGN,CAAAA,EAAmB,GAAI,EAC5B","file":"index.mjs","sourcesContent":["/**\n * @file This file provides the core slice for the Zustand store, responsible for managing the state of transactions.\n * It includes functions and types for initializing the store and performing basic CRUD operations on the transaction pool.\n */\n\nimport { Draft, produce } from 'immer';\n\nimport { EvmTransaction, InitialTransaction, StoreSlice, Transaction } from '../types';\n\n/**\n * Defines the structure of the transaction pool, which is a record of transactions indexed by their unique keys.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n */\nexport type TransactionPool<TR, T extends Transaction<TR>> = Record<string, T>;\n\n/**\n * A utility type that extracts a subset of fields from the `Transaction` type\n * that are updatable via the `updateTxParams` action.\n * @template TR - The type of the tracker identifier.\n */\ntype UpdatedParamsFields<TR> = Pick<\n EvmTransaction<TR>,\n | 'to'\n | 'nonce'\n | 'txKey'\n | 'pending'\n | 'hash'\n | 'status'\n | 'replacedTxHash'\n | 'errorMessage'\n | 'finishedTimestamp'\n | 'isTrackedModalOpen'\n | 'isError'\n | 'maxPriorityFeePerGas'\n | 'maxFeePerGas'\n | 'input'\n | 'value'\n>;\n\n/**\n * Defines the interface for the base transaction tracking store slice.\n * It includes the state and actions for managing transactions.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n */\nexport type IInitializeTxTrackingStore<TR, T extends Transaction<TR>> = {\n /** An optional callback function to be executed when a transaction successfully completes. */\n onSucceedCallbacks?: (tx: T) => Promise<void> | void;\n /** A pool of all transactions currently being tracked, indexed by their `txKey`. */\n transactionsPool: TransactionPool<TR, T>;\n /** The key of the most recently added transaction. */\n lastAddedTxKey?: string;\n /** The state of a transaction that is currently being initiated but not yet submitted. */\n initialTx?: InitialTransaction;\n\n /** Adds a new transaction to the tracking pool. */\n addTxToPool: ({ tx }: { tx: T }) => void;\n /** Updates one or more parameters of an existing transaction in the pool. */\n updateTxParams: (fields: UpdatedParamsFields<TR>) => void;\n /** Removes a transaction from the tracking pool using its key. */\n removeTxFromPool: (txKey: string) => void;\n /** Closes the tracking modal for a specific transaction. */\n closeTxTrackedModal: (txKey?: string) => void;\n /** Returns the key of the last transaction that was added to the pool. */\n getLastTxKey: () => string | undefined;\n};\n\n/**\n * Creates a Zustand store slice containing the core logic for transaction tracking.\n * This function is a slice creator and is meant to be used within `createStore` from Zustand.\n * @param {object} options - Configuration options for the store slice.\n * @param {function} [options.onSucceedCallbacks] - An optional async callback to run when a transaction succeeds.\n * @returns {StoreSlice<IInitializeTxTrackingStore<TR, T>>} A Zustand store slice.\n */\nexport function initializeTxTrackingStore<TR, T extends Transaction<TR>>({\n onSucceedCallbacks,\n}: {\n onSucceedCallbacks?: (tx: T) => Promise<void> | void;\n}): StoreSlice<IInitializeTxTrackingStore<TR, T>> {\n return (set, get) => ({\n onSucceedCallbacks,\n\n transactionsPool: {},\n lastAddedTxKey: undefined,\n initialTx: undefined,\n\n addTxToPool: ({ tx }) => {\n set({ lastAddedTxKey: tx.txKey });\n set((state) =>\n produce(state, (draft) => {\n if (tx.txKey) {\n draft.transactionsPool[tx.txKey] = {\n ...tx,\n pending: true,\n } as Draft<T>;\n }\n }),\n );\n },\n\n updateTxParams: (tx) => {\n set((state) =>\n produce(state, (draft) => {\n // Ensure the transaction exists before attempting to update\n if (draft.transactionsPool[tx.txKey]) {\n draft.transactionsPool[tx.txKey] = {\n ...draft.transactionsPool[tx.txKey],\n ...tx,\n };\n }\n }),\n );\n },\n\n removeTxFromPool: (txKey) => {\n set((state) =>\n produce(state, (draft) => {\n delete draft.transactionsPool[txKey];\n }),\n );\n },\n\n closeTxTrackedModal: (txKey) => {\n if (txKey) {\n set((state) =>\n produce(state, (draft) => {\n if (draft.transactionsPool[txKey]) {\n draft.transactionsPool[txKey].isTrackedModalOpen = false;\n }\n }),\n );\n }\n // Always clear the initial transaction state when a modal is closed\n set({ initialTx: undefined });\n },\n\n getLastTxKey: () => {\n return get().lastAddedTxKey;\n },\n });\n}\n","/**\n * @file This file contains selector functions for deriving state from the transaction tracking store.\n * Selectors help abstract away the shape of the state and provide memoized, efficient access to computed data.\n */\n\nimport { Transaction } from '../types';\nimport { TransactionPool } from './initializeTxTrackingStore';\n\n/**\n * Selects all transactions from the pool and sorts them by their creation timestamp.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @returns {T[]} An array of all transactions, sorted chronologically.\n */\nexport const selectAllTransactions = <TR, T extends Transaction<TR>>(transactionsPool: TransactionPool<TR, T>): T[] => {\n return Object.values(transactionsPool).sort((a, b) => Number(a.localTimestamp) - Number(b.localTimestamp));\n};\n\n/**\n * Selects all transactions that are currently in a pending state.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @returns {T[]} An array of pending transactions.\n */\nexport const selectPendingTransactions = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n): T[] => {\n return selectAllTransactions(transactionsPool).filter((tx) => tx.pending);\n};\n\n/**\n * Selects a single transaction from the pool by its unique transaction key (`txKey`).\n * This is the most direct way to retrieve a transaction.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @param {string} key - The `txKey` of the transaction to retrieve.\n * @returns {T | undefined} The transaction object if found, otherwise undefined.\n */\nexport const selectTXByKey = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n key: string,\n): T | undefined => {\n return transactionsPool[key];\n};\n\n/**\n * Selects all transactions initiated by a specific wallet address.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @param {string} from - The wallet address (`from` address) to filter transactions by.\n * @returns {T[]} An array of transactions associated with the given wallet.\n */\nexport const selectAllTransactionsByActiveWallet = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n from: string,\n): T[] => {\n return selectAllTransactions(transactionsPool).filter((tx) => tx.from === from);\n};\n\n/**\n * Selects all pending transactions initiated by a specific wallet address.\n * @template TR - The type of the tracker identifier.\n * @template T - The transaction type.\n * @param {TransactionPool<TR, T>} transactionsPool - The entire pool of transactions from the store.\n * @param {string} from - The wallet address (`from` address) to filter transactions by.\n * @returns {T[]} An array of pending transactions associated with the given wallet.\n */\nexport const selectPendingTransactionsByActiveWallet = <TR, T extends Transaction<TR>>(\n transactionsPool: TransactionPool<TR, T>,\n from: string,\n): T[] => {\n return selectPendingTransactions(transactionsPool).filter((tx) => tx.from === from);\n};\n","import { Transaction, TransactionAdapter, TxAdapter } from '../types';\n\n/**\n * Selects and returns a transaction adapter from a list of adapters based on the provided adapter key.\n * If no matching adapter is found, the first adapter in the list is returned as a fallback.\n *\n * @template TR - Represents the transaction response type.\n * @template T - Extends the Transaction type and represents the transaction entity.\n * @template A - Represents the adapter type.\n *\n * @param {Object} params - Configuration object for selecting the adapter.\n * @param {TransactionAdapter} params.adapterKey - The key used to identify the desired transaction adapter.\n * @param {TxAdapter<TR, T, A>[]} params.adapters - An array of available transaction adapters.\n *\n * @returns {TxAdapter<TR, T, A>} The transaction adapter corresponding to the provided key, or the first adapter in the list.\n */\nexport const selectAdapterByKey = <TR, T extends Transaction<TR>, A>({\n adapterKey,\n adapters,\n}: {\n adapterKey: TransactionAdapter;\n adapters: TxAdapter<TR, T, A>[];\n}): TxAdapter<TR, T, A> => {\n const adapter = adapters.find((adapter) => adapter.key === adapterKey);\n if (adapter) {\n return adapter;\n } else {\n return adapters[0];\n }\n};\n","import dayjs from 'dayjs';\nimport { Draft, produce } from 'immer';\nimport { persist, PersistOptions } from 'zustand/middleware';\nimport { createStore } from 'zustand/vanilla';\n\nimport { ITxTrackingStore, Transaction, TxAdapter } from '../types';\nimport { selectAdapterByKey } from '../utils/selectAdapterByKey';\nimport { initializeTxTrackingStore } from './initializeTxTrackingStore';\n\nexport function createPulsarStore<TR, T extends Transaction<TR>, A>({\n onSucceedCallbacks,\n adapters,\n ...options\n}: {\n onSucceedCallbacks?: (tx: T) => Promise<void> | void;\n adapters: TxAdapter<TR, T, A>[];\n} & PersistOptions<ITxTrackingStore<TR, T, A>>) {\n return createStore<ITxTrackingStore<TR, T, A>>()(\n persist(\n (set, get) => ({\n ...initializeTxTrackingStore<TR, T>({ onSucceedCallbacks })(set, get),\n\n /**\n * Initializes trackers for all pending transactions in the pool.\n * This is essential for resuming tracking after a page reload.\n */\n initializeTransactionsPool: async () => {\n await Promise.all(\n Object.values(get().transactionsPool).map(async (tx) => {\n if (tx.pending) {\n const adapter = selectAdapterByKey({ adapterKey: tx.adapter, adapters });\n adapter?.checkAndInitializeTrackerInStore({ tx, ...get() });\n }\n }),\n );\n },\n\n /**\n * The main function to orchestrate sending and tracking a new transaction.\n * It handles chain switching, wallet interactions, state updates, and tracker initialization.\n */\n handleTransaction: async ({ defaultTracker, actionFunction, params }) => {\n set({ initialTx: undefined }); // Clear any previous initial state\n const { desiredChainID, ...restParams } = params;\n const localTimestamp = dayjs().unix();\n\n const adapter = selectAdapterByKey({ adapterKey: restParams.adapter, adapters });\n\n const { walletType, walletAddress } = adapter ? adapter.getWalletInfo() : {};\n\n const txInitialParams = {\n ...restParams,\n walletType,\n from: walletAddress,\n tracker: defaultTracker,\n chainId: desiredChainID,\n localTimestamp,\n txKey: '', // Will be populated after the action\n pending: false,\n isTrackedModalOpen: params.withTrackedModal,\n } as Draft<T>;\n\n const handleError = (e: unknown) => {\n const errorMessage = e instanceof Error ? e.message : String(e);\n set((state) =>\n produce(state, (draft) => {\n if (draft.initialTx) {\n draft.initialTx.isInitializing = false;\n draft.initialTx.errorMessage = errorMessage;\n }\n }),\n );\n // Re-throw to allow the caller to handle the error as well\n throw new Error(`Transaction failed to initialize: ${errorMessage}`);\n };\n\n // Set initial state for immediate UI feedback\n set({\n initialTx: {\n ...params,\n localTimestamp,\n isInitializing: true,\n },\n });\n\n if (adapter) {\n try {\n // 1. Ensure the wallet is on the correct chain\n await adapter.checkChainForTx(desiredChainID);\n\n // 2. Execute the action (e.g., wallet call) to get a transaction key (hash, taskId, etc.)\n const txKeyFromAction = await actionFunction();\n\n if (txKeyFromAction) {\n // 3. Determine the correct tracker and final txKey\n const { tracker: updatedTracker, txKey: finalTxKey } = adapter.checkTransactionsTracker(\n txKeyFromAction,\n txInitialParams.walletType,\n );\n\n // 4. Add the transaction to the pool\n get().addTxToPool({\n tx: {\n ...txInitialParams,\n tracker: updatedTracker,\n txKey: finalTxKey,\n hash: updatedTracker === 'ethereum' ? txKeyFromAction : undefined,\n } as T,\n });\n\n // Update initial state to reflect that initialization is complete\n set((state) =>\n produce(state, (draft) => {\n if (draft.initialTx) {\n draft.initialTx.isInitializing = false;\n draft.initialTx.lastTxKey = finalTxKey;\n }\n }),\n );\n\n // 5. Start the background tracking process for the new transaction\n const tx = get().transactionsPool[finalTxKey];\n await adapter.checkAndInitializeTrackerInStore({ tx, ...get() });\n } else {\n // Action was likely cancelled by the user, clear the initial state\n set({ initialTx: undefined });\n }\n } catch (e) {\n handleError(e);\n }\n } else {\n handleError('No adapter found for this transaction.');\n }\n },\n }),\n {\n ...options, // Zustand persist middleware options\n },\n ),\n );\n}\n","/**\n * @file This file defines the core data structures and TypeScript types for the Pulsar transaction tracking engine.\n * It includes types for transactions, their statuses, store interfaces, and utility types for Zustand slices.\n * These types are framework-agnostic and form the foundation of the entire tracking system.\n */\n\nimport { StoreApi } from 'zustand';\n\nimport { IInitializeTxTrackingStore, TransactionPool } from './store/initializeTxTrackingStore';\n\n/**\n * A utility type for creating modular Zustand store slices.\n * @template T The state slice type.\n * @template E The full store state type, defaults to T.\n */\nexport type StoreSlice<T extends object, E extends object = T> = (\n set: StoreApi<E extends T ? E : E & T>['setState'],\n get: StoreApi<E extends T ? E : E & T>['getState'],\n) => T;\n\n/**\n * Represents the blockchain adapter for a transaction.\n */\nexport enum TransactionAdapter {\n /** EVM adapter. */\n EVM = 'evm',\n /** Solana adapter. */\n SOLANA = 'solana',\n /** Starknet adapter. */\n Starknet = 'Starknet',\n}\n\n/**\n * Represents the final status of a transaction.\n */\nexport enum TransactionStatus {\n /** The transaction failed to execute. */\n Failed = 'Failed',\n /** The transaction was successfully mined and executed. */\n Success = 'Success',\n /** The transaction was replaced by another (e.g., speed-up). */\n Replaced = 'Replaced',\n}\n\n/**\n * The base structure for any transaction being tracked.\n * @template T The type of the tracker identifier (e.g., 'evm', 'safe').\n */\nexport type BaseTransaction<T> = {\n /** A key identifying the retry logic for this transaction from the actions registry. */\n actionKey?: string;\n /** The chain identifier (e.g., 1 for Ethereum Mainnet, 'SN_MAIN' for Starknet). */\n chainId: number | string;\n /** A description for the transaction, with states for [pending, success, error, replaced]. */\n description?: string | [string, string, string, string];\n /** An error message if the transaction failed. */\n errorMessage?: string;\n /** The timestamp (in seconds) when the transaction was finalized on-chain. */\n finishedTimestamp?: number;\n /** The sender's address. */\n from: string;\n /** A flag indicating if the transaction is in a failed state. */\n isError?: boolean;\n /** A flag indicating if the detailed tracking modal should be open for this transaction. For UI purposes. */\n isTrackedModalOpen?: boolean;\n /** The local timestamp (in seconds) when the transaction was initiated. */\n localTimestamp: number;\n /** Any additional data associated with the transaction. */\n payload?: object;\n /** Indicates if the transaction is still pending confirmation. */\n pending: boolean;\n /** The final status of the transaction. */\n status?: TransactionStatus;\n /** A title for the transaction, with states for [pending, success, error, replaced]. */\n title?: string | [string, string, string, string];\n /** The specific tracker responsible for monitoring this transaction (e.g., 'evm', 'safe', 'gelato', etc.). */\n tracker: T;\n /** The unique key for the transaction within its tracker (e.g., EVM hash, Gelato task ID). */\n txKey: string;\n /** The type or category of the transaction (e.g., 'increment', 'approve'). */\n type: string;\n /** The type of wallet used for the transaction. */\n walletType: string;\n};\n\n/**\n * Represents an EVM-specific transaction, extending the base properties.\n * @template T The type of the tracker identifier.\n */\nexport type EvmTransaction<T> = BaseTransaction<T> & {\n /** The transaction adapter type. */\n adapter: TransactionAdapter.EVM;\n /** The on-chain transaction hash, available after submission. */\n hash?: string;\n /** The data payload for the transaction, typically for contract interactions. */\n input?: string;\n /** The maximum fee per gas for the transaction (EIP-1559). */\n maxFeePerGas?: string;\n /** The maximum priority fee per gas for the transaction (EIP-1559). */\n maxPriorityFeePerGas?: string;\n /** The transaction nonce. */\n nonce?: number;\n /** The hash of a transaction that this one replaced (e.g., for speed-up). */\n replacedTxHash?: string;\n /** The recipient's address. */\n to?: string;\n /** The value (in wei) being sent with the transaction. */\n value?: string;\n};\n\n/**\n * Represents a Solana-specific transaction, extending the base properties.\n * @template T The type of the tracker identifier.\n */\nexport type SolanaTransaction<T> = BaseTransaction<T> & {\n /** The transaction adapter type. */\n adapter: TransactionAdapter.SOLANA;\n /** The transaction fee. */\n fee?: number;\n /** The instructions included in the transaction. */\n instructions?: any[];\n /** The recent blockhash used for the transaction. */\n recentBlockhash?: string;\n /** The slot in which the transaction was processed. */\n slot?: number;\n};\n\n/**\n * Represents a Starknet-specific transaction, extending the base properties.\n * @template T The type of the tracker identifier.\n */\nexport type StarknetTransaction<T> = BaseTransaction<T> & {\n /** The actual fee paid for the transaction. */\n actualFee?: { amount: string; unit: string };\n /** The address of the contract being interacted with. */\n contractAddress?: string;\n /** The transaction adapter type. */\n adapter: TransactionAdapter.Starknet;\n /** The reason for transaction failure, if applicable. */\n revertReason?: string;\n};\n\n/** A union type representing any possible transaction structure. */\nexport type Transaction<T> = EvmTransaction<T> | SolanaTransaction<T> | StarknetTransaction<T>;\n\n/** A registry of functions that can be re-executed via the 'Retry' button. The key should match `actionKey` on a transaction. */\nexport type TxActions = Record<string, (...args: any[]) => Promise<unknown>>;\n\n/**\n * Represents the parameters required to initiate a new transaction.\n */\nexport type InitialTransactionParams = {\n /** The transaction adapter type. */\n adapter: TransactionAdapter;\n /** A key identifying the retry logic from the actions registry. */\n actionKey?: string;\n /** A description for the transaction, with states for [pending, success, error, replaced]. */\n description?: string | [string, string, string, string];\n /** The ID of the desired blockchain network. */\n desiredChainID: number | string;\n /** Any additional data to be associated with the transaction. */\n payload?: object;\n /** A title for the transaction, with states for [pending, success, error, replaced]. */\n title?: string | [string, string, string, string];\n /** The type or category of the transaction (e.g., 'increment', 'approve'). */\n type: string;\n /** If true, the detailed tracking modal will open automatically for this transaction. */\n withTrackedModal?: boolean;\n};\n\n/**\n * Represents a transaction in its initial, pre-submission state within the store.\n * This is used for UI feedback while the transaction is being signed and sent.\n */\nexport type InitialTransaction = InitialTransactionParams & {\n /** An error message if the initialization process fails (e.g., user rejects signature). */\n errorMessage?: string;\n /** True if the transaction is currently being processed (e.g., waiting for user signature). */\n isInitializing: boolean;\n /** The key of the on-chain transaction that this action produced, used for linking. */\n lastTxKey?: string;\n /** The local timestamp when the user initiated the action. */\n localTimestamp: number;\n};\n\n/**\n * Represents the type for a transaction adapter which provides utilities for handling transaction-related operations.\n *\n * @template TR - Represents the transaction tracker type.\n * @template T - Represents the type of the transaction, extending the base Transaction<TR>.\n * @template A - Represents the type for the action transaction key.\n */\nexport type TxAdapter<TR, T extends Transaction<TR>, A> = {\n key: TransactionAdapter;\n getWalletInfo: () => {\n /** Wallet address. */\n walletAddress: string;\n /** Type of the wallet. (injected, wallet connect, etc.) */\n walletType: string;\n };\n checkChainForTx: (chainId: string | number) => Promise<void>;\n checkTransactionsTracker: (actionTxKey: A, walletType: string) => { txKey: string; tracker: TR };\n checkAndInitializeTrackerInStore: ({\n tx,\n ...rest\n }: { tx: T } & Pick<\n ITxTrackingStore<TR, T, A>,\n 'transactionsPool' | 'updateTxParams' | 'onSucceedCallbacks' | 'removeTxFromPool'\n >) => Promise<void>;\n cancelTxAction?: (tx: T) => Promise<string>;\n speedUpTxAction?: (tx: T) => Promise<string>;\n retryTxAction?: ({\n tx,\n actions,\n onClose,\n handleTransaction,\n }: {\n txKey: string;\n tx: InitialTransactionParams;\n actions?: TxActions;\n onClose: (txKey?: string) => void;\n } & Partial<Pick<ITxTrackingStore<TR, T, A>, 'handleTransaction'>>) => Promise<void>;\n explorerLink: (transactionsPool: TransactionPool<TR, T>, txKey: string, replacedTxHash?: string) => string;\n};\n\n/**\n * Interface for the complete transaction tracking store.\n * @template TR The type of the tracker identifier.\n * @template T The transaction type.\n * @template C The configuration object type (e.g., wagmi config).\n * @template A The return type of the action function being wrapped.\n */\nexport type ITxTrackingStore<TR, T extends Transaction<TR>, A> = IInitializeTxTrackingStore<TR, T> & {\n /**\n * A wrapper function that handles the entire lifecycle of a transaction.\n * It creates an `InitialTransaction`, executes the on-chain action, and tracks its status.\n * @param params - The parameters for handling the transaction.\n */\n handleTransaction: (params: {\n /** The async function to execute (e.g., a smart contract write call). */\n actionFunction: () => Promise<A | undefined>;\n /** The metadata for the transaction to be created, of type `InitialTransactionParams`. */\n params: InitialTransactionParams;\n\n defaultTracker?: TR;\n }) => Promise<void>;\n\n /**\n * Initializes all active trackers for pending transactions in the pool.\n * This is useful for resuming tracking after a page reload.\n */\n initializeTransactionsPool: () => Promise<void>;\n};\n","/**\n * @file This file provides a utility for creating a bounded Zustand hook from a vanilla store.\n * This is a recommended pattern for using vanilla stores with React to ensure full type safety.\n *\n * @see https://zustand.docs.pmnd.rs/guides/typescript#bounded-usestore-hook-for-vanilla-stores\n */\n\nimport { StoreApi, useStore } from 'zustand';\n\n/**\n * A utility type to infer the state shape from a Zustand store type.\n * @template S The type of the Zustand store (`StoreApi`).\n */\ntype ExtractState<S> = S extends { getState: () => infer X } ? X : never;\n\n/**\n * Creates a bounded `useStore` hook from a vanilla Zustand store instance.\n * The returned hook is fully typed and can be used with or without a selector.\n *\n * @template S The type of the Zustand store (`StoreApi`).\n * @param {S} store - The vanilla Zustand store instance.\n * @returns {function} A hook that can be called with an optional selector function.\n * - When called with a selector (`useBoundedStore(state => state.someValue)`), it returns the selected slice of the state.\n */\nexport const createBoundedUseStore = ((store) => (selector) => useStore(store, selector)) as <\n S extends StoreApi<unknown>,\n>(\n store: S,\n) => {\n (): ExtractState<S>;\n <T>(selector: (state: ExtractState<S>) => T): T;\n};\n","/**\n * @file This file contains a generic utility for creating a polling mechanism to track asynchronous tasks,\n * such as API-based transaction status checks (e.g., for Gelato or Safe).\n */\n\nimport { Transaction } from '../types';\n\n/**\n * Defines the configuration object for the `initializePollingTracker` function.\n * @template R The expected type of the successful API response from the fetcher.\n * @template T The type of the transaction object being tracked.\n * @template TR The type of the tracker identifier used in the `Transaction` type.\n */\nexport type InitializePollingTracker<R, T, TR> = {\n /** The transaction object to be tracked. It must include `txKey` and an optional `pending` status. */\n tx: T & Pick<Transaction<TR>, 'txKey'> & { pending?: boolean };\n /** The function that performs the actual data fetching (e.g., an API call). */\n fetcher: (params: {\n /** The transaction object being tracked. */\n tx: T;\n /** A callback to stop the polling mechanism, typically called on success or terminal failure. */\n clearWatch: (withoutRemoving?: boolean) => void;\n /** Callback to be invoked when the fetcher determines the transaction has succeeded. */\n onSucceed: (response: R) => void;\n /** Callback to be invoked when the fetcher determines the transaction has failed. */\n onFailed: (response: R) => void;\n /** Optional callback for each successful poll, useful for updating UI with intermediate states. */\n onIntervalTick?: (response: R) => void;\n /** Optional callback for when a transaction is replaced by another. */\n onReplaced?: (response: R) => void;\n }) => Promise<Response>;\n\n /** Optional callback executed once when the tracker is initialized. */\n onInitialize?: () => void;\n /** Callback to be invoked when the transaction has succeeded. */\n onSucceed: (response: R) => void;\n /** Callback to be invoked when the transaction has failed. */\n onFailed: (response: R) => void;\n /** Optional callback for each successful poll. */\n onIntervalTick?: (response: R) => void;\n /** Optional callback for when a transaction is replaced. */\n onReplaced?: (response: R) => void;\n /** Optional function to remove the transaction from the main pool, typically after polling stops. */\n removeTxFromPool?: (taskId: string) => void;\n /** The interval (in milliseconds) between polling attempts. Defaults to 5000ms. */\n pollingInterval?: number;\n /** The number of consecutive failed fetches before stopping the tracker. Defaults to 10. */\n retryCount?: number;\n};\n\n/**\n * Initializes a generic polling tracker that repeatedly calls a fetcher function\n * to monitor the status of a transaction or any asynchronous task.\n *\n * @template R The expected type of the successful API response.\n * @template T The type of the transaction object.\n * @template TR The type of the tracker identifier.\n * @param {InitializePollingTracker<R, T, TR>} params - The configuration object for the tracker.\n * @returns {Promise<void>} A promise that resolves when the tracker is set up (note: polling happens asynchronously).\n */\nexport async function initializePollingTracker<R, T, TR>({\n onInitialize,\n tx,\n removeTxFromPool,\n fetcher,\n onFailed,\n onIntervalTick,\n onSucceed,\n pollingInterval,\n retryCount,\n onReplaced,\n}: InitializePollingTracker<R, T, TR>): Promise<void> {\n if (onInitialize) {\n onInitialize();\n }\n\n // Early exit if the transaction is not pending\n if (!tx?.pending) {\n return;\n }\n\n let pollingIntervalId: number | undefined;\n\n /**\n * Stops the polling interval and optionally removes the transaction from the pool.\n * @param {boolean} [withoutRemoving=false] - If true, the transaction will not be removed from the pool.\n */\n const clearWatch = (withoutRemoving?: boolean) => {\n clearInterval(pollingIntervalId);\n if (removeTxFromPool && !withoutRemoving) {\n removeTxFromPool(tx.txKey);\n }\n };\n\n let retriesLeft = retryCount ?? 10;\n\n pollingIntervalId = window.setInterval(async () => {\n if (retriesLeft <= 0) {\n clearWatch();\n return;\n }\n\n try {\n const response = await fetcher({\n tx,\n onSucceed,\n onFailed,\n onIntervalTick,\n onReplaced,\n clearWatch,\n });\n\n // If the API call fails (e.g., 404 Not Found), decrement the retry counter.\n // The fetcher itself is responsible for calling `clearWatch` on terminal statuses.\n if (!response.ok) {\n retriesLeft--;\n }\n } catch (error) {\n console.error('Polling fetcher function threw an error:', error);\n retriesLeft--;\n }\n }, pollingInterval ?? 5000);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/pulsar-core",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.3.815bc21.acc55b8",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",