@tuwaio/nova-transactions 0.5.3 → 0.7.0

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 CHANGED
@@ -1,165 +1,105 @@
1
1
  # @tuwaio/nova-transactions
2
2
 
3
3
  [![NPM Version](https://img.shields.io/npm/v/@tuwaio/nova-transactions.svg)](https://www.npmjs.com/package/@tuwaio/nova-transactions)
4
- [![License](https://img.shields.io/npm/l/@tuwaio/nova-transactions.svg)](./LICENSE)
4
+ [![License](https://img.shields.io/npm/l/@tuwaio/nova-transactions.svg)](https://github.com/TuwaIO/nova-uikit/blob/main/packages/nova-transactions/LICENSE)
5
5
 
6
- `@tuwaio/nova-transactions` is the **UI Components (L7)** package of the TUWA Ecosystem transaction lifecycle tracking system. It provides the visual layer to monitor, display, and manage active on-chain transactions, consuming state directly from the headless **[Pulsar Engine](https://github.com/TuwaIO/pulsar-core)** state machine.
7
-
8
- By coupling the UI manager to Pulsar stores, it automatically handles pending loaders, speed-up options, failure overlays, and success notifications, keeping the user in the loop even during congested block space periods.
6
+ `@tuwaio/nova-transactions` is the transactions Layer 7 (L7) package of **Nova UI Kit**, the user interface project of TUWA Stage 4 ("User Interface"). Built on **`react`**, **`react-toastify`**, **`framer-motion`** and [`@tuwaio/nova-core`](https://stories.tuwa.io/?path=/docs/packages-nova-core-overview--docs), it renders the transactions of a [Pulsar](https://pulsar.docs.tuwa.io) store: progress toasts, a tracking modal and the transaction history. It keeps no transaction state of its own: the state, the trackers and the wallet actions stay in `@tuwaio/pulsar-core`.
9
7
 
10
8
  ---
11
9
 
12
10
  ## 🏛️ Core Capabilities
13
11
 
14
- - **🧩 Interactive Visual Nodes:** Built-in dialogs and widget cards (`TrackingTxModal` for individual status, `TransactionsInfoModal` for full transaction lists, and `ToastTransaction` feeds).
15
- - **🔌 Isolated Provider Hooks:** The `<NovaTransactionsProvider />` bridges your React tree with Pulsar's transaction history pools and signature polling events.
16
- - **🎨 Custom Styling overrides:** Style sub-components via CSS variables from `@tuwaio/nova-core` or replace components using the `customization` property.
17
- - **🌍 Dynamic Internationalization:** Supports overriding labels configuration to localize status messages (`pending`, `success`, `failed`, `replaced`) and actions.
12
+ - **Provider:** `NovaTransactionsProvider` (`/providers`) takes the Pulsar store values (`transactionsPool`, `initialTx`, `executeTxAction`, `closeTxTrackedModal`) and the Pulsar adapters, and renders, each behind a feature flag that is on by default: a toast for every tracked transaction, a tracking modal for the latest one, the transaction history modal, and an error toast when `executeTxAction` fails before the transaction reaches the pool.
13
+ - **Transaction actions:** the toasts and the tracking modal offer speed-up and cancel for a pending, unconfirmed EVM transaction (`ethereum` tracker) sent with MetaMask, when the adapter has `speedUpTxAction` and `cancelTxAction` (the toast also requires the connected wallet to be the sender); the tracking modal offers retry through the adapter's `retryTxAction` while the `initialTx` of the failed submission is in the store. Explorer links come from the adapter's `getExplorerTxUrl` and `getExplorerUrl`; a link is hidden when the adapter returns no URL.
14
+ - **Components:** `ToastTransaction`, `TrackingTxModal` (with `TxStatusVisual`, `TxProgressIndicator`, `TxInfoBlock`, `TxErrorBlock`), `TransactionsInfoModal`, `TransactionsHistory`, `TransactionHistoryItem`, `TransactionDetails`, `TransactionKey`, `HashLink`, `TransactionStatusBadge`, `StatusAwareText` and `TxActionButton` can also be rendered on their own. Many of them take a `customization` prop with class name functions and replacement components for their parts.
15
+ - **Labels:** `defaultLabels` (English) are merged with the `labels` prop of the provider; `NovaTransactionsLabelsProvider` and `useLabels` give the labels to custom components.
18
16
 
19
17
  ---
20
18
 
21
19
  ## 💾 Installation
22
20
 
23
- ```bash
24
- pnpm add @tuwaio/nova-transactions @tuwaio/nova-core @tuwaio/pulsar-core @tuwaio/pulsar-react
25
- ```
21
+ The package has two entry points:
26
22
 
27
- ### Peer Dependencies Check
23
+ | Import path | Provides |
24
+ | ------------------------------------- | ------------------------------------------------------------------------------- |
25
+ | `@tuwaio/nova-transactions` | The components, `defaultLabels` and the label types |
26
+ | `@tuwaio/nova-transactions/providers` | `NovaTransactionsProvider`, `NovaTransactionsLabelsProvider`, the error context |
28
27
 
29
- Make sure your project contains the required layout and utility engines:
28
+ Importing the package adds the `relativeTime` plugin to `dayjs`. Both entry points need the same peer dependencies: `@tuwaio/nova-core`, `@tuwaio/pulsar-core` (>=0.7), `@tuwaio/orbit-core` (>=0.3), `react` (>=19.2.3), `react-toastify` (>=11), `framer-motion`, `@heroicons/react` (2.x) and `dayjs` (1.x), plus the peer dependencies of `@tuwaio/nova-core`:
30
29
 
31
30
  ```bash
32
- # State & Utilities
33
- pnpm add zustand immer dayjs clsx tailwind-merge framer-motion
31
+ pnpm add @tuwaio/nova-transactions @tuwaio/nova-core @tuwaio/pulsar-core @tuwaio/orbit-core react react-toastify framer-motion @heroicons/react dayjs @radix-ui/react-dialog @web3icons/react @web3icons/common clsx tailwind-merge
32
+ ```
33
+
34
+ Import the stylesheets of `@tuwaio/nova-core` (theme variables) and of this package (the component styles, Tailwind CSS v4 utilities prefixed with `novatx:`):
34
35
 
35
- # Dialog Primitives & Notifications
36
- pnpm add @radix-ui/react-dialog @heroicons/react @web3icons/common @web3icons/react react-toastify
36
+ ```css
37
+ @import '@tuwaio/nova-core/dist/index.css';
38
+ @import '@tuwaio/nova-transactions/dist/index.css';
37
39
  ```
38
40
 
39
41
  ---
40
42
 
41
- ## 🚀 Quick Start Setup
42
-
43
- ### 1. Create the Transaction Store (Pulsar)
43
+ ## 🚀 Usage
44
44
 
45
- Initialize the local-first persistent transaction store with chain-specific state adapters:
45
+ Render the provider once, next to your app, with the values of your Pulsar store:
46
46
 
47
47
  ```tsx
48
- // src/hooks/usePulsarStore.ts
49
48
  'use client';
50
49
 
51
- import { createBoundedUseStore, createPulsarStore, Transaction } from '@tuwaio/pulsar-core';
50
+ import { NovaTransactionsProvider } from '@tuwaio/nova-transactions/providers';
51
+ import { OrbitAdapter } from '@tuwaio/orbit-core';
52
+ import { createBoundedUseStore, createPulsarStore, type Transaction } from '@tuwaio/pulsar-core';
52
53
  import { pulsarEvmAdapter } from '@tuwaio/pulsar-evm';
53
- import { pulsarSolanaAdapter } from '@tuwaio/pulsar-solana';
54
- import { wagmiConfig, appEVMChains, solanaRPCUrls } from '@/config/appConfig';
55
-
56
- const storageName = 'transactions-tracking-storage';
57
-
58
- export enum TxType {
59
- swap = 'swap',
60
- }
61
-
62
- type SwapTx = Transaction & {
63
- type: TxType.swap;
64
- payload: { from: string; to: string; amount: string };
65
- };
54
+ import { useInitializeTransactionsPool } from '@tuwaio/pulsar-react';
55
+ import { createConfig, http, injected } from '@wagmi/core';
56
+ import { mainnet } from 'viem/chains';
66
57
 
67
- export type TransactionUnion = SwapTx;
58
+ const appChains = [mainnet] as const;
59
+ const wagmiConfig = createConfig({ chains: appChains, connectors: [injected()], transports: { [mainnet.id]: http() } });
68
60
 
69
61
  export const usePulsarStore = createBoundedUseStore(
70
- createPulsarStore<TransactionUnion>({
71
- name: storageName,
72
- adapter: [pulsarEvmAdapter(wagmiConfig, appEVMChains), pulsarSolanaAdapter({ rpcUrls: solanaRPCUrls })],
73
- maxTransactions: 50, // prevent localStorage bloat
74
- }),
62
+ createPulsarStore<Transaction>({ name: 'pulsar-transactions', adapter: pulsarEvmAdapter(wagmiConfig, appChains) }),
75
63
  );
76
- ```
77
-
78
- ### 2. Setup the Transactions UI Provider
79
-
80
- Create a bridge component connecting your Pulsar store parameters and Satellite wallet state with the Nova Transactions UI:
81
-
82
- ```tsx
83
- // src/providers/NovaTransactionsWrapper.tsx
84
- 'use client';
85
-
86
- import { useSatelliteConnectStore } from '@tuwaio/nova-connect/satellite';
87
- import { NovaTransactionsProvider as NTP } from '@tuwaio/nova-transactions/providers';
88
- import { getAdapterFromConnectorType } from '@tuwaio/orbit-core';
89
- import { useInitializeTransactionsPool } from '@tuwaio/pulsar-react';
90
-
91
- import { usePulsarStore } from '@/hooks/usePulsarStore';
92
64
 
93
- export function NovaTransactionsWrapper() {
94
- const getAdapter = usePulsarStore((state) => state.getAdapter);
95
- const initialTx = usePulsarStore((state) => state.initialTx);
96
- const closeTxTrackedModal = usePulsarStore((state) => state.closeTxTrackedModal);
65
+ export function TransactionsUI({ walletAddress }: { walletAddress?: string }) {
97
66
  const transactionsPool = usePulsarStore((state) => state.transactionsPool);
67
+ const initialTx = usePulsarStore((state) => state.initialTx);
98
68
  const executeTxAction = usePulsarStore((state) => state.executeTxAction);
69
+ const closeTxTrackedModal = usePulsarStore((state) => state.closeTxTrackedModal);
99
70
  const initializeTransactionsPool = usePulsarStore((state) => state.initializeTransactionsPool);
71
+ const getAdapter = usePulsarStore((state) => state.getAdapter);
100
72
 
101
- const activeConnection = useSatelliteConnectStore((state) => state.activeConnection);
102
-
103
- // Resume tracking for active pending signatures on mount
104
73
  useInitializeTransactionsPool({ initializeTransactionsPool });
105
74
 
106
75
  return (
107
- <NTP
76
+ <NovaTransactionsProvider
77
+ adapter={getAdapter()}
108
78
  transactionsPool={transactionsPool}
109
79
  initialTx={initialTx}
110
- closeTxTrackedModal={closeTxTrackedModal}
111
80
  executeTxAction={executeTxAction}
112
- connectedWalletAddress={activeConnection?.isConnected ? activeConnection.address : undefined}
113
- connectedAdapterType={getAdapterFromConnectorType(activeConnection?.connectorType ?? 'evm:')}
114
- adapter={getAdapter()}
81
+ closeTxTrackedModal={closeTxTrackedModal}
82
+ connectedWalletAddress={walletAddress}
83
+ connectedAdapterType={OrbitAdapter.EVM}
115
84
  />
116
85
  );
117
86
  }
118
87
  ```
119
88
 
120
- ### 3. Usage in Action Buttons
89
+ Start transactions with the store's `executeTxAction`. A full app with Satellite Connect, Nova Connect, SIWX and a Pulsar store synced with a server is in the **[TUWA SDK documentation](https://sdk.docs.tuwa.io/full-stack)**, and every component can be tried in the Storybook sections **Nova Transactions** of [stories.tuwa.io](https://stories.tuwa.io/).
121
90
 
122
- Call the action wrapper to trigger on-chain operations and auto-render status modals:
91
+ ---
123
92
 
124
- ```tsx
125
- import { usePulsarStore, TxType } from '@/hooks/usePulsarStore';
126
- import { OrbitAdapter } from '@tuwaio/orbit-core';
127
- import { mainnet } from 'viem/chains';
93
+ ## 🌐 External Services
128
94
 
129
- export function SwapButton() {
130
- const executeTxAction = usePulsarStore((state) => state.executeTxAction);
95
+ The package sends no network requests. Explorer links are built by the Pulsar adapters and opened by the browser only when clicked; the RPC requests of the trackers are made by Pulsar. The package does not use `localStorage` (the Pulsar store persists the transactions).
131
96
 
132
- const triggerSwap = async () => {
133
- const swapFunction = async () => {
134
- // Execute smart contract write method and return the hash
135
- return '0x...';
136
- };
137
-
138
- await executeTxAction({
139
- actionFunction: swapFunction,
140
- onSuccess: (tx) => console.log('Transaction succeeded!', tx.hash),
141
- params: {
142
- type: TxType.swap,
143
- adapter: OrbitAdapter.EVM,
144
- desiredChainID: mainnet.id,
145
- title: 'Swap ETH',
146
- description: 'Swapping 1 ETH for USDC',
147
- payload: { from: 'ETH', to: 'USDC', amount: '1' },
148
- withTrackedModal: true, // opens tracking overlay automatically
149
- },
150
- });
151
- };
97
+ ---
152
98
 
153
- return (
154
- <button onClick={triggerSwap} className="btn-primary">
155
- Execute Swap
156
- </button>
157
- );
158
- }
159
- ```
99
+ ## 📚 API Reference
160
100
 
161
- ---
101
+ Every export, with signatures and types generated from the source, is documented at **[stories.tuwa.io → Packages → nova-transactions](https://stories.tuwa.io/?path=/docs/packages-nova-transactions-overview--docs)**.
162
102
 
163
103
  ## 📄 License
164
104
 
165
- Licensed under the **Apache-2.0 License**. See the [LICENSE](./LICENSE) file for details.
105
+ Licensed under the **Apache-2.0 License**. See the [LICENSE](https://github.com/TuwaIO/nova-uikit/blob/main/packages/nova-transactions/LICENSE) file for details.