Skip to content

Commit

Permalink
fix: handle fixed amount lnurls in send screen
Browse files Browse the repository at this point in the history
  • Loading branch information
reneaaron committed Sep 24, 2024
1 parent c39a191 commit a253715
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
11 changes: 2 additions & 9 deletions pages/send/LNURLPay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,10 @@ export function LNURLPay() {
const [isAmountReadOnly, setAmountReadOnly] = React.useState(false);

useEffect(() => {

// Handle fixed amount LNURLs
if (lnurlDetails.minSendable === lnurlDetails.maxSendable) {
// Allow users to enter a comment if the LNURL allows it,
// otherwise go to the confirmation step directly
setAmount((lnurlDetails.minSendable / 1000).toString());

if (lnurlDetails.commentAllowed) {
setAmountReadOnly(true);
} else {
requestInvoice(lnurlDetails.minSendable / 1000);
}
setAmountReadOnly(true);
}
}, [lnurlDetails.minSendable, lnurlDetails.maxSendable]);

Expand Down Expand Up @@ -85,6 +77,7 @@ export function LNURLPay() {
value={comment}
onChangeText={setComment}
returnKeyType="done"
maxLength={lnurlDetails.commentAllowed}
/>
</View>
}
Expand Down
30 changes: 23 additions & 7 deletions pages/send/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,29 @@ export function Send() {
throw new Error("LNURL tag " + lnurlDetails.tag + " not supported");
}

router.replace({
pathname: "/send/lnurl-pay",
params: {
lnurlDetailsJSON: JSON.stringify(lnurlDetails),
originalText,
},
});
// Handle fixed amount LNURLs
if (lnurlDetails.minSendable === lnurlDetails.maxSendable && !lnurlDetails.commentAllowed) {
try {
const callback = new URL(lnurlDetails.callback);
callback.searchParams.append("amount", (lnurlDetails.minSendable).toString());
const lnurlPayInfo = await lnurl.getPayRequest(callback.toString());
router.push({
pathname: "/send/confirm",
params: { invoice: lnurlPayInfo.pr, originalText },
});
} catch (error) {
console.error(error);
errorToast(error);
}
} else {
router.replace({
pathname: "/send/lnurl-pay",
params: {
lnurlDetailsJSON: JSON.stringify(lnurlDetails),
originalText,
},
});
}
} else {
// Check if this is a valid invoice
new Invoice({
Expand Down

0 comments on commit a253715

Please sign in to comment.