ekzyis d3ca87a78b
Add WebLN for sending payments (#1274)
* Add WebLN for sending payments

* attach docs for alby

---------

Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
2024-07-23 13:23:48 -05:00

22 lines
652 B
JavaScript

export * from 'wallets/webln'
export const sendPayment = async (bolt11) => {
if (typeof window.webln === 'undefined') {
throw new Error('WebLN provider not found')
}
// this will prompt the user to unlock the wallet if it's locked
await window.webln.enable()
// this will prompt for payment if no budget is set
const response = await window.webln.sendPayment(bolt11)
if (!response) {
// sendPayment returns nothing if WebLN was enabled
// but browser extension that provides WebLN was then disabled
// without reloading the page
throw new Error('sendPayment returned no response')
}
return response.preimage
}