-
Notifications
You must be signed in to change notification settings - Fork 1
Prevent request to pay being clicked twice #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
import { cn, getInitials } from "@/lib/utils" | ||
import { formatDate, humanReadableDuration } from "@/utils/dates" | ||
|
||
|
@@ -222,19 +222,21 @@ | |
isFetching, | ||
newKeyset, | ||
ebillPaid, | ||
requestedToPay, | ||
}: { | ||
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) | ||
|
||
const effectiveDiscount = useMemo(() => { | ||
if (!offerFormData) return | ||
|
@@ -311,7 +313,7 @@ | |
}, | ||
}) | ||
|
||
const requestToMintMutation = useMutation({ | ||
const requestToPayMutation = useMutation({ | ||
mutationFn: async () => { | ||
const { data } = await requestToMint({ | ||
body: { | ||
|
@@ -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` }) | ||
}, | ||
onSettled: () => { | ||
toast.dismiss(`quote-${value.id}-request-to-pay`) | ||
|
@@ -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], | ||
}) | ||
}, | ||
}) | ||
|
||
|
@@ -371,8 +376,8 @@ | |
activateKeysetMutation.mutate() | ||
} | ||
|
||
const onRequestToMint = () => { | ||
requestToMintMutation.mutate() | ||
const onRequestToPay = () => { | ||
requestToPayMutation.mutate() | ||
} | ||
return ( | ||
<> | ||
|
@@ -476,20 +481,20 @@ | |
<></> | ||
)} | ||
|
||
{value.status === "Accepted" && "keyset_id" in value && !ebillPaid && !newKeyset ? ( | ||
{value.status === "Accepted" && "keyset_id" in value && !ebillPaid && !newKeyset && !requestedToPay ? ( | ||
<ConfirmDrawer | ||
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} | ||
onSubmit={() => { | ||
onRequestToMint() | ||
setRequestToMintConfirmDrawerOpen(false) | ||
onRequestToPay() | ||
setRequestToPayConfirmDrawerOpen(false) | ||
}} | ||
submitButtonText="Yes, request to mint" | ||
submitButtonText="Yes, request to pay" | ||
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" />} | ||
</Button> | ||
} | ||
/> | ||
|
@@ -498,18 +503,18 @@ | |
)} | ||
</div> | ||
|
||
{mintRequestResponse && ( | ||
{payRequestResponse && ( | ||
<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> | ||
</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} | ||
</div> | ||
</div> | ||
</div> | ||
|
@@ -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 : "" | ||
|
||
const { data: keysetData } = useQuery({ | ||
queryKey: ["keyset", keysetId], | ||
|
@@ -686,6 +692,18 @@ | |
enabled: shouldFetchKeyset, | ||
}) | ||
|
||
const { data: paymentData } = useQuery({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
queryKey: ["bill_id", billId], | ||
queryFn: () => | ||
paymentStatus({ | ||
path: { bill_id: billId }, | ||
}), | ||
enabled: !!billId, | ||
}) | ||
|
||
const requestedToPay = paymentData?.data?.payment_status.requested_to_pay ?? false | ||
const paymentAddress = paymentData?.data?.payment_details?.address_to_pay ?? "" | ||
|
||
const ebillPaid = keysetData?.data && "active" in keysetData.data && keysetData.data.active === false | ||
const newKeyset = "keyset_id" in value && (!keysetData?.data || !("active" in keysetData.data)) | ||
|
||
|
@@ -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> | ||
) : ( | ||
<></> | ||
)} | ||
<TableRow> | ||
<TableCell className="font-bold">Status: </TableCell> | ||
<TableCell> | ||
|
@@ -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} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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" 🤔
There was a problem hiding this comment.
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