stacker.news/components/lnqr.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-06-27 03:18:32 +00:00
import QRCode from 'qrcode.react'
import { CopyInput, InputSkeleton } from './form'
import InvoiceStatus from './invoice-status'
2021-09-07 17:52:59 +00:00
import { requestProvider } from 'webln'
import { useEffect } from 'react'
2021-06-27 03:18:32 +00:00
2021-09-07 17:52:59 +00:00
export default function LnQR ({ value, webLn, statusVariant, status }) {
2021-06-27 03:18:32 +00:00
const qrValue = 'lightning:' + value.toUpperCase()
2021-09-07 17:52:59 +00:00
useEffect(async () => {
if (webLn) {
try {
const provider = await requestProvider()
2021-09-07 18:04:56 +00:00
await provider.sendPayment(value)
2021-09-07 17:52:59 +00:00
} catch (e) {
2021-09-07 18:04:56 +00:00
console.log(e.message)
2021-09-07 17:52:59 +00:00
}
}
}, [])
2021-06-27 03:18:32 +00:00
return (
<>
2021-06-27 18:46:15 +00:00
<a className='d-block' href={qrValue}>
2021-06-27 03:18:32 +00:00
<QRCode className='h-auto mw-100' value={qrValue} renderAs='svg' size={300} />
2021-06-27 18:46:15 +00:00
</a>
2021-06-27 03:18:32 +00:00
<div className='mt-3 w-100'>
<CopyInput type='text' placeholder={value} readOnly />
</div>
<InvoiceStatus variant={statusVariant} status={status} />
</>
)
}
export function LnQRSkeleton ({ status }) {
return (
<>
<div className='h-auto w-100 clouds' style={{ paddingTop: 'min(300px, 100%)', maxWidth: '300px' }} />
<div className='mt-3 w-100'>
<InputSkeleton />
</div>
<InvoiceStatus variant='default' status={status} />
</>
)
}