Skip to content

Commit f5b0f45

Browse files
committed
Request to Pay
1 parent 06e2639 commit f5b0f45

File tree

3 files changed

+140
-57
lines changed

3 files changed

+140
-57
lines changed

src/generated/client/sdk.gen.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

33
import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
4-
import type { ListQuotesData, ListQuotesResponse, ListPendingQuotesData, ListPendingQuotesResponse, AdminLookupQuoteData, AdminLookupQuoteResponse, AdminUpdateQuoteData, AdminUpdateQuoteResponse, ResolveOfferData, EnquireQuoteData, EnquireQuoteResponse, LookupQuoteData, LookupQuoteResponse, ActivateKeysetData, ActivateKeysetResponse, DebitData, CreditData, ECashBalance, OnChainBalanceData, OnChainData, KeysetInfoData, KeySetInfo, RequestToMintData, RequestToMintResponseInfo, IdentityDetailData, IdentityDetailInfo} from './types.gen';
4+
import type { ListQuotesData, ListQuotesResponse, ListPendingQuotesData, ListPendingQuotesResponse, AdminLookupQuoteData, AdminLookupQuoteResponse, AdminUpdateQuoteData, AdminUpdateQuoteResponse, ResolveOfferData, EnquireQuoteData, EnquireQuoteResponse, LookupQuoteData, LookupQuoteResponse, ActivateKeysetData, ActivateKeysetResponse, DebitData, CreditData, ECashBalance, OnChainBalanceData, OnChainData, KeysetInfoData, KeySetInfo, RequestToMintData, RequestToMintResponseInfo, IdentityDetailData, IdentityDetailInfo, BillPaymentData, BillPaymentState} from './types.gen';
55

66
import { client as _heyApiClient } from './client.gen';
77

@@ -168,3 +168,18 @@ export const identityDetail = <ThrowOnError extends boolean = false>(options?: O
168168
}
169169
});
170170
};
171+
172+
/**
173+
* --------------------------- BillPaymentStatus
174+
*/
175+
176+
export const paymentStatus = <ThrowOnError extends boolean = false>(options?: Options<BillPaymentData, ThrowOnError>) => {
177+
return (_heyApiClient).get<BillPaymentState, unknown, ThrowOnError>({
178+
url: '/v1/admin/bill/payment_status/{bill_id}',
179+
...options,
180+
headers: {
181+
'Content-Type': 'application/json',
182+
...options?.headers
183+
}
184+
});
185+
};

src/generated/client/types.gen.ts

Lines changed: 87 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -498,67 +498,102 @@ export type KeysetInfoData = {
498498
};
499499

500500
/**
501-
* Request Mint
502-
*/
501+
* Request Mint
502+
*/
503+
504+
export type RequestToMintRequest = {
505+
ebill_id: string;
506+
amount: number;
507+
};
503508

504-
export type RequestToMintRequest = {
505-
ebill_id: string;
506-
amount: number;
507-
};
509+
export type RequestToMintResponseInfo = {
510+
request_id: string;
511+
request: string;
512+
};
508513

509-
export type RequestToMintResponseInfo = {
510-
request_id: string;
511-
request: string;
512-
};
514+
export type RequestToMintResponse = {
515+
/**
516+
* Successful response
517+
*/
518+
200: RequestToMintResponseInfo;
519+
};
513520

514-
export type RequestToMintResponse = {
515-
/**
521+
export type RequestToMintData = {
522+
body?: RequestToMintRequest;
523+
path?: never;
524+
query?: never;
525+
url: '/v1/admin/treasury/debit/request_to_mint_from_ebill'
526+
};
527+
528+
/**
529+
* Node ID
530+
*/
531+
532+
export type IdentityDetailRequest = {
533+
};
534+
535+
export type IdentityDetailInfo = {
536+
node_id: string;
537+
name: string;
538+
email: string | null;
539+
bitcoin_public_key: string;
540+
npub: string;
541+
postal_address: PostalAddress | null;
542+
date_of_birth: string | null;
543+
country_of_birth: string | null;
544+
city_of_birth: string | null;
545+
identification_number: string | null;
546+
profile_picture_file: string | null;
547+
identity_document_file: string | null;
548+
nostr_relays: Array<string>;
549+
};
550+
551+
export type IdentityDetailResponse = {
552+
/**
516553
* Successful response
517554
*/
518-
200: RequestToMintResponseInfo;
519-
};
520-
521-
export type RequestToMintData = {
522-
body?: RequestToMintRequest;
523-
path?: never;
524-
query?: never;
525-
url: '/v1/admin/treasury/debit/request_to_mint_from_ebill'
526-
};
555+
200: IdentityDetailInfo;
556+
};
527557

528-
/**
529-
* Node ID
530-
*/
531558

532-
export type IdentityDetailRequest = {
533-
};
559+
export type IdentityDetailData = {
560+
body?: never;
561+
path?: never;
562+
query?: never;
563+
url: '/v1/admin/identity/detail'
564+
};
534565

535-
export type IdentityDetailInfo = {
536-
node_id: string;
537-
name: string;
538-
email: string | null;
539-
bitcoin_public_key: string;
540-
npub: string;
541-
postal_address: PostalAddress | null;
542-
date_of_birth: string | null;
543-
country_of_birth: string | null;
544-
city_of_birth: string | null;
545-
identification_number: string | null;
546-
profile_picture_file: string | null;
547-
identity_document_file: string | null;
548-
nostr_relays: Array<string>;
549-
};
566+
/**
567+
* Bill Payment Status
568+
*/
569+
570+
export type BillWaitingForPaymentState = {
571+
time_of_request: number,
572+
currency: string,
573+
sum: string,
574+
link_to_pay: string,
575+
address_to_pay: string,
576+
mempool_link_for_address_to_pay: string,
577+
}
550578

551-
export type IdentityDetailResponse = {
552-
/**
553-
* Successful response
554-
*/
555-
200: IdentityDetailInfo;
556-
};
579+
export type BillPaymentStatus = {
580+
time_of_request_to_pay: number | null,
581+
requested_to_pay: boolean,
582+
paid: boolean,
583+
request_to_pay_timed_out: boolean,
584+
rejected_to_pay: boolean,
585+
}
557586

587+
export type BillPaymentState = {
588+
payment_status: BillPaymentStatus,
589+
payment_details: BillWaitingForPaymentState | null,
590+
}
558591

559-
export type IdentityDetailData = {
560-
body?: never;
561-
path?: never;
562-
query?: never;
563-
url: '/v1/admin/identity/detail'
592+
export type BillPaymentData = {
593+
body?: never;
594+
path: {
595+
bill_id: string;
564596
};
597+
query?: never;
598+
url: '/v1/admin/bill/payment_status/{bill_id}';
599+
};

src/pages/quotes/QuotePage.tsx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
adminLookupQuoteQueryKey,
1919
adminUpdateQuoteMutation,
2020
} 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"
2222
import { cn, getInitials } from "@/lib/utils"
2323
import { formatDate, humanReadableDuration } from "@/utils/dates"
2424

@@ -222,11 +222,13 @@ function QuoteActions({
222222
isFetching,
223223
newKeyset,
224224
ebillPaid,
225+
requestedToPay,
225226
}: {
226227
value: InfoReply
227228
isFetching: boolean
228229
newKeyset: boolean
229230
ebillPaid: boolean
231+
requestedToPay: boolean
230232
}) {
231233
const [offerFormData, setOfferFormData] = useState<OfferFormResult>()
232234
const [offerFormDrawerOpen, setOfferFormDrawerOpen] = useState(false)
@@ -323,7 +325,7 @@ function QuoteActions({
323325
return data
324326
},
325327
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` })
327329
},
328330
onSettled: () => {
329331
toast.dismiss(`quote-${value.id}-request-to-pay`)
@@ -476,7 +478,7 @@ function QuoteActions({
476478
<></>
477479
)}
478480

479-
{value.status === "Accepted" && "keyset_id" in value && !ebillPaid && !newKeyset ? (
481+
{value.status === "Accepted" && "keyset_id" in value && !ebillPaid && !newKeyset && !requestedToPay ? (
480482
<ConfirmDrawer
481483
title="Confirm requesting to mint"
482484
description="Are you sure you want to request to mint from this e-bill?"
@@ -676,6 +678,7 @@ function Quote({ value, isFetching }: { value: InfoReply; isFetching: boolean })
676678
const shouldFetchKeyset = (value.status === "Offered" || value.status === "Accepted") && "keyset_id" in value
677679

678680
const keysetId = "keyset_id" in value ? value.keyset_id : ""
681+
const billId = "bill" in value && "id" in value.bill ? value.bill.id : ""
679682

680683
const { data: keysetData } = useQuery({
681684
queryKey: ["keyset", keysetId],
@@ -686,6 +689,20 @@ function Quote({ value, isFetching }: { value: InfoReply; isFetching: boolean })
686689
enabled: shouldFetchKeyset,
687690
})
688691

692+
const { data: paymentData } = useQuery({
693+
queryKey: ["bill_id", billId],
694+
queryFn: () =>
695+
paymentStatus({
696+
path: { bill_id: billId },
697+
}),
698+
})
699+
700+
const requestedToPay = paymentData?.data?.payment_status.requested_to_pay ?? false
701+
const paymentAddress = paymentData?.data?.payment_details?.address_to_pay ?? ""
702+
703+
console.log(billId)
704+
console.log(paymentData)
705+
689706
const ebillPaid = keysetData?.data && "active" in keysetData.data && keysetData.data.active === false
690707
const newKeyset = "keyset_id" in value && (!keysetData?.data || !("active" in keysetData.data))
691708

@@ -727,6 +744,16 @@ function Quote({ value, isFetching }: { value: InfoReply; isFetching: boolean })
727744
) : (
728745
<></>
729746
)}
747+
{requestedToPay ? (
748+
<TableRow>
749+
<TableCell className="font-bold">Payment Address: </TableCell>
750+
<TableCell className="flex items-center gap-2">
751+
<span className="font-mono">{paymentAddress}</span>
752+
</TableCell>
753+
</TableRow>
754+
) : (
755+
<></>
756+
)}
730757
<TableRow>
731758
<TableCell className="font-bold">Status: </TableCell>
732759
<TableCell>
@@ -796,7 +823,13 @@ function Quote({ value, isFetching }: { value: InfoReply; isFetching: boolean })
796823
</TableBody>
797824
</Table>
798825

799-
<QuoteActions value={value} isFetching={isFetching} newKeyset={newKeyset} ebillPaid={ebillPaid ?? false} />
826+
<QuoteActions
827+
value={value}
828+
isFetching={isFetching}
829+
newKeyset={newKeyset}
830+
ebillPaid={ebillPaid ?? false}
831+
requestedToPay={requestedToPay ?? false}
832+
/>
800833
</div>
801834
)
802835
}

0 commit comments

Comments
 (0)