From dd45e6b4d5509095c0e2ffa8328c3977d4d1c95e Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 20 May 2024 20:05:02 +0500 Subject: [PATCH] Updated on 2026-08-14 --- .../tokens/GetNetworkAddressesUseCase.kt | 17 ++++++++++------- .../SendRecipientWalletListConverter.kt | 2 ++ .../presentation/viewmodel/SendViewModel.kt | 18 ++++++++++-------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetNetworkAddressesUseCase.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetNetworkAddressesUseCase.kt index 0cc768a333..aea1cad8eb 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetNetworkAddressesUseCase.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/GetNetworkAddressesUseCase.kt @@ -11,14 +11,17 @@ class GetNetworkAddressesUseCase( internal val networksRepository: NetworksRepository, ) { - operator fun invoke(userWalletId: UserWalletId, network: Network): Flow = + operator fun invoke(userWalletId: UserWalletId, network: Network): Flow> = networksRepository.getNetworkStatusesUpdates(userWalletId, setOf(network)) .map { networkStatuses -> - when (val networkStatus = networkStatuses.singleOrNull { it.network.id == network.id }?.value) { - is NetworkStatus.NoAccount -> networkStatus.address.defaultAddress.value - is NetworkStatus.Unreachable -> networkStatus.address?.defaultAddress?.value.orEmpty() - is NetworkStatus.Verified -> networkStatus.address.defaultAddress.value - else -> "" - } + networkStatuses.filter { it.network.id == network.id } + .map { networkStatus -> + when (val status = networkStatus.value) { + is NetworkStatus.NoAccount -> status.address.defaultAddress.value + is NetworkStatus.Unreachable -> status.address?.defaultAddress?.value.orEmpty() + is NetworkStatus.Verified -> status.address.defaultAddress.value + else -> "" + } + } } } \ No newline at end of file diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/recipient/SendRecipientWalletListConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/recipient/SendRecipientWalletListConverter.kt index 6b92680baf..dae1452696 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/recipient/SendRecipientWalletListConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/recipient/SendRecipientWalletListConverter.kt @@ -9,6 +9,7 @@ import com.tangem.features.send.impl.presentation.state.recipient.utils.emptyLis import com.tangem.utils.converter.Converter import kotlinx.collections.immutable.PersistentList import kotlinx.collections.immutable.toPersistentList +import kotlinx.coroutines.flow.filter internal class SendRecipientWalletListConverter : Converter, PersistentList> { @@ -21,6 +22,7 @@ internal class SendRecipientWalletListConverter : private fun List.filterWallets(): PersistentList { var walletsCounter = 0 return this.filterNotNull() + .filter { it.address.isNotBlank() } .groupBy { item -> item.name } .values.map { it.mapIndexed { index, item -> diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt index 078ff442a9..ff49afe1c3 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt @@ -410,7 +410,7 @@ internal class SendViewModel @Inject constructor( }.onSuccess { result -> combine(*result.toTypedArray()) { it } .onEach { wallets -> - userWallets = wallets.filter { it.address.isNotBlank() }.toList() + userWallets = wallets.flatMap { it }.toList() uiState = stateFactory.onLoadedWalletsList(wallets = userWallets) } .flowOn(dispatchers.main) @@ -421,7 +421,7 @@ internal class SendViewModel @Inject constructor( } } - private suspend fun List.toAvailableWallets(): List> = + private suspend fun List.toAvailableWallets(): List>> = filterNot { it.walletId == userWalletId || it.isLocked } .mapNotNull { wallet -> val status = if (!wallet.isMultiCurrency) { @@ -435,12 +435,14 @@ internal class SendViewModel @Inject constructor( } else { getNetworkAddressesUseCase(wallet.walletId, cryptoCurrency.network) } - status?.map { address -> - AvailableWallet( - name = wallet.name, - address = address, - userWalletId = wallet.walletId, - ) + status?.map { addresses -> + addresses.map { address -> + AvailableWallet( + name = wallet.name, + address = address, + userWalletId = wallet.walletId, + ) + } } }