Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/generated/client/sdk.gen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts

import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
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';
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';

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

Expand Down Expand Up @@ -168,3 +168,18 @@
}
});
};

/**
* --------------------------- BillPaymentStatus
*/

export const paymentStatus = <ThrowOnError extends boolean = false>(options?: Options<BillPaymentData, ThrowOnError>) => {
return (_heyApiClient).get<BillPaymentState, unknown, ThrowOnError>({
url: '/v1/admin/bill/payment_status/{bill_id}',
...options,
headers: {
'Content-Type': 'application/json',
...options?.headers
}
});
};

Check warning on line 185 in src/generated/client/sdk.gen.ts

View check run for this annotation

Codecov / codecov/patch

src/generated/client/sdk.gen.ts#L176-L185

Added lines #L176 - L185 were not covered by tests
139 changes: 87 additions & 52 deletions src/generated/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,67 +498,102 @@ export type KeysetInfoData = {
};

/**
* Request Mint
*/
* Request Mint
*/

export type RequestToMintRequest = {
ebill_id: string;
amount: number;
};

export type RequestToMintRequest = {
ebill_id: string;
amount: number;
};
export type RequestToMintResponseInfo = {
request_id: string;
request: string;
};

export type RequestToMintResponseInfo = {
request_id: string;
request: string;
};
export type RequestToMintResponse = {
/**
* Successful response
*/
200: RequestToMintResponseInfo;
};

export type RequestToMintResponse = {
/**
export type RequestToMintData = {
body?: RequestToMintRequest;
path?: never;
query?: never;
url: '/v1/admin/treasury/debit/request_to_mint_from_ebill'
};

/**
* Node ID
*/

export type IdentityDetailRequest = {
};

export type IdentityDetailInfo = {
node_id: string;
name: string;
email: string | null;
bitcoin_public_key: string;
npub: string;
postal_address: PostalAddress | null;
date_of_birth: string | null;
country_of_birth: string | null;
city_of_birth: string | null;
identification_number: string | null;
profile_picture_file: string | null;
identity_document_file: string | null;
nostr_relays: Array<string>;
};

export type IdentityDetailResponse = {
/**
* Successful response
*/
200: RequestToMintResponseInfo;
};

export type RequestToMintData = {
body?: RequestToMintRequest;
path?: never;
query?: never;
url: '/v1/admin/treasury/debit/request_to_mint_from_ebill'
};
200: IdentityDetailInfo;
};

/**
* Node ID
*/

export type IdentityDetailRequest = {
};
export type IdentityDetailData = {
body?: never;
path?: never;
query?: never;
url: '/v1/admin/identity/detail'
};

export type IdentityDetailInfo = {
node_id: string;
name: string;
email: string | null;
bitcoin_public_key: string;
npub: string;
postal_address: PostalAddress | null;
date_of_birth: string | null;
country_of_birth: string | null;
city_of_birth: string | null;
identification_number: string | null;
profile_picture_file: string | null;
identity_document_file: string | null;
nostr_relays: Array<string>;
};
/**
* Bill Payment Status
*/

export type BillWaitingForPaymentState = {
time_of_request: number,
currency: string,
sum: string,
link_to_pay: string,
address_to_pay: string,
mempool_link_for_address_to_pay: string,
}

export type IdentityDetailResponse = {
/**
* Successful response
*/
200: IdentityDetailInfo;
};
export type BillPaymentStatus = {
time_of_request_to_pay: number | null,
requested_to_pay: boolean,
paid: boolean,
request_to_pay_timed_out: boolean,
rejected_to_pay: boolean,
}

export type BillPaymentState = {
payment_status: BillPaymentStatus,
payment_details: BillWaitingForPaymentState | null,
}

export type IdentityDetailData = {
body?: never;
path?: never;
query?: never;
url: '/v1/admin/identity/detail'
export type BillPaymentData = {
body?: never;
path: {
bill_id: string;
};
query?: never;
url: '/v1/admin/bill/payment_status/{bill_id}';
};
78 changes: 56 additions & 22 deletions src/pages/quotes/QuotePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
adminLookupQuoteQueryKey,
adminUpdateQuoteMutation,
} from "@/generated/client/@tanstack/react-query.gen"
import { activateKeyset, keysetInfo, requestToMint } from "@/generated/client/sdk.gen"
import { activateKeyset, keysetInfo, paymentStatus, requestToMint } from "@/generated/client/sdk.gen"

Check warning on line 21 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L21

Added line #L21 was not covered by tests
import { cn, getInitials } from "@/lib/utils"
import { formatDate, humanReadableDuration } from "@/utils/dates"

Expand Down Expand Up @@ -222,19 +222,21 @@
isFetching,
newKeyset,
ebillPaid,
requestedToPay,

Check warning on line 225 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L225

Added line #L225 was not covered by tests
}: {
value: InfoReply
isFetching: boolean
newKeyset: boolean
ebillPaid: boolean
requestedToPay: boolean
}) {
const [offerFormData, setOfferFormData] = useState<OfferFormResult>()
const [offerFormDrawerOpen, setOfferFormDrawerOpen] = useState(false)
const [offerConfirmDrawerOpen, setOfferConfirmDrawerOpen] = useState(false)
const [denyConfirmDrawerOpen, setDenyConfirmDrawerOpen] = useState(false)
const [activateKeysetConfirmDrawerOpen, setActivateKeysetConfirmDrawerOpen] = useState(false)
const [requestToMintConfirmDrawerOpen, setRequestToMintConfirmDrawerOpen] = useState(false)
const [mintRequestResponse, setMintRequestResponse] = useState<RequestToMintResponseInfo | null>(null)
const [requestToPayConfirmDrawerOpen, setRequestToPayConfirmDrawerOpen] = useState(false)
const [payRequestResponse, setPayRequestResponse] = useState<RequestToMintResponseInfo | null>(null)

Check warning on line 239 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L238-L239

Added lines #L238 - L239 were not covered by tests

const effectiveDiscount = useMemo(() => {
if (!offerFormData) return
Expand Down Expand Up @@ -311,7 +313,7 @@
},
})

const requestToMintMutation = useMutation({
const requestToPayMutation = useMutation({

Check warning on line 316 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L316

Added line #L316 was not covered by tests
mutationFn: async () => {
const { data } = await requestToMint({
body: {
Expand All @@ -323,7 +325,7 @@
return data
},
onMutate: () => {
toast.loading("Requesting to pay…", { id: `quote-${value.id}-request-to-mint` })
toast.loading("Requesting to pay…", { id: `quote-${value.id}-request-to-pay` })

Check warning on line 328 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L328

Added line #L328 was not covered by tests
},
onSettled: () => {
toast.dismiss(`quote-${value.id}-request-to-pay`)
Expand All @@ -334,7 +336,10 @@
},
onSuccess: (data) => {
toast.success("Payment request has been created.")
setMintRequestResponse(data)
setPayRequestResponse(data)
void queryClient.invalidateQueries({
queryKey: ["bill_id", value.bill.id],
})

Check warning on line 342 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L339-L342

Added lines #L339 - L342 were not covered by tests
},
})

Expand Down Expand Up @@ -371,8 +376,8 @@
activateKeysetMutation.mutate()
}

const onRequestToMint = () => {
requestToMintMutation.mutate()
const onRequestToPay = () => {
requestToPayMutation.mutate()

Check warning on line 380 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L379-L380

Added lines #L379 - L380 were not covered by tests
}
return (
<>
Expand Down Expand Up @@ -476,20 +481,20 @@
<></>
)}

{value.status === "Accepted" && "keyset_id" in value && !ebillPaid && !newKeyset ? (
{value.status === "Accepted" && "keyset_id" in value && !ebillPaid && !newKeyset && !requestedToPay ? (

Check warning on line 484 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L484

Added line #L484 was not covered by tests
<ConfirmDrawer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit confusing that this button and the confirmation vary between "request to pay" and "request to mint" 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll adjust for consistency

title="Confirm requesting to mint"
description="Are you sure you want to request to mint from this e-bill?"
open={requestToMintConfirmDrawerOpen}
onOpenChange={setRequestToMintConfirmDrawerOpen}
title="Confirm requesting to pay"
description="Are you sure you want to request to pay this e-bill?"
open={requestToPayConfirmDrawerOpen}
onOpenChange={setRequestToPayConfirmDrawerOpen}

Check warning on line 489 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L486-L489

Added lines #L486 - L489 were not covered by tests
onSubmit={() => {
onRequestToMint()
setRequestToMintConfirmDrawerOpen(false)
onRequestToPay()
setRequestToPayConfirmDrawerOpen(false)

Check warning on line 492 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L491-L492

Added lines #L491 - L492 were not covered by tests
}}
submitButtonText="Yes, request to mint"
submitButtonText="Yes, request to pay"

Check warning on line 494 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L494

Added line #L494 was not covered by tests
trigger={
<Button className="flex-1" disabled={isFetching || requestToMintMutation.isPending} variant="default">
Request to Pay {requestToMintMutation.isPending && <LoaderIcon className="stroke-1 animate-spin" />}
<Button className="flex-1" disabled={isFetching || requestToPayMutation.isPending} variant="default">
Request to Pay {requestToPayMutation.isPending && <LoaderIcon className="stroke-1 animate-spin" />}

Check warning on line 497 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L496-L497

Added lines #L496 - L497 were not covered by tests
</Button>
}
/>
Expand All @@ -498,18 +503,18 @@
)}
</div>

{mintRequestResponse && (
{payRequestResponse && (

Check warning on line 506 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L506

Added line #L506 was not covered by tests
<div className="mt-4 p-4 bg-gray-50 rounded-lg">
<h3 className="font-bold mb-2">Payment Request</h3>
<div className="space-y-2">
<div>
<span className="font-bold">ID</span>
<span className="font-mono ml-2">{mintRequestResponse.request_id}</span>
<span className="font-mono ml-2">{payRequestResponse.request_id}</span>

Check warning on line 512 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L512

Added line #L512 was not covered by tests
</div>
<div>
<span className="font-bold">Details</span>
<div className="font-mono text-sm mt-1 p-2 bg-white rounded border break-all">
{mintRequestResponse.request}
{payRequestResponse.request}

Check warning on line 517 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L517

Added line #L517 was not covered by tests
</div>
</div>
</div>
Expand Down Expand Up @@ -676,6 +681,7 @@
const shouldFetchKeyset = (value.status === "Offered" || value.status === "Accepted") && "keyset_id" in value

const keysetId = "keyset_id" in value ? value.keyset_id : ""
const billId = "bill" in value && "id" in value.bill ? value.bill.id : ""

Check warning on line 684 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L684

Added line #L684 was not covered by tests

const { data: keysetData } = useQuery({
queryKey: ["keyset", keysetId],
Expand All @@ -686,6 +692,18 @@
enabled: shouldFetchKeyset,
})

const { data: paymentData } = useQuery({
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an enabled: !!billId flag to this query to avoid unnecessary network requests when billId is empty.

Copilot uses AI. Check for mistakes.

queryKey: ["bill_id", billId],
queryFn: () =>
paymentStatus({
path: { bill_id: billId },
}),
enabled: !!billId,
})

Check warning on line 702 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L695-L702

Added lines #L695 - L702 were not covered by tests

const requestedToPay = paymentData?.data?.payment_status.requested_to_pay ?? false
const paymentAddress = paymentData?.data?.payment_details?.address_to_pay ?? ""

Check warning on line 705 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L704-L705

Added lines #L704 - L705 were not covered by tests

const ebillPaid = keysetData?.data && "active" in keysetData.data && keysetData.data.active === false
const newKeyset = "keyset_id" in value && (!keysetData?.data || !("active" in keysetData.data))

Expand Down Expand Up @@ -727,6 +745,16 @@
) : (
<></>
)}
{requestedToPay ? (
<TableRow>
<TableCell className="font-bold">Payment Address: </TableCell>
<TableCell className="flex items-center gap-2">
<span className="font-mono">{paymentAddress}</span>
</TableCell>
</TableRow>

Check warning on line 754 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L748-L754

Added lines #L748 - L754 were not covered by tests
) : (
<></>

Check warning on line 756 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L756

Added line #L756 was not covered by tests
)}
<TableRow>
<TableCell className="font-bold">Status: </TableCell>
<TableCell>
Expand Down Expand Up @@ -796,7 +824,13 @@
</TableBody>
</Table>

<QuoteActions value={value} isFetching={isFetching} newKeyset={newKeyset} ebillPaid={ebillPaid ?? false} />
<QuoteActions
value={value}
isFetching={isFetching}
newKeyset={newKeyset}
ebillPaid={ebillPaid ?? false}
requestedToPay={requestedToPay ?? false}
/>

Check warning on line 833 in src/pages/quotes/QuotePage.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/quotes/QuotePage.tsx#L827-L833

Added lines #L827 - L833 were not covered by tests
</div>
)
}
Expand Down
Loading