Fix filter for wallets that can send
Testing for canSend is not enough since it can also return true if the wallet is not enabled. This is the case because we want to allow disabling wallets but canSend must still return true in this case if send is configured. This should probably be changed such that canSend only returns true when the wallet is enabled without preventing disabling of wallets.
This commit is contained in:
parent
b1cdd953a0
commit
14a92ee5ce
|
@ -34,7 +34,7 @@ export function useWalletPayment () {
|
|||
|
||||
const walletsWithPayments = useMemo(() => {
|
||||
return wallets
|
||||
.filter(wallet => canSend(wallet))
|
||||
.filter(wallet => canSend(wallet) && wallet.config.enabled)
|
||||
.map(wallet => {
|
||||
const logger = loggers[wallet.def.name]
|
||||
return {
|
||||
|
@ -48,6 +48,12 @@ export function useWalletPayment () {
|
|||
let walletError = new WalletAggregateError([])
|
||||
let walletInvoice = invoice
|
||||
|
||||
// throw a special error that caller can handle separately if no payment was attempted
|
||||
const noWalletAvailable = walletsWithPayments.length === 0
|
||||
if (noWalletAvailable) {
|
||||
throw new WalletsNotAvailableError()
|
||||
}
|
||||
|
||||
for (const [i, wallet] of walletsWithPayments.entries()) {
|
||||
const controller = invoiceController(walletInvoice, invoiceHelper.isInvoice)
|
||||
try {
|
||||
|
@ -94,13 +100,6 @@ export function useWalletPayment () {
|
|||
}
|
||||
|
||||
// if we reach this line, no wallet payment succeeded
|
||||
|
||||
// throw a special error that caller can handle separately if no payment was attempted
|
||||
const noWalletAvailable = walletError.errors.every(e => e instanceof WalletConfigurationError)
|
||||
if (noWalletAvailable) {
|
||||
throw new WalletsNotAvailableError()
|
||||
}
|
||||
|
||||
// only return payment errors
|
||||
const paymentErrors = walletError.errors.filter(e => e instanceof WalletPaymentError)
|
||||
throw new WalletAggregateError(paymentErrors, walletInvoice)
|
||||
|
|
Loading…
Reference in New Issue