Fix payments if recv-only wallet enabled
This commit is contained in:
parent
d99caa43fc
commit
ed82d9cfc0
@ -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 {
|
export class SenderError extends Error {
|
||||||
constructor (name, invoice, message) {
|
constructor (name, invoice, message) {
|
||||||
super(`${name} failed to pay invoice ${invoice.hash}: ${message}`)
|
super(`${name} failed to pay invoice ${invoice.hash}: ${message}`)
|
||||||
|
@ -5,7 +5,8 @@ import { formatSats } from '@/lib/format'
|
|||||||
import { useWalletLogger } from '@/components/wallet-logger'
|
import { useWalletLogger } from '@/components/wallet-logger'
|
||||||
import { useInvoice } from '@/components/payment'
|
import { useInvoice } from '@/components/payment'
|
||||||
import { FAST_POLL_INTERVAL } from '@/lib/constants'
|
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 () {
|
export function useWalletPayment () {
|
||||||
const { wallets } = useWallets()
|
const { wallets } = useWallets()
|
||||||
@ -56,7 +57,7 @@ export function useWalletPayment () {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
// cancel invoice to make sure it cannot be paid later.
|
// 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.
|
// 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) {
|
if (paymentAttempt) {
|
||||||
await invoiceHelper.cancel(walletInvoice)
|
await invoiceHelper.cancel(walletInvoice)
|
||||||
|
|
||||||
@ -74,7 +75,8 @@ export function useWalletPayment () {
|
|||||||
|
|
||||||
// try next wallet if the payment failed because of the wallet
|
// try next wallet if the payment failed because of the wallet
|
||||||
// and not because it expired or was canceled
|
// 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)
|
walletError = new WalletAggregateError([...walletError.errors, err], walletInvoice)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -145,6 +147,10 @@ function sendPayment (wallet, logger) {
|
|||||||
throw new WalletNotEnabledError(wallet.def.name)
|
throw new WalletNotEnabledError(wallet.def.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!canSend(wallet)) {
|
||||||
|
throw new WalletSendNotConfiguredError(wallet.def.name)
|
||||||
|
}
|
||||||
|
|
||||||
const { bolt11, satsRequested } = invoice
|
const { bolt11, satsRequested } = invoice
|
||||||
|
|
||||||
logger.info(`↗ sending payment: ${formatSats(satsRequested)}`, { bolt11 })
|
logger.info(`↗ sending payment: ${formatSats(satsRequested)}`, { bolt11 })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user