Updated on 2026-08-14
This commit is contained in:
parent
f0c1615a35
commit
dd45e6b4d5
3 changed files with 22 additions and 15 deletions
|
|
@ -11,14 +11,17 @@ class GetNetworkAddressesUseCase(
|
|||
internal val networksRepository: NetworksRepository,
|
||||
) {
|
||||
|
||||
operator fun invoke(userWalletId: UserWalletId, network: Network): Flow<String> =
|
||||
operator fun invoke(userWalletId: UserWalletId, network: Network): Flow<List<String>> =
|
||||
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 -> ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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<List<AvailableWallet?>, PersistentList<SendRecipientListContent>> {
|
||||
|
|
@ -21,6 +22,7 @@ internal class SendRecipientWalletListConverter :
|
|||
private fun List<AvailableWallet?>.filterWallets(): PersistentList<SendRecipientListContent> {
|
||||
var walletsCounter = 0
|
||||
return this.filterNotNull()
|
||||
.filter { it.address.isNotBlank() }
|
||||
.groupBy { item -> item.name }
|
||||
.values.map {
|
||||
it.mapIndexed { index, item ->
|
||||
|
|
|
|||
|
|
@ -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<UserWallet>.toAvailableWallets(): List<Flow<AvailableWallet>> =
|
||||
private suspend fun List<UserWallet>.toAvailableWallets(): List<Flow<List<AvailableWallet>>> =
|
||||
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,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue