diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/component/preview/PreviewManageTokensComponent.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/component/preview/PreviewManageTokensComponent.kt index a0058fc2e9..abecdf97cb 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/component/preview/PreviewManageTokensComponent.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/component/preview/PreviewManageTokensComponent.kt @@ -27,6 +27,7 @@ import kotlinx.coroutines.flow.update internal class PreviewManageTokensComponent( private val isLoading: Boolean, + private val showTangemIcon: Boolean, params: ManageTokensComponent.Params, ) : ManageTokensComponent { @@ -65,6 +66,7 @@ internal class PreviewManageTokensComponent( loadMore = { false }, saveChanges = {}, isSavingInProgress = false, + needToAddDerivations = showTangemIcon, ), ) diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/managetokens/ManageTokensUM.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/managetokens/ManageTokensUM.kt index d16e17e84a..708b149aca 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/managetokens/ManageTokensUM.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/entity/managetokens/ManageTokensUM.kt @@ -42,6 +42,7 @@ internal sealed class ManageTokensUM { val saveChanges: () -> Unit, val hasChanges: Boolean, val isSavingInProgress: Boolean, + val needToAddDerivations: Boolean, ) : ManageTokensUM() fun copySealed( @@ -52,6 +53,7 @@ internal sealed class ManageTokensUM { isNextBatchLoading: Boolean = this.isNextBatchLoading, isSavingInProgress: Boolean = this is ManageContent && this.isSavingInProgress, scrollToTop: StateEvent = this.scrollToTop, + needToAddDerivations: Boolean = this is ManageContent && this.needToAddDerivations, ): ManageTokensUM { return when (this) { is ManageContent -> copy( @@ -62,6 +64,7 @@ internal sealed class ManageTokensUM { isNextBatchLoading = isNextBatchLoading, isSavingInProgress = isSavingInProgress, scrollToTop = scrollToTop, + needToAddDerivations = needToAddDerivations, ) is ReadContent -> copy( search = search, diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/ManageTokensModel.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/ManageTokensModel.kt index f5375b9b43..36916e335d 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/ManageTokensModel.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/model/ManageTokensModel.kt @@ -17,6 +17,7 @@ import com.tangem.core.ui.event.triggeredEvent import com.tangem.core.ui.extensions.resourceReference import com.tangem.core.ui.extensions.stringReference import com.tangem.core.ui.message.SnackbarMessage +import com.tangem.domain.card.HasMissedDerivationsUseCase import com.tangem.domain.managetokens.SaveManagedTokensUseCase import com.tangem.domain.wallets.models.UserWalletId import com.tangem.features.managetokens.analytics.CustomTokenAnalyticsEvent @@ -47,6 +48,7 @@ internal class ManageTokensModel @Inject constructor( private val router: Router, private val manageTokensListManager: ManageTokensListManager, private val messageSender: UiMessageSender, + private val hasMissedDerivationsUseCase: HasMissedDerivationsUseCase, private val saveManagedTokensUseCase: SaveManagedTokensUseCase, private val analyticsEventHandler: AnalyticsEventHandler, paramsContainer: ParamsContainer, @@ -140,6 +142,7 @@ internal class ManageTokensModel @Inject constructor( hasChanges = false, saveChanges = ::saveChanges, loadMore = ::loadMoreItems, + needToAddDerivations = false, isSavingInProgress = false, ) } @@ -255,10 +258,22 @@ internal class ManageTokensModel @Inject constructor( } private fun updateChangedItems(currenciesToAdd: ChangedCurrencies, currenciesToRemove: ChangedCurrencies) { - state.update { state -> - state.copySealed( - hasChanges = currenciesToAdd.isNotEmpty() || currenciesToRemove.isNotEmpty(), - ) + modelScope.launch { + val hasMissedDerivations = params.userWalletId?.let { walletId -> + val networks = currenciesToAdd.values + .flatten() + .toSet() + .associate { it.backendId to null } + + hasMissedDerivationsUseCase(walletId, networks) + } + + state.update { state -> + state.copySealed( + hasChanges = currenciesToAdd.isNotEmpty() || currenciesToRemove.isNotEmpty(), + needToAddDerivations = hasMissedDerivations ?: false, + ) + } } } diff --git a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/ui/ManageTokensScreen.kt b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/ui/ManageTokensScreen.kt index 6b2547a8fd..2d604c67ee 100644 --- a/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/ui/ManageTokensScreen.kt +++ b/features/manage-tokens/impl/src/main/kotlin/com/tangem/features/managetokens/ui/ManageTokensScreen.kt @@ -33,11 +33,17 @@ import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.compose.ui.unit.dp import androidx.compose.ui.util.fastForEachIndexed -import com.tangem.core.ui.components.* +import com.tangem.core.ui.components.BottomFade +import com.tangem.core.ui.components.RectangleShimmer +import com.tangem.core.ui.components.TangemSwitch +import com.tangem.core.ui.components.TextShimmer import com.tangem.core.ui.components.appbar.TangemTopAppBar import com.tangem.core.ui.components.appbar.models.TopAppBarButtonUM import com.tangem.core.ui.components.buttons.SecondarySmallButton import com.tangem.core.ui.components.buttons.SmallButtonConfig +import com.tangem.core.ui.components.buttons.common.TangemButton +import com.tangem.core.ui.components.buttons.common.TangemButtonIconPosition +import com.tangem.core.ui.components.buttons.common.TangemButtonsDefaults import com.tangem.core.ui.components.currency.icon.CurrencyIcon import com.tangem.core.ui.components.currency.icon.CurrencyIconState import com.tangem.core.ui.components.fields.SearchBar @@ -122,6 +128,7 @@ internal fun ManageTokensScreen(state: ManageTokensUM, modifier: Modifier = Modi .fillMaxWidth(), isVisible = state.hasChanges, showProgress = state.isSavingInProgress, + showIcon = state.needToAddDerivations, onClick = state.saveChanges, ) } @@ -158,6 +165,7 @@ private fun ManageTokensTopBar(topBar: ManageTokensTopBarUM?, search: SearchBarU private fun SaveChangesButton( isVisible: Boolean, showProgress: Boolean, + showIcon: Boolean, onClick: () -> Unit, modifier: Modifier = Modifier, ) { @@ -168,10 +176,17 @@ private fun SaveChangesButton( exit = fadeOut(), label = "save_button_visibility", ) { - PrimaryButtonIconEnd( + TangemButton( text = stringResource(id = R.string.common_save), - iconResId = R.drawable.ic_tangem_24, + icon = if (showIcon) { + TangemButtonIconPosition.End(R.drawable.ic_tangem_24) + } else { + TangemButtonIconPosition.None + }, showProgress = showProgress, + colors = TangemButtonsDefaults.primaryButtonColors, + enabled = true, + animateContentChange = true, onClick = onClick, ) } @@ -472,6 +487,7 @@ private class PreviewManageTokensComponentProvider : PreviewParameterProvider