From b15390685cbc60512c0cc6c143e7de259dabaaed Mon Sep 17 00:00:00 2001 From: Peyman Date: Sun, 2 Jun 2024 12:58:23 +0330 Subject: [PATCH] Fix wallet amount condition Fix retry status after giving up --- .../ports/postgres/impl/FinancialActionPersisterImpl.kt | 5 +++-- .../opex/wallet/ports/postgres/impl/WalletManagerImpl.kt | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/FinancialActionPersisterImpl.kt b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/FinancialActionPersisterImpl.kt index 3e41b0a99..8a74ba7b6 100644 --- a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/FinancialActionPersisterImpl.kt +++ b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/FinancialActionPersisterImpl.kt @@ -103,14 +103,15 @@ class FinancialActionPersisterImpl( //Do nothing } else { with(retryModel) { + val giveUp = retries + 1 >= retryCount faRetryRepository.scheduleNext( id!!, retries + 1, LocalDateTime.now().plusSeconds(retries * delayMultiplier * delaySeconds), - retries >= retryCount + giveUp ).awaitSingleOrNull() - if (hasGivenUp) + if (giveUp) status = FinancialActionStatus.ERROR } } diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/WalletManagerImpl.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/WalletManagerImpl.kt index a9cbb25ef..4ced9dce1 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/WalletManagerImpl.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/impl/WalletManagerImpl.kt @@ -79,7 +79,7 @@ class WalletManagerImpl( } override suspend fun isWithdrawAllowed(wallet: Wallet, amount: BigDecimal): Boolean { - if (amount <= BigDecimal.ZERO) + if (amount < BigDecimal.ZERO) throw OpexError.InvalidAmount.exception() var evaluate = wallet.balance.amount >= amount