import { useState, useEffect } from 'react' import { numWithUnits } from '@/lib/format' import AccordianItem from './accordian-item' import Qr, { QrSkeleton } from './qr' import { CompactLongCountdown } from './countdown' import PayerData from './payer-data' import Bolt11Info from './bolt11-info' import { useQuery } from '@apollo/client' import { INVOICE } from '@/fragments/wallet' import { FAST_POLL_INTERVAL, SSR } from '@/lib/constants' import { NoAttachedWalletError } from '@/wallets/errors' import ItemJob from './item-job' import Item from './item' import { CommentFlat } from './comment' import classNames from 'classnames' import Moon from '@/svgs/moon-fill.svg' export default function Invoice ({ id, query = INVOICE, modal, onPayment, onCanceled, info, successVerb = 'deposited', heldVerb = 'settling', useWallet = true, walletError, poll, waitFor, ...props }) { const [expired, setExpired] = useState(false) const { data, error } = useQuery(query, SSR ? {} : { pollInterval: FAST_POLL_INTERVAL, variables: { id }, nextFetchPolicy: 'cache-and-network', skip: !poll }) const invoice = data?.invoice useEffect(() => { if (!invoice) { return } if (waitFor?.(invoice)) { onPayment?.(invoice) } if (invoice.cancelled || invoice.actionError) { onCanceled?.(invoice) } setExpired(new Date(invoice.expiredAt) <= new Date()) }, [invoice, onPayment, setExpired]) if (error) { return
{walletError.message}
{JSON.stringify(nostr, null, 2)}
}
/>
: null}