@tuwaio/pulsar-core 0.0.4 β 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -34
- package/dist/index.d.mts +244 -153
- package/dist/index.d.ts +244 -153
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -6,76 +6,116 @@
|
|
|
6
6
|
|
|
7
7
|
The core, framework-agnostic engine for real-time tracking of Web3 transaction lifecycles (pending, success, failed, replaced).
|
|
8
8
|
|
|
9
|
+
---
|
|
10
|
+
|
|
9
11
|
## ποΈ What is `@tuwaio/pulsar-core`?
|
|
10
12
|
|
|
11
|
-
`@tuwaio/pulsar-core` is the central nervous system of the Pulsar
|
|
13
|
+
`@tuwaio/pulsar-core` is the central nervous system of the Pulsar ecosystem. It is a **headless** and **framework-agnostic** library, meaning it contains no UI components or framework-specific code (like React hooks).
|
|
14
|
+
|
|
15
|
+
Its sole purpose is to provide a powerful state machine for managing multi-chain transactions, built on top of **Zustand** (for state management) and **Immer** (for immutable updates). Think of it as a pre-configured, extensible "brain" that you can integrate into any JavaScript or TypeScript application to handle complex transaction tracking logic with ease.
|
|
16
|
+
|
|
17
|
+
This package exports one primary factory function: `createPulsarStore`.
|
|
18
|
+
|
|
19
|
+
---
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
## β¨ Key Features
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
- **Framework-Agnostic:** Use it with React, Vue, Svelte, or even in a Node.js environment.
|
|
24
|
+
- **Multi-Chain by Design:** Built to handle different blockchain architectures via a powerful adapter system.
|
|
25
|
+
- **Persistent State:** Automatically saves transaction state to `localStorage`, allowing tracking to resume after a page refresh.
|
|
26
|
+
- **Extensible:** Customize its behavior with adapters, callbacks, and custom trackers.
|
|
27
|
+
- **Type-Safe:** Written entirely in TypeScript for a robust developer experience.
|
|
28
|
+
|
|
29
|
+
---
|
|
16
30
|
|
|
17
31
|
## πΎ Installation
|
|
18
32
|
|
|
19
|
-
This package
|
|
33
|
+
This package requires `zustand` and `immer` as peer dependencies. You must install them alongside `@tuwaio/pulsar-core`.
|
|
20
34
|
|
|
21
35
|
```bash
|
|
36
|
+
# Using pnpm
|
|
22
37
|
pnpm add @tuwaio/pulsar-core zustand immer
|
|
38
|
+
|
|
39
|
+
# Using npm
|
|
40
|
+
npm install @tuwaio/pulsar-core zustand immer
|
|
41
|
+
|
|
42
|
+
# Using yarn
|
|
43
|
+
yarn add @tuwaio/pulsar-core zustand immer
|
|
23
44
|
```
|
|
24
45
|
|
|
46
|
+
---
|
|
47
|
+
|
|
25
48
|
## π API & Usage
|
|
26
49
|
|
|
27
50
|
### `createPulsarStore(config)`
|
|
28
51
|
|
|
29
|
-
This is the main factory function that creates your transaction store. It takes a configuration object and returns a ready-to-use Zustand store.
|
|
52
|
+
This is the main factory function that creates your transaction store. It takes a configuration object and returns a fully typed, ready-to-use vanilla Zustand store.
|
|
30
53
|
|
|
31
|
-
#### Configuration
|
|
54
|
+
#### **Configuration Example**
|
|
32
55
|
|
|
33
56
|
```ts
|
|
34
57
|
import { createPulsarStore } from '@tuwaio/pulsar-core';
|
|
35
|
-
|
|
58
|
+
// Example adapter for EVM chains
|
|
59
|
+
import { evmAdapter } from '@tuwaio/pulsar-evm';
|
|
60
|
+
import { wagmiConfig, chains } from './path/to/your/wagmi/config';
|
|
36
61
|
|
|
37
62
|
const pulsarStore = createPulsarStore({
|
|
38
|
-
//
|
|
39
|
-
name: 'pulsar-storage',
|
|
40
|
-
|
|
63
|
+
// A unique name for Zustand's persistence middleware. This will be the key in localStorage.
|
|
64
|
+
name: 'my-app-pulsar-storage',
|
|
65
|
+
|
|
66
|
+
// An array of adapters for different blockchain ecosystems.
|
|
67
|
+
// Each adapter provides chain-specific logic.
|
|
41
68
|
adapters: [
|
|
42
|
-
evmAdapter(
|
|
69
|
+
evmAdapter(wagmiConfig, chains),
|
|
70
|
+
// ... add other adapters like solanaAdapter here
|
|
43
71
|
],
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
|
|
73
|
+
// (Optional) A callback function to execute on every successful transaction.
|
|
74
|
+
// Ideal for global logic like showing a success notification.
|
|
75
|
+
onSucceedCallbacks: (tx) => {
|
|
76
|
+
console.log('Transaction succeeded!', tx);
|
|
77
|
+
// e.g., showToast('Success!', { type: 'success' });
|
|
48
78
|
},
|
|
49
79
|
});
|
|
80
|
+
|
|
81
|
+
export default pulsarStore;
|
|
50
82
|
```
|
|
51
83
|
|
|
52
|
-
### The Returned Store
|
|
84
|
+
### The Returned Store API
|
|
85
|
+
|
|
86
|
+
The `createPulsarStore` function returns a vanilla Zustand store with the following state and actions:
|
|
87
|
+
|
|
88
|
+
#### **State**
|
|
89
|
+
|
|
90
|
+
- `transactionsPool: Record<string, T>`: The primary state object. This is a map of all tracked transactions, where the key is the transaction's unique `txKey` (e.g., a transaction hash).
|
|
91
|
+
- `initialTx?: InitialTransaction`: Holds the state of a transaction that is currently being initiated (e.g., waiting for a user's signature) but is not yet submitted to the network. Useful for providing instant UI feedback.
|
|
92
|
+
- `lastAddedTxKey?: string`: The `txKey` of the most recently added transaction.
|
|
93
|
+
|
|
94
|
+
#### **Actions**
|
|
95
|
+
|
|
96
|
+
- `handleTransaction(params)`: The primary, all-in-one function for initiating, sending, and tracking a new transaction. This is the main action you will use.
|
|
97
|
+
- `initializeTransactionsPool()`: An async function to re-initialize trackers for any pending transactions found in storage. **This is crucial for resuming tracking after a page reload.**
|
|
98
|
+
- `addTxToPool(tx)`: Adds a new transaction directly to the tracking pool.
|
|
99
|
+
- `updateTxParams(txKey, fields)`: Updates one or more properties of an existing transaction in the pool.
|
|
100
|
+
- `removeTxFromPool(txKey)`: Removes a transaction from the pool by its key.
|
|
101
|
+
- `closeTxTrackedModal(txKey?)`: A helper to manage UI state, which sets `isTrackedModalOpen` to `false` and clears the `initialTx` state.
|
|
53
102
|
|
|
54
|
-
|
|
103
|
+
---
|
|
55
104
|
|
|
56
|
-
|
|
57
|
-
- `transactionsPool: Record<string, T>`: The primary state object. A map of all tracked transactions, where the key is the transaction's unique `txKey`.
|
|
58
|
-
- `initialTx?: InitialTransaction`: Holds the state of a transaction that is currently being initiated (e.g., waiting for a user's signature) but is not yet on-chain.
|
|
59
|
-
- `lastAddedTxKey?: string`: The `txKey` of the most recently added transaction, useful for quick access.
|
|
105
|
+
## β¨ How It Connects to the Ecosystem
|
|
60
106
|
|
|
61
|
-
|
|
62
|
-
- `handleTransaction(params)`: The primary, all-in-one function for initiating, sending, and tracking a new transaction.
|
|
63
|
-
- `initializeTransactionsPool()`: An async function to re-initialize trackers for any pending transactions stored from a previous session. Crucial for resuming tracking after a page reload.
|
|
64
|
-
- `addTxToPool({ tx })`: Adds a new transaction directly to the tracking pool.
|
|
65
|
-
- `updateTxParams(fields)`: Updates one or more properties of an existing transaction in the pool.
|
|
66
|
-
- `removeTxFromPool(txKey)`: Removes a transaction from the pool by its key.
|
|
67
|
-
- `closeTxTrackedModal(txKey?)`: Closes the tracking modal for a specific transaction and clears the `initialTx` state.
|
|
107
|
+
Pulsar is a modular ecosystem. Hereβs how the pieces fit together:
|
|
68
108
|
|
|
69
|
-
|
|
109
|
+
- **`@tuwaio/pulsar-core` (this package):** Provides the generic, headless state machine (`createPulsarStore`). It knows _how_ to manage state but doesn't know anything about specific blockchains.
|
|
110
|
+
- **`@tuwaio/pulsar-evm`**: An adapter that plugs into the `adapters` config. It teaches the core store how to interact with EVM chains (e.g., how to check transaction receipts, get wallet info from Wagmi, etc.).
|
|
111
|
+
- **`@tuwaio/pulsar-react`**: Provides React bindings and hooks (like `useInitializeTransactionsPool`) to easily connect the Pulsar store to your React application's lifecycle.
|
|
70
112
|
|
|
71
|
-
|
|
72
|
-
- **`@tuwaio/pulsar-evm`**: An adapter that plugs into the `adapters` config to provide EVM-specific logic.
|
|
73
|
-
- **`@tuwaio/pulsar-react`**: Provides React bindings (`useInitializeTransactionsPool`) to easily reactivate tracking transactions after page reload.
|
|
113
|
+
---
|
|
74
114
|
|
|
75
115
|
## π€ Contributing
|
|
76
116
|
|
|
77
|
-
Contributions are welcome
|
|
117
|
+
Contributions are welcome\! Please read our main **[Contribution Guidelines](https://github.com/TuwaIO/workflows/blob/main/CONTRIBUTING.md)** for details on our code of conduct and the process for submitting pull requests.
|
|
78
118
|
|
|
79
119
|
## π License
|
|
80
120
|
|
|
81
|
-
This project is licensed under the **Apache-2.0 License
|
|
121
|
+
This project is licensed under the **Apache-2.0 License** - see the [LICENSE](./LICENSE) file for details.
|