From 854de6a971c49a4d4f8f298c55722b6002473114 Mon Sep 17 00:00:00 2001 From: Andrei Ashikhmin Date: Mon, 21 Aug 2023 08:08:47 +0700 Subject: [PATCH] fix: stuck saved currency on Receive screen --- .../ui/enter_amount/EnterAmountViewModel.kt | 15 ++++++++++++--- .../wallet/ui/payments/ReceiveFragment.kt | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/org/dash/wallet/common/ui/enter_amount/EnterAmountViewModel.kt b/common/src/main/java/org/dash/wallet/common/ui/enter_amount/EnterAmountViewModel.kt index d227994dab..ab4e97de03 100644 --- a/common/src/main/java/org/dash/wallet/common/ui/enter_amount/EnterAmountViewModel.kt +++ b/common/src/main/java/org/dash/wallet/common/ui/enter_amount/EnterAmountViewModel.kt @@ -96,15 +96,18 @@ class EnterAmountViewModel @Inject constructor( } init { + // User picked a currency on the Enter Amount screen _selectedCurrencyCode .filterNotNull() .flatMapLatest(exchangeRates::observeExchangeRate) .onEach(_selectedExchangeRate::postValue) .launchIn(viewModelScope) - viewModelScope.launch { - selectedCurrencyCode = walletUIConfig.getExchangeCurrencyCode() - } + // User changed the currency in Settings + walletUIConfig.observe(WalletUIConfig.SELECTED_CURRENCY) + .filterNotNull() + .onEach { _selectedCurrencyCode.value = it } + .launchIn(viewModelScope) } fun setMaxAmount(coin: Coin) { @@ -119,4 +122,10 @@ class EnterAmountViewModel @Inject constructor( suspend fun getSelectedCurrencyCode(): String { return walletUIConfig.getExchangeCurrencyCode() } + + fun resetCurrency() { + viewModelScope.launch { + _selectedCurrencyCode.value = walletUIConfig.getExchangeCurrencyCode() + } + } } diff --git a/wallet/src/de/schildbach/wallet/ui/payments/ReceiveFragment.kt b/wallet/src/de/schildbach/wallet/ui/payments/ReceiveFragment.kt index 3785b33d6f..383f6c3d05 100644 --- a/wallet/src/de/schildbach/wallet/ui/payments/ReceiveFragment.kt +++ b/wallet/src/de/schildbach/wallet/ui/payments/ReceiveFragment.kt @@ -77,4 +77,9 @@ class ReceiveFragment : Fragment(R.layout.fragment_receive) { dialogFragment.show(requireActivity()) } } + + override fun onDestroy() { + enterAmountViewModel.resetCurrency() + super.onDestroy() + } }