Fix pending forwards considered paid by client
This commit is contained in:
parent
756e75ed7c
commit
8cb89574ae
|
@ -4,6 +4,8 @@ import { InvoiceCanceledError, InvoiceExpiredError, WalletReceiverError } from '
|
||||||
import { RETRY_PAID_ACTION } from '@/fragments/paidAction'
|
import { RETRY_PAID_ACTION } from '@/fragments/paidAction'
|
||||||
import { INVOICE, CANCEL_INVOICE } from '@/fragments/wallet'
|
import { INVOICE, CANCEL_INVOICE } from '@/fragments/wallet'
|
||||||
|
|
||||||
|
const PENDING_FORWARD_STATES = ['PENDING_HELD', 'FORWARDING']
|
||||||
|
|
||||||
export default function useInvoice () {
|
export default function useInvoice () {
|
||||||
const client = useApolloClient()
|
const client = useApolloClient()
|
||||||
const [retryPaidAction] = useMutation(RETRY_PAID_ACTION)
|
const [retryPaidAction] = useMutation(RETRY_PAID_ACTION)
|
||||||
|
@ -16,24 +18,29 @@ export default function useInvoice () {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
const { cancelled, cancelledAt, actionError, expiresAt, forwardStatus } = data.invoice
|
const { cancelled, cancelledAt, actionState, actionError, expiresAt, forwardStatus } = data.invoice
|
||||||
|
|
||||||
const expired = cancelledAt && new Date(expiresAt) < new Date(cancelledAt)
|
const expired = cancelledAt && new Date(expiresAt) < new Date(cancelledAt)
|
||||||
if (expired) {
|
if (expired) {
|
||||||
throw new InvoiceExpiredError(data.invoice)
|
throw new InvoiceExpiredError(data.invoice)
|
||||||
}
|
}
|
||||||
|
|
||||||
const failed = cancelled || actionError
|
const failedForward = forwardStatus && forwardStatus !== 'CONFIRMED'
|
||||||
|
if (failedForward) {
|
||||||
if (failed && (forwardStatus && forwardStatus !== 'CONFIRMED')) {
|
|
||||||
throw new WalletReceiverError(data.invoice)
|
throw new WalletReceiverError(data.invoice)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const failed = cancelled || actionError
|
||||||
if (failed) {
|
if (failed) {
|
||||||
throw new InvoiceCanceledError(data.invoice, actionError)
|
throw new InvoiceCanceledError(data.invoice, actionError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { invoice: data.invoice, check: that(data.invoice) }
|
// never let check pass if a forward is pending
|
||||||
|
// see https://github.com/stackernews/stacker.news/issues/1707
|
||||||
|
const pendingForward = PENDING_FORWARD_STATES.includes(actionState)
|
||||||
|
const check = that(data.invoice) && !pendingForward
|
||||||
|
|
||||||
|
return { invoice: data.invoice, check }
|
||||||
}, [client])
|
}, [client])
|
||||||
|
|
||||||
const cancel = useCallback(async ({ hash, hmac }) => {
|
const cancel = useCallback(async ({ hash, hmac }) => {
|
||||||
|
|
Loading…
Reference in New Issue