@t402/react 2.3.0 → 2.3.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 +167 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # @t402/react
2
+
3
+ React components and hooks for the t402 Payment Protocol. Build payment-aware UIs with pre-built components and reactive hooks.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @t402/react
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```tsx
14
+ import { PaymentProvider, PaymentButton, usePaymentRequired } from "@t402/react";
15
+
16
+ function App() {
17
+ return (
18
+ <PaymentProvider>
19
+ <ProtectedContent />
20
+ </PaymentProvider>
21
+ );
22
+ }
23
+
24
+ function ProtectedContent() {
25
+ const { paymentRequired, requirements, pay, status } = usePaymentRequired("/api/data");
26
+
27
+ if (paymentRequired) {
28
+ return <PaymentButton requirements={requirements} onPay={pay} status={status} />;
29
+ }
30
+
31
+ return <div>Premium content loaded!</div>;
32
+ }
33
+ ```
34
+
35
+ ## Components
36
+
37
+ ### PaymentButton
38
+
39
+ Renders a payment action button with loading and status states.
40
+
41
+ ```tsx
42
+ import { PaymentButton } from "@t402/react";
43
+
44
+ <PaymentButton
45
+ requirements={requirements}
46
+ onPay={handlePay}
47
+ status={status}
48
+ />
49
+ ```
50
+
51
+ ### PaymentDetails
52
+
53
+ Displays payment requirements (amount, network, recipient).
54
+
55
+ ```tsx
56
+ import { PaymentDetails } from "@t402/react";
57
+
58
+ <PaymentDetails requirements={requirements} />
59
+ ```
60
+
61
+ ### PaymentStatusDisplay
62
+
63
+ Shows the current payment status with appropriate UI feedback.
64
+
65
+ ```tsx
66
+ import { PaymentStatusDisplay } from "@t402/react";
67
+
68
+ <PaymentStatusDisplay status={status} />
69
+ ```
70
+
71
+ ### AddressDisplay
72
+
73
+ Renders a blockchain address with truncation and copy functionality.
74
+
75
+ ```tsx
76
+ import { AddressDisplay } from "@t402/react";
77
+
78
+ <AddressDisplay address="0x1234...5678" />
79
+ ```
80
+
81
+ ## Hooks
82
+
83
+ ### usePaymentRequired
84
+
85
+ Detects 402 responses and extracts payment requirements.
86
+
87
+ ```tsx
88
+ const {
89
+ paymentRequired, // boolean - whether payment is needed
90
+ requirements, // PaymentRequirements[] from 402 response
91
+ pay, // () => Promise<void> - trigger payment
92
+ status, // PaymentStatus - current state
93
+ } = usePaymentRequired(url, options);
94
+ ```
95
+
96
+ ### usePaymentStatus
97
+
98
+ Tracks the lifecycle of a payment (idle, pending, confirming, complete, error).
99
+
100
+ ```tsx
101
+ const { status, error, reset } = usePaymentStatus();
102
+ ```
103
+
104
+ ### useAsyncPayment
105
+
106
+ Manages async payment flows with automatic retry and status tracking.
107
+
108
+ ```tsx
109
+ const { execute, status, error } = useAsyncPayment(paymentFn);
110
+ ```
111
+
112
+ ## Provider
113
+
114
+ ### PaymentProvider
115
+
116
+ Wraps your app to provide payment context to all child components.
117
+
118
+ ```tsx
119
+ import { PaymentProvider } from "@t402/react";
120
+
121
+ <PaymentProvider>
122
+ <App />
123
+ </PaymentProvider>
124
+ ```
125
+
126
+ Access context directly with `usePaymentContext()`.
127
+
128
+ ## Utilities
129
+
130
+ ```typescript
131
+ import {
132
+ isEvmNetwork,
133
+ isSvmNetwork,
134
+ isTonNetwork,
135
+ getNetworkDisplayName,
136
+ truncateAddress,
137
+ formatTokenAmount,
138
+ choosePaymentRequirement,
139
+ } from "@t402/react";
140
+
141
+ // Network detection
142
+ isEvmNetwork("eip155:8453"); // true
143
+
144
+ // Display helpers
145
+ getNetworkDisplayName("eip155:8453"); // "Base"
146
+ truncateAddress("0x1234567890abcdef"); // "0x1234...cdef"
147
+ formatTokenAmount(1500000n, 6); // "1.50"
148
+ ```
149
+
150
+ ## Peer Dependencies
151
+
152
+ - `react` ^18.0.0 || ^19.0.0
153
+ - `react-dom` ^18.0.0 || ^19.0.0
154
+
155
+ ## Development
156
+
157
+ ```bash
158
+ pnpm build # Build the package
159
+ pnpm test # Run unit tests
160
+ ```
161
+
162
+ ## Related Packages
163
+
164
+ - `@t402/core` - Core protocol types
165
+ - `@t402/vue` - Vue components & composables
166
+ - `@t402/paywall` - Universal paywall UI
167
+ - `@t402/fetch` - Fetch wrapper with automatic payment
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t402/react",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "module": "./dist/esm/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -43,7 +43,7 @@
43
43
  "vitest": "^3.2.4"
44
44
  },
45
45
  "dependencies": {
46
- "@t402/core": "2.3.0"
46
+ "@t402/core": "2.3.1"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "react": "^18.0.0 || ^19.0.0",