diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/UiActions.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/UiActions.kt index a4fa64ab24..48a3d55f55 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/UiActions.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/models/UiActions.kt @@ -15,6 +15,7 @@ data class UiActions( val openPermissionBottomSheet: () -> Unit, val onChangeApproveType: (ApproveType) -> Unit, // region new actions + val onRetryClick: () -> Unit, val onClickFee: () -> Unit, val onSelectFeeType: (TxFee) -> Unit, val onProviderClick: (String) -> Unit, diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt index 094eac3c40..a1c6e1e09f 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/ui/StateBuilder.kt @@ -429,6 +429,17 @@ internal class StateBuilder( iconResId = R.drawable.ic_alert_circle_24, ), ) + is DataError.UnknownError -> SwapWarning.GeneralWarning( + notificationConfig = NotificationConfig( + title = resourceReference(R.string.common_error), + subtitle = resourceReference(R.string.swapping_generic_error), + iconResId = R.drawable.img_attention_20, + buttonsState = NotificationConfig.ButtonsState.SecondaryButtonConfig( + text = resourceReference(R.string.warning_button_refresh), + onClick = actions.onRetryClick, + ), + ), + ) else -> SwapWarning.GeneralWarning( notificationConfig = NotificationConfig( title = resourceReference(R.string.common_error), diff --git a/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapViewModel.kt b/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapViewModel.kt index e37c581deb..51bc827a3b 100644 --- a/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapViewModel.kt +++ b/features/swap/presentation/src/main/java/com/tangem/feature/swap/viewmodels/SwapViewModel.kt @@ -338,6 +338,9 @@ internal class SwapViewModel @Inject constructor( ) } is SwapState.SwapError -> { + if (state.error is DataError.UnknownError) { + singleTaskScheduler.cancelTask() + } uiState = stateBuilder.createQuotesErrorState( uiStateHolder = uiState, swapProvider = provider, @@ -422,6 +425,7 @@ internal class SwapViewModel @Inject constructor( } } + @Suppress("LongMethod") private fun onSwapClick() { singleTaskScheduler.cancelTask() uiState = stateBuilder.createSwapInProgressState(uiState) @@ -833,6 +837,9 @@ internal class SwapViewModel @Inject constructor( swapRouter.openTokenDetails(it.walletId, swapInteractor.getNativeToken(dataState.networkId)) } }, + onRetryClick = { + startLoadingQuotesFromLastState() + }, ) }