From 1a75708b603c58b0a581dd03929740690669b2e6 Mon Sep 17 00:00:00 2001 From: bakyt Date: Wed, 12 Jun 2024 15:08:04 +0600 Subject: [PATCH] Handle error state --- .../topcoins/MarketTopCoinsViewModel2.kt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsViewModel2.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsViewModel2.kt index f46c32ce25..a2fad7e89c 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsViewModel2.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/market/topcoins/MarketTopCoinsViewModel2.kt @@ -71,9 +71,13 @@ class MarketTopCoinsViewModel2( init { viewModelScope.launch(Dispatchers.Default) { - reload() + try { + reload() - viewState = ViewState.Success + viewState = ViewState.Success + } catch (e: Throwable) { + viewState = ViewState.Error(e) + } emitState() } @@ -89,9 +93,13 @@ class MarketTopCoinsViewModel2( viewModelScope.launch(Dispatchers.Default) { currencyManager.baseCurrencyUpdatedFlow.collect { - reload() + try { + reload() - viewState = ViewState.Success + viewState = ViewState.Success + } catch (e: Throwable) { + viewState = ViewState.Error(e) + } emitState() } @@ -146,9 +154,13 @@ class MarketTopCoinsViewModel2( emitState() viewModelScope.launch(Dispatchers.Default) { - reload() + try { + reload() - viewState = ViewState.Success + viewState = ViewState.Success + } catch (e: Throwable) { + viewState = ViewState.Error(e) + } isRefreshing = false emitState()