stacker.news/pages/invoices/[id].js

43 lines
927 B
JavaScript
Raw Normal View History

2021-05-06 21:15:22 +00:00
import { useQuery } from '@apollo/client'
import gql from 'graphql-tag'
2021-06-27 03:09:39 +00:00
import { Invoice } from '../../components/invoice'
import { LnQRSkeleton } from '../../components/lnqr'
2021-05-06 21:15:22 +00:00
import LayoutCenter from '../../components/layout-center'
export async function getServerSideProps ({ params: { id } }) {
return {
props: {
id
}
}
}
export default function FullInvoice ({ id }) {
const query = gql`
{
2021-05-11 15:52:50 +00:00
invoice(id: ${id}) {
id
bolt11
msatsReceived
cancelled
confirmedAt
expiresAt
}
2021-05-06 21:15:22 +00:00
}`
return (
<LayoutCenter>
<LoadInvoice query={query} />
</LayoutCenter>
)
}
function LoadInvoice ({ query }) {
2021-05-11 15:52:50 +00:00
const { loading, error, data } = useQuery(query, { pollInterval: 1000 })
2021-05-06 21:15:22 +00:00
if (error) return <div>error</div>
if (!data || loading) {
2021-06-27 03:09:39 +00:00
return <LnQRSkeleton status='loading' />
2021-05-06 21:15:22 +00:00
}
return <Invoice invoice={data.invoice} />
}