stacker.news/wallets/errors.js
soxa f72af08882
fix: WebLN QR fallback for anon users (#1858)
* fix: WebLN QR fallback for anon users

* wip: clear zap color on payment fail

* reverse clearItemMeAnonSats

* webln-specific retry bypass

* cleanup

* send WebLN payment when user is Anon AND on QR

* skip wallet checking on anon

* Use WalletError for all errors in webln.sendPayment

---------

Co-authored-by: ekzyis <ek@stacker.news>
Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
2025-03-01 16:56:18 -06:00

103 lines
2.8 KiB
JavaScript

export class InvoiceCanceledError extends Error {
constructor (invoice, actionError) {
super(actionError ?? `invoice canceled: ${invoice.hash}`)
this.name = 'InvoiceCanceledError'
this.invoice = invoice
this.actionError = actionError
}
}
export class InvoiceExpiredError extends Error {
constructor (invoice) {
super(`invoice expired: ${invoice.hash}`)
this.name = 'InvoiceExpiredError'
this.invoice = invoice
}
}
export class WalletError extends Error {}
export class WalletPaymentError extends WalletError {}
export class WalletConfigurationError extends WalletError {}
export class WalletNotEnabledError extends WalletConfigurationError {
constructor (name) {
super(`wallet is not enabled: ${name}`)
this.name = 'WalletNotEnabledError'
this.wallet = name
this.reason = 'wallet is not enabled'
}
}
export class WalletSendNotConfiguredError extends WalletConfigurationError {
constructor (name) {
super(`wallet send is not configured: ${name}`)
this.name = 'WalletSendNotConfiguredError'
this.wallet = name
this.reason = 'wallet send is not configured'
}
}
export class WalletSenderError extends WalletPaymentError {
constructor (name, invoice, message) {
super(`${name} failed to pay invoice ${invoice.hash}: ${message}`)
this.name = 'WalletSenderError'
this.wallet = name
this.invoice = invoice
this.reason = message
}
}
export class WalletReceiverError extends WalletPaymentError {
constructor (invoice) {
super(`payment forwarding failed for invoice ${invoice.hash}`)
this.name = 'WalletReceiverError'
this.invoice = invoice
}
}
export class WalletsNotAvailableError extends WalletConfigurationError {
constructor () {
super('no wallet available')
this.name = 'WalletsNotAvailableError'
}
}
export class AnonWalletError extends WalletConfigurationError {
constructor () {
super('anon cannot pay with wallets')
this.name = 'AnonWalletError'
}
}
export class WalletAggregateError extends WalletError {
constructor (errors, invoice) {
super('WalletAggregateError')
this.name = 'WalletAggregateError'
this.errors = errors.reduce((acc, e) => {
if (Array.isArray(e?.errors)) {
acc.push(...e.errors)
} else {
acc.push(e)
}
return acc
}, [])
this.invoice = invoice
}
}
export class WalletPaymentAggregateError extends WalletPaymentError {
constructor (errors, invoice) {
super('WalletPaymentAggregateError')
this.name = 'WalletPaymentAggregateError'
this.errors = errors.reduce((acc, e) => {
if (Array.isArray(e?.errors)) {
acc.push(...e.errors)
} else {
acc.push(e)
}
return acc
}, []).filter(e => e instanceof WalletPaymentError)
this.invoice = invoice
}
}