@@ -4,7 +4,7 @@ import { PropsValidation } from "@/lib/validation";
4
4
import { zodResolver } from "@hookform/resolvers/zod" ;
5
5
import PaymentWidget from "@requestnetwork/payment-widget/react" ;
6
6
import { CopyIcon } from "lucide-react" ;
7
- import { useRef , useState } from "react" ;
7
+ import { useEffect , useRef , useState } from "react" ;
8
8
import { useForm } from "react-hook-form" ;
9
9
import { z } from "zod" ;
10
10
import { Button } from "./ui/button" ;
@@ -21,6 +21,9 @@ import {
21
21
AccordionTrigger ,
22
22
} from "./ui/accordion" ;
23
23
24
+ import { cn } from "@/lib/utils" ;
25
+ import { ZERO_ADDRESS } from "@/lib/constants" ;
26
+
24
27
export const Playground = ( ) => {
25
28
const {
26
29
register,
@@ -38,6 +41,8 @@ export const Playground = () => {
38
41
buyerInfo : { } ,
39
42
invoiceNumber : "" ,
40
43
enableBuyerInfo : false ,
44
+ feeAddress : ZERO_ADDRESS ,
45
+ feeAmount : 0 ,
41
46
} ,
42
47
} ) ;
43
48
@@ -65,6 +70,10 @@ export const Playground = () => {
65
70
formValues . supportedCurrencies ?. length &&
66
71
`supportedCurrencies={${ JSON . stringify ( formValues . supportedCurrencies ) } }` ,
67
72
formValues . invoiceNumber && `invoiceNumber="${ formValues . invoiceNumber } "` ,
73
+ formValues . feeAddress &&
74
+ formValues . feeAddress !== ZERO_ADDRESS &&
75
+ `feeAddress="${ formValues . feeAddress } "` ,
76
+ formValues . feeAmount && `feeAmountInUSD={${ formValues . feeAmount } }` ,
68
77
]
69
78
. filter ( Boolean )
70
79
. join ( "\n " ) ;
@@ -99,6 +108,13 @@ const YourComponent = () => {
99
108
}
100
109
} ;
101
110
111
+ useEffect ( ( ) => {
112
+ if ( formValues . feeAddress ?. length === 0 ) {
113
+ setValue ( "feeAddress" , ZERO_ADDRESS ) ;
114
+ setValue ( "feeAmount" , 0 ) ;
115
+ }
116
+ } , [ formValues . feeAddress , formValues . feeAmount ] ) ;
117
+
102
118
return (
103
119
< div className = "flex flex-col gap-4 mt-4" >
104
120
< section className = "flex flex-col gap-6 lg:gap-4 items-center md:items-start md:justify-between lg:flex-row" >
@@ -359,10 +375,17 @@ const YourComponent = () => {
359
375
</ div >
360
376
{ /* Seller Address */ }
361
377
< div className = "flex flex-col gap-2" >
362
- < Label > Seller address</ Label >
378
+ < Label className = "flex items-center" >
379
+ Seller address
380
+ < span className = "text-red-500 ml-1" > *</ span >
381
+ </ Label >
363
382
< Input
364
383
placeholder = "0x1234567890123456789012345678901234567890"
365
384
{ ...register ( "sellerAddress" ) }
385
+ className = { cn (
386
+ "border-2" ,
387
+ errors . sellerAddress ? "border-red-500" : "border-gray-200"
388
+ ) }
366
389
/>
367
390
{ errors . sellerAddress ?. message && (
368
391
< Error > { errors . sellerAddress . message } </ Error >
@@ -371,12 +394,19 @@ const YourComponent = () => {
371
394
372
395
{ /* Amount in USD */ }
373
396
< div className = "flex flex-col gap-2" >
374
- < Label > Amount in USD</ Label >
397
+ < Label className = "flex items-center" >
398
+ Amount in USD
399
+ < span className = "text-red-500 ml-1" > *</ span >
400
+ </ Label >
375
401
< Input
376
402
placeholder = "25.55"
377
403
{ ...register ( "amountInUSD" , {
378
404
valueAsNumber : true ,
379
405
} ) }
406
+ className = { cn (
407
+ "border-2" ,
408
+ errors . amountInUSD ? "border-red-500" : "border-gray-200"
409
+ ) }
380
410
/>
381
411
{ errors . amountInUSD ?. message && (
382
412
< Error > { errors . amountInUSD . message } </ Error >
@@ -392,10 +422,44 @@ const YourComponent = () => {
392
422
) }
393
423
</ div >
394
424
425
+ { /* Fee */ }
426
+ < div className = "flex flex-col gap-2" >
427
+ < Label > Fee Address</ Label >
428
+ < Input
429
+ placeholder = "0x1234567890123456789012345678901234567890"
430
+ { ...register ( "feeAddress" ) }
431
+ />
432
+ { errors . feeAddress ?. message && (
433
+ < Error > { errors . feeAddress . message } </ Error >
434
+ ) }
435
+ < Label > Fee Amount in USD</ Label >
436
+ < Input
437
+ placeholder = "25.55"
438
+ { ...register ( "feeAmount" , {
439
+ valueAsNumber : true ,
440
+ } ) }
441
+ />
442
+ { errors . feeAmount ?. message && (
443
+ < Error > { errors . feeAmount . message } </ Error >
444
+ ) }
445
+ </ div >
446
+
395
447
{ /* Currencies */ }
396
448
< div className = "flex flex-col gap-2" >
397
- < Label > Currencies</ Label >
398
- < CurrencyCombobox register = { register } name = "supportedCurrencies" />
449
+ < Label className = "flex items-center" >
450
+ Currencies
451
+ < span className = "text-red-500 ml-1" > *</ span >
452
+ </ Label >
453
+ < CurrencyCombobox
454
+ register = { register }
455
+ name = "supportedCurrencies"
456
+ className = { cn (
457
+ "border-2" ,
458
+ errors . supportedCurrencies
459
+ ? "border-red-500"
460
+ : "border-gray-200"
461
+ ) }
462
+ />
399
463
< div className = "flex items-center gap-2 flex-wrap" >
400
464
{ formValues . supportedCurrencies ?. map ( ( currency ) => {
401
465
return (
@@ -408,6 +472,9 @@ const YourComponent = () => {
408
472
) ;
409
473
} ) }
410
474
</ div >
475
+ { errors . supportedCurrencies ?. message && (
476
+ < Error > { errors . supportedCurrencies . message } </ Error >
477
+ ) }
411
478
</ div >
412
479
</ div >
413
480
< div className = "w-full lg:w-1/2" >
@@ -426,6 +493,18 @@ const YourComponent = () => {
426
493
// @ts -ignore
427
494
supportedCurrencies = { formValues . supportedCurrencies }
428
495
invoiceNumber = { formValues . invoiceNumber }
496
+ feeAddress = {
497
+ formValues . feeAddress && formValues . feeAddress . length > 0
498
+ ? formValues . feeAddress
499
+ : ZERO_ADDRESS
500
+ }
501
+ feeAmountInUSD = {
502
+ formValues . feeAddress &&
503
+ formValues . feeAddress . length > 0 &&
504
+ formValues . feeAddress !== ZERO_ADDRESS
505
+ ? formValues . feeAmount
506
+ : 0
507
+ }
429
508
/>
430
509
</ div >
431
510
</ section >
0 commit comments