Updated on 2026-08-14

This commit is contained in:
Tangem 2024-05-22 15:48:14 +05:00
parent a204ef0bd6
commit 6d8bb28f02
6 changed files with 39 additions and 15 deletions

View file

@ -13,6 +13,7 @@ import com.tangem.domain.common.extensions.fromNetworkId
import com.tangem.domain.common.util.cardTypesResolver
import com.tangem.domain.demo.DemoConfig
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyAddress
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.tokens.model.NetworkStatus
import com.tangem.domain.tokens.repository.NetworksRepository
@ -78,7 +79,10 @@ internal class DefaultNetworksRepository(
return blockchain == Blockchain.Aptos
}
override suspend fun getNetworkAddresses(userWalletId: UserWalletId, network: Network): List<String> {
override suspend fun getNetworkAddresses(
userWalletId: UserWalletId,
network: Network,
): List<CryptoCurrencyAddress> {
// Get list of currencies matching [network]
val currencies = getCurrencies(userWalletId)
.filter { currency -> network.id == currency.network.id }
@ -87,9 +91,12 @@ internal class DefaultNetworksRepository(
if (currencies.toList().isEmpty()) return emptyList()
return currencies.toList().map { currency ->
walletManagersFacade.getAddresses(userWalletId, currency.network)
.firstOrNull { it.type == AddressType.Default }
?.value.orEmpty()
CryptoCurrencyAddress(
cryptoCurrency = currency,
address = walletManagersFacade.getAddresses(userWalletId, currency.network)
.firstOrNull { it.type == AddressType.Default }
?.value.orEmpty(),
)
}
}

View file

@ -0,0 +1,6 @@
package com.tangem.domain.tokens.model
data class CryptoCurrencyAddress(
val cryptoCurrency: CryptoCurrency,
val address: String,
)

View file

@ -1,5 +1,6 @@
package com.tangem.domain.tokens
import com.tangem.domain.tokens.model.CryptoCurrencyAddress
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.tokens.repository.NetworksRepository
import com.tangem.domain.wallets.models.UserWalletId
@ -8,7 +9,7 @@ class GetNetworkAddressesUseCase(
internal val networksRepository: NetworksRepository,
) {
suspend fun invokeSync(userWalletId: UserWalletId, network: Network): List<String> {
suspend fun invokeSync(userWalletId: UserWalletId, network: Network): List<CryptoCurrencyAddress> {
return networksRepository.getNetworkAddresses(userWalletId, network)
}
}

View file

@ -1,5 +1,6 @@
package com.tangem.domain.tokens.repository
import com.tangem.domain.tokens.model.CryptoCurrencyAddress
import com.tangem.domain.tokens.model.Network
import com.tangem.domain.tokens.model.NetworkStatus
import com.tangem.domain.wallets.models.UserWalletId
@ -46,5 +47,5 @@ interface NetworksRepository {
fun isNeedToCreateAccountWithoutReserve(network: Network): Boolean
suspend fun getNetworkAddresses(userWalletId: UserWalletId, network: Network): List<String>
suspend fun getNetworkAddresses(userWalletId: UserWalletId, network: Network): List<CryptoCurrencyAddress>
}

View file

@ -1,6 +1,7 @@
package com.tangem.features.send.impl.presentation.domain
import androidx.compose.runtime.Immutable
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.wallets.models.UserWalletId
/**
@ -15,4 +16,5 @@ data class AvailableWallet(
val name: String,
val userWalletId: UserWalletId,
val address: String,
val cryptoCurrency: CryptoCurrency,
)

View file

@ -418,8 +418,11 @@ internal class SendViewModel @Inject constructor(
}
}
private suspend fun List<UserWallet>.toAvailableWallets(): List<AvailableWallet> =
filterNot { it.walletId == userWalletId || it.isLocked }
private suspend fun List<UserWallet>.toAvailableWallets(): List<AvailableWallet> {
val currentAddress: String = kotlin.runCatching {
cryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value
}.getOrNull().orEmpty()
return filterNot { it.isLocked }
.mapNotNull { wallet ->
val addresses = if (!wallet.isMultiCurrency) {
getCryptoCurrencyUseCase(wallet.walletId).getOrNull()?.let {
@ -432,14 +435,18 @@ internal class SendViewModel @Inject constructor(
} else {
getNetworkAddressesUseCase.invokeSync(wallet.walletId, cryptoCurrency.network)
}
addresses?.map { address ->
AvailableWallet(
name = wallet.name,
address = address,
userWalletId = wallet.walletId,
)
}?.fastDistinctBy { it.address }
addresses
?.filter { it.address != currentAddress }
?.map { (cryptoCurrency, address) ->
AvailableWallet(
name = wallet.name,
address = address,
cryptoCurrency = cryptoCurrency,
userWalletId = wallet.walletId,
)
}?.fastDistinctBy { it.address }
}.flatten()
}
private suspend fun getTxHistory() {
val txHistoryList = getFixedTxHistoryItemsUseCase.getSync(