Skip to content

Commit

Permalink
fix: stuck saved currency on Receive screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Syn-McJ committed Aug 21, 2023
1 parent 187e5ea commit 854de6a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -119,4 +122,10 @@ class EnterAmountViewModel @Inject constructor(
suspend fun getSelectedCurrencyCode(): String {
return walletUIConfig.getExchangeCurrencyCode()
}

fun resetCurrency() {
viewModelScope.launch {
_selectedCurrencyCode.value = walletUIConfig.getExchangeCurrencyCode()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ class ReceiveFragment : Fragment(R.layout.fragment_receive) {
dialogFragment.show(requireActivity())
}
}

override fun onDestroy() {
enterAmountViewModel.resetCurrency()
super.onDestroy()
}
}

0 comments on commit 854de6a

Please sign in to comment.