diff --git a/p2p_wallet/Scenes/Main/BankTransfer/WithdrawCalculator/WithdrawCalculatorView.swift b/p2p_wallet/Scenes/Main/BankTransfer/WithdrawCalculator/WithdrawCalculatorView.swift index d6e12e4182..df1fda1946 100644 --- a/p2p_wallet/Scenes/Main/BankTransfer/WithdrawCalculator/WithdrawCalculatorView.swift +++ b/p2p_wallet/Scenes/Main/BankTransfer/WithdrawCalculator/WithdrawCalculatorView.swift @@ -30,11 +30,15 @@ struct WithdrawCalculatorView: View { .padding(.horizontal, 16) } .onAppear { + viewModel.isViewAppeared.send(true) DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { // We need delay because BigInputView is UITextField viewModel.isFromFirstResponder = true } } + .onDisappear { + viewModel.isViewAppeared.send(false) + } } var contentView: some View { diff --git a/p2p_wallet/Scenes/Main/BankTransfer/WithdrawCalculator/WithdrawCalculatorViewModel.swift b/p2p_wallet/Scenes/Main/BankTransfer/WithdrawCalculator/WithdrawCalculatorViewModel.swift index a4b4bc9047..a6b6c3cf1e 100644 --- a/p2p_wallet/Scenes/Main/BankTransfer/WithdrawCalculator/WithdrawCalculatorViewModel.swift +++ b/p2p_wallet/Scenes/Main/BankTransfer/WithdrawCalculator/WithdrawCalculatorViewModel.swift @@ -24,6 +24,7 @@ final class WithdrawCalculatorViewModel: BaseViewModel, ObservableObject { let openBankTransfer = PassthroughSubject() let openWithdraw = PassthroughSubject() let proceedWithdraw = PassthroughSubject() + let isViewAppeared = PassthroughSubject() @Published var actionData = WithdrawCalculatorAction.zero @Published var isLoading = false @@ -55,7 +56,6 @@ final class WithdrawCalculatorViewModel: BaseViewModel, ObservableObject { override init() { super.init() - loadRates() bindProperties() bindReachibility() bindAccounts() @@ -190,6 +190,16 @@ private extension WithdrawCalculatorViewModel { .receive(on: RunLoop.main) .assignWeak(to: \.actionData, on: self) .store(in: &subscriptions) + + isViewAppeared + .sink { [weak self] isAppeared in + if isAppeared { + self?.loadRates() + } else { + self?.cancelUpdate() + } + } + .store(in: &subscriptions) } func bindAccounts() {