Fix insufficient funds error detection

This commit is contained in:
ekzyis 2023-07-22 22:39:04 +02:00
parent 773f658e00
commit 1cd9750be5
2 changed files with 11 additions and 4 deletions

View File

@ -12,6 +12,7 @@ import Overlay from 'react-bootstrap/Overlay'
import Popover from 'react-bootstrap/Popover' import Popover from 'react-bootstrap/Popover'
import { useShowModal } from './modal' import { useShowModal } from './modal'
import { LightningConsumer } from './lightning' import { LightningConsumer } from './lightning'
import { isInsufficientFundsError } from '../lib/anonymous'
const getColor = (meSats) => { const getColor = (meSats) => {
if (!meSats || meSats <= 10) { if (!meSats || meSats <= 10) {
@ -175,9 +176,7 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats }
} }
}) })
} catch (error) { } catch (error) {
if (!timerRef.current) return if (isInsufficientFundsError(error)) {
if (error.toString().includes('insufficient funds')) {
showModal(onClose => { showModal(onClose => {
return ( return (
<FundError <FundError
@ -191,6 +190,7 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats }
}) })
return return
} }
if (!timerRef.current) return
throw new Error({ message: error.toString() }) throw new Error({ message: error.toString() })
} }
}, 500, pendingSats) }, 500, pendingSats)

View File

@ -92,6 +92,13 @@ const Invoice = ({ id, hash, errorCount, repeat, ...props }) => {
) )
} }
export const isInsufficientFundsError = (error) => {
if (Array.isArray(error)) {
return error.some(({ message }) => message.includes('insufficient funds'))
}
return error.toString().includes('insufficient funds')
}
const defaultOptions = { const defaultOptions = {
forceInvoice: false forceInvoice: false
} }
@ -161,7 +168,7 @@ export const useAnonymous = (fn, options = defaultOptions) => {
try { try {
return await fn(amount, ...args) return await fn(amount, ...args)
} catch (error) { } catch (error) {
if (error.toString().includes('insufficient funds')) { if (isInsufficientFundsError(error)) {
showModal(onClose => { showModal(onClose => {
return ( return (
<FundError <FundError