Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-20 18:25:51 +05:00
parent e51c82e615
commit f2585c4134
9 changed files with 46 additions and 23 deletions

View file

@ -1,6 +1,7 @@
package com.tangem.common.ui.amountScreen.converters.field
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import com.tangem.common.ui.R
import com.tangem.common.ui.amountScreen.models.AmountState
@ -81,6 +82,10 @@ class AmountFieldChangeTransformer(
cryptoAmount = amountTextField.cryptoAmount.copy(value = BigDecimal.ZERO),
fiatAmount = amountTextField.fiatAmount.copy(value = BigDecimal.ZERO),
isError = false,
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.None,
keyboardType = KeyboardType.Number,
),
),
)
}

View file

@ -70,7 +70,7 @@ internal class DefaultStakingRepository(
private val dispatchers: CoroutineDispatcherProvider,
private val stakingFeatureToggle: StakingFeatureToggles,
private val walletManagersFacade: WalletManagersFacade,
private val moshi: Moshi,
moshi: Moshi,
) : StakingRepository {
private val stakingNetworkTypeConverter = StakingNetworkTypeConverter()
@ -111,6 +111,10 @@ internal class DefaultStakingRepository(
private val tronStakeKitTransactionAdapter: JsonAdapter<TronStakeKitTransaction> =
moshi.adapter(TronStakeKitTransaction::class.java)
override fun getIntegrationKey(cryptoCurrencyId: CryptoCurrency.ID): String = with(cryptoCurrencyId) {
rawNetworkId.plus(rawCurrencyId)
}
override fun isStakingSupported(integrationKey: String): Boolean {
return integrationIdMap.containsKey(integrationKey)
}
@ -165,7 +169,7 @@ internal class DefaultStakingRepository(
val yields = getEnabledYields() ?: return@withContext StakingAvailability.Unavailable
val prefetchedYield = findPrefetchedYield(yields, rawCurrencyId, symbol)
val isSupported = isStakingSupported(cryptoCurrencyId.getIntegrationKey())
val isSupported = isStakingSupported(getIntegrationKey(cryptoCurrencyId))
when {
prefetchedYield != null && isSupported -> {
@ -273,7 +277,7 @@ internal class DefaultStakingRepository(
) = withContext(dispatchers.io) {
if (!stakingFeatureToggle.isStakingEnabled) return@withContext
val integrationId = integrationIdMap[cryptoCurrency.id.getIntegrationKey()] ?: return@withContext
val integrationId = integrationIdMap[getIntegrationKey(cryptoCurrency.id)] ?: return@withContext
val address = walletManagersFacade.getDefaultAddress(userWalletId, cryptoCurrency.network).orEmpty()
@ -307,7 +311,7 @@ internal class DefaultStakingRepository(
send(YieldBalance.Empty)
} else {
launch(dispatchers.io) {
val integrationId = integrationIdMap[cryptoCurrency.id.getIntegrationKey()]
val integrationId = integrationIdMap[getIntegrationKey(cryptoCurrency.id)]
?: error("Could not get integrationId")
stakingBalanceStore.get(userWalletId, integrationId)
.collectLatest {
@ -340,7 +344,7 @@ internal class DefaultStakingRepository(
} else {
fetchSingleYieldBalance(userWalletId, cryptoCurrency)
val integrationId = integrationIdMap[cryptoCurrency.id.getIntegrationKey()]
val integrationId = integrationIdMap[getIntegrationKey(cryptoCurrency.id)]
?: error("Could not get integrationId")
val result = stakingBalanceStore.getSyncOrNull(userWalletId, integrationId)
?: return@withContext YieldBalance.Error
@ -371,7 +375,7 @@ internal class DefaultStakingRepository(
val availableCurrencies = cryptoCurrencies
.mapNotNull { currency ->
val address = walletManagersFacade.getDefaultAddress(userWalletId, currency.network)
val integrationId = integrationIdMap[currency.id.getIntegrationKey()]
val integrationId = integrationIdMap[getIntegrationKey(currency.id)]
if (integrationId != null && address != null) {
address to integrationId
@ -561,7 +565,7 @@ internal class DefaultStakingRepository(
}
override fun getStakingApproval(cryptoCurrency: CryptoCurrency): StakingApproval {
return when (cryptoCurrency.id.getIntegrationKey()) {
return when (getIntegrationKey(cryptoCurrency.id)) {
Blockchain.Ethereum.id + Blockchain.Polygon.toCoinId() -> {
StakingApproval.Needed(ETHEREUM_POLYGON_APPROVE_SPENDER)
}
@ -575,6 +579,7 @@ internal class DefaultStakingRepository(
Blockchain.Solana,
Blockchain.Cosmos,
-> TransactionData.Compiled.Data.Bytes(unsignedTransaction.hexToBytes())
Blockchain.BSC,
Blockchain.Ethereum,
-> TransactionData.Compiled.Data.RawString(unsignedTransaction)
Blockchain.Tron -> {
@ -611,8 +616,6 @@ internal class DefaultStakingRepository(
private fun getYieldBalancesKey(userWalletId: UserWalletId) = "yield_balance_${userWalletId.stringValue}"
private fun CryptoCurrency.ID.getIntegrationKey(): String = rawNetworkId.plus(rawCurrencyId)
private fun getTronResource(network: Network): TronResource? {
val blockchain = Blockchain.fromNetworkId(network.backendId)
@ -629,11 +632,11 @@ internal class DefaultStakingRepository(
const val SOLANA_INTEGRATION_ID = "solana-sol-native-multivalidator-staking"
const val COSMOS_INTEGRATION_ID = "cosmos-atom-native-staking"
const val ETHEREUM_POLYGON_INTEGRATION_ID = "ethereum-matic-native-staking"
const val BINANCE_INTEGRATION_ID = "bsc-bnb-native-staking"
const val POLKADOT_INTEGRATION_ID = "polkadot-dot-validator-staking"
const val AVALANCHE_INTEGRATION_ID = "avalanche-avax-native-staking"
const val TRON_INTEGRATION_ID = "tron-trx-native-staking"
const val CRONOS_INTEGRATION_ID = "cronos-cro-native-staking"
const val BINANCE_INTEGRATION_ID = "bsc-bnb-native-staking"
const val KAVA_INTEGRATION_ID = "kava-kava-native-staking"
const val NEAR_INTEGRATION_ID = "near-near-native-staking"
const val TEZOS_INTEGRATION_ID = "tezos-xtz-native-staking"
@ -645,11 +648,11 @@ internal class DefaultStakingRepository(
Blockchain.Solana.run { id + toCoinId() } to SOLANA_INTEGRATION_ID,
Blockchain.Cosmos.run { id + toCoinId() } to COSMOS_INTEGRATION_ID,
Blockchain.Ethereum.id + Blockchain.Polygon.toCoinId() to ETHEREUM_POLYGON_INTEGRATION_ID,
Blockchain.BSC.run { id + toCoinId() } to BINANCE_INTEGRATION_ID,
// Blockchain.Polkadot.run { id + toCoinId() } to POLKADOT_INTEGRATION_ID,
// Blockchain.Avalanche.run { id + toCoinId() } to AVALANCHE_INTEGRATION_ID,
Blockchain.Tron.run { id + toCoinId() } to TRON_INTEGRATION_ID,
// Blockchain.Cronos.run { id + toCoinId() } to CRONOS_INTEGRATION_ID,
// Blockchain.BSC.run { id + toCoinId() } to BINANCE_INTEGRATION_ID,
// Blockchain.Kava.run { id + toCoinId() } to KAVA_INTEGRATION_ID,
// Blockchain.Near.run { id + toCoinId() } to NEAR_INTEGRATION_ID,
// Blockchain.Tezos.run { id + toCoinId() } to TEZOS_INTEGRATION_ID,

View file

@ -5,13 +5,10 @@ sealed class YieldBalanceList {
data class Data(
val balances: List<YieldBalance>,
) : YieldBalanceList() {
fun getBalance(rawCurrencyId: String?, networkName: String): YieldBalance {
fun getBalance(rawCurrencyId: String?): YieldBalance {
return balances.firstOrNull { yield ->
(yield as? YieldBalance.Data)?.balance?.items
?.any {
rawCurrencyId == it.rawCurrencyId &&
networkName.equals(it.rawNetworkId, ignoreCase = true)
} == true
?.any { rawCurrencyId == it.rawCurrencyId } == true
} ?: YieldBalance.Error
}
}

View file

@ -22,6 +22,8 @@ import kotlinx.coroutines.flow.Flow
@Suppress("TooManyFunctions")
interface StakingRepository {
fun getIntegrationKey(cryptoCurrencyId: CryptoCurrency.ID): String
fun isStakingSupported(integrationKey: String): Boolean
suspend fun fetchEnabledYields(refresh: Boolean)

View file

@ -144,10 +144,14 @@ internal class CurrenciesStatusesLceOperations(
currencies.map { currency ->
val quote = quotes?.firstOrNull { it.rawCurrencyId == currency.id.rawCurrencyId }
val networkStatus = networksStatuses?.firstOrNull { it.network == currency.network }
val yieldBalance = (yieldBalances as? YieldBalanceList.Data)?.getBalance(
rawCurrencyId = currency.id.rawCurrencyId,
networkName = currency.network.name,
val isStakingSupported = stakingRepository.isStakingSupported(
stakingRepository.getIntegrationKey(currency.id),
)
val yieldBalance = if (isStakingSupported) {
(yieldBalances as? YieldBalanceList.Data)?.getBalance(currency.id.rawCurrencyId)
} else {
null
}
createCurrencyStatus(
currency = currency,

View file

@ -260,10 +260,14 @@ internal class CurrenciesStatusesOperations(
currencies.map { currency ->
val quote = quotes?.firstOrNull { it.rawCurrencyId == currency.id.rawCurrencyId }
val networkStatus = networksStatuses?.firstOrNull { it.network == currency.network }
val yieldBalance = (yieldBalances as? YieldBalanceList.Data)?.getBalance(
rawCurrencyId = currency.id.rawCurrencyId,
networkName = currency.network.name,
val isStakingSupported = stakingRepository.isStakingSupported(
stakingRepository.getIntegrationKey(currency.id),
)
val yieldBalance = if (isStakingSupported) {
(yieldBalances as? YieldBalanceList.Data)?.getBalance(currency.id.rawCurrencyId)
} else {
null
}
createCurrencyStatus(
currency = currency,
quote = quote,

View file

@ -24,6 +24,9 @@ import org.joda.time.DateTime
import java.math.BigDecimal
class MockStakingRepository : StakingRepository {
override fun getIntegrationKey(cryptoCurrencyId: CryptoCurrency.ID): String = ""
override fun isStakingSupported(currencyId: String): Boolean = true
override suspend fun fetchEnabledYields(refresh: Boolean) {

View file

@ -1,5 +1,6 @@
package com.tangem.features.staking.impl.presentation.state.transformers.amount
import androidx.compose.ui.text.input.ImeAction
import com.tangem.common.extensions.isZero
import com.tangem.common.ui.amountScreen.models.AmountState
import com.tangem.core.ui.extensions.resourceReference
@ -31,6 +32,7 @@ internal class AmountRequirementStateTransformer(
val isRequirementError = isRequirementError(prevState, amountRequirements)
return if (isRequirementError) {
prevState.copy(
isPrimaryButtonEnabled = false,
amountTextField = prevState.amountTextField.copy(
isError = true,
error = resourceReference(
@ -43,6 +45,9 @@ internal class AmountRequirementStateTransformer(
),
),
),
keyboardOptions = prevState.amountTextField.keyboardOptions.copy(
imeAction = ImeAction.None,
),
),
)
} else {

View file

@ -88,7 +88,7 @@ markdown = "0.7.2"
# endregion Other libraries
# region Tangem
tangemBlockchainSdk = "develop-740"
tangemBlockchainSdk = "develop-745"
#tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
tangemCardSdk = "develop-378"
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^