From c45301b490894247c33c6be49485ec1fd1a6f252 Mon Sep 17 00:00:00 2001 From: Tangem Date: Wed, 17 Sep 2025 15:18:46 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../tangem/domain/models/network/NetworkStatus.kt | 10 ++++++++++ .../CachedCurrenciesStatusesOperations.kt | 6 +++--- .../tokens/utils/CurrencyStatusProxyCreator.kt | 3 ++- .../tangem/domain/tokens/utils/NetworkAddressExt.kt | 13 ------------- 4 files changed, 15 insertions(+), 17 deletions(-) delete mode 100644 domain/tokens/src/main/kotlin/com/tangem/domain/tokens/utils/NetworkAddressExt.kt diff --git a/domain/models/src/main/kotlin/com/tangem/domain/models/network/NetworkStatus.kt b/domain/models/src/main/kotlin/com/tangem/domain/models/network/NetworkStatus.kt index d5f1834bf3..a98e61e40b 100644 --- a/domain/models/src/main/kotlin/com/tangem/domain/models/network/NetworkStatus.kt +++ b/domain/models/src/main/kotlin/com/tangem/domain/models/network/NetworkStatus.kt @@ -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 + } } \ No newline at end of file diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CachedCurrenciesStatusesOperations.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CachedCurrenciesStatusesOperations.kt index ef89e15b90..d261a865d9 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CachedCurrenciesStatusesOperations.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/operations/CachedCurrenciesStatusesOperations.kt @@ -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) diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/utils/CurrencyStatusProxyCreator.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/utils/CurrencyStatusProxyCreator.kt index bad702ce42..215e06104f 100644 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/utils/CurrencyStatusProxyCreator.kt +++ b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/utils/CurrencyStatusProxyCreator.kt @@ -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 diff --git a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/utils/NetworkAddressExt.kt b/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/utils/NetworkAddressExt.kt deleted file mode 100644 index 1a20e0c8bc..0000000000 --- a/domain/tokens/src/main/kotlin/com/tangem/domain/tokens/utils/NetworkAddressExt.kt +++ /dev/null @@ -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 - } -} \ No newline at end of file