From 8aa158cdb69a07206b22638881eb9657a8d073a2 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 18 Oct 2023 19:23:58 +0800 Subject: [PATCH] Updated on 2026-08-14 --- .../tokens/legacy/redux/TokensMiddleware.kt | 21 ++++++++++++++----- ...tMissedAddressesCryptoCurrenciesUseCase.kt | 2 +- .../component/token/NonFiatContentBlock.kt | 3 +-- .../state/components/WalletCardState.kt | 20 ++++++++++-------- .../utils/FiatBalanceToWalletCardConverter.kt | 1 + .../WalletNotificationsListFactory.kt | 9 ++++---- .../wallet/viewmodels/WalletViewModel.kt | 5 +++++ 7 files changed, 40 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/tangem/tap/features/tokens/legacy/redux/TokensMiddleware.kt b/app/src/main/java/com/tangem/tap/features/tokens/legacy/redux/TokensMiddleware.kt index 353c66a79a..c108b2602f 100644 --- a/app/src/main/java/com/tangem/tap/features/tokens/legacy/redux/TokensMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/features/tokens/legacy/redux/TokensMiddleware.kt @@ -222,10 +222,21 @@ object TokensMiddleware { ) { val config = CardConfig.createConfig(scanResponse.card) val derivationDataList = currencyList.mapNotNull { currency -> - config.primaryCurve(blockchain = Blockchain.fromId(currency.network.id.value)) - ?.let { curve -> getNewDerivations(curve, scanResponse, currency) } + val curve = config.primaryCurve(blockchain = Blockchain.fromId(currency.network.id.value)) + curve?.let { getNewDerivations(curve, scanResponse, currency) } } - val derivations = derivationDataList.associate(DerivationData::derivations) + val derivations = buildMap> { + derivationDataList.forEach { + val current = this[it.derivations.first] + if (current != null) { + current.addAll(it.derivations.second) + current.distinct() + } else { + this[it.derivations.first] = it.derivations.second.toMutableList() + } + } + } + if (derivations.isEmpty()) { onSuccess(scanResponse) return @@ -371,10 +382,10 @@ object TokensMiddleware { ) currenciesRepository.addCurrencies(userWalletId = userWalletId, currencies = currencyList) - val networks = currencyList.map { it.network }.toSet() + networksRepository.getNetworkStatusesSync( userWalletId = userWalletId, - networks = networks, + networks = currencyList.map(CryptoCurrency::network).toSet(), refresh = true, ) } diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetMissedAddressesCryptoCurrenciesUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetMissedAddressesCryptoCurrenciesUseCase.kt index 7b213da578..c6a1f90774 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetMissedAddressesCryptoCurrenciesUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetMissedAddressesCryptoCurrenciesUseCase.kt @@ -15,7 +15,7 @@ class GetMissedAddressesCryptoCurrenciesUseCase(private val currenciesRepository operator fun invoke(userWalletId: UserWalletId): Flow>> { return currenciesRepository.getMissedAddressesCryptoCurrencies(userWalletId) - .map, Either>> { it.right() } + .map, Either>>(List::right) .catch { emit(GetCurrenciesError.DataError(it).left()) } } } \ No newline at end of file diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/NonFiatContentBlock.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/NonFiatContentBlock.kt index 478991676d..ab86fc3d08 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/NonFiatContentBlock.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/common/component/token/NonFiatContentBlock.kt @@ -2,7 +2,6 @@ package com.tangem.feature.wallet.presentation.common.component.token import androidx.annotation.StringRes import androidx.compose.animation.AnimatedContent -import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.size import androidx.compose.material3.Icon @@ -19,7 +18,6 @@ import com.tangem.feature.wallet.presentation.common.state.TokenItemState import org.burnoutcrew.reorderable.ReorderableLazyListState import org.burnoutcrew.reorderable.detectReorder -@OptIn(ExperimentalAnimationApi::class) @Composable internal fun NonFiatContentBlock( state: TokenItemState, @@ -30,6 +28,7 @@ internal fun NonFiatContentBlock( targetState = state, label = "Update non content fiat block", modifier = modifier, + contentKey = { it::class.java }, ) { animatedState -> when (animatedState) { is TokenItemState.Draggable -> DraggableImage(reorderableTokenListState = reorderableTokenListState) diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt index 5e74bd00af..094d5338c1 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/state/components/WalletCardState.kt @@ -74,23 +74,25 @@ internal sealed interface WalletCardState { /** * Wallet card error state * - * @property id wallet id - * @property title wallet name - * @property imageResId wallet image resource id - * @property onRenameClick lambda be invoked when Rename button is clicked - * @property onDeleteClick lambda be invoked when Delete button is clicked + * @property id wallet id + * @property title wallet name + * @property imageResId wallet image resource id + * @property onRenameClick lambda be invoked when Rename button is clicked + * @property onDeleteClick lambda be invoked when Delete button is clicked */ data class Error( override val id: UserWalletId, override val title: String, + override val additionalInfo: WalletAdditionalInfo? = defaultAdditionalInfo, override val imageResId: Int?, override val onRenameClick: (UserWalletId, String) -> Unit, override val onDeleteClick: (UserWalletId) -> Unit, ) : WalletCardState { - override val additionalInfo: WalletAdditionalInfo = WalletAdditionalInfo( - hideable = true, - content = EMPTY_BALANCE_TEXT, - ) + + private companion object { + val defaultAdditionalInfo: WalletAdditionalInfo + get() = WalletAdditionalInfo(hideable = true, content = EMPTY_BALANCE_TEXT) + } } /** diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/FiatBalanceToWalletCardConverter.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/FiatBalanceToWalletCardConverter.kt index 6a26f73f7b..7c479d0c98 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/FiatBalanceToWalletCardConverter.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/utils/FiatBalanceToWalletCardConverter.kt @@ -32,6 +32,7 @@ internal class FiatBalanceToWalletCardConverter( return WalletCardState.Error( id = id, title = title, + additionalInfo = additionalInfo, imageResId = imageResId, onDeleteClick = onDeleteClick, onRenameClick = onRenameClick, diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt index 28676c50c8..6e78a23669 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletNotificationsListFactory.kt @@ -16,6 +16,7 @@ import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.conflate /** * Wallet notifications list factory @@ -45,10 +46,10 @@ internal class WalletNotificationsListFactory( cryptoCurrencyList: List, ): Flow> { return combine( - flow = wasCardScannedUseCase(cardTypesResolver.getCardId()), - flow2 = isReadyToShowRateAppUseCase(), - flow3 = isNeedToBackupUseCase(selectedWalletId), - flow4 = getMissedAddressCryptoCurrenciesUseCase(selectedWalletId), + flow = wasCardScannedUseCase(cardTypesResolver.getCardId()).conflate(), + flow2 = isReadyToShowRateAppUseCase().conflate(), + flow3 = isNeedToBackupUseCase(selectedWalletId).conflate(), + flow4 = getMissedAddressCryptoCurrenciesUseCase(selectedWalletId).conflate(), ) { wasCardScanned, isReadyToShowRating, isNeedToBackup, maybeMissedAddressCurrencies -> readyForRateAppNotification = true buildList { diff --git a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt index 1abc88cba9..8dbd1e55da 100644 --- a/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt +++ b/features/wallet/impl/src/main/java/com/tangem/feature/wallet/presentation/wallet/viewmodels/WalletViewModel.kt @@ -1014,6 +1014,7 @@ internal class WalletViewModel @Inject constructor( initAndSetupWc(tokenListFlow, wallet) tokenListFlow + .conflate() .distinctUntilChanged() .onEach { maybeTokenList -> uiState = stateFactory.getStateByTokensList(maybeTokenList.getTokenListWithWallet(wallet)) @@ -1119,6 +1120,7 @@ internal class WalletViewModel @Inject constructor( private fun getSingleCurrencyContent(index: Int) { val wallet = getWallet(index) getPrimaryCurrencyStatusUpdatesUseCase(wallet.walletId) + .conflate() .distinctUntilChanged() .onEach { maybeCryptoCurrencyStatus -> uiState = stateFactory.getSingleCurrencyLoadedBalanceState(maybeCryptoCurrencyStatus) @@ -1159,6 +1161,7 @@ internal class WalletViewModel @Inject constructor( val wallet = getWallet(walletIndex) getCardTokensListUseCase(userWalletId = state.walletsListConfig.wallets[walletIndex].id) + .conflate() .distinctUntilChanged() .onEach { maybeTokenList -> uiState = stateFactory.getStateByTokensList(maybeTokenList.getTokenListWithWallet(wallet)) @@ -1225,6 +1228,7 @@ internal class WalletViewModel @Inject constructor( private fun updateButtons(userWalletId: UserWalletId, currencyStatus: CryptoCurrencyStatus) { getCryptoCurrencyActionsUseCase(userWalletId = userWalletId, cryptoCurrencyStatus = currencyStatus) + .conflate() .distinctUntilChanged() .onEach { uiState = stateFactory.getSingleCurrencyManageButtonsState(actionsState = it) } .flowOn(dispatchers.io) @@ -1249,6 +1253,7 @@ internal class WalletViewModel @Inject constructor( listOfNotNull(singleWalletCryptoCurrencyStatus) }, ) + .conflate() .distinctUntilChanged() .onEach { uiState = stateFactory.getStateByNotifications(notifications = it) } .flowOn(dispatchers.io)