diff --git a/app/src/main/java/com/plcoding/cryptocurrencyappyt/presentation/coin_detail/CoinDetailViewModel.kt b/app/src/main/java/com/plcoding/cryptocurrencyappyt/presentation/coin_detail/CoinDetailViewModel.kt index b1ed800..e3eb410 100644 --- a/app/src/main/java/com/plcoding/cryptocurrencyappyt/presentation/coin_detail/CoinDetailViewModel.kt +++ b/app/src/main/java/com/plcoding/cryptocurrencyappyt/presentation/coin_detail/CoinDetailViewModel.kt @@ -31,18 +31,12 @@ class CoinDetailViewModel @Inject constructor( private fun getCoin(coinId: String) { getCoinUseCase(coinId).onEach { result -> - when (result) { - is Resource.Success -> { - _state.value = CoinDetailState(coin = result.data) - } - is Resource.Error -> { - _state.value = CoinDetailState( + _state.value = when (result) { + is Resource.Success -> CoinDetailState(coin = result.data) + is Resource.Error -> CoinDetailState( error = result.message ?: "An unexpected error occured" ) - } - is Resource.Loading -> { - _state.value = CoinDetailState(isLoading = true) - } + is Resource.Loading -> CoinDetailState(isLoading = true) } }.launchIn(viewModelScope) } diff --git a/app/src/main/java/com/plcoding/cryptocurrencyappyt/presentation/coin_list/CoinListViewModel.kt b/app/src/main/java/com/plcoding/cryptocurrencyappyt/presentation/coin_list/CoinListViewModel.kt index 1d8e7ff..cec03f9 100644 --- a/app/src/main/java/com/plcoding/cryptocurrencyappyt/presentation/coin_list/CoinListViewModel.kt +++ b/app/src/main/java/com/plcoding/cryptocurrencyappyt/presentation/coin_list/CoinListViewModel.kt @@ -25,18 +25,12 @@ class CoinListViewModel @Inject constructor( private fun getCoins() { getCoinsUseCase().onEach { result -> - when (result) { - is Resource.Success -> { - _state.value = CoinListState(coins = result.data ?: emptyList()) - } - is Resource.Error -> { - _state.value = CoinListState( + _state.value = when (result) { + is Resource.Success -> CoinListState(coins = result.data ?: emptyList()) + is Resource.Error -> CoinListState( error = result.message ?: "An unexpected error occured" ) - } - is Resource.Loading -> { - _state.value = CoinListState(isLoading = true) - } + is Resource.Loading -> CoinListState(isLoading = true) } }.launchIn(viewModelScope) }