From 1cd9750be5e6a625c6f068b1a2f2f9c00fa60152 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sat, 22 Jul 2023 22:39:04 +0200 Subject: [PATCH] Fix insufficient funds error detection --- components/upvote.js | 6 +++--- lib/anonymous.js | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/components/upvote.js b/components/upvote.js index a04e69a4..95ec48e5 100644 --- a/components/upvote.js +++ b/components/upvote.js @@ -12,6 +12,7 @@ import Overlay from 'react-bootstrap/Overlay' import Popover from 'react-bootstrap/Popover' import { useShowModal } from './modal' import { LightningConsumer } from './lightning' +import { isInsufficientFundsError } from '../lib/anonymous' const getColor = (meSats) => { if (!meSats || meSats <= 10) { @@ -175,9 +176,7 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats } } }) } catch (error) { - if (!timerRef.current) return - - if (error.toString().includes('insufficient funds')) { + if (isInsufficientFundsError(error)) { showModal(onClose => { return ( { ) } +export const isInsufficientFundsError = (error) => { + if (Array.isArray(error)) { + return error.some(({ message }) => message.includes('insufficient funds')) + } + return error.toString().includes('insufficient funds') +} + const defaultOptions = { forceInvoice: false } @@ -161,7 +168,7 @@ export const useAnonymous = (fn, options = defaultOptions) => { try { return await fn(amount, ...args) } catch (error) { - if (error.toString().includes('insufficient funds')) { + if (isInsufficientFundsError(error)) { showModal(onClose => { return (