stacker.news/components/invoice.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-05-06 21:15:22 +00:00
import QRCode from 'qrcode.react'
2021-05-13 13:28:38 +00:00
import { CopyInput, InputSkeleton } from './form'
import InvoiceStatus from './invoice-status'
2021-05-06 21:15:22 +00:00
export function Invoice ({ invoice }) {
2021-05-11 15:52:50 +00:00
const qrValue = 'lightning:' + invoice.bolt11.toUpperCase()
2021-05-13 13:28:38 +00:00
let variant = 'default'
2021-05-11 15:52:50 +00:00
let status = 'waiting for you'
if (invoice.confirmedAt) {
2021-05-13 13:28:38 +00:00
variant = 'confirmed'
2021-05-11 15:52:50 +00:00
status = `${invoice.msatsReceived / 1000} sats deposited`
} else if (invoice.cancelled) {
2021-05-13 13:28:38 +00:00
variant = 'failed'
2021-05-11 15:52:50 +00:00
status = 'cancelled'
} else if (invoice.expiresAt <= new Date()) {
2021-05-13 13:28:38 +00:00
variant = 'failed'
2021-05-11 15:52:50 +00:00
status = 'expired'
}
2021-05-06 21:15:22 +00:00
return (
<>
<div>
2021-05-11 15:52:50 +00:00
<QRCode className='h-auto mw-100' value={qrValue} renderAs='svg' size={300} />
2021-05-06 21:15:22 +00:00
</div>
<div className='mt-3 w-100'>
2021-05-13 13:28:38 +00:00
<CopyInput type='text' placeholder={invoice.bolt11} readOnly />
2021-05-06 21:15:22 +00:00
</div>
2021-05-13 13:28:38 +00:00
<InvoiceStatus variant={variant} status={status} />
2021-05-06 21:15:22 +00:00
</>
)
}
2021-05-11 15:52:50 +00:00
export function InvoiceSkeleton ({ status }) {
2021-05-06 21:15:22 +00:00
return (
<>
<div className='h-auto w-100 clouds' style={{ paddingTop: 'min(300px, 100%)', maxWidth: '300px' }} />
<div className='mt-3 w-100'>
2021-05-13 13:28:38 +00:00
<InputSkeleton />
2021-05-06 21:15:22 +00:00
</div>
2021-05-13 13:28:38 +00:00
<InvoiceStatus variant='default' status={status} />
2021-05-06 21:15:22 +00:00
</>
)
}