@@ -18,7 +18,7 @@ import {
18
18
adminLookupQuoteQueryKey ,
19
19
adminUpdateQuoteMutation ,
20
20
} from "@/generated/client/@tanstack/react-query.gen"
21
- import { activateKeyset , keysetInfo , requestToMint } from "@/generated/client/sdk.gen"
21
+ import { activateKeyset , keysetInfo , paymentStatus , requestToMint } from "@/generated/client/sdk.gen"
22
22
import { cn , getInitials } from "@/lib/utils"
23
23
import { formatDate , humanReadableDuration } from "@/utils/dates"
24
24
@@ -222,19 +222,21 @@ function QuoteActions({
222
222
isFetching,
223
223
newKeyset,
224
224
ebillPaid,
225
+ requestedToPay,
225
226
} : {
226
227
value : InfoReply
227
228
isFetching : boolean
228
229
newKeyset : boolean
229
230
ebillPaid : boolean
231
+ requestedToPay : boolean
230
232
} ) {
231
233
const [ offerFormData , setOfferFormData ] = useState < OfferFormResult > ( )
232
234
const [ offerFormDrawerOpen , setOfferFormDrawerOpen ] = useState ( false )
233
235
const [ offerConfirmDrawerOpen , setOfferConfirmDrawerOpen ] = useState ( false )
234
236
const [ denyConfirmDrawerOpen , setDenyConfirmDrawerOpen ] = useState ( false )
235
237
const [ activateKeysetConfirmDrawerOpen , setActivateKeysetConfirmDrawerOpen ] = useState ( false )
236
- const [ requestToMintConfirmDrawerOpen , setRequestToMintConfirmDrawerOpen ] = useState ( false )
237
- const [ mintRequestResponse , setMintRequestResponse ] = useState < RequestToMintResponseInfo | null > ( null )
238
+ const [ requestToPayConfirmDrawerOpen , setRequestToPayConfirmDrawerOpen ] = useState ( false )
239
+ const [ payRequestResponse , setPayRequestResponse ] = useState < RequestToMintResponseInfo | null > ( null )
238
240
239
241
const effectiveDiscount = useMemo ( ( ) => {
240
242
if ( ! offerFormData ) return
@@ -311,7 +313,7 @@ function QuoteActions({
311
313
} ,
312
314
} )
313
315
314
- const requestToMintMutation = useMutation ( {
316
+ const requestToPayMutation = useMutation ( {
315
317
mutationFn : async ( ) => {
316
318
const { data } = await requestToMint ( {
317
319
body : {
@@ -323,7 +325,7 @@ function QuoteActions({
323
325
return data
324
326
} ,
325
327
onMutate : ( ) => {
326
- toast . loading ( "Requesting to pay…" , { id : `quote-${ value . id } -request-to-mint ` } )
328
+ toast . loading ( "Requesting to pay…" , { id : `quote-${ value . id } -request-to-pay ` } )
327
329
} ,
328
330
onSettled : ( ) => {
329
331
toast . dismiss ( `quote-${ value . id } -request-to-pay` )
@@ -334,7 +336,10 @@ function QuoteActions({
334
336
} ,
335
337
onSuccess : ( data ) => {
336
338
toast . success ( "Payment request has been created." )
337
- setMintRequestResponse ( data )
339
+ setPayRequestResponse ( data )
340
+ void queryClient . invalidateQueries ( {
341
+ queryKey : [ "bill_id" , value . bill . id ] ,
342
+ } )
338
343
} ,
339
344
} )
340
345
@@ -371,8 +376,8 @@ function QuoteActions({
371
376
activateKeysetMutation . mutate ( )
372
377
}
373
378
374
- const onRequestToMint = ( ) => {
375
- requestToMintMutation . mutate ( )
379
+ const onRequestToPay = ( ) => {
380
+ requestToPayMutation . mutate ( )
376
381
}
377
382
return (
378
383
< >
@@ -476,20 +481,20 @@ function QuoteActions({
476
481
< > </ >
477
482
) }
478
483
479
- { value . status === "Accepted" && "keyset_id" in value && ! ebillPaid && ! newKeyset ? (
484
+ { value . status === "Accepted" && "keyset_id" in value && ! ebillPaid && ! newKeyset && ! requestedToPay ? (
480
485
< ConfirmDrawer
481
- title = "Confirm requesting to mint "
482
- description = "Are you sure you want to request to mint from this e-bill?"
483
- open = { requestToMintConfirmDrawerOpen }
484
- onOpenChange = { setRequestToMintConfirmDrawerOpen }
486
+ title = "Confirm requesting to pay "
487
+ description = "Are you sure you want to request to pay this e-bill?"
488
+ open = { requestToPayConfirmDrawerOpen }
489
+ onOpenChange = { setRequestToPayConfirmDrawerOpen }
485
490
onSubmit = { ( ) => {
486
- onRequestToMint ( )
487
- setRequestToMintConfirmDrawerOpen ( false )
491
+ onRequestToPay ( )
492
+ setRequestToPayConfirmDrawerOpen ( false )
488
493
} }
489
- submitButtonText = "Yes, request to mint "
494
+ submitButtonText = "Yes, request to pay "
490
495
trigger = {
491
- < Button className = "flex-1" disabled = { isFetching || requestToMintMutation . isPending } variant = "default" >
492
- Request to Pay { requestToMintMutation . isPending && < LoaderIcon className = "stroke-1 animate-spin" /> }
496
+ < Button className = "flex-1" disabled = { isFetching || requestToPayMutation . isPending } variant = "default" >
497
+ Request to Pay { requestToPayMutation . isPending && < LoaderIcon className = "stroke-1 animate-spin" /> }
493
498
</ Button >
494
499
}
495
500
/>
@@ -498,18 +503,18 @@ function QuoteActions({
498
503
) }
499
504
</ div >
500
505
501
- { mintRequestResponse && (
506
+ { payRequestResponse && (
502
507
< div className = "mt-4 p-4 bg-gray-50 rounded-lg" >
503
508
< h3 className = "font-bold mb-2" > Payment Request</ h3 >
504
509
< div className = "space-y-2" >
505
510
< div >
506
511
< span className = "font-bold" > ID</ span >
507
- < span className = "font-mono ml-2" > { mintRequestResponse . request_id } </ span >
512
+ < span className = "font-mono ml-2" > { payRequestResponse . request_id } </ span >
508
513
</ div >
509
514
< div >
510
515
< span className = "font-bold" > Details</ span >
511
516
< div className = "font-mono text-sm mt-1 p-2 bg-white rounded border break-all" >
512
- { mintRequestResponse . request }
517
+ { payRequestResponse . request }
513
518
</ div >
514
519
</ div >
515
520
</ div >
@@ -676,6 +681,7 @@ function Quote({ value, isFetching }: { value: InfoReply; isFetching: boolean })
676
681
const shouldFetchKeyset = ( value . status === "Offered" || value . status === "Accepted" ) && "keyset_id" in value
677
682
678
683
const keysetId = "keyset_id" in value ? value . keyset_id : ""
684
+ const billId = "bill" in value && "id" in value . bill ? value . bill . id : ""
679
685
680
686
const { data : keysetData } = useQuery ( {
681
687
queryKey : [ "keyset" , keysetId ] ,
@@ -686,6 +692,18 @@ function Quote({ value, isFetching }: { value: InfoReply; isFetching: boolean })
686
692
enabled : shouldFetchKeyset ,
687
693
} )
688
694
695
+ const { data : paymentData } = useQuery ( {
696
+ queryKey : [ "bill_id" , billId ] ,
697
+ queryFn : ( ) =>
698
+ paymentStatus ( {
699
+ path : { bill_id : billId } ,
700
+ } ) ,
701
+ enabled : ! ! billId ,
702
+ } )
703
+
704
+ const requestedToPay = paymentData ?. data ?. payment_status . requested_to_pay ?? false
705
+ const paymentAddress = paymentData ?. data ?. payment_details ?. address_to_pay ?? ""
706
+
689
707
const ebillPaid = keysetData ?. data && "active" in keysetData . data && keysetData . data . active === false
690
708
const newKeyset = "keyset_id" in value && ( ! keysetData ?. data || ! ( "active" in keysetData . data ) )
691
709
@@ -727,6 +745,16 @@ function Quote({ value, isFetching }: { value: InfoReply; isFetching: boolean })
727
745
) : (
728
746
< > </ >
729
747
) }
748
+ { requestedToPay ? (
749
+ < TableRow >
750
+ < TableCell className = "font-bold" > Payment Address: </ TableCell >
751
+ < TableCell className = "flex items-center gap-2" >
752
+ < span className = "font-mono" > { paymentAddress } </ span >
753
+ </ TableCell >
754
+ </ TableRow >
755
+ ) : (
756
+ < > </ >
757
+ ) }
730
758
< TableRow >
731
759
< TableCell className = "font-bold" > Status: </ TableCell >
732
760
< TableCell >
@@ -796,7 +824,13 @@ function Quote({ value, isFetching }: { value: InfoReply; isFetching: boolean })
796
824
</ TableBody >
797
825
</ Table >
798
826
799
- < QuoteActions value = { value } isFetching = { isFetching } newKeyset = { newKeyset } ebillPaid = { ebillPaid ?? false } />
827
+ < QuoteActions
828
+ value = { value }
829
+ isFetching = { isFetching }
830
+ newKeyset = { newKeyset }
831
+ ebillPaid = { ebillPaid ?? false }
832
+ requestedToPay = { requestedToPay ?? false }
833
+ />
800
834
</ div >
801
835
)
802
836
}
0 commit comments