Fix insufficient funds error detection
This commit is contained in:
		
							parent
							
								
									773f658e00
								
							
						
					
					
						commit
						1cd9750be5
					
				@ -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 (
 | 
			
		||||
                <FundError
 | 
			
		||||
@ -191,6 +190,7 @@ export default function UpVote ({ item, className, pendingSats, setPendingSats }
 | 
			
		||||
            })
 | 
			
		||||
            return
 | 
			
		||||
          }
 | 
			
		||||
          if (!timerRef.current) return
 | 
			
		||||
          throw new Error({ message: error.toString() })
 | 
			
		||||
        }
 | 
			
		||||
      }, 500, pendingSats)
 | 
			
		||||
 | 
			
		||||
@ -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 = {
 | 
			
		||||
  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 (
 | 
			
		||||
              <FundError
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user