From d02235a85abfce66473bee9bb8a8a22182458ec0 Mon Sep 17 00:00:00 2001 From: Elizaveta Semenova Date: Thu, 20 Jul 2023 19:03:12 +0300 Subject: [PATCH] [PWN-9256] Update only toAmount if rates are changed --- .../WithdrawCalculatorViewModel.swift | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/p2p_wallet/Scenes/Main/BankTransfer/WithdrawCalculator/WithdrawCalculatorViewModel.swift b/p2p_wallet/Scenes/Main/BankTransfer/WithdrawCalculator/WithdrawCalculatorViewModel.swift index 2f2325298a..714c36cf06 100644 --- a/p2p_wallet/Scenes/Main/BankTransfer/WithdrawCalculator/WithdrawCalculatorViewModel.swift +++ b/p2p_wallet/Scenes/Main/BankTransfer/WithdrawCalculator/WithdrawCalculatorViewModel.swift @@ -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 } @@ -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(