Updated on 2026-08-14
This commit is contained in:
commit
59daa44548
15 changed files with 143 additions and 60 deletions
|
|
@ -169,6 +169,7 @@ private fun handleWalletAction(action: Action) {
|
||||||
is OnboardingWalletAction.FinishOnboarding -> {
|
is OnboardingWalletAction.FinishOnboarding -> {
|
||||||
store.dispatch(GlobalAction.Onboarding.Stop)
|
store.dispatch(GlobalAction.Onboarding.Stop)
|
||||||
navigateToWalletScreen()
|
navigateToWalletScreen()
|
||||||
|
store.dispatch(BackupAction.DiscardBackup)
|
||||||
}
|
}
|
||||||
is OnboardingWalletAction.ResumeBackup -> {
|
is OnboardingWalletAction.ResumeBackup -> {
|
||||||
val newAction = when (val backupState = backupService.currentState) {
|
val newAction = when (val backupState = backupService.currentState) {
|
||||||
|
|
|
||||||
|
|
@ -537,7 +537,7 @@ class OnboardingWalletFragment :
|
||||||
val cardIdFormatter = CardIdFormatter(CardIdDisplayFormat.LastMasked(4))
|
val cardIdFormatter = CardIdFormatter(CardIdDisplayFormat.LastMasked(4))
|
||||||
getString(
|
getString(
|
||||||
R.string.onboarding_subtitle_scan_backup_card_format,
|
R.string.onboarding_subtitle_scan_backup_card_format,
|
||||||
state.primaryCardId?.let { cardIdFormatter.getFormattedCardId(it) },
|
cardIdFormatter.getFormattedCardId(state.backupCardIds[cardNumber - 1]),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,11 @@ internal fun OkHttpClient.Builder.addHeaders(requestHeaders: Map<String, Provide
|
||||||
return addInterceptor(
|
return addInterceptor(
|
||||||
Interceptor { chain ->
|
Interceptor { chain ->
|
||||||
val request = chain.request().newBuilder().apply {
|
val request = chain.request().newBuilder().apply {
|
||||||
requestHeaders.forEach { addHeader(it.key, it.value.invoke()) }
|
requestHeaders.forEach {
|
||||||
|
val value = it.value.invoke()
|
||||||
|
|
||||||
|
if (value.isNotBlank()) addHeader(name = it.key, value = value)
|
||||||
|
}
|
||||||
}.build()
|
}.build()
|
||||||
|
|
||||||
chain.proceed(request)
|
chain.proceed(request)
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,8 @@ internal class SwapViewModel @Inject constructor(
|
||||||
private val fromTokenBalanceJobHolder = JobHolder()
|
private val fromTokenBalanceJobHolder = JobHolder()
|
||||||
private val toTokenBalanceJobHolder = JobHolder()
|
private val toTokenBalanceJobHolder = JobHolder()
|
||||||
|
|
||||||
|
private var isAmountChangedByUser: Boolean = false
|
||||||
|
|
||||||
val currentScreen: SwapNavScreen
|
val currentScreen: SwapNavScreen
|
||||||
get() = swapRouter.currentScreen
|
get() = swapRouter.currentScreen
|
||||||
|
|
||||||
|
|
@ -480,11 +482,22 @@ internal class SwapViewModel @Inject constructor(
|
||||||
val currentSelected = dataState.selectedProvider
|
val currentSelected = dataState.selectedProvider
|
||||||
if (currentSelected != null && consideredProviders.keys.contains(currentSelected)) {
|
if (currentSelected != null && consideredProviders.keys.contains(currentSelected)) {
|
||||||
// logic for always choose best if already selected provider
|
// logic for always choose best if already selected provider
|
||||||
bestQuotesProvider ?: currentSelected
|
if (isAmountChangedByUser) {
|
||||||
|
isAmountChangedByUser = false
|
||||||
|
bestQuotesProvider ?: currentSelected
|
||||||
|
} else {
|
||||||
|
currentSelected
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
val recommendedProvider = successLoadedData.keys.firstOrNull { it.isRecommended }
|
val recommendedProvider = successLoadedData.keys.firstOrNull { it.isRecommended }
|
||||||
triggerPromoProviderEvent(recommendedProvider, bestQuotesProvider)
|
triggerPromoProviderEvent(recommendedProvider, bestQuotesProvider)
|
||||||
recommendedProvider ?: bestQuotesProvider ?: consideredProviders.keys.first()
|
|
||||||
|
if (isAmountChangedByUser) {
|
||||||
|
isAmountChangedByUser = false
|
||||||
|
recommendedProvider ?: bestQuotesProvider ?: consideredProviders.keys.first()
|
||||||
|
} else {
|
||||||
|
recommendedProvider ?: consideredProviders.keys.first()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state.keys.first()
|
state.keys.first()
|
||||||
|
|
@ -775,6 +788,11 @@ internal class SwapViewModel @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dataState.fromCryptoCurrency != null && dataState.tokensDataState != null) {
|
||||||
|
isAmountChangedByUser = true
|
||||||
|
}
|
||||||
|
|
||||||
dataState = dataState.copy(
|
dataState = dataState.copy(
|
||||||
fromCryptoCurrency = fromToken,
|
fromCryptoCurrency = fromToken,
|
||||||
toCryptoCurrency = toToken,
|
toCryptoCurrency = toToken,
|
||||||
|
|
@ -828,6 +846,8 @@ internal class SwapViewModel @Inject constructor(
|
||||||
val newToToken = dataState.fromCryptoCurrency
|
val newToToken = dataState.fromCryptoCurrency
|
||||||
|
|
||||||
if (newFromToken != null && newToToken != null) {
|
if (newFromToken != null && newToToken != null) {
|
||||||
|
isAmountChangedByUser = true
|
||||||
|
|
||||||
dataState = dataState.copy(
|
dataState = dataState.copy(
|
||||||
fromCryptoCurrency = newFromToken,
|
fromCryptoCurrency = newFromToken,
|
||||||
toCryptoCurrency = newToToken,
|
toCryptoCurrency = newToToken,
|
||||||
|
|
@ -859,10 +879,16 @@ internal class SwapViewModel @Inject constructor(
|
||||||
val decimals = fromToken.currency.decimals
|
val decimals = fromToken.currency.decimals
|
||||||
val cutValue = cutAmountWithDecimals(decimals, value)
|
val cutValue = cutAmountWithDecimals(decimals, value)
|
||||||
lastAmount.value = cutValue
|
lastAmount.value = cutValue
|
||||||
uiState =
|
uiState = stateBuilder.updateSwapAmount(
|
||||||
stateBuilder.updateSwapAmount(uiState, inputNumberFormatter.formatWithThousands(cutValue, decimals))
|
uiState = uiState,
|
||||||
|
amount = inputNumberFormatter.formatWithThousands(cutValue, decimals),
|
||||||
|
)
|
||||||
|
|
||||||
if (toToken != null) {
|
if (toToken != null) {
|
||||||
|
if (toToken.value.amount != null) {
|
||||||
|
isAmountChangedByUser = true
|
||||||
|
}
|
||||||
|
|
||||||
amountDebouncer.debounce(viewModelScope, DEBOUNCE_AMOUNT_DELAY) {
|
amountDebouncer.debounce(viewModelScope, DEBOUNCE_AMOUNT_DELAY) {
|
||||||
startLoadingQuotes(
|
startLoadingQuotes(
|
||||||
fromToken = fromToken,
|
fromToken = fromToken,
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,21 @@ import com.tangem.domain.common.util.cardTypesResolver
|
||||||
import com.tangem.domain.common.util.getCardsCount
|
import com.tangem.domain.common.util.getCardsCount
|
||||||
import com.tangem.domain.demo.DemoConfig
|
import com.tangem.domain.demo.DemoConfig
|
||||||
import com.tangem.domain.wallets.models.UserWallet
|
import com.tangem.domain.wallets.models.UserWallet
|
||||||
|
import com.tangem.domain.wallets.repository.WalletsRepository
|
||||||
import com.tangem.feature.wallet.impl.R
|
import com.tangem.feature.wallet.impl.R
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wallet image resolver
|
* Wallet image resolver
|
||||||
*
|
*
|
||||||
|
* @property walletsRepository wallets repository
|
||||||
|
*
|
||||||
[REDACTED_AUTHOR]
|
[REDACTED_AUTHOR]
|
||||||
*/
|
*/
|
||||||
internal object WalletImageResolver {
|
internal class WalletImageResolver @Inject constructor(
|
||||||
|
private val walletsRepository: WalletsRepository,
|
||||||
private const val WALLET_WITHOUT_BACKUP_COUNT = 1
|
) {
|
||||||
private const val WALLET_WITH_ONE_BACKUP_COUNT = 2
|
|
||||||
private const val WALLET_WITH_TWO_BACKUPS_COUNT = 3
|
|
||||||
|
|
||||||
/** Get a specified wallet [userWallet] image */
|
/** Get a specified wallet [userWallet] image */
|
||||||
@Suppress("CyclomaticComplexMethod")
|
@Suppress("CyclomaticComplexMethod")
|
||||||
|
|
@ -36,6 +39,7 @@ internal object WalletImageResolver {
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
cardTypesResolver.isDevKit() -> R.drawable.ill_dev_120_106
|
cardTypesResolver.isDevKit() -> R.drawable.ill_dev_120_106
|
||||||
|
userWallet.isRing() -> userWallet.resolveWalletWithRing()
|
||||||
cobrandImage != null -> userWallet.resolveWallet2Cobrand(image = cobrandImage)
|
cobrandImage != null -> userWallet.resolveWallet2Cobrand(image = cobrandImage)
|
||||||
cardTypesResolver.isWallet2() -> userWallet.resolveWallet2()
|
cardTypesResolver.isWallet2() -> userWallet.resolveWallet2()
|
||||||
cardTypesResolver.isShibaWallet() -> userWallet.resolveShibaWallet()
|
cardTypesResolver.isShibaWallet() -> userWallet.resolveShibaWallet()
|
||||||
|
|
@ -48,6 +52,18 @@ internal object WalletImageResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun UserWallet.isRing(): Boolean {
|
||||||
|
return scanResponse.cardTypesResolver.isRing() ||
|
||||||
|
runBlocking { walletsRepository.isWalletWithRing(userWalletId = this@isRing.walletId) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun UserWallet.resolveWalletWithRing(): Int? {
|
||||||
|
return resolveWallet2(
|
||||||
|
oneBackupResId = R.drawable.ill_card_with_ring_120_106,
|
||||||
|
twoBackupResId = R.drawable.ill_card2_with_ring_120_106,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun UserWallet.resolveWallet2Cobrand(image: Wallet2CobrandImage): Int? {
|
private fun UserWallet.resolveWallet2Cobrand(image: Wallet2CobrandImage): Int? {
|
||||||
return resolveWallet2(oneBackupResId = image.cards2ResId, twoBackupResId = image.cards3ResId)
|
return resolveWallet2(oneBackupResId = image.cards2ResId, twoBackupResId = image.cards3ResId)
|
||||||
}
|
}
|
||||||
|
|
@ -90,4 +106,10 @@ internal object WalletImageResolver {
|
||||||
|
|
||||||
return if (count != null) resolve(count) else null
|
return if (count != null) resolve(count) else null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
const val WALLET_WITHOUT_BACKUP_COUNT = 1
|
||||||
|
const val WALLET_WITH_ONE_BACKUP_COUNT = 2
|
||||||
|
const val WALLET_WITH_TWO_BACKUPS_COUNT = 3
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.tangem.feature.wallet.presentation.wallet.state.transformers
|
package com.tangem.feature.wallet.presentation.wallet.state.transformers
|
||||||
|
|
||||||
import com.tangem.domain.wallets.models.UserWallet
|
import com.tangem.domain.wallets.models.UserWallet
|
||||||
|
import com.tangem.feature.wallet.presentation.wallet.domain.WalletImageResolver
|
||||||
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState
|
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState
|
||||||
import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletLoadingStateFactory
|
import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletLoadingStateFactory
|
||||||
import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents
|
import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents
|
||||||
|
|
@ -9,10 +10,14 @@ import kotlinx.collections.immutable.toImmutableList
|
||||||
internal class AddWalletTransformer(
|
internal class AddWalletTransformer(
|
||||||
private val userWallet: UserWallet,
|
private val userWallet: UserWallet,
|
||||||
private val clickIntents: WalletClickIntents,
|
private val clickIntents: WalletClickIntents,
|
||||||
|
private val walletImageResolver: WalletImageResolver,
|
||||||
) : WalletScreenStateTransformer {
|
) : WalletScreenStateTransformer {
|
||||||
|
|
||||||
private val walletLoadingStateFactory by lazy {
|
private val walletLoadingStateFactory by lazy {
|
||||||
WalletLoadingStateFactory(clickIntents = clickIntents)
|
WalletLoadingStateFactory(
|
||||||
|
clickIntents = clickIntents,
|
||||||
|
walletImageResolver = walletImageResolver,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun transform(prevState: WalletScreenState): WalletScreenState {
|
override fun transform(prevState: WalletScreenState): WalletScreenState {
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,12 @@ internal class InitializeWalletsTransformer(
|
||||||
private val selectedWalletIndex: Int,
|
private val selectedWalletIndex: Int,
|
||||||
private val wallets: List<UserWallet>,
|
private val wallets: List<UserWallet>,
|
||||||
private val clickIntents: WalletClickIntents,
|
private val clickIntents: WalletClickIntents,
|
||||||
|
private val walletImageResolver: WalletImageResolver,
|
||||||
) : WalletScreenStateTransformer {
|
) : WalletScreenStateTransformer {
|
||||||
|
|
||||||
private val walletLoadingStateFactory by lazy { WalletLoadingStateFactory(clickIntents = clickIntents) }
|
private val walletLoadingStateFactory by lazy {
|
||||||
|
WalletLoadingStateFactory(clickIntents = clickIntents, walletImageResolver = walletImageResolver)
|
||||||
|
}
|
||||||
|
|
||||||
override fun transform(prevState: WalletScreenState): WalletScreenState {
|
override fun transform(prevState: WalletScreenState): WalletScreenState {
|
||||||
return prevState.copy(
|
return prevState.copy(
|
||||||
|
|
@ -78,7 +81,7 @@ internal class InitializeWalletsTransformer(
|
||||||
id = walletId,
|
id = walletId,
|
||||||
title = name,
|
title = name,
|
||||||
additionalInfo = WalletAdditionalInfoFactory.resolve(wallet = this),
|
additionalInfo = WalletAdditionalInfoFactory.resolve(wallet = this),
|
||||||
imageResId = WalletImageResolver.resolve(userWallet = this),
|
imageResId = walletImageResolver.resolve(userWallet = this),
|
||||||
onRenameClick = clickIntents::onRenameBeforeConfirmationClick,
|
onRenameClick = clickIntents::onRenameBeforeConfirmationClick,
|
||||||
onDeleteClick = clickIntents::onDeleteBeforeConfirmationClick,
|
onDeleteClick = clickIntents::onDeleteBeforeConfirmationClick,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.tangem.feature.wallet.presentation.wallet.state.transformers
|
||||||
|
|
||||||
import com.tangem.domain.wallets.models.UserWallet
|
import com.tangem.domain.wallets.models.UserWallet
|
||||||
import com.tangem.domain.wallets.models.UserWalletId
|
import com.tangem.domain.wallets.models.UserWalletId
|
||||||
|
import com.tangem.feature.wallet.presentation.wallet.domain.WalletImageResolver
|
||||||
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState
|
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState
|
||||||
import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletLoadingStateFactory
|
import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletLoadingStateFactory
|
||||||
import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents
|
import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntents
|
||||||
|
|
@ -20,9 +21,12 @@ internal class ReinitializeWalletTransformer(
|
||||||
private val prevWalletId: UserWalletId,
|
private val prevWalletId: UserWalletId,
|
||||||
private val newUserWallet: UserWallet,
|
private val newUserWallet: UserWallet,
|
||||||
private val clickIntents: WalletClickIntents,
|
private val clickIntents: WalletClickIntents,
|
||||||
|
private val walletImageResolver: WalletImageResolver,
|
||||||
) : WalletScreenStateTransformer {
|
) : WalletScreenStateTransformer {
|
||||||
|
|
||||||
private val walletLoadingStateFactory by lazy { WalletLoadingStateFactory(clickIntents = clickIntents) }
|
private val walletLoadingStateFactory by lazy {
|
||||||
|
WalletLoadingStateFactory(clickIntents = clickIntents, walletImageResolver = walletImageResolver)
|
||||||
|
}
|
||||||
|
|
||||||
override fun transform(prevState: WalletScreenState): WalletScreenState {
|
override fun transform(prevState: WalletScreenState): WalletScreenState {
|
||||||
return prevState.copy(
|
return prevState.copy(
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.tangem.feature.wallet.presentation.wallet.state.transformers
|
||||||
|
|
||||||
import com.tangem.domain.wallets.models.UserWallet
|
import com.tangem.domain.wallets.models.UserWallet
|
||||||
import com.tangem.domain.wallets.models.UserWalletId
|
import com.tangem.domain.wallets.models.UserWalletId
|
||||||
|
import com.tangem.feature.wallet.presentation.wallet.domain.WalletImageResolver
|
||||||
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState
|
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletScreenState
|
||||||
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState
|
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletState
|
||||||
import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletLoadingStateFactory
|
import com.tangem.feature.wallet.presentation.wallet.state.utils.WalletLoadingStateFactory
|
||||||
|
|
@ -12,9 +13,12 @@ import timber.log.Timber
|
||||||
internal class UnlockWalletTransformer(
|
internal class UnlockWalletTransformer(
|
||||||
private val unlockedWallets: List<UserWallet>,
|
private val unlockedWallets: List<UserWallet>,
|
||||||
private val clickIntents: WalletClickIntents,
|
private val clickIntents: WalletClickIntents,
|
||||||
|
private val walletImageResolver: WalletImageResolver,
|
||||||
) : WalletScreenStateTransformer {
|
) : WalletScreenStateTransformer {
|
||||||
|
|
||||||
private val walletLoadingStateFactory by lazy { WalletLoadingStateFactory(clickIntents = clickIntents) }
|
private val walletLoadingStateFactory by lazy {
|
||||||
|
WalletLoadingStateFactory(clickIntents = clickIntents, walletImageResolver = walletImageResolver)
|
||||||
|
}
|
||||||
|
|
||||||
override fun transform(prevState: WalletScreenState): WalletScreenState {
|
override fun transform(prevState: WalletScreenState): WalletScreenState {
|
||||||
return prevState.copy(
|
return prevState.copy(
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import timber.log.Timber
|
||||||
|
|
||||||
internal class UpdateWalletCardsCountTransformer(
|
internal class UpdateWalletCardsCountTransformer(
|
||||||
private val userWallet: UserWallet,
|
private val userWallet: UserWallet,
|
||||||
|
private val walletImageResolver: WalletImageResolver,
|
||||||
) : WalletStateTransformer(userWallet.walletId) {
|
) : WalletStateTransformer(userWallet.walletId) {
|
||||||
|
|
||||||
override fun transform(prevState: WalletState): WalletState {
|
override fun transform(prevState: WalletState): WalletState {
|
||||||
|
|
@ -37,7 +38,7 @@ internal class UpdateWalletCardsCountTransformer(
|
||||||
return when (this) {
|
return when (this) {
|
||||||
is WalletCardState.Content -> copy(
|
is WalletCardState.Content -> copy(
|
||||||
additionalInfo = WalletAdditionalInfoFactory.resolve(wallet = userWallet),
|
additionalInfo = WalletAdditionalInfoFactory.resolve(wallet = userWallet),
|
||||||
imageResId = WalletImageResolver.resolve(userWallet = userWallet),
|
imageResId = walletImageResolver.resolve(userWallet = userWallet),
|
||||||
cardCount = userWallet.getCardsCount(),
|
cardCount = userWallet.getCardsCount(),
|
||||||
)
|
)
|
||||||
else -> this
|
else -> this
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,10 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
*
|
*
|
||||||
* @property clickIntents click intents
|
* @property clickIntents click intents
|
||||||
*/
|
*/
|
||||||
internal class WalletLoadingStateFactory(private val clickIntents: WalletClickIntents) {
|
internal class WalletLoadingStateFactory(
|
||||||
|
private val clickIntents: WalletClickIntents,
|
||||||
|
private val walletImageResolver: WalletImageResolver,
|
||||||
|
) {
|
||||||
|
|
||||||
fun create(userWallet: UserWallet): WalletState {
|
fun create(userWallet: UserWallet): WalletState {
|
||||||
return userWallet.createStateByWalletType(
|
return userWallet.createStateByWalletType(
|
||||||
|
|
@ -80,7 +83,7 @@ internal class WalletLoadingStateFactory(private val clickIntents: WalletClickIn
|
||||||
id = walletId,
|
id = walletId,
|
||||||
title = name,
|
title = name,
|
||||||
additionalInfo = if (isMultiCurrency) WalletAdditionalInfoFactory.resolve(wallet = this) else null,
|
additionalInfo = if (isMultiCurrency) WalletAdditionalInfoFactory.resolve(wallet = this) else null,
|
||||||
imageResId = WalletImageResolver.resolve(userWallet = this),
|
imageResId = walletImageResolver.resolve(userWallet = this),
|
||||||
onRenameClick = clickIntents::onRenameBeforeConfirmationClick,
|
onRenameClick = clickIntents::onRenameBeforeConfirmationClick,
|
||||||
onDeleteClick = clickIntents::onDeleteBeforeConfirmationClick,
|
onDeleteClick = clickIntents::onDeleteBeforeConfirmationClick,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,11 @@
|
||||||
package com.tangem.feature.wallet.presentation.wallet.ui.components.common
|
package com.tangem.feature.wallet.presentation.wallet.ui.components.common
|
||||||
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.compose.animation.AnimatedContent
|
import androidx.compose.animation.*
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.animation.fadeOut
|
|
||||||
import androidx.compose.animation.togetherWith
|
|
||||||
import androidx.compose.foundation.LocalIndication
|
import androidx.compose.foundation.LocalIndication
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.gestures.detectTapGestures
|
import androidx.compose.foundation.gestures.detectTapGestures
|
||||||
|
|
@ -26,9 +25,11 @@ import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.layout.onSizeChanged
|
import androidx.compose.ui.layout.onSizeChanged
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.platform.LocalHapticFeedback
|
import androidx.compose.ui.platform.LocalHapticFeedback
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
|
@ -54,7 +55,7 @@ import com.tangem.feature.wallet.impl.R
|
||||||
import com.tangem.feature.wallet.presentation.common.WalletPreviewData
|
import com.tangem.feature.wallet.presentation.common.WalletPreviewData
|
||||||
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState
|
import com.tangem.feature.wallet.presentation.wallet.state.model.WalletCardState
|
||||||
|
|
||||||
// private const val HALF_OF_ITEM_WIDTH = 0.5
|
private const val HALF_OF_ITEM_WIDTH = 0.5
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wallet card
|
* Wallet card
|
||||||
|
|
@ -116,33 +117,31 @@ internal fun WalletCard(state: WalletCardState, isBalanceHidden: Boolean, modifi
|
||||||
bottom.linkTo(anchor = parent.bottom, margin = contentVerticalMargin)
|
bottom.linkTo(anchor = parent.bottom, margin = contentVerticalMargin)
|
||||||
|
|
||||||
if (additionalText != null) {
|
if (additionalText != null) {
|
||||||
width = Dimension.wrapContent
|
width = if (state.imageResId != null) {
|
||||||
// TODO: [REDACTED_JIRA]
|
end.linkTo(imageRef.start)
|
||||||
// width = if (state.imageResId != null) {
|
Dimension.fillToConstraints
|
||||||
// end.linkTo(imageRef.start)
|
} else {
|
||||||
// Dimension.fillToConstraints
|
Dimension.wrapContent
|
||||||
// } else {
|
}
|
||||||
// Dimension.wrapContent
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: [REDACTED_JIRA]
|
|
||||||
// If balance has a large width then image must be hidden
|
// If balance has a large width then image must be hidden
|
||||||
// val hasSpaceForImage by remember(key1 = balanceWidth, key2 = itemSize.width) {
|
val hasSpaceForImage by remember(key1 = balanceWidth, key2 = itemSize.width) {
|
||||||
// mutableStateOf(value = balanceWidth < itemSize.width * HALF_OF_ITEM_WIDTH)
|
mutableStateOf(value = balanceWidth < itemSize.width * HALF_OF_ITEM_WIDTH)
|
||||||
// }
|
}
|
||||||
// if (hasSpaceForImage) {
|
|
||||||
// Image(
|
if (hasSpaceForImage) {
|
||||||
// id = state.imageResId,
|
Image(
|
||||||
// modifier = Modifier.constrainAs(imageRef) {
|
id = state.imageResId,
|
||||||
// end.linkTo(parent.end)
|
modifier = Modifier.constrainAs(imageRef) {
|
||||||
// bottom.linkTo(parent.bottom)
|
end.linkTo(parent.end)
|
||||||
// height = Dimension.fillToConstraints
|
bottom.linkTo(parent.bottom)
|
||||||
// },
|
height = Dimension.fillToConstraints
|
||||||
// )
|
},
|
||||||
// }
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -371,19 +370,19 @@ private fun LockedContent(modifier: Modifier = Modifier) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Composable
|
@Composable
|
||||||
// private fun Image(@DrawableRes id: Int?, modifier: Modifier = Modifier) {
|
private fun Image(@DrawableRes id: Int?, modifier: Modifier = Modifier) {
|
||||||
// AnimatedVisibility(visible = id != null, modifier = modifier) {
|
AnimatedVisibility(visible = id != null, modifier = modifier) {
|
||||||
// val imageRes = id ?: return@AnimatedVisibility
|
val imageRes = id ?: return@AnimatedVisibility
|
||||||
//
|
|
||||||
// Image(
|
Image(
|
||||||
// painter = painterResource(id = imageRes),
|
painter = painterResource(id = imageRes),
|
||||||
// contentDescription = null,
|
contentDescription = null,
|
||||||
// modifier = Modifier.width(width = TangemTheme.dimens.size120),
|
modifier = Modifier.width(width = TangemTheme.dimens.size120),
|
||||||
// contentScale = ContentScale.FillWidth,
|
contentScale = ContentScale.FillWidth,
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// region Preview
|
// region Preview
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import com.tangem.feature.wallet.presentation.deeplink.WalletDeepLinksHandler
|
||||||
import com.tangem.feature.wallet.presentation.router.InnerWalletRouter
|
import com.tangem.feature.wallet.presentation.router.InnerWalletRouter
|
||||||
import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent
|
import com.tangem.feature.wallet.presentation.wallet.analytics.WalletScreenAnalyticsEvent
|
||||||
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.SelectedWalletAnalyticsSender
|
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.SelectedWalletAnalyticsSender
|
||||||
|
import com.tangem.feature.wallet.presentation.wallet.domain.WalletImageResolver
|
||||||
import com.tangem.feature.wallet.presentation.wallet.domain.WalletNameMigrationUseCase
|
import com.tangem.feature.wallet.presentation.wallet.domain.WalletNameMigrationUseCase
|
||||||
import com.tangem.feature.wallet.presentation.wallet.loaders.WalletScreenContentLoader
|
import com.tangem.feature.wallet.presentation.wallet.loaders.WalletScreenContentLoader
|
||||||
import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController
|
import com.tangem.feature.wallet.presentation.wallet.state.WalletStateController
|
||||||
|
|
@ -67,6 +68,7 @@ internal class WalletViewModel @Inject constructor(
|
||||||
private val refreshMultiCurrencyWalletQuotesUseCase: RefreshMultiCurrencyWalletQuotesUseCase,
|
private val refreshMultiCurrencyWalletQuotesUseCase: RefreshMultiCurrencyWalletQuotesUseCase,
|
||||||
private val shouldAskPermissionUseCase: ShouldAskPermissionUseCase,
|
private val shouldAskPermissionUseCase: ShouldAskPermissionUseCase,
|
||||||
private val marketsFeatureToggles: MarketsFeatureToggles,
|
private val marketsFeatureToggles: MarketsFeatureToggles,
|
||||||
|
private val walletImageResolver: WalletImageResolver,
|
||||||
analyticsEventsHandler: AnalyticsEventHandler,
|
analyticsEventsHandler: AnalyticsEventHandler,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
|
|
@ -267,7 +269,12 @@ internal class WalletViewModel @Inject constructor(
|
||||||
coroutineScope = viewModelScope,
|
coroutineScope = viewModelScope,
|
||||||
)
|
)
|
||||||
|
|
||||||
stateHolder.update(transformer = UpdateWalletCardsCountTransformer(action.selectedWallet))
|
stateHolder.update(
|
||||||
|
transformer = UpdateWalletCardsCountTransformer(
|
||||||
|
userWallet = action.selectedWallet,
|
||||||
|
walletImageResolver = walletImageResolver,
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
is WalletsUpdateActionResolver.Action.UpdateWalletName -> {
|
is WalletsUpdateActionResolver.Action.UpdateWalletName -> {
|
||||||
stateHolder.update(transformer = RenameWalletTransformer(action.selectedWalletId, action.name))
|
stateHolder.update(transformer = RenameWalletTransformer(action.selectedWalletId, action.name))
|
||||||
|
|
@ -290,6 +297,7 @@ internal class WalletViewModel @Inject constructor(
|
||||||
selectedWalletIndex = action.selectedWalletIndex,
|
selectedWalletIndex = action.selectedWalletIndex,
|
||||||
wallets = action.wallets,
|
wallets = action.wallets,
|
||||||
clickIntents = clickIntents,
|
clickIntents = clickIntents,
|
||||||
|
walletImageResolver = walletImageResolver,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -322,6 +330,7 @@ internal class WalletViewModel @Inject constructor(
|
||||||
prevWalletId = action.prevWalletId,
|
prevWalletId = action.prevWalletId,
|
||||||
newUserWallet = action.selectedWallet,
|
newUserWallet = action.selectedWallet,
|
||||||
clickIntents = clickIntents,
|
clickIntents = clickIntents,
|
||||||
|
walletImageResolver = walletImageResolver,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -337,6 +346,7 @@ internal class WalletViewModel @Inject constructor(
|
||||||
AddWalletTransformer(
|
AddWalletTransformer(
|
||||||
userWallet = action.selectedWallet,
|
userWallet = action.selectedWallet,
|
||||||
clickIntents = clickIntents,
|
clickIntents = clickIntents,
|
||||||
|
walletImageResolver = walletImageResolver,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -386,6 +396,7 @@ internal class WalletViewModel @Inject constructor(
|
||||||
transformer = UnlockWalletTransformer(
|
transformer = UnlockWalletTransformer(
|
||||||
unlockedWallets = action.unlockedWallets,
|
unlockedWallets = action.unlockedWallets,
|
||||||
clickIntents = clickIntents,
|
clickIntents = clickIntents,
|
||||||
|
walletImageResolver = walletImageResolver,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 160 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 126 KiB |
Loading…
Add table
Add a link
Reference in a new issue