Fix 0 amount invoice bug

This commit is contained in:
austinkelsay 2024-12-23 16:21:00 -06:00
parent a08d6a7af3
commit 410ee763cd
No known key found for this signature in database
GPG Key ID: 44CB4EC6D9F2FA02

View File

@ -71,9 +71,16 @@ const CoursePaymentButton = ({ lnAddress, amount, onSuccess, onError, courseId }
const fetchInvoice = async () => { const fetchInvoice = async () => {
setIsLoading(true); setIsLoading(true);
try { try {
if (discountApplied && calculateDiscount(amount).discountedAmount === 0) {
handlePaymentSuccess({ paid: true, preimage: 'course_pass' });
return;
}
const ln = new LightningAddress(lnAddress); const ln = new LightningAddress(lnAddress);
await ln.fetch(); await ln.fetch();
const invoice = await ln.requestInvoice({ satoshi: discountApplied ? calculateDiscount(amount).discountedAmount : amount }); const invoice = await ln.requestInvoice({
satoshi: discountApplied ? calculateDiscount(amount).discountedAmount : amount
});
setInvoice(invoice); setInvoice(invoice);
setDialogVisible(true); setDialogVisible(true);
} catch (error) { } catch (error) {
@ -176,7 +183,7 @@ const CoursePaymentButton = ({ lnAddress, amount, onSuccess, onError, courseId }
{discountApplied && ( {discountApplied && (
<div className="text-xs text-gray-500 flex items-center gap-1"> <div className="text-xs text-gray-500 flex items-center gap-1">
<span className="line-through">{amount} sats</span> <span className="line-through">{amount} sats</span>
<span className="text-green-500 font-semibold"><EFBFBD><EFBFBD><EFBFBD> {calculateDiscount(amount).discountedAmount} sats</span> <span className="text-green-500 font-semibold">{calculateDiscount(amount).discountedAmount} sats</span>
</div> </div>
)} )}
</div> </div>