@tuwaio/pulsar-core 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +43 -9
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -33,14 +33,8 @@ This package exports one primary factory function: `createPulsarStore`.
33
33
  This package requires `zustand`, `immer` and `dayjs` as peer dependencies. You must install them alongside `@tuwaio/pulsar-core`.
34
34
 
35
35
  ```bash
36
- # Using pnpm
36
+ # Using pnpm (recommended), but you can use npm, yarn or bun as well
37
37
  pnpm add @tuwaio/pulsar-core @tuwaio/orbit-core zustand immer dayjs
38
-
39
- # Using npm
40
- npm install @tuwaio/pulsar-core @tuwaio/orbit-core zustand immer dayjs
41
-
42
- # Using yarn
43
- yarn add @tuwaio/pulsar-core @tuwaio/orbit-core zustand immer dayjs
44
38
  ```
45
39
 
46
40
  ---
@@ -55,7 +49,7 @@ This is the main factory function that creates your transaction store. It takes
55
49
 
56
50
  ```ts
57
51
  import { createBoundedUseStore, createPulsarStore, Transaction } from '@tuwaio/pulsar-core';
58
- import { evmAdapter } from '@tuwaio/pulsar-evm';
52
+ import { pulsarEvmAdapter } from '@tuwaio/pulsar-evm';
59
53
 
60
54
  import { appChains, config } from '@/configs/wagmiConfig';
61
55
 
@@ -77,11 +71,19 @@ export type TransactionUnion = ExampleTx;
77
71
  export const usePulsarStore = createBoundedUseStore(
78
72
  createPulsarStore<TransactionUnion>({
79
73
  name: storageName,
80
- adapter: evmAdapter(config, appChains),
74
+ adapter: pulsarEvmAdapter(config, appChains),
75
+ maxTransactions: 100, // Optional: defaults to 50
81
76
  }),
82
77
  );
83
78
  ```
84
79
 
80
+ ### Transaction Pool Management (FIFO)
81
+
82
+ To prevent the `localStorage` from growing indefinitely, Pulsar Core implements a **FIFO (First-In, First-Out) Eviction Policy**.
83
+
84
+ - **Maximum Transactions:** By default, the store keeps the last **50** transactions. You can customize this via the `maxTransactions` property in the `createPulsarStore` config.
85
+ - **Eviction Process:** When the pool exceeds the `maxTransactions` limit, the oldest transaction (based on `localTimestamp`) is automatically removed from the state and storage when a new one is added.
86
+
85
87
  ### The Returned Store API
86
88
 
87
89
  The `createPulsarStore` function returns a vanilla Zustand store with the following state and actions:
@@ -100,6 +102,38 @@ The `createPulsarStore` function returns a vanilla Zustand store with the follow
100
102
  - `updateTxParams(txKey, fields)`: Updates one or more properties of an existing transaction in the pool.
101
103
  - `removeTxFromPool(txKey)`: Removes a transaction from the pool by its key.
102
104
  - `closeTxTrackedModal(txKey?)`: A helper to manage UI state, which sets `isTrackedModalOpen` to `false` and clears the `initialTx` state.
105
+ - `getLastTxKey()`: Returns the `txKey` of the most recently added transaction.
106
+
107
+ #### **Selectors**
108
+
109
+ The package also provides a set of selector functions to help you efficiently query the transaction pool:
110
+
111
+ - `selectAllTransactions(pool)`: Returns all transactions sorted chronologically.
112
+ - `selectPendingTransactions(pool)`: Returns only transactions that are currently pending.
113
+ - `selectTxByKey(pool, txKey)`: Retrieves a specific transaction by its key.
114
+ - `selectAllTransactionsByActiveWallet(pool, address)`: Returns all transactions for a specific wallet.
115
+ - `selectPendingTransactionsByActiveWallet(pool, address)`: Returns pending transactions for a specific wallet.
116
+
117
+ ---
118
+
119
+ ## 🛠️ Advanced Usage: `initializePollingTracker`
120
+
121
+ For custom tracking requirements (like server-side tracking or non-standard APIs), you can use the low-level `initializePollingTracker` utility. This is the same engine used internally by Pulsar adapters for Gelato, Safe, and Solana.
122
+
123
+ ```ts
124
+ import { initializePollingTracker } from '@tuwaio/pulsar-core';
125
+
126
+ await initializePollingTracker({
127
+ tx: myTransaction,
128
+ fetcher: async ({ stopPolling, onSuccess, onFailure }) => {
129
+ const status = await checkMyCustomApi(myTransaction.txKey);
130
+ if (status === 'done') onSuccess(status);
131
+ if (status === 'error') onFailure(status);
132
+ },
133
+ onSuccess: (status) => console.log('Success!', status),
134
+ onFailure: (status) => console.error('Failed!', status),
135
+ });
136
+ ```
103
137
 
104
138
  ---
105
139
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/pulsar-core",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -46,7 +46,7 @@
46
46
  "zustand": "5.x.x"
47
47
  },
48
48
  "devDependencies": {
49
- "@tuwaio/orbit-core": "^0.2.4",
49
+ "@tuwaio/orbit-core": "^0.2.5",
50
50
  "dayjs": "^1.11.19",
51
51
  "immer": "^11.1.3",
52
52
  "tsup": "^8.5.1",