πBest Practices
Inform & ask before you prompt
Prioritize WebLN, offer fallback options
Code Example
// check if the browser supports WebLN
if (window.webln) {
try {
// if webln is available, ask the user for permission (typically happens only once)
await window.webln.enable();
try {
// if the user gave permission to use webln, initate the payment
const res = await window.webln.sendPayment(parsed.invoice);
// the response contains the pre-image of the payment and could be used to verify the payment by comparing the hashes
console.log(res);
}
catch(e) {
// something went wrong during the payment, inform the user
showError(e);
}
}
catch(e) {
// if the user cancels or something goes wrong, we show the modal with the invoice and the QR code (as it is currently)
showModal();
}
} else {
// if webln is not supported we simply show the modal as we currently do
showModal();
}Don't Assume a Particular Client
Last updated
Was this helpful?