Updated on 2026-08-14

This commit is contained in:
Tangem 2025-09-15 17:50:32 +05:00
commit 2002834e57
30 changed files with 461 additions and 31 deletions

View file

@ -30,6 +30,7 @@ object MockNetworkStatusFactory {
),
amounts = mapOf(),
pendingTransactions = mapOf(),
yieldSupplyStatuses = mapOf(),
source = source,
)
.let(transform),

View file

@ -2,7 +2,9 @@ package com.tangem.common.test.domain.walletmanager
import com.tangem.blockchainsdk.models.UpdateWalletManagerResult
import com.tangem.blockchainsdk.models.UpdateWalletManagerResult.*
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.TxInfo
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import java.math.BigDecimal
/**
@ -41,6 +43,41 @@ class MockUpdateWalletManagerResultFactory {
)
}
fun createVerifiedWithToken(): Verified {
return Verified(
selectedAddress = "0x1",
addresses = setOf(Address(value = "0x1", type = Address.Type.Primary)),
currenciesAmounts = setOf(
CryptoCurrencyAmount.Token.BasicToken(
value = BigDecimal.ONE,
currencyRawId = CryptoCurrency.RawID("token"),
contractAddress = "0xTokenAddress",
),
),
currentTransactions = setOf(CryptoCurrencyTransaction.Coin(txInfo)),
)
}
fun createVerifiedWithSuppliedToken(): Verified {
return Verified(
selectedAddress = "0x1",
addresses = setOf(Address(value = "0x1", type = Address.Type.Primary)),
currenciesAmounts = setOf(
CryptoCurrencyAmount.Token.YieldSupplyToken(
value = BigDecimal.ONE,
currencyRawId = CryptoCurrency.RawID("token"),
contractAddress = "0xTokenAddress",
yieldSupplyStatus = YieldSupplyStatus(
isActive = true,
isInitialized = true,
isAllowedToSpend = false,
),
),
),
currentTransactions = setOf(CryptoCurrencyTransaction.Coin(txInfo)),
)
}
private companion object {
val txInfo = TxInfo(

View file

@ -2,8 +2,6 @@ package com.tangem.datasource.local.network.entity
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import com.tangem.datasource.local.network.entity.NetworkStatusDM.NoAccount
import com.tangem.datasource.local.network.entity.NetworkStatusDM.Verified
import dev.onenowy.moshipolymorphicadapter.PolymorphicAdapterType
import dev.onenowy.moshipolymorphicadapter.annotations.NameLabel
import java.math.BigDecimal
@ -44,6 +42,7 @@ sealed interface NetworkStatusDM {
@Json(name = "selected_address") override val selectedAddress: String,
@Json(name = "available_addresses") override val availableAddresses: Set<Address>,
@Json(name = "amounts") val amounts: Map<String, BigDecimal>,
@Json(name = "yield_supply_statuses") val yieldSupplyStatuses: Map<String, YieldSupplyStatus?> = emptyMap(),
) : NetworkStatusDM
/**
@ -107,4 +106,11 @@ sealed interface NetworkStatusDM {
Secondary,
}
}
@JsonClass(generateAdapter = true)
data class YieldSupplyStatus(
@Json(name = "is_active") val isActive: Boolean,
@Json(name = "is_initialized") val isInitialized: Boolean,
@Json(name = "is_allowed_to_spend") val isAllowedToSpend: Boolean,
)
}

View file

@ -42,7 +42,10 @@ class NetworkStatusDMSerializationTest {
{ "value": "0x123456", "type": "primary" },
{ "value": "0xabcdef", "type": "secondary" }
],
"amounts": { "ETH": "1.2345" }
"amounts": { "ETH": "1.2345" },
"yield_supply_statuses": {
"ETH": { "is_active": false, "is_initialized": false, "is_allowed_to_spend": false }
}
}
""".trimIndent()
@ -62,6 +65,13 @@ class NetworkStatusDMSerializationTest {
NetworkStatusDM.Address("0xabcdef", NetworkStatusDM.Address.Type.Secondary),
),
amounts = mapOf("ETH" to BigDecimal("1.2345")),
yieldSupplyStatuses = mapOf(
"ETH" to NetworkStatusDM.YieldSupplyStatus(
isActive = false,
isInitialized = false,
isAllowedToSpend = false,
),
),
)
Truth.assertThat(result).isEqualTo(expected)
@ -82,6 +92,13 @@ class NetworkStatusDMSerializationTest {
NetworkStatusDM.Address("0xabcdef", NetworkStatusDM.Address.Type.Secondary),
),
amounts = mapOf("ETH" to BigDecimal("1.2345")),
yieldSupplyStatuses = mapOf(
"ETH" to NetworkStatusDM.YieldSupplyStatus(
isActive = false,
isInitialized = false,
isAllowedToSpend = false,
),
),
)
// Act
@ -100,7 +117,10 @@ class NetworkStatusDMSerializationTest {
{ "value": "0x123456", "type": "primary" },
{ "value": "0xabcdef", "type": "secondary" }
],
"amounts": { "ETH": "1.2345" }
"amounts": { "ETH": "1.2345" },
"yield_supply_statuses": {
"ETH": { "is_active": false, "is_initialized": false, "is_allowed_to_spend": false }
}
}
""".stripJsonWhitespace()

View file

@ -81,6 +81,7 @@ class UserTokensResponseAddressesEnricherTest {
},
amounts = emptyMap(),
pendingTransactions = emptyMap(),
yieldSupplyStatuses = emptyMap(),
source = StatusSource.ACTUAL,
),
),
@ -124,6 +125,7 @@ class UserTokensResponseAddressesEnricherTest {
},
amounts = emptyMap(),
pendingTransactions = emptyMap(),
yieldSupplyStatuses = emptyMap(),
source = StatusSource.ACTUAL,
),
),
@ -161,6 +163,7 @@ class UserTokensResponseAddressesEnricherTest {
},
amounts = emptyMap(),
pendingTransactions = emptyMap(),
yieldSupplyStatuses = emptyMap(),
source = StatusSource.ACTUAL,
),
),

View file

@ -22,6 +22,7 @@ internal object NetworkStatusDataModelConverter : Converter<NetworkStatus, Netwo
selectedAddress = address.selectedAddress,
availableAddresses = address.addresses,
amounts = NetworkAmountsConverter.convertBack(value = status.amounts),
yieldSupplyStatuses = NetworkYieldSupplyStatusConverter.convertBack(status.yieldSupplyStatuses),
)
}
is NetworkStatus.NoAccount -> {

View file

@ -0,0 +1,46 @@
package com.tangem.data.networks.converters
import com.tangem.datasource.local.network.entity.NetworkStatusDM
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import com.tangem.utils.converter.TwoWayConverter
import com.tangem.utils.extensions.mapNotNullValues
private typealias YieldSupplyStatusDataModel = Map<String, NetworkStatusDM.YieldSupplyStatus?>
private typealias YieldSupplyStatusDomainModel = Map<CryptoCurrency.ID, YieldSupplyStatus?>
internal object NetworkYieldSupplyStatusConverter :
TwoWayConverter<YieldSupplyStatusDataModel, YieldSupplyStatusDomainModel> {
override fun convert(value: YieldSupplyStatusDataModel): YieldSupplyStatusDomainModel {
return value
.mapKeys { CryptoCurrency.ID.fromValue(value = it.key) }
.mapValues { (_, yieldSupplyStatus) ->
if (yieldSupplyStatus != null) {
YieldSupplyStatus(
isActive = yieldSupplyStatus.isActive,
isInitialized = yieldSupplyStatus.isInitialized,
isAllowedToSpend = yieldSupplyStatus.isAllowedToSpend,
)
} else {
null
}
}
}
override fun convertBack(value: YieldSupplyStatusDomainModel): YieldSupplyStatusDataModel {
return value
.mapKeys { (id, _) -> id.value }
.mapNotNullValues { (_, yieldSupplyStatus) ->
if (yieldSupplyStatus != null) {
NetworkStatusDM.YieldSupplyStatus(
isActive = yieldSupplyStatus.isActive,
isInitialized = yieldSupplyStatus.isInitialized,
isAllowedToSpend = yieldSupplyStatus.isAllowedToSpend,
)
} else {
null
}
}
}
}

View file

@ -29,6 +29,7 @@ internal object SimpleNetworkStatusConverter : Converter<NetworkStatusDM, Simple
amounts = NetworkAmountsConverter.convert(value = value.amounts),
pendingTransactions = emptyMap(),
source = StatusSource.CACHE,
yieldSupplyStatuses = NetworkYieldSupplyStatusConverter.convert(value = value.yieldSupplyStatuses),
)
}
is NetworkStatusDM.NoAccount -> {

View file

@ -8,6 +8,7 @@ import com.tangem.domain.models.network.Network
import com.tangem.domain.models.network.NetworkAddress
import com.tangem.domain.models.network.NetworkStatus
import com.tangem.domain.models.network.TxInfo
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import timber.log.Timber
/** Factory for creating [NetworkStatus] */
@ -70,6 +71,10 @@ object NetworkStatusFactory {
transactions = result.currentTransactions,
currencies = addedCurrencies,
),
yieldSupplyStatuses = formatYieldSupplyStatuses(
amounts = result.currenciesAmounts,
currencies = addedCurrencies,
),
source = StatusSource.ACTUAL,
)
}
@ -107,6 +112,31 @@ object NetworkStatusFactory {
}
}
private fun formatYieldSupplyStatuses(
amounts: Set<CryptoCurrencyAmount>,
currencies: Set<CryptoCurrency>,
): Map<CryptoCurrency.ID, YieldSupplyStatus?> {
return currencies.associate { currency ->
val amount = when (currency) {
is CryptoCurrency.Coin -> null
is CryptoCurrency.Token -> {
amounts.filterIsInstance<CryptoCurrencyAmount.Token.YieldSupplyToken>()
.firstOrNull { amount ->
currency.id.rawCurrencyId == amount.currencyRawId &&
currency.contractAddress.equals(amount.contractAddress, ignoreCase = true)
}
}
}
if (amount == null) {
Timber.w("Unable to find amount for cryptocurrency: $currency")
currency.id to null
} else {
currency.id to amount.yieldSupplyStatus
}
}
}
private fun formatTransactions(
transactions: Set<CryptoCurrencyTransaction>,
currencies: Set<CryptoCurrency>,

View file

@ -11,6 +11,7 @@ import com.tangem.domain.models.network.Network
import com.tangem.domain.models.network.NetworkAddress
import com.tangem.domain.models.network.NetworkStatus
import com.tangem.domain.models.network.NetworkStatus.Amount
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
@ -59,6 +60,22 @@ internal class NetworkStatusDataModelConverterTest {
) to Amount.NotFound,
),
pendingTransactions = mapOf(), // doesn't matter
yieldSupplyStatuses = mapOf(
ID(
prefix = Prefix.COIN_PREFIX,
body = Body.NetworkId(rawId = "BCH"),
suffix = ID.Suffix.RawID(rawId = "bitcoin-cash"),
) to YieldSupplyStatus(
isActive = false,
isInitialized = false,
isAllowedToSpend = false,
),
ID(
prefix = Prefix.COIN_PREFIX,
body = Body.NetworkId(rawId = "BTC"),
suffix = ID.Suffix.RawID(rawId = "bitcoin"),
) to null,
),
source = StatusSource.ACTUAL, // doesn't matter
),
),
@ -76,6 +93,13 @@ internal class NetworkStatusDataModelConverterTest {
),
),
amounts = mapOf("coin⟨BCH⟩bitcoin-cash" to BigDecimal.ZERO),
yieldSupplyStatuses = mapOf(
"coin⟨BCH⟩bitcoin-cash" to NetworkStatusDM.YieldSupplyStatus(
isActive = false,
isInitialized = false,
isAllowedToSpend = false,
),
),
),
),
// endregion

View file

@ -0,0 +1,83 @@
package com.tangem.data.networks.converters
import com.google.common.truth.Truth
import com.tangem.datasource.local.network.entity.NetworkStatusDM
import com.tangem.domain.models.currency.CryptoCurrency.ID
import com.tangem.domain.models.currency.CryptoCurrency.ID.Body
import com.tangem.domain.models.currency.CryptoCurrency.ID.Prefix
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import org.junit.jupiter.api.Test
internal class NetworkYieldSupplyStatusConverterTest {
@Test
fun convert() {
// Arrange
val value = mapOf(
"coin⟨ETH⟩ethereum" to NetworkStatusDM.YieldSupplyStatus(
isActive = false,
isInitialized = false,
isAllowedToSpend = false,
),
"coin⟨ETH→12367123⟩ethereum" to null,
)
// Act
val actual = NetworkYieldSupplyStatusConverter.convert(value)
// Assert
val expected = mapOf(
ID(
prefix = Prefix.COIN_PREFIX,
body = Body.NetworkId(rawId = "ETH"),
suffix = ID.Suffix.RawID(rawId = "ethereum"),
) to YieldSupplyStatus(
isActive = false,
isInitialized = false,
isAllowedToSpend = false,
),
ID(
prefix = Prefix.COIN_PREFIX,
body = Body.NetworkIdWithDerivationPath(rawId = "ETH", derivationPathHashCode = 12367123),
suffix = ID.Suffix.RawID(rawId = "ethereum"),
) to null,
)
Truth.assertThat(actual).isEqualTo(expected)
}
@Test
fun convertBack() {
// Arrange
val value = mapOf(
ID(
prefix = Prefix.COIN_PREFIX,
body = Body.NetworkId(rawId = "ETH"),
suffix = ID.Suffix.RawID(rawId = "ethereum"),
) to YieldSupplyStatus(
isActive = false,
isInitialized = false,
isAllowedToSpend = false,
),
ID(
prefix = Prefix.COIN_PREFIX,
body = Body.NetworkIdWithDerivationPath(rawId = "ETH", derivationPathHashCode = 12367123),
suffix = ID.Suffix.RawID(rawId = "ethereum"),
) to null,
)
// Act
val actual = NetworkYieldSupplyStatusConverter.convertBack(value)
// Assert
val expected = mapOf(
"coin⟨ETH⟩ethereum" to NetworkStatusDM.YieldSupplyStatus(
isActive = false,
isInitialized = false,
isAllowedToSpend = false,
),
)
Truth.assertThat(actual).isEqualTo(expected)
}
}

View file

@ -12,6 +12,7 @@ import com.tangem.domain.models.network.Network
import com.tangem.domain.models.network.NetworkAddress
import com.tangem.domain.models.network.NetworkStatus
import com.tangem.domain.models.network.NetworkStatus.Amount
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
@ -68,6 +69,14 @@ internal class SimpleNetworkStatusConverterTest {
"coin⟨BCH⟩bitcoin-cash" to BigDecimal.ZERO,
"coin⟨ETH→12367123⟩ethereum" to BigDecimal.ONE,
),
yieldSupplyStatuses = mapOf(
"coin⟨ETH⟩ethereum" to NetworkStatusDM.YieldSupplyStatus(
isActive = false,
isInitialized = false,
isAllowedToSpend = false,
),
"coin⟨ETH⟩ethereum" to null,
),
),
expected = SimpleNetworkStatus(
id = Network.ID(
@ -104,6 +113,22 @@ internal class SimpleNetworkStatusConverterTest {
) to Amount.Loaded(value = BigDecimal.ONE),
),
pendingTransactions = emptyMap(),
yieldSupplyStatuses = mapOf(
ID(
prefix = Prefix.COIN_PREFIX,
body = Body.NetworkId(rawId = "ETH"),
suffix = ID.Suffix.RawID(rawId = "ethereum"),
) to YieldSupplyStatus(
isActive = false,
isInitialized = false,
isAllowedToSpend = false,
),
ID(
prefix = Prefix.COIN_PREFIX,
body = Body.NetworkId(rawId = "ETH"),
suffix = ID.Suffix.RawID(rawId = "ethereum"),
) to null,
),
source = StatusSource.CACHE,
),
).let(Result.Companion::success),
@ -178,6 +203,7 @@ internal class SimpleNetworkStatusConverterTest {
),
),
amounts = emptyMap(),
yieldSupplyStatuses = emptyMap(),
),
expected = Result.failure(
exception = IllegalArgumentException("Selected address must not be null"),
@ -193,6 +219,7 @@ internal class SimpleNetworkStatusConverterTest {
selectedAddress = "0x1",
availableAddresses = setOf(),
amounts = emptyMap(),
yieldSupplyStatuses = emptyMap(),
),
expected = Result.failure(
exception = IllegalArgumentException("Selected address must not be null"),
@ -217,6 +244,7 @@ internal class SimpleNetworkStatusConverterTest {
),
),
amounts = emptyMap(),
yieldSupplyStatuses = emptyMap(),
),
expected = Result.failure(
exception = IllegalArgumentException("Selected address must not be null"),

View file

@ -149,6 +149,11 @@ internal class CommonNetworkStatusFetcherTest {
pendingTransactions = mapOf(
CryptoCurrency.ID.fromValue(value = "token⟨ETH⟩NEVER-MIND⚓NEVER-MIND") to emptySet(),
),
yieldSupplyStatuses = mapOf(
CryptoCurrency.ID.fromValue(
value = "token⟨ETH⟩NEVER-MIND⚓NEVER-MIND",
) to null,
),
)
},
),

View file

@ -13,6 +13,7 @@ import com.tangem.domain.models.network.NetworkAddress
import com.tangem.domain.models.network.NetworkStatus
import com.tangem.domain.models.network.NetworkStatus.Amount
import com.tangem.domain.models.network.TxInfo
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
@ -222,6 +223,57 @@ internal class NetworkStatusFactoryTest(private val model: Model) {
currencies.last().id to setOf(),
),
source = StatusSource.ACTUAL,
yieldSupplyStatuses = mapOf(),
),
),
createSuccess(
result = updateWalletManagerResultFactory.createVerifiedWithToken(),
currencies = currencies,
status = NetworkStatus.Verified(
address = NetworkAddress.Single(
defaultAddress = NetworkAddress.Address(
value = "0x1",
type = NetworkAddress.Address.Type.Primary,
),
),
amounts = mapOf(
currencies.first().id to Amount.Loaded(BigDecimal.ONE),
currencies.last().id to Amount.NotFound,
),
pendingTransactions = mapOf(
currencies.first().id to setOf(txInfo),
currencies.last().id to setOf(txInfo),
),
source = StatusSource.ACTUAL,
yieldSupplyStatuses = mapOf(),
),
),
createSuccess(
result = updateWalletManagerResultFactory.createVerifiedWithSuppliedToken(),
currencies = currencies,
status = NetworkStatus.Verified(
address = NetworkAddress.Single(
defaultAddress = NetworkAddress.Address(
value = "0x1",
type = NetworkAddress.Address.Type.Primary,
),
),
amounts = mapOf(
currencies.first().id to Amount.Loaded(BigDecimal.ONE),
currencies.last().id to Amount.NotFound,
),
pendingTransactions = mapOf(
currencies.first().id to setOf(txInfo),
currencies.last().id to setOf(txInfo),
),
source = StatusSource.ACTUAL,
yieldSupplyStatuses = mapOf(
currencies.first().id to YieldSupplyStatus(
isActive = false,
isInitialized = false,
isAllowedToSpend = false,
),
),
),
),
// endregion

View file

@ -1,24 +1,20 @@
package com.tangem.data.walletmanager
import com.tangem.blockchain.common.Amount
import com.tangem.blockchain.common.AmountType
import com.tangem.blockchain.common.Token
import com.tangem.blockchain.common.TransactionData
import com.tangem.blockchain.common.TransactionStatus
import com.tangem.blockchain.common.WalletManager
import com.tangem.blockchain.common.*
import com.tangem.blockchain.common.address.Address
import com.tangem.blockchainsdk.models.UpdateWalletManagerResult
import com.tangem.blockchainsdk.utils.amountToCreateAccount
import com.tangem.data.walletmanager.utils.SdkAddressToAddressConverter
import com.tangem.data.walletmanager.utils.TransactionDataToTxHistoryItemConverter
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import timber.log.Timber
import java.math.BigDecimal
/** Factory for creating [com.tangem.blockchainsdk.models.UpdateWalletManagerResult] */
/** Factory for creating [UpdateWalletManagerResult] */
internal class UpdateWalletManagerResultFactory {
/** Get [com.tangem.blockchainsdk.models.UpdateWalletManagerResult.Verified] result for [walletManager] */
/** Get [UpdateWalletManagerResult.Verified] result for [walletManager] */
fun getResult(walletManager: WalletManager): UpdateWalletManagerResult.Verified {
val wallet = walletManager.wallet
val addresses = getAvailableAddresses(wallet.addresses)
@ -110,7 +106,7 @@ internal class UpdateWalletManagerResultFactory {
is AmountType.Token -> {
val value = getCurrencyAmountValue(amount) ?: return null
UpdateWalletManagerResult.CryptoCurrencyAmount.Token(
UpdateWalletManagerResult.CryptoCurrencyAmount.Token.BasicToken(
currencyRawId = type.token.id?.let(CryptoCurrency::RawID),
contractAddress = type.token.contractAddress,
value = value,
@ -121,6 +117,20 @@ internal class UpdateWalletManagerResultFactory {
UpdateWalletManagerResult.CryptoCurrencyAmount.Coin(value = value)
}
is AmountType.TokenYieldSupply -> {
val value = getCurrencyAmountValue(amount) ?: return null
UpdateWalletManagerResult.CryptoCurrencyAmount.Token.YieldSupplyToken(
value = value,
currencyRawId = type.token.id?.let(CryptoCurrency::RawID),
contractAddress = type.token.contractAddress,
yieldSupplyStatus = YieldSupplyStatus(
isActive = type.isActive,
isInitialized = type.isInitialized,
isAllowedToSpend = type.isAllowedToSpend,
),
)
}
is AmountType.FeeResource,
is AmountType.Reserve,
-> null
@ -147,7 +157,7 @@ internal class UpdateWalletManagerResultFactory {
)
return tokens.mapTo(demoAmounts) { token ->
UpdateWalletManagerResult.CryptoCurrencyAmount.Token(
UpdateWalletManagerResult.CryptoCurrencyAmount.Token.BasicToken(
currencyRawId = token.id?.let(CryptoCurrency::RawID),
contractAddress = token.contractAddress,
value = amountValue,
@ -188,6 +198,15 @@ internal class UpdateWalletManagerResultFactory {
txInfo = txHistoryItem,
)
}
is AmountType.TokenYieldSupply -> {
val txHistoryItem = txHistoryItemConverter.convert(data) ?: return null
UpdateWalletManagerResult.CryptoCurrencyTransaction.Token(
tokenId = type.token.id,
contractAddress = type.token.contractAddress,
txInfo = txHistoryItem,
)
}
is AmountType.FeeResource,
is AmountType.Reserve,
-> null

View file

@ -188,7 +188,7 @@ internal class UpdateWalletManagerResultFactoryTest {
),
currenciesAmounts = setOf(
UpdateWalletManagerResult.CryptoCurrencyAmount.Coin(value = BigDecimal.ONE),
UpdateWalletManagerResult.CryptoCurrencyAmount.Token(
UpdateWalletManagerResult.CryptoCurrencyAmount.Token.BasicToken(
value = BigDecimal.ZERO,
currencyRawId = usdtToken.id?.let(CryptoCurrency::RawID),
contractAddress = usdtToken.contractAddress,
@ -416,7 +416,7 @@ internal class UpdateWalletManagerResultFactoryTest {
),
currenciesAmounts = setOf(
UpdateWalletManagerResult.CryptoCurrencyAmount.Coin(value = BigDecimal.ZERO),
UpdateWalletManagerResult.CryptoCurrencyAmount.Token(
UpdateWalletManagerResult.CryptoCurrencyAmount.Token.BasicToken(
value = BigDecimal.ZERO,
currencyRawId = usdtToken.id?.let(CryptoCurrency::RawID),
contractAddress = usdtToken.contractAddress,
@ -477,7 +477,7 @@ internal class UpdateWalletManagerResultFactoryTest {
),
currenciesAmounts = setOf(
UpdateWalletManagerResult.CryptoCurrencyAmount.Coin(value = BigDecimal.TEN),
UpdateWalletManagerResult.CryptoCurrencyAmount.Token(
UpdateWalletManagerResult.CryptoCurrencyAmount.Token.BasicToken(
value = BigDecimal.TEN,
currencyRawId = usdtToken.id?.let(CryptoCurrency::RawID),
contractAddress = usdtToken.contractAddress,

View file

@ -6,6 +6,7 @@ import com.tangem.domain.models.network.NetworkAddress
import com.tangem.domain.models.network.TxInfo
import com.tangem.domain.models.serialization.SerializedBigDecimal
import com.tangem.domain.models.staking.YieldBalance
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import kotlinx.serialization.Serializable
/**
@ -58,6 +59,12 @@ data class CryptoCurrencyStatus(
/** Staking yield balance */
val yieldBalance: YieldBalance? get() = null
/**
* !!! DO NOT CONFUSE with STAKING YIELD BALANCE
* Yield supply status
*/
val yieldSupplyStatus: YieldSupplyStatus? get() = null
/** Sources */
val sources: Sources get() = Sources()
}
@ -157,6 +164,7 @@ data class CryptoCurrencyStatus(
override val fiatRate: SerializedBigDecimal,
override val priceChange: SerializedBigDecimal,
override val yieldBalance: YieldBalance?,
override val yieldSupplyStatus: YieldSupplyStatus?,
override val hasCurrentNetworkTransactions: Boolean,
override val pendingTransactions: Set<TxInfo>,
override val networkAddress: NetworkAddress,
@ -184,6 +192,7 @@ data class CryptoCurrencyStatus(
override val fiatRate: SerializedBigDecimal?,
override val priceChange: SerializedBigDecimal?,
override val yieldBalance: YieldBalance?,
override val yieldSupplyStatus: YieldSupplyStatus?,
override val hasCurrentNetworkTransactions: Boolean,
override val pendingTransactions: Set<TxInfo>,
override val networkAddress: NetworkAddress,
@ -205,6 +214,7 @@ data class CryptoCurrencyStatus(
data class NoQuote(
override val amount: SerializedBigDecimal,
override val yieldBalance: YieldBalance?,
override val yieldSupplyStatus: YieldSupplyStatus?,
override val hasCurrentNetworkTransactions: Boolean,
override val pendingTransactions: Set<TxInfo>,
override val networkAddress: NetworkAddress,

View file

@ -2,6 +2,7 @@ package com.tangem.domain.models.network
import com.tangem.domain.models.StatusSource
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import java.math.BigDecimal
/**
@ -58,6 +59,7 @@ data class NetworkStatus(val network: Network, val value: Value) {
val address: NetworkAddress,
val amounts: Map<CryptoCurrency.ID, Amount>,
val pendingTransactions: Map<CryptoCurrency.ID, Set<TxInfo>>,
val yieldSupplyStatuses: Map<CryptoCurrency.ID, YieldSupplyStatus?>,
override val source: StatusSource,
) : Value()

View file

@ -0,0 +1,20 @@
package com.tangem.domain.models.yield.supply
import kotlinx.serialization.Serializable
/**
* Represents the status of yield supply for a cryptocurrency asset.
*
* This data class encapsulates the current state of yield supply, including whether it is active,
* initialized, and allowed to spend.
*
* @property isActive Indicates if the yield token is currently active.
* @property isInitialized Indicates if the yield token has been initialized.
* @property isAllowedToSpend Indicates if spending from the yield module is permitted.
*/
@Serializable
data class YieldSupplyStatus(
val isActive: Boolean,
val isInitialized: Boolean,
val isAllowedToSpend: Boolean,
)

View file

@ -94,6 +94,7 @@ internal class CurrencyStatusOperations(
} else {
null
}
val yieldSupplyStatus = networkStatusValue.yieldSupplyStatuses[currency.id]
val quoteValue = quoteStatus?.value
@ -108,6 +109,7 @@ internal class CurrencyStatusOperations(
pendingTransactions = currentTransactions,
networkAddress = networkStatusValue.address,
yieldBalance = currentYieldBalance,
yieldSupplyStatus = yieldSupplyStatus,
sources = CryptoCurrencyStatus.Sources(
networkSource = networkStatusValue.source,
quoteSource = quoteStatus?.value?.source ?: StatusSource.ACTUAL,
@ -120,6 +122,7 @@ internal class CurrencyStatusOperations(
pendingTransactions = currentTransactions,
networkAddress = networkStatusValue.address,
yieldBalance = currentYieldBalance,
yieldSupplyStatus = yieldSupplyStatus,
sources = CryptoCurrencyStatus.Sources(
networkSource = networkStatusValue.source,
quoteSource = quoteStatus?.value?.source ?: StatusSource.ACTUAL,
@ -135,6 +138,7 @@ internal class CurrencyStatusOperations(
pendingTransactions = currentTransactions,
networkAddress = networkStatusValue.address,
yieldBalance = currentYieldBalance,
yieldSupplyStatus = yieldSupplyStatus,
sources = CryptoCurrencyStatus.Sources(
networkSource = networkStatusValue.source,
quoteSource = quoteValue.source,

View file

@ -97,6 +97,7 @@ internal object MockNetworks {
defaultAddress = NetworkAddress.Address(value = "mock", NetworkAddress.Address.Type.Primary),
),
source = StatusSource.ACTUAL,
yieldSupplyStatuses = mapOf(),
),
)
@ -113,6 +114,7 @@ internal object MockNetworks {
defaultAddress = NetworkAddress.Address(value = "mock", NetworkAddress.Address.Type.Primary),
),
source = StatusSource.ACTUAL,
yieldSupplyStatuses = mapOf(),
),
)
@ -130,6 +132,7 @@ internal object MockNetworks {
defaultAddress = NetworkAddress.Address(value = "mock", NetworkAddress.Address.Type.Primary),
),
source = StatusSource.ACTUAL,
yieldSupplyStatuses = mapOf(),
),
)
}

View file

@ -156,6 +156,7 @@ internal object MockTokensStates {
).address,
yieldBalance = null,
sources = CryptoCurrencyStatus.Sources(),
yieldSupplyStatus = null,
)
is QuoteStatus.Data -> CryptoCurrencyStatus.Loaded(
amount = amount,
@ -167,6 +168,7 @@ internal object MockTokensStates {
networkAddress = requireNotNull(networkStatus.value as? NetworkStatus.Verified).address,
yieldBalance = null,
sources = CryptoCurrencyStatus.Sources(),
yieldSupplyStatus = null,
)
}
status.copy(value = value)
@ -185,6 +187,7 @@ internal object MockTokensStates {
).address,
yieldBalance = null,
sources = CryptoCurrencyStatus.Sources(),
yieldSupplyStatus = null,
),
)
}

View file

@ -172,6 +172,7 @@ class FeeCalculationUtilsTest {
hasCurrentNetworkTransactions = false,
pendingTransactions = emptySet(),
networkAddress = mockk(relaxed = true),
yieldSupplyStatus = null,
sources = CryptoCurrencyStatus.Sources(),
)
} else {

View file

@ -135,6 +135,7 @@ internal class SetVisaInfoTransformer(
fiatRate = visaCurrency.fiatRate,
priceChange = visaCurrency.priceChange,
yieldBalance = null,
yieldSupplyStatus = null,
hasCurrentNetworkTransactions = false,
pendingTransactions = emptySet(),
networkAddress = visaCurrency.paymentAccountAddress,

View file

@ -795,6 +795,7 @@ class DefaultPromoDeeplinkHandlerTest {
amounts = emptyMap(),
pendingTransactions = emptyMap(),
source = StatusSource.ACTUAL,
yieldSupplyStatuses = emptyMap(),
)
return NetworkStatus(network = network, value = value)

View file

@ -5,7 +5,7 @@
# https://github.com/tangem/tangem-sdk-android/
# https://github.com/tangem/vico
tangemBlockchainSdk = "develop-1222"
tangemBlockchainSdk = "develop-1225"
#tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
tangemCardSdk = "develop-561"
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^

View file

@ -7,6 +7,7 @@ import com.tangem.blockchain.common.WalletManagerFactory
import com.tangem.blockchain.common.datastorage.BlockchainDataStorage
import com.tangem.blockchain.common.logging.BlockchainSDKLogger
import com.tangem.blockchainsdk.providers.BlockchainProviderTypes
import com.tangem.core.configtoggle.feature.FeatureTogglesManager
import timber.log.Timber
import javax.inject.Inject
@ -23,6 +24,7 @@ internal class WalletManagerFactoryCreator @Inject constructor(
private val accountCreator: AccountCreator,
private val blockchainDataStorage: BlockchainDataStorage,
private val blockchainSDKLogger: BlockchainSDKLogger,
private val featureTogglesManager: FeatureTogglesManager,
) {
fun create(config: BlockchainSdkConfig, blockchainProviderTypes: BlockchainProviderTypes): WalletManagerFactory {
@ -32,7 +34,9 @@ internal class WalletManagerFactoryCreator @Inject constructor(
config = config,
blockchainProviderTypes = blockchainProviderTypes,
accountCreator = accountCreator,
featureToggles = BlockchainFeatureToggles(),
featureToggles = BlockchainFeatureToggles(
isYieldSupplyEnabled = featureTogglesManager.isFeatureEnabled("YIELD_SUPPLY_FEATURE_ENABLED"),
),
blockchainDataStorage = blockchainDataStorage,
loggers = listOf(blockchainSDKLogger),
)

View file

@ -17,6 +17,7 @@ import com.tangem.blockchainsdk.providers.BlockchainProvidersTypesManager
import com.tangem.blockchainsdk.providers.DevBlockchainProvidersTypesManager
import com.tangem.blockchainsdk.providers.ProdBlockchainProvidersTypesManager
import com.tangem.blockchainsdk.providers.dev.BlockchainProvidersResponseSerializer
import com.tangem.core.configtoggle.feature.FeatureTogglesManager
import com.tangem.datasource.api.tangemTech.TangemTechApi
import com.tangem.datasource.di.NetworkMoshi
import com.tangem.datasource.local.config.environment.EnvironmentConfigStorage
@ -90,11 +91,13 @@ internal object BlockchainSDKFactoryModule {
tangemTechApi: TangemTechApi,
appPreferencesStore: AppPreferencesStore,
blockchainSDKLogger: BlockchainSDKLogger,
featureTogglesManager: FeatureTogglesManager,
): WalletManagerFactoryCreator {
return WalletManagerFactoryCreator(
accountCreator = DefaultAccountCreator(tangemTechApi),
blockchainDataStorage = DefaultBlockchainDataStorage(appPreferencesStore),
blockchainSDKLogger = blockchainSDKLogger,
featureTogglesManager = featureTogglesManager,
)
}
}

View file

@ -2,6 +2,7 @@ package com.tangem.blockchainsdk.models
import com.tangem.domain.models.currency.CryptoCurrency
import com.tangem.domain.models.network.TxInfo
import com.tangem.domain.models.yield.supply.YieldSupplyStatus
import java.math.BigDecimal
/** Result of updating wallet manager */
@ -65,18 +66,38 @@ sealed class UpdateWalletManagerResult {
*/
data class Coin(override val value: BigDecimal) : CryptoCurrencyAmount
/**
* Token
*
* @property currencyRawId crypto currency id
* @property contractAddress token contract address
* @property value amount value
*/
data class Token(
override val value: BigDecimal,
val currencyRawId: CryptoCurrency.RawID?,
val contractAddress: String,
) : CryptoCurrencyAmount
sealed interface Token : CryptoCurrencyAmount {
val currencyRawId: CryptoCurrency.RawID?
val contractAddress: String
/**
* Basic Token
*
* @property currencyRawId crypto currency id
* @property contractAddress token contract address
* @property value amount value
*/
data class BasicToken(
override val value: BigDecimal,
override val currencyRawId: CryptoCurrency.RawID?,
override val contractAddress: String,
) : Token
/**
* Yield Supply Token
*
* @property currencyRawId crypto currency id
* @property contractAddress token contract address
* @property value amount value
* @property yieldSupplyStatus status of the yield token
*/
data class YieldSupplyToken(
override val value: BigDecimal,
override val currencyRawId: CryptoCurrency.RawID?,
override val contractAddress: String,
val yieldSupplyStatus: YieldSupplyStatus,
) : Token
}
}
/** Crypto currency transaction */

View file

@ -9,4 +9,5 @@ fun Network.toBlockchain(): Blockchain = id.toBlockchain()
/** Converts [Network.ID] to [Blockchain] */
fun Network.ID.toBlockchain(): Blockchain = rawId.toBlockchain()
/** Converts [Network.RawID] to [Blockchain] */
fun Network.RawID.toBlockchain(): Blockchain = Blockchain.fromId(id = value)