Updated on 2026-08-14

This commit is contained in:
Tangem 2025-09-12 14:01:41 +05:00
parent 4aa6a9666b
commit c3bfe301a5
11 changed files with 133 additions and 24 deletions

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

@ -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