Fix payments if recv-only wallet enabled

This commit is contained in:
ekzyis 2024-11-26 04:27:44 +01:00
parent d99caa43fc
commit ed82d9cfc0
2 changed files with 16 additions and 3 deletions

View File

@ -21,6 +21,13 @@ export class WalletNotEnabledError extends Error {
}
}
export class WalletSendNotConfiguredError extends Error {
constructor (name) {
super(`wallet send is not configured: ${name}`)
this.name = 'WalletSendNotConfiguredError'
}
}
export class SenderError extends Error {
constructor (name, invoice, message) {
super(`${name} failed to pay invoice ${invoice.hash}: ${message}`)

View File

@ -5,7 +5,8 @@ import { formatSats } from '@/lib/format'
import { useWalletLogger } from '@/components/wallet-logger'
import { useInvoice } from '@/components/payment'
import { FAST_POLL_INTERVAL } from '@/lib/constants'
import { NoWalletAvailableError, SenderError, WalletAggregateError, WalletNotEnabledError } from '@/wallets/errors'
import { NoWalletAvailableError, SenderError, WalletAggregateError, WalletNotEnabledError, WalletSendNotConfiguredError } from '@/wallets/errors'
import { canSend } from './common'
export function useWalletPayment () {
const { wallets } = useWallets()
@ -56,7 +57,7 @@ export function useWalletPayment () {
} catch (err) {
// cancel invoice to make sure it cannot be paid later.
// we only need to do this if payment was attempted which is not the case if the wallet is not enabled.
const paymentAttempt = !(err instanceof WalletNotEnabledError)
const paymentAttempt = !(err instanceof WalletNotEnabledError || err instanceof WalletSendNotConfiguredError)
if (paymentAttempt) {
await invoiceHelper.cancel(walletInvoice)
@ -74,7 +75,8 @@ export function useWalletPayment () {
// try next wallet if the payment failed because of the wallet
// and not because it expired or was canceled
if (err instanceof WalletNotEnabledError || err instanceof SenderError) {
const isWalletError = err instanceof WalletNotEnabledError || err instanceof WalletSendNotConfiguredError || err instanceof SenderError
if (isWalletError) {
walletError = new WalletAggregateError([...walletError.errors, err], walletInvoice)
continue
}
@ -145,6 +147,10 @@ function sendPayment (wallet, logger) {
throw new WalletNotEnabledError(wallet.def.name)
}
if (!canSend(wallet)) {
throw new WalletSendNotConfiguredError(wallet.def.name)
}
const { bolt11, satsRequested } = invoice
logger.info(`↗ sending payment: ${formatSats(satsRequested)}`, { bolt11 })