Updated on 2026-08-14
This commit is contained in:
parent
704e5812a6
commit
c45301b490
4 changed files with 15 additions and 17 deletions
|
|
@ -91,4 +91,14 @@ data class NetworkStatus(val network: Network, val value: Value) {
|
|||
/** Amount which failed to load */
|
||||
data object NotFound : Amount
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets the address from the NetworkStatus if available */
|
||||
fun NetworkStatus?.getAddress(): String? {
|
||||
return when (val value = this?.value) {
|
||||
is NetworkStatus.NoAccount -> value.address.defaultAddress.value
|
||||
is NetworkStatus.Unreachable -> value.address?.defaultAddress?.value
|
||||
is NetworkStatus.Verified -> value.address.defaultAddress.value
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@ import com.tangem.domain.models.currency.CryptoCurrency
|
|||
import com.tangem.domain.models.currency.CryptoCurrencyStatus
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.network.NetworkStatus
|
||||
import com.tangem.domain.models.network.getAddress
|
||||
import com.tangem.domain.models.quote.QuoteStatus
|
||||
import com.tangem.domain.models.staking.StakingID
|
||||
import com.tangem.domain.models.staking.YieldBalance
|
||||
|
|
@ -32,7 +33,6 @@ import com.tangem.domain.tokens.MultiWalletCryptoCurrenciesSupplier
|
|||
import com.tangem.domain.tokens.error.TokenListError
|
||||
import com.tangem.domain.tokens.operations.CurrenciesStatusesOperations.Error
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.tokens.utils.extractAddress
|
||||
import com.tangem.utils.extensions.addOrReplace
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
|
|
@ -143,7 +143,7 @@ class CachedCurrenciesStatusesOperations(
|
|||
currencies.associate { currency ->
|
||||
val networkStatus = networksStatuses.firstOrNull { it.network == currency.network }
|
||||
|
||||
currency.id to extractAddress(networkStatus)
|
||||
currency.id to networkStatus.getAddress()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -208,7 +208,7 @@ class CachedCurrenciesStatusesOperations(
|
|||
if (yieldBalances.isNullOrEmpty()) return null
|
||||
|
||||
val supportedIntegration = StakingIntegrationID.create(currencyId = currency.id)?.value
|
||||
val address = extractAddress(networkStatus)
|
||||
val address = networkStatus.getAddress()
|
||||
|
||||
return if (supportedIntegration != null && address != null) {
|
||||
val stakingId = StakingID(integrationId = supportedIntegration, address = address)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import arrow.core.toNonEmptySetOrNull
|
|||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.currency.CryptoCurrencyStatus
|
||||
import com.tangem.domain.models.network.NetworkStatus
|
||||
import com.tangem.domain.models.network.getAddress
|
||||
import com.tangem.domain.models.quote.QuoteStatus
|
||||
import com.tangem.domain.models.staking.StakingID
|
||||
import com.tangem.domain.models.staking.YieldBalance
|
||||
|
|
@ -72,7 +73,7 @@ class CurrencyStatusProxyCreator {
|
|||
currencies.map { currency ->
|
||||
val quote = quoteStatuses?.firstOrNull { it.rawCurrencyId == currency.id.rawCurrencyId }
|
||||
val networkStatus = networksStatuses?.firstOrNull { it.network == currency.network }
|
||||
val address = extractAddress(networkStatus)
|
||||
val address = networkStatus.getAddress()
|
||||
|
||||
val supportedIntegration = StakingIntegrationID.create(currencyId = currency.id)?.value
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
package com.tangem.domain.tokens.utils
|
||||
|
||||
import com.tangem.domain.models.network.NetworkStatus
|
||||
|
||||
/** Extract address from [networkStatus] */
|
||||
internal fun extractAddress(networkStatus: NetworkStatus?): String? {
|
||||
return when (val value = networkStatus?.value) {
|
||||
is NetworkStatus.NoAccount -> value.address.defaultAddress.value
|
||||
is NetworkStatus.Unreachable -> value.address?.defaultAddress?.value
|
||||
is NetworkStatus.Verified -> value.address.defaultAddress.value
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue