Skip to content

Commit

Permalink
[PWN-9256] Update only toAmount if rates are changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Elizaveta Semenova committed Jul 20, 2023
1 parent d298f4a commit d02235a
Showing 1 changed file with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private extension WithdrawCalculatorViewModel {
func bindProperties() {
Publishers.CombineLatest(
$fromAmount.eraseToAnyPublisher(),
$exchangeRates.eraseToAnyPublisher()
$exchangeRates.eraseToAnyPublisher() // Calculate only toAmount with newRates and not visa versa
)
.sink { [weak self] amount, rates in
guard let self, let rates else { return }
Expand All @@ -84,20 +84,17 @@ private extension WithdrawCalculatorViewModel {
}
.store(in: &subscriptions)

Publishers.CombineLatest(
$toAmount.eraseToAnyPublisher(),
$exchangeRates.eraseToAnyPublisher()
)
.sink { [weak self] amount, rates in
guard let self, let rates else { return }
var newFromAmount: Double?
if let amount {
newFromAmount = amount / Double(rates.sell)
$toAmount
.sink { [weak self] amount in
guard let self, let rates = self.exchangeRates else { return }
var newFromAmount: Double?
if let amount {
newFromAmount = amount / Double(rates.sell)
}
guard self.fromAmount != newFromAmount else { return }
self.fromAmount = newFromAmount
}
guard self.fromAmount != newFromAmount else { return }
self.fromAmount = newFromAmount
}
.store(in: &subscriptions)
.store(in: &subscriptions)

// Validation
Publishers.CombineLatest3(
Expand Down

0 comments on commit d02235a

Please sign in to comment.