From be6f0efeecd3701ce53e374ff629b7314f0c9590 Mon Sep 17 00:00:00 2001 From: Tangem Date: Mon, 16 Dec 2024 13:30:29 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../data/staking/DefaultStakingRepository.kt | 6 +++--- .../repository/DefaultCurrenciesRepository.kt | 16 +++++++++++----- .../fee/custom/EthereumEIPCustomFeeConverter.kt | 10 ++++++++-- .../com/tangem/blockchainsdk/utils/Blockchain.kt | 9 ++++++--- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingRepository.kt b/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingRepository.kt index be7dc4d12e..f2f8cf8090 100644 --- a/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingRepository.kt +++ b/data/staking/src/main/java/com/tangem/data/staking/DefaultStakingRepository.kt @@ -10,7 +10,7 @@ import com.tangem.blockchain.common.TransactionStatus import com.tangem.blockchain.common.transaction.Fee import com.tangem.blockchainsdk.utils.fromNetworkId import com.tangem.blockchainsdk.utils.toCoinId -import com.tangem.blockchainsdk.utils.toMigratedCointId +import com.tangem.blockchainsdk.utils.toMigratedCoinId import com.tangem.common.extensions.hexToBytes import com.tangem.common.extensions.toCompressedPublicKey import com.tangem.data.common.api.safeApiCall @@ -555,7 +555,7 @@ internal class DefaultStakingRepository( override fun getStakingApproval(cryptoCurrency: CryptoCurrency): StakingApproval { return when (getIntegrationKey(cryptoCurrency.id)) { Blockchain.Ethereum.id + Blockchain.Polygon.toCoinId(), - Blockchain.Ethereum.id + Blockchain.Polygon.toMigratedCointId(), + Blockchain.Ethereum.id + Blockchain.Polygon.toMigratedCoinId(), -> StakingApproval.Needed(ETHEREUM_POLYGON_APPROVE_SPENDER) else -> StakingApproval.Empty } @@ -644,7 +644,7 @@ internal class DefaultStakingRepository( Blockchain.Solana.run { id + toCoinId() } to SOLANA_INTEGRATION_ID, Blockchain.Cosmos.run { id + toCoinId() } to COSMOS_INTEGRATION_ID, Blockchain.Tron.run { id + toCoinId() } to TRON_INTEGRATION_ID, - Blockchain.Ethereum.id + Blockchain.Polygon.toMigratedCointId() to ETHEREUM_POLYGON_INTEGRATION_ID, + Blockchain.Ethereum.id + Blockchain.Polygon.toMigratedCoinId() to ETHEREUM_POLYGON_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, diff --git a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt index a5d7aa511a..ea747277bc 100644 --- a/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt +++ b/data/tokens/src/main/kotlin/com/tangem/data/tokens/repository/DefaultCurrenciesRepository.kt @@ -2,10 +2,7 @@ package com.tangem.data.tokens.repository import com.tangem.blockchain.common.Blockchain import com.tangem.blockchainsdk.compatibility.getL2CompatibilityTokenComparison -import com.tangem.blockchainsdk.utils.ExcludedBlockchains -import com.tangem.blockchainsdk.utils.fromNetworkId -import com.tangem.blockchainsdk.utils.toCoinId -import com.tangem.blockchainsdk.utils.toNetworkId +import com.tangem.blockchainsdk.utils.* import com.tangem.data.common.api.safeApiCall import com.tangem.data.common.cache.CacheRegistry import com.tangem.data.common.currency.* @@ -360,7 +357,9 @@ internal class DefaultCurrenciesRepository( val storedCoin = storedTokens.tokens .find { - it.networkId == blockchainNetworkId && it.id == coinId && it.derivationPath == derivationPath.value + it.networkId == blockchainNetworkId && + compareIdWithMigrations(it, coinId) && + it.derivationPath == derivationPath.value } ?: error("Coin in this network $networkId not found") val coin = responseCurrenciesFactory.createCurrency(storedCoin, userWallet.scanResponse) @@ -548,6 +547,13 @@ internal class DefaultCurrenciesRepository( ) } + private fun compareIdWithMigrations(token: UserTokensResponse.Token, coinId: String): Boolean { + return when { + token.id == OLD_POLYGON_NAME -> NEW_POLYGON_NAME == coinId + else -> token.id == coinId + } + } + private suspend fun fetchTokens(userWallet: UserWallet) { val userWalletId = userWallet.walletId diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/EthereumEIPCustomFeeConverter.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/EthereumEIPCustomFeeConverter.kt index a3d874d526..14a249de6c 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/EthereumEIPCustomFeeConverter.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/fee/custom/EthereumEIPCustomFeeConverter.kt @@ -61,8 +61,14 @@ internal class EthereumEIPCustomFeeConverter( value: ImmutableList, ): Fee.Ethereum.EIP1559 { val feeAmount = value[FEE_AMOUNT].value.parseToBigDecimal(value[FEE_AMOUNT].decimals) - val maxFee = value[MAX_FEE].value.parseToBigDecimal(GAS_DECIMALS).toBigInteger() - val priorityFee = value[PRIORITY_FEE].value.parseToBigDecimal(GAS_DECIMALS).toBigInteger() + val maxFeeDecimals = value[MAX_FEE].decimals + val maxFee = value[MAX_FEE].value.parseToBigDecimal(maxFeeDecimals) + .movePointRight(maxFeeDecimals) + .toBigInteger() + val priorityFeeDecimals = value[PRIORITY_FEE].decimals + val priorityFee = value[PRIORITY_FEE].value.parseToBigDecimal(priorityFeeDecimals) + .movePointRight(priorityFeeDecimals) + .toBigInteger() val gasLimit = value[GAS_LIMIT].value.parseToBigDecimal(GAS_DECIMALS).toBigInteger() return normalFee.copy( diff --git a/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/utils/Blockchain.kt b/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/utils/Blockchain.kt index 024c33e797..952be8affd 100644 --- a/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/utils/Blockchain.kt +++ b/libs/blockchain-sdk/src/main/java/com/tangem/blockchainsdk/utils/Blockchain.kt @@ -303,7 +303,7 @@ fun Blockchain.toCoinId(): String { Blockchain.EthereumClassic, Blockchain.EthereumClassicTestnet -> "ethereum-classic" Blockchain.Stellar, Blockchain.StellarTestnet -> "stellar" Blockchain.Cardano -> "cardano" - Blockchain.Polygon, Blockchain.PolygonTestnet -> "polygon-ecosystem-token" + Blockchain.Polygon, Blockchain.PolygonTestnet -> NEW_POLYGON_NAME Blockchain.Arbitrum, Blockchain.ArbitrumTestnet -> "arbitrum-one" Blockchain.Avalanche, Blockchain.AvalancheTestnet -> "avalanche-2" Blockchain.Solana, Blockchain.SolanaTestnet -> "solana" @@ -387,8 +387,8 @@ fun Blockchain.toCoinId(): String { * New CoinId to existing coin "id" field. * To support both old and new coin id. */ -fun Blockchain.toMigratedCointId(): String = when (this) { - Blockchain.Polygon, Blockchain.PolygonTestnet -> "polygon-ecosystem-token" +fun Blockchain.toMigratedCoinId(): String = when (this) { + Blockchain.Polygon, Blockchain.PolygonTestnet -> NEW_POLYGON_NAME else -> toCoinId() } @@ -422,5 +422,8 @@ fun Blockchain.minimalAmount(): BigDecimal { return BigDecimal.ONE.movePointLeft(decimals()) } +const val OLD_POLYGON_NAME = "matic-network" +const val NEW_POLYGON_NAME = "polygon-ecosystem-token" + private const val NODL = "NODL" private const val NODL_AMOUNT_TO_CREATE_ACCOUNT = 1.5 \ No newline at end of file