@volr/react-ui 0.1.92 → 0.1.94

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,6 +1,6 @@
1
1
  # @volr/react-ui
2
2
 
3
- Pre-built UI components for Volr, built on top of `@volr/react` and `@volr/sdk-core`, with minimal, modern design.
3
+ Pre-built UI components for Volr Payment Gateway, built on top of `@volr/react` and `@volr/sdk-core`, with minimal, modern design.
4
4
 
5
5
  ## Installation
6
6
 
@@ -23,7 +23,7 @@ const volrConfig: VolrUIConfig = {
23
23
  projectApiKey: 'your-project-api-key',
24
24
  appName: 'My App',
25
25
  accentColor: '#3b82f6',
26
- enabledLoginMethods: ['email', 'social', 'siwe'],
26
+ enabledLoginMethods: ['email', 'social'],
27
27
  socialProviders: ['google', 'twitter'],
28
28
  };
29
29
 
@@ -36,12 +36,153 @@ function App() {
36
36
  }
37
37
  ```
38
38
 
39
- ### 2. Use useVolrModal Hook
39
+ ---
40
+
41
+ ## Payment Integration
42
+
43
+ Volr provides a simple, Stripe-like payment experience for Web3 applications.
44
+
45
+ ### Basic Payment
46
+
47
+ ```tsx
48
+ import { useVolrPay } from '@volr/react-ui';
49
+
50
+ function CheckoutButton() {
51
+ const { pay } = useVolrPay();
52
+
53
+ const handleCheckout = async () => {
54
+ const payment = await pay({
55
+ amount: 9.99,
56
+ item: {
57
+ name: 'Premium Plan',
58
+ description: 'Monthly subscription',
59
+ },
60
+ handlers: {
61
+ onSuccess: (result) => {
62
+ console.log('Payment confirmed!', result.txHash);
63
+ },
64
+ onError: (error) => {
65
+ console.error('Payment failed:', error.message);
66
+ },
67
+ },
68
+ });
69
+
70
+ // Optionally wait for confirmation
71
+ const result = await payment.wait();
72
+ };
73
+
74
+ return <button onClick={handleCheckout}>Subscribe $9.99</button>;
75
+ }
76
+ ```
77
+
78
+ ### Payment with Reference ID
79
+
80
+ Track payments with your own order ID:
81
+
82
+ ```tsx
83
+ const payment = await pay({
84
+ amount: 29.99,
85
+ item: { name: 'Pro License' },
86
+ referenceId: 'order_12345', // Your order ID
87
+ metadata: {
88
+ userId: 'user_abc',
89
+ plan: 'pro',
90
+ },
91
+ });
92
+ ```
93
+
94
+ ### Idempotent Payments
95
+
96
+ Prevent duplicate payments with idempotency key:
97
+
98
+ ```tsx
99
+ const payment = await pay({
100
+ amount: 49.99,
101
+ item: { name: 'Enterprise License' },
102
+ idempotencyKey: `order_${orderId}_${userId}`, // Unique per payment intent
103
+ });
104
+ ```
105
+
106
+ ### Check Payment Status
107
+
108
+ ```tsx
109
+ import { useVolrPay } from '@volr/react-ui';
110
+
111
+ function OrderStatus({ paymentId }: { paymentId: string }) {
112
+ const { checkPayment } = useVolrPay();
113
+ const [status, setStatus] = useState<string>('loading');
114
+
115
+ useEffect(() => {
116
+ checkPayment(paymentId).then((result) => {
117
+ setStatus(result.status); // 'CONFIRMED' | 'PENDING' | 'FAILED' | ...
118
+ });
119
+ }, [paymentId]);
120
+
121
+ return <div>Payment Status: {status}</div>;
122
+ }
123
+ ```
124
+
125
+ ### Payment History
126
+
127
+ ```tsx
128
+ import { useVolrPay } from '@volr/react-ui';
129
+
130
+ function PaymentHistory() {
131
+ const { getPaymentHistory } = useVolrPay();
132
+ const [payments, setPayments] = useState([]);
133
+
134
+ useEffect(() => {
135
+ getPaymentHistory({ take: 10 }).then((result) => {
136
+ setPayments(result.payments);
137
+ });
138
+ }, []);
139
+
140
+ return (
141
+ <ul>
142
+ {payments.map((p) => (
143
+ <li key={p.id}>
144
+ {p.itemName} - {p.amount} {p.token.symbol} - {p.status}
145
+ </li>
146
+ ))}
147
+ </ul>
148
+ );
149
+ }
150
+ ```
151
+
152
+ ### PayOptions Reference
153
+
154
+ | Property | Type | Required | Description |
155
+ |----------|------|----------|-------------|
156
+ | `amount` | `number` | ✅ | Amount in token units (before decimals) |
157
+ | `item.name` | `string` | ❌ | Item name displayed in modal |
158
+ | `item.description` | `string` | ❌ | Item description |
159
+ | `item.image` | `string` | ❌ | Item image URL (falls back to project logo) |
160
+ | `referenceId` | `string` | ❌ | Your order/reference ID |
161
+ | `metadata` | `Record<string, string>` | ❌ | Custom metadata (max 50 keys) |
162
+ | `idempotencyKey` | `string` | ❌ | Unique key to prevent duplicates |
163
+ | `expiresInSec` | `number` | ❌ | Expiration time (default: 900 = 15 min) |
164
+ | `handlers.onCreated` | `(payment) => void` | ❌ | Called when payment is created |
165
+ | `handlers.onProcessing` | `(payment) => void` | ❌ | Called when transaction is broadcasted |
166
+ | `handlers.onSuccess` | `(result) => void` | ❌ | Called when payment is confirmed |
167
+ | `handlers.onError` | `(error) => void` | ❌ | Called on error |
168
+ | `handlers.onCancel` | `() => void` | ❌ | Called when user cancels |
169
+
170
+ ### Payment Modal Flow
171
+
172
+ 1. **Payment Info** - Shows item details, amount, and user's balance
173
+ 2. **Processing** - Passkey signing → Transaction broadcast → On-chain confirmation
174
+ 3. **Result** - Success or failure with retry option
175
+
176
+ ---
177
+
178
+ ## Account & Authentication
179
+
180
+ ### Login / Account Modal
40
181
 
41
182
  ```tsx
42
183
  import { useVolrModal, useVolr } from '@volr/react-ui';
43
184
 
44
- function Example() {
185
+ function AuthButton() {
45
186
  const { open } = useVolrModal();
46
187
  const { evmAddress, isLoggedIn, logout } = useVolr();
47
188
 
@@ -50,12 +191,7 @@ function Example() {
50
191
  {isLoggedIn ? (
51
192
  <>
52
193
  <p>Wallet: {evmAddress}</p>
53
- <button onClick={() => open({ mode: 'account' })}>
54
- My Account
55
- </button>
56
- <button onClick={() => open({ mode: 'deposit' })}>
57
- Deposit
58
- </button>
194
+ <button onClick={() => open({ mode: 'account' })}>My Account</button>
59
195
  <button onClick={logout}>Logout</button>
60
196
  </>
61
197
  ) : (
@@ -66,84 +202,95 @@ function Example() {
66
202
  }
67
203
  ```
68
204
 
69
- ### 3. Direct Asset Deposit
205
+ ### Deposit Modal
70
206
 
71
- Open deposit modal with a specific asset pre-selected:
207
+ Open deposit modal to let users top up their wallet:
72
208
 
73
209
  ```tsx
210
+ import { useVolrModal } from '@volr/react-ui';
211
+
74
212
  function DepositButton() {
75
213
  const { open } = useVolrModal();
76
214
 
77
- const handleDeposit = () => {
78
- open({
79
- mode: 'deposit',
80
- asset: { chainId: 8453, symbol: 'USDC' },
81
- });
82
- };
83
-
84
- return <button onClick={handleDeposit}>Deposit USDC</button>;
215
+ return (
216
+ <button onClick={() => open({ mode: 'deposit' })}>
217
+ Deposit
218
+ </button>
219
+ );
85
220
  }
221
+
222
+ // With specific asset pre-selected
223
+ <button onClick={() => open({ mode: 'deposit', asset: { chainId: 8453, symbol: 'USDC' } })}>
224
+ Deposit USDC
225
+ </button>
86
226
  ```
87
227
 
228
+ ---
229
+
88
230
  ## Configuration
89
231
 
90
232
  ### VolrUIProvider Props
91
233
 
92
234
  | Prop | Type | Default | Description |
93
235
  |------|------|---------|-------------|
94
- | `config` | `VolrUIConfig` | **Required** | Volr UI configuration (extends VolrConfig) |
95
236
  | `config.defaultChainId` | `number` | **Required** | Default chain ID |
96
237
  | `config.projectApiKey` | `string` | **Required** | Project API key |
97
238
  | `config.appName` | `string` | **Required** | Application name |
98
- | `config.accentColor` | `string` | `'#303030'` | Accent color for buttons and links |
99
- | `config.enabledLoginMethods` | `('email' \| 'social' \| 'siwe')[]` | `['email', 'social', 'siwe']` | Enabled login methods |
100
- | `config.socialProviders` | `('google' \| 'twitter' \| 'apple')[]` | `['google', 'twitter', 'apple']` | Enabled social providers |
239
+ | `config.accentColor` | `string` | `'#303030'` | Accent color for buttons |
240
+ | `config.enabledLoginMethods` | `('email' \| 'social' \| 'siwe')[]` | `['email', 'social', 'siwe']` | Login methods |
241
+ | `config.socialProviders` | `('google' \| 'twitter')[]` | `['google', 'twitter']` | Social providers |
101
242
  | `config.keyStorageType` | `'passkey' \| 'mpc'` | `'passkey'` | Key storage type |
102
- | `config.branding` | `BrandingConfig` | `undefined` | Custom branding configuration |
103
- | `config.providerPolicy` | `object` | `{ enforceOnFirstLogin: true }` | Provider policy settings |
243
+ | `config.branding` | `BrandingConfig` | `undefined` | Custom branding |
104
244
 
105
- > **Note:** Deposit assets are now configured via the Volr Dashboard, not in the SDK config.
245
+ > **Note:** Payment token and deposit assets are configured via the Volr Dashboard.
246
+
247
+ ---
106
248
 
107
249
  ## API Reference
108
250
 
109
- ### useVolrModal
251
+ ### useVolrPay
110
252
 
111
- Hook for controlling modals.
253
+ Hook for payment operations.
112
254
 
113
255
  ```tsx
114
- import { useVolrModal } from '@volr/react-ui';
256
+ import { useVolrPay } from '@volr/react-ui';
115
257
 
116
- const { isOpen, mode, asset, open, close } = useVolrModal();
258
+ const {
259
+ pay, // (options: PayOptions) => Promise<PaymentHandle>
260
+ checkPayment, // (id: string) => Promise<PaymentResult>
261
+ getPaymentHistory, // (options?) => Promise<{ payments, total }>
262
+ updatePaymentToProcessing,// (id, txId) => Promise<PaymentResult>
263
+ cancelPayment, // (id) => Promise<PaymentResult>
264
+ pollPaymentStatus, // (id) => Promise<PaymentResult>
265
+ isLoading, // boolean
266
+ } = useVolrPay();
267
+ ```
117
268
 
118
- // Open account modal (default) - shows login if not logged in, account info if logged in
119
- open();
120
- open({ mode: 'account' });
269
+ ### useVolrModal
121
270
 
122
- // Open deposit modal
123
- open({ mode: 'deposit' });
271
+ Hook for controlling modals.
124
272
 
125
- // Open deposit with specific asset
126
- open({ mode: 'deposit', asset: { chainId: 8453, symbol: 'ETH' } });
273
+ ```tsx
274
+ import { useVolrModal } from '@volr/react-ui';
127
275
 
128
- // Close modal
276
+ const { isOpen, mode, open, close } = useVolrModal();
277
+
278
+ open(); // Account modal (login or account info)
279
+ open({ mode: 'account' }); // Same as above
280
+ open({ mode: 'deposit' }); // Deposit modal
281
+ open({ mode: 'deposit', asset: {...} }); // Deposit with specific asset
282
+ open({ mode: 'payment', payment: {...} }); // Payment modal (internal)
129
283
  close();
130
284
  ```
131
285
 
132
- | Property | Type | Description |
133
- |----------|------|-------------|
134
- | `isOpen` | `boolean` | Whether modal is open |
135
- | `mode` | `'account' \| 'deposit'` | Current modal mode |
136
- | `asset` | `{ chainId: number; symbol: string } \| null` | Selected asset for deposit |
137
- | `open` | `(options?) => void` | Open modal with optional mode/asset |
138
- | `close` | `() => void` | Close modal |
139
-
140
286
  ### useVolr
141
287
 
288
+ Hook for wallet and user state.
289
+
142
290
  ```tsx
143
291
  import { useVolr } from '@volr/react-ui';
144
292
 
145
293
  const {
146
- evm, // (chainId: number) => EvmClient
147
294
  evmAddress, // `0x${string}` | undefined
148
295
  email, // string | undefined
149
296
  isLoggedIn, // boolean
@@ -154,156 +301,94 @@ const {
154
301
  } = useVolr();
155
302
  ```
156
303
 
157
- ### EvmClient
158
-
159
- Returned by `evm(chainId)`.
304
+ ---
160
305
 
161
- ```tsx
162
- const client = evm(8453);
163
-
164
- // Read contract
165
- const balance = await client.readContract({
166
- address: tokenAddress,
167
- abi: erc20Abi,
168
- functionName: 'balanceOf',
169
- args: [userAddress],
170
- });
306
+ ## Advanced: Web3 Transactions
171
307
 
172
- // Send single transaction
173
- const result = await client.sendTransaction({
174
- to: '0x...',
175
- data: '0x...',
176
- value: 0n,
177
- });
308
+ For advanced use cases beyond payments, you can send arbitrary transactions.
178
309
 
179
- // Send batch (with ABI)
180
- const result = await client.sendBatch([
181
- {
182
- target: tokenAddress,
183
- abi: erc20Abi,
184
- functionName: 'transfer',
185
- args: [recipient, amount],
186
- gasLimit: 100000n,
187
- },
188
- ]);
189
- ```
310
+ ### EvmClient
190
311
 
191
- ## Modal Modes
312
+ ```tsx
313
+ import { useVolr } from '@volr/react-ui';
192
314
 
193
- ### Account Mode (`mode: 'account'`)
315
+ function SendToken() {
316
+ const { evm, evmAddress } = useVolr();
194
317
 
195
- - **Not logged in**: Shows login screen (email, social, SIWE)
196
- - **Logged in**: Shows account info (wallet address, email) and logout button
318
+ const handleSend = async () => {
319
+ const client = evm(8453); // Base chain
197
320
 
198
- ### Deposit Mode (`mode: 'deposit'`)
321
+ // Read contract
322
+ const balance = await client.readContract({
323
+ address: tokenAddress,
324
+ abi: erc20Abi,
325
+ functionName: 'balanceOf',
326
+ args: [evmAddress],
327
+ });
199
328
 
200
- - **Not logged in**: Shows login first, then deposit screen
201
- - **Logged in**: Shows deposit QR code and address
202
- - **With asset**: Pre-selects the specified asset
329
+ // Send transaction
330
+ const result = await client.sendTransaction({
331
+ to: '0x...',
332
+ data: '0x...',
333
+ value: 0n,
334
+ });
203
335
 
204
- ## Features
336
+ // Send batch
337
+ const result = await client.sendBatch([
338
+ {
339
+ target: tokenAddress,
340
+ abi: erc20Abi,
341
+ functionName: 'transfer',
342
+ args: [recipient, amount],
343
+ gasLimit: 100000n,
344
+ },
345
+ ]);
346
+ };
347
+ }
348
+ ```
205
349
 
206
- - **Email Login**: Email verification with 6-digit code
207
- - **Social Login**: Google, Twitter, Apple OAuth
208
- - **SIWE**: Sign-In with Ethereum (wallet login)
209
- - **Passkey Wallet**: Automatic passkey-based wallet creation
210
- - **Deposit**: QR code-based crypto deposits
211
- - **Minimal Design**: Clean, modern UI
212
- - **Customizable**: Accent color and enabled methods
213
- - **Type-Safe**: Full TypeScript support
350
+ ---
214
351
 
215
- ## Login Flow
352
+ ## Login Flows
216
353
 
217
354
  ### Email Login
218
- 1. User clicks "Email Login"
219
- 2. Enter email address
220
- 3. Receive 6-digit verification code
221
- 4. Enter code
222
- 5. **New users**: Passkey setup
223
- 6. **Existing users**: Success
224
-
225
- ### Social Login (Google, Twitter, Apple)
226
- 1. User clicks social login button
227
- 2. Redirect to OAuth provider
228
- 3. Authorize and return
229
- 4. **New users**: Passkey setup
230
- 5. **Existing users**: Success
355
+ 1. Enter email Receive 6-digit code → Enter code → Passkey setup (new users)
231
356
 
232
- ### Wallet Login (SIWE)
233
- 1. User clicks "Wallet Login"
234
- 2. Connect MetaMask or other wallet
235
- 3. Sign SIWE message
236
- 4. **New users**: Passkey setup
237
- 5. **Existing users**: Success
238
-
239
- ## Examples
240
-
241
- ### Login/Account Button
242
-
243
- ```tsx
244
- import { useVolrModal, useVolr } from '@volr/react-ui';
245
-
246
- function AuthButton() {
247
- const { open } = useVolrModal();
248
- const { isLoggedIn, evmAddress } = useVolr();
249
-
250
- if (isLoggedIn) {
251
- return (
252
- <button onClick={() => open({ mode: 'account' })}>
253
- {evmAddress?.slice(0, 6)}...{evmAddress?.slice(-4)}
254
- </button>
255
- );
256
- }
257
-
258
- return <button onClick={() => open()}>Connect</button>;
259
- }
260
- ```
261
-
262
- ### Deposit Button
357
+ ### Social Login (Google, Twitter)
358
+ 1. Click social button → OAuth redirect → Authorize → Passkey setup (new users)
263
359
 
264
- ```tsx
265
- import { useVolrModal, useVolr } from '@volr/react-ui';
360
+ ### Wallet Login (SIWE)
361
+ 1. Click Wallet Login Connect wallet → Sign message → Passkey setup (new users)
266
362
 
267
- function DepositButton() {
268
- const { open } = useVolrModal();
269
- const { isLoggedIn } = useVolr();
363
+ ---
270
364
 
271
- return (
272
- <button
273
- onClick={() => open({ mode: 'deposit' })}
274
- disabled={!isLoggedIn}
275
- >
276
- Deposit
277
- </button>
278
- );
279
- }
280
- ```
365
+ ## Examples
281
366
 
282
367
  ### Email Only Config
283
368
 
284
369
  ```tsx
285
370
  const volrConfig: VolrUIConfig = {
286
371
  defaultChainId: 8453,
287
- projectApiKey: 'your-project-api-key',
372
+ projectApiKey: 'your-api-key',
288
373
  appName: 'My App',
289
- accentColor: '#6366f1',
290
374
  enabledLoginMethods: ['email'],
291
375
  };
292
376
  ```
293
377
 
294
- ### Google and Apple Only
378
+ ### Social Only Config
295
379
 
296
380
  ```tsx
297
381
  const volrConfig: VolrUIConfig = {
298
382
  defaultChainId: 8453,
299
- projectApiKey: 'your-project-api-key',
383
+ projectApiKey: 'your-api-key',
300
384
  appName: 'My App',
301
- accentColor: '#8b5cf6',
302
385
  enabledLoginMethods: ['social'],
303
- socialProviders: ['google', 'apple'],
386
+ socialProviders: ['google'],
304
387
  };
305
388
  ```
306
389
 
390
+ ---
391
+
307
392
  ## License
308
393
 
309
394
  MIT