Updated on 2026-08-14
This commit is contained in:
parent
4aa6a9666b
commit
c3bfe301a5
11 changed files with 133 additions and 24 deletions
|
|
@ -30,6 +30,7 @@ object MockNetworkStatusFactory {
|
|||
),
|
||||
amounts = mapOf(),
|
||||
pendingTransactions = mapOf(),
|
||||
yieldSupplyStatuses = mapOf(),
|
||||
source = source,
|
||||
)
|
||||
.let(transform),
|
||||
|
|
|
|||
|
|
@ -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>,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
)
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ internal class SetVisaInfoTransformer(
|
|||
fiatRate = visaCurrency.fiatRate,
|
||||
priceChange = visaCurrency.priceChange,
|
||||
yieldBalance = null,
|
||||
yieldSupplyStatus = null,
|
||||
hasCurrentNetworkTransactions = false,
|
||||
pendingTransactions = emptySet(),
|
||||
networkAddress = visaCurrency.paymentAccountAddress,
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
# https://github.com/tangem/tangem-sdk-android/
|
||||
# https://github.com/tangem/vico
|
||||
|
||||
tangemBlockchainSdk = "develop-1222"
|
||||
#tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
|
||||
#tangemBlockchainSdk = "develop-1222"
|
||||
tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
|
||||
tangemCardSdk = "develop-561"
|
||||
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^
|
||||
tangemVico = "2.0.0-alpha.25-tangem12"
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue