Updated on 2026-08-14

This commit is contained in:
Tangem 2023-12-11 18:26:02 +02:00
parent ca612b304c
commit 6ef8539672
5 changed files with 63 additions and 40 deletions

View file

@ -579,14 +579,18 @@ internal class StateBuilder(
}
}
fun createInitialErrorState(uiState: SwapStateHolder, onRefreshClick: () -> Unit): SwapStateHolder {
fun createInitialErrorState(
uiState: SwapStateHolder,
code: Int,
onRefreshClick: () -> Unit,
): SwapStateHolder {
return uiState.copy(
warnings = listOf(
SwapWarning.GeneralWarning(
notificationConfig = NotificationConfig(
title = TextReference.Res(R.string.warning_express_refresh_required_title),
subtitle = TextReference.EMPTY,
iconResId = R.drawable.ic_alert_circle_24,
subtitle = TextReference.Res(R.string.generic_error_code, wrappedList(code)),
iconResId = R.drawable.ic_alert_triangle_20,
buttonsState = NotificationConfig.ButtonsState.PrimaryButtonConfig(
text = TextReference.Res(R.string.warning_button_refresh),
onClick = onRefreshClick,

View file

@ -18,6 +18,7 @@ import com.tangem.feature.swap.analytics.SwapEvents
import com.tangem.feature.swap.domain.BlockchainInteractor
import com.tangem.feature.swap.domain.SwapInteractor
import com.tangem.feature.swap.domain.models.DataError
import com.tangem.feature.swap.domain.models.ExpressException
import com.tangem.feature.swap.domain.models.domain.PermissionOptions
import com.tangem.feature.swap.domain.models.domain.SwapDataModel
import com.tangem.feature.swap.domain.models.domain.SwapProvider
@ -174,13 +175,14 @@ internal class SwapViewModel @Inject constructor(
selectedCurrency = null,
)
uiState = stateBuilder.createInitialErrorState(uiState) {
uiState = stateBuilder.createInitialLoadingState(
initialCurrency = initialCryptoCurrency,
networkInfo = blockchainInteractor.getBlockchainInfo(initialCryptoCurrency.network.backendId),
)
initTokens()
}
uiState =
stateBuilder.createInitialErrorState(uiState, (it as? ExpressException)?.dataError?.code ?: DataError.UnknownError.code) {
uiState = stateBuilder.createInitialLoadingState(
initialCurrency = initialCryptoCurrency,
networkInfo = blockchainInteractor.getBlockchainInfo(initialCryptoCurrency.network.backendId),
)
initTokens()
}
}
}
}