Skip to content

Commit

Permalink
Use context provider to pay invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Dec 28, 2023
1 parent 97e8e6d commit 9ddd13a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions components/qr.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import QRCode from 'qrcode.react'
import { CopyInput, InputSkeleton } from './form'
import InvoiceStatus from './invoice-status'
import { requestProvider } from 'webln'
import { useEffect } from 'react'
import { useWebLN } from './webln'

export default function Qr ({ asIs, value, webLn, statusVariant, description, status }) {
const qrValue = asIs ? value : 'lightning:' + value.toUpperCase()
const { provider } = useWebLN()

useEffect(() => {
async function effect () {
if (webLn) {
try {
const provider = await requestProvider()
await provider.sendPayment(value)
if (provider) {
// TODO in strict mode, this tries to pay the invoice twice
// so an error is logged to the console for the second attempt.
// but the payment still succeeds. (only tested with LNbits so far)
await provider.sendPayment(value)
}
} catch (e) {
console.log(e.message)
}
Expand Down

0 comments on commit 9ddd13a

Please sign in to comment.