2023-08-08 18:19:31 +00:00
|
|
|
import AccordianItem from './accordian-item'
|
2023-01-18 18:49:20 +00:00
|
|
|
import Qr from './qr'
|
2023-08-08 21:04:06 +00:00
|
|
|
import { numWithUnits } from '../lib/format'
|
2021-05-06 21:15:22 +00:00
|
|
|
|
|
|
|
export function Invoice ({ invoice }) {
|
2021-05-13 13:28:38 +00:00
|
|
|
let variant = 'default'
|
2021-05-11 15:52:50 +00:00
|
|
|
let status = 'waiting for you'
|
2023-08-08 18:19:31 +00:00
|
|
|
let webLn = true
|
2021-05-11 15:52:50 +00:00
|
|
|
if (invoice.confirmedAt) {
|
2021-05-13 13:28:38 +00:00
|
|
|
variant = 'confirmed'
|
2023-08-08 21:04:06 +00:00
|
|
|
status = `${numWithUnits(invoice.satsReceived, { abbreviate: false })} deposited`
|
2023-08-08 18:19:31 +00:00
|
|
|
webLn = false
|
2021-05-11 15:52:50 +00:00
|
|
|
} else if (invoice.cancelled) {
|
2021-05-13 13:28:38 +00:00
|
|
|
variant = 'failed'
|
2021-05-11 15:52:50 +00:00
|
|
|
status = 'cancelled'
|
2023-08-08 18:19:31 +00:00
|
|
|
webLn = false
|
2021-05-11 15:52:50 +00:00
|
|
|
} 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'
|
2023-08-08 18:19:31 +00:00
|
|
|
webLn = false
|
2021-05-11 15:52:50 +00:00
|
|
|
}
|
2021-05-06 21:15:22 +00:00
|
|
|
|
2023-08-08 18:19:31 +00:00
|
|
|
const { nostr } = invoice
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Qr webLn={webLn} value={invoice.bolt11} statusVariant={variant} status={status} />
|
|
|
|
<div className='w-100'>
|
|
|
|
{nostr
|
|
|
|
? <AccordianItem
|
|
|
|
header='Nostr Zap Request'
|
|
|
|
body={
|
|
|
|
<pre>
|
|
|
|
<code>
|
|
|
|
{JSON.stringify(nostr, null, 2)}
|
|
|
|
</code>
|
|
|
|
</pre>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
: null}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
2021-05-06 21:15:22 +00:00
|
|
|
}
|