Updated on 2026-08-14
This commit is contained in:
parent
4bb7fde041
commit
4341673767
20 changed files with 276 additions and 351 deletions
|
|
@ -2,7 +2,6 @@ package com.tangem.features.details.entity
|
|||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import com.tangem.common.ui.userwallet.state.UserWalletItemUM
|
||||
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
||||
|
|
@ -12,5 +11,4 @@ internal data class UserWalletListUM(
|
|||
val isWalletSavingInProgress: Boolean,
|
||||
val addNewWalletText: TextReference,
|
||||
val onAddNewWalletClick: () -> Unit,
|
||||
val addWalletBottomSheet: TangemBottomSheetConfig = TangemBottomSheetConfig.Empty,
|
||||
)
|
||||
|
|
@ -6,14 +6,8 @@ import com.tangem.core.decompose.di.ModelScoped
|
|||
import com.tangem.core.decompose.model.Model
|
||||
import com.tangem.core.decompose.navigation.Router
|
||||
import com.tangem.core.decompose.ui.UiMessageSender
|
||||
import com.tangem.core.navigation.url.UrlOpener
|
||||
import com.tangem.core.ui.R.*
|
||||
import com.tangem.core.ui.components.bottomsheets.BottomSheetOption
|
||||
import com.tangem.core.ui.components.bottomsheets.OptionsBottomSheetContent
|
||||
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.domain.wallets.usecase.GenerateBuyTangemCardLinkUseCase
|
||||
import com.tangem.domain.wallets.usecase.ShouldSaveUserWalletsUseCase
|
||||
import com.tangem.features.details.entity.UserWalletListUM
|
||||
import com.tangem.features.details.impl.R
|
||||
|
|
@ -27,7 +21,6 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
|
|
@ -38,8 +31,6 @@ internal class UserWalletListModel @Inject constructor(
|
|||
private val router: Router,
|
||||
private val messageSender: UiMessageSender,
|
||||
override val dispatchers: CoroutineDispatcherProvider,
|
||||
private val generateBuyTangemCardLinkUseCase: GenerateBuyTangemCardLinkUseCase,
|
||||
private val urlOpener: UrlOpener,
|
||||
private val userWalletSaver: UserWalletSaver,
|
||||
private val hotWalletFeatureToggles: HotWalletFeatureToggles,
|
||||
) : Model() {
|
||||
|
|
@ -58,7 +49,6 @@ internal class UserWalletListModel @Inject constructor(
|
|||
isWalletSavingInProgress = false,
|
||||
addNewWalletText = TextReference.EMPTY,
|
||||
onAddNewWalletClick = ::onAddNewWalletClick,
|
||||
addWalletBottomSheet = TangemBottomSheetConfig.Empty,
|
||||
),
|
||||
)
|
||||
|
||||
|
|
@ -90,62 +80,11 @@ internal class UserWalletListModel @Inject constructor(
|
|||
|
||||
private fun onAddNewWalletClick() {
|
||||
if (hotWalletFeatureToggles.isHotWalletEnabled) {
|
||||
state.update { currentState ->
|
||||
currentState.copy(
|
||||
addWalletBottomSheet = TangemBottomSheetConfig(
|
||||
isShown = true,
|
||||
onDismissRequest = ::dismissAddWalletBottomSheet,
|
||||
content = createAddWalletBottomSheetContent(),
|
||||
),
|
||||
)
|
||||
}
|
||||
router.push(AppRoute.CreateWalletSelection)
|
||||
} else {
|
||||
withProgress(isWalletSavingInProgress) {
|
||||
userWalletSaver.scanAndSaveUserWallet(modelScope)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun dismissAddWalletBottomSheet() {
|
||||
state.update { currentState ->
|
||||
currentState.copy(
|
||||
addWalletBottomSheet = currentState.addWalletBottomSheet.copy(isShown = false),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createAddWalletBottomSheetContent(): OptionsBottomSheetContent {
|
||||
return OptionsBottomSheetContent(
|
||||
options = persistentListOf(
|
||||
BottomSheetOption(
|
||||
key = ADD_WALLET_KEY_CREATE,
|
||||
label = resourceReference(string.home_button_create_new_wallet),
|
||||
),
|
||||
BottomSheetOption(
|
||||
key = ADD_WALLET_KEY_ADD,
|
||||
label = resourceReference(string.home_button_add_existing_wallet),
|
||||
),
|
||||
BottomSheetOption(
|
||||
key = ADD_WALLET_KEY_BUY,
|
||||
label = resourceReference(string.details_buy_wallet),
|
||||
),
|
||||
),
|
||||
onOptionClick = { optionKey ->
|
||||
dismissAddWalletBottomSheet()
|
||||
when (optionKey) {
|
||||
ADD_WALLET_KEY_CREATE -> router.push(AppRoute.CreateWalletSelection)
|
||||
ADD_WALLET_KEY_ADD -> router.push(AppRoute.AddExistingWallet)
|
||||
ADD_WALLET_KEY_BUY -> modelScope.launch {
|
||||
generateBuyTangemCardLinkUseCase.invoke().let { urlOpener.openUrl(it) }
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val ADD_WALLET_KEY_CREATE = "create"
|
||||
private const val ADD_WALLET_KEY_ADD = "add"
|
||||
private const val ADD_WALLET_KEY_BUY = "buy"
|
||||
}
|
||||
}
|
||||
|
|
@ -15,13 +15,9 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
|
||||
import com.tangem.common.ui.userwallet.UserWalletItem
|
||||
import com.tangem.core.ui.R.*
|
||||
import com.tangem.core.ui.components.block.BlockCard
|
||||
import com.tangem.core.ui.components.bottomsheets.OptionsBottomSheet
|
||||
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
|
||||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.resolveReference
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.res.TangemTheme
|
||||
import com.tangem.core.ui.res.TangemThemePreview
|
||||
import com.tangem.features.details.component.UserWalletListComponent
|
||||
|
|
@ -48,8 +44,6 @@ internal fun UserWalletListBlock(state: UserWalletListUM, modifier: Modifier = M
|
|||
onClick = state.onAddNewWalletClick,
|
||||
)
|
||||
}
|
||||
|
||||
AddWalletBottomSheet(state.addWalletBottomSheet)
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
|
@ -100,15 +94,6 @@ private fun AddWalletButton(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AddWalletBottomSheet(config: TangemBottomSheetConfig) {
|
||||
OptionsBottomSheet(
|
||||
config = config,
|
||||
title = resourceReference(string.auth_info_add_wallet_title),
|
||||
containerColor = TangemTheme.colors.background.tertiary,
|
||||
)
|
||||
}
|
||||
|
||||
// region Preview
|
||||
@Composable
|
||||
@Preview(showBackground = true, widthDp = 360)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue