Skip to content

Commit

Permalink
[PWN-9256] Fixes for validation logic and error handling (stop timer …
Browse files Browse the repository at this point in the history
…if error came)
  • Loading branch information
Elizaveta Semenova committed Jul 21, 2023
1 parent 1434d98 commit 55c9a84
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct WithdrawCalculatorView: View {
action: viewModel.actionPressed.send
)
.padding(.top, 12)
.padding(.bottom, 36)
.padding(.bottom, 16)
.background(Color(Asset.Colors.smoke.color).edgesIgnoringSafeArea(.bottom))
})
.scrollDismissesKeyboard()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,28 @@ private extension WithdrawCalculatorViewModel {
$fromAmount.eraseToAnyPublisher(),
$toAmount.eraseToAnyPublisher()
)
.filter { $0.0 != nil } // Only if $exchangeRates is not failed. Otherwise it has own state
.sink { [weak self] _, fromAmount, toAmount in
guard let self else { return }
switch (fromAmount, toAmount) {
case (nil, _), (Double.zero, _):
self.actionData = .zero
self.fromAmountTextColor = Asset.Colors.night.color
case (fromAmount, toAmount) where fromAmount > self.fromBalance:
self.actionData = WithdrawCalculatorAction(isEnabled: false, title: L10n.notEnoughMoney)
self.fromAmountTextColor = Asset.Colors.rose.color
case (fromAmount, toAmount) where toAmount < Constants.EUR.min:
case (fromAmount, toAmount) where toAmount > Constants.EUR.max:
actionData = WithdrawCalculatorAction(
isEnabled: false,
title: L10n.asMinimalAmountForTransfer(Constants.EUR.min.formattedFiat(currency: .eur))
title: L10n.onlyPerOneTransfer(Constants.EUR.max.formattedFiat(currency: .eur))
)
self.fromAmountTextColor = Asset.Colors.rose.color
case (fromAmount, toAmount) where toAmount > Constants.EUR.max:
case (fromAmount, toAmount) where toAmount < Constants.EUR.min:
actionData = WithdrawCalculatorAction(
isEnabled: false,
title: L10n.onlyPerOneTransfer(Constants.EUR.max.formattedFiat(currency: .eur))
title: L10n.asMinimalAmountForTransfer(Constants.EUR.min.formattedFiat(currency: .eur))
)
self.fromAmountTextColor = Asset.Colors.rose.color
case (fromAmount, toAmount) where fromAmount > self.fromBalance:
self.actionData = WithdrawCalculatorAction(isEnabled: false, title: L10n.notEnoughMoney)
self.fromAmountTextColor = Asset.Colors.rose.color
default:
actionData = WithdrawCalculatorAction(isEnabled: true, title: L10n.next.uppercaseFirst)
self.fromAmountTextColor = Asset.Colors.night.color
Expand Down Expand Up @@ -216,8 +217,8 @@ private extension WithdrawCalculatorViewModel {
reachability
.isDisconnected
.sink { [weak self] in
self?.cancelUpdate()
self?.notificationService.showConnectionErrorNotification()
self?.commonErrorHandling()
}
.store(in: &subscriptions)
}
Expand All @@ -236,6 +237,7 @@ private extension WithdrawCalculatorViewModel {
exchangeRatesFailCount = 0
scheduleRatesUpdate()
changeEditing(isEnabled: true)
isFromFirstResponder = true
} catch let error as NSError where error.isNetworkConnectionError {
notificationService.showConnectionErrorNotification()
commonErrorHandling()
Expand All @@ -252,6 +254,7 @@ private extension WithdrawCalculatorViewModel {
}

func commonErrorHandling() {
cancelUpdate()
arePricesLoading = false
actionData = WithdrawCalculatorAction.failure
exchangeRates = nil
Expand Down

0 comments on commit 55c9a84

Please sign in to comment.