Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-28 18:38:10 +03:00
commit 7d9a59ad6a
12 changed files with 57 additions and 9 deletions

View file

@ -72,7 +72,7 @@ class WalletConnectSdkHelper {
}
// TODO move fee calculation to SDK getFee() [REDACTED_JIRA]
val gasLimit = getGasLimitFromTx(value, walletManager, transaction)
val gasLimit = getGasLimitFromTx(value, walletManager, transaction, blockchain)
val gasPrice = getGasPrice(walletManager, transaction)
val feeDecimal = (gasLimit * gasPrice).movePointLeft(decimals)
@ -170,6 +170,7 @@ class WalletConnectSdkHelper {
value: BigDecimal,
walletManager: WalletManager,
transaction: WcEthereumTransaction,
blockchain: Blockchain,
): BigDecimal {
return transaction.gas?.hexToBigDecimal()
?: transaction.gasLimit?.hexToBigDecimal()
@ -177,7 +178,7 @@ class WalletConnectSdkHelper {
value = value,
walletManager = walletManager,
transaction = transaction,
)
).increaseForMantleIfNeeded(blockchain)
}
private suspend fun getGasLimitFromBlockchain(
@ -200,6 +201,15 @@ class WalletConnectSdkHelper {
}
}
// TODO Workaround for Mantle. Remove after [REDACTED_JIRA]
private fun BigDecimal.increaseForMantleIfNeeded(blockchain: Blockchain): BigDecimal {
return if (blockchain == Blockchain.Mantle) {
this.multiply(MANTLE_FEE_ESTIMATE_MULTIPLIER)
} else {
this
}
}
private suspend fun sendTransaction(data: WcTransactionData, cardId: String?): String? {
val result = (data.walletManager as TransactionSender).send(
transactionData = data.transaction,

View file

@ -272,22 +272,24 @@ class TransactionManagerImpl(
* @param blockchain
*/
private fun createMultipleProxyFees(gasPrice: BigInteger, gasLimit: BigInteger, blockchain: Blockchain): ProxyFees {
val gasPriceNormal = gasPrice.increaseBigIntegerByPercents(MULTIPLIER_GAS_PRICE_FOR_NORMAL_FEE)
val patchedGasLimit = gasLimit.toBigDecimal().increaseForMantleIfNeeded(blockchain).toBigInteger()
val gasPriceNormal = gasPrice
.increaseBigIntegerByPercents(MULTIPLIER_GAS_PRICE_FOR_NORMAL_FEE)
val gasPricePriority = gasPrice.increaseBigIntegerByPercents(MULTIPLIER_GAS_PRICE_FOR_PRIORITY_FEE)
val feeMin = gasLimit.multiply(gasPrice).toBigDecimal(
val feeMin = patchedGasLimit.multiply(gasPrice).toBigDecimal(
scale = blockchain.decimals(),
mathContext = MathContext(blockchain.decimals(), RoundingMode.HALF_EVEN),
).increaseForMantleIfNeeded(blockchain)
val feeNormal = gasLimit.multiply(gasPriceNormal).toBigDecimal(
val feeNormal = patchedGasLimit.multiply(gasPriceNormal).toBigDecimal(
scale = blockchain.decimals(),
mathContext = MathContext(blockchain.decimals(), RoundingMode.HALF_EVEN),
).increaseForMantleIfNeeded(blockchain)
val feePriority = gasLimit.multiply(gasPricePriority).toBigDecimal(
val feePriority = patchedGasLimit.multiply(gasPricePriority).toBigDecimal(
scale = blockchain.decimals(),
mathContext = MathContext(blockchain.decimals(), RoundingMode.HALF_EVEN),
).increaseForMantleIfNeeded(blockchain)
val minFee = ProxyFee.Common(
gasLimit = gasLimit,
gasLimit = patchedGasLimit,
fee = ProxyAmount(
currencySymbol = blockchain.currency,
value = feeMin,
@ -295,7 +297,7 @@ class TransactionManagerImpl(
),
)
val normalFee = ProxyFee.Common(
gasLimit = gasLimit,
gasLimit = patchedGasLimit,
fee = ProxyAmount(
currencySymbol = blockchain.currency,
value = feeNormal,
@ -303,7 +305,7 @@ class TransactionManagerImpl(
),
)
val priorityFee = ProxyFee.Common(
gasLimit = gasLimit,
gasLimit = patchedGasLimit,
fee = ProxyAmount(
currencySymbol = blockchain.currency,
value = feePriority,

View file

@ -875,6 +875,8 @@
<string name="warning_low_signatures_message">Auf dieser Karte sind nur noch %s Unterschriften übrig. Du musst dein gesamtes Guthaben abheben.</string>
<string name="warning_low_signatures_title">Geringe Anzahl von Unterschriften</string>
<string name="warning_manage_tokens_legacy_derivation_message">Token in verschiedenen Netzwerken können unterschiedliche Adressen haben. Überprüfe bei der Überweisung noch einmal, ob deine Adresse mit der des Netzwerks übereinstimmt.</string>
<string name="warning_matic_migration_title">Migration von MATIC zu POL</string>
<string name="warning_matic_migration_message">MATIC wird auf POL migriert. Es gibt jedoch keine Frist, und MATIC wird noch nicht abgeschafft. Du kannst MATIC-Token weiterhin verwenden oder sie über eien Exchange gegen POL tauschen.</string>
<plurals name="warning_missing_derivation_message">
<item quantity="one">Verwende deine Karte, um eine Adresse für das %d-Netz zu erhalten</item>
<item quantity="other">Verwende deine Karte, um mehrere Adressen für die %d-Netzwerke zu erhalten</item>

View file

@ -863,6 +863,8 @@
<string name="warning_low_signatures_message">このカードには%sの署名のみが残っています。資金をすべて引き出す必要があります。</string>
<string name="warning_low_signatures_title">署名数が少ないです</string>
<string name="warning_manage_tokens_legacy_derivation_message">異なるネットワーク上のトークンは、異なるアドレスを持つ場合があります。資金を送金する際には、アドレスがネットワークと一致していることを再確認してください。</string>
<string name="warning_matic_migration_title">MATICからPOLへの移行</string>
<string name="warning_matic_migration_message">MATICはPOLに移行中です。ただし、期限は設定されておらず、MATICはまだ廃止されていません。MATICトークンを引き続き安全に使用することも、取引所でPOLに交換することもできます。</string>
<plurals name="warning_missing_derivation_message">
<item quantity="other">%d ネットワークのアドレスを取得するために、カードを利用してください</item>
</plurals>

View file

@ -882,6 +882,8 @@
<string name="warning_low_signatures_message">На этой карте осталось всего %s подписей. Вам следует вывести все ваши средства.</string>
<string name="warning_low_signatures_title">Малое количество подписей</string>
<string name="warning_manage_tokens_legacy_derivation_message">Токены на разных сетях могут иметь разные адреса. Пожалуйста, убедитесь при переводе средств, что ваш адрес соответствует сети.</string>
<string name="warning_matic_migration_title">Миграция MATIC в POL</string>
<string name="warning_matic_migration_message">Токен MATIC мигрирует на POL. Однако крайний срок не установлен, и MATIC пока не устарел. Вы можете спокойно продолжать использовать токен MATIC или воспользоваться биржами, чтобы обменять его на POL.</string>
<plurals name="warning_missing_derivation_message">
<item quantity="one">Используйте вашу карту, чтобы получить адрес для %d сети</item>
<item quantity="few">Используйте вашу карту, чтобы получить адреса для %d сетей</item>

View file

@ -875,6 +875,8 @@
<string name="warning_low_signatures_message">Only %s signatures are left on this card. You must withdraw all of your funds.</string>
<string name="warning_low_signatures_title">Low signature count</string>
<string name="warning_manage_tokens_legacy_derivation_message">Tokens on different networks can have different addresses. Double-check that your address matches the network when you transfer funds.</string>
<string name="warning_matic_migration_title">MATIC to POL Migration</string>
<string name="warning_matic_migration_message">MATIC is being migrated to POL. However there is no deadline set and MATIC isn\'t being deprecated yet. You can safely continue using MATIC token or use exchanges to swap it for POL.</string>
<plurals name="warning_missing_derivation_message">
<item quantity="one">Use your card to get an address for %d network</item>
<item quantity="other">Use your card to get an addresses for %d networks</item>

View file

@ -48,6 +48,8 @@ sealed class CryptoCurrencyWarning {
data object BeaconChainShutdown : CryptoCurrencyWarning()
data object MigrationMaticToPol : CryptoCurrencyWarning()
/**
* Shows a warning about an available fee resource for a transaction in several blockchains (ex. Koinos)
*/

View file

@ -76,6 +76,7 @@ class GetCurrencyWarningsUseCase(
getNetworkNoAccountWarning(currencyStatus),
getBeaconChainShutdownWarning(currency.network.id),
getAssetRequirementsWarning(userWalletId = userWalletId, currency = currency),
getMigrationFromMaticToPolWarning(currency),
)
}.flowOn(dispatchers.io)
}
@ -304,7 +305,19 @@ class GetCurrencyWarningsUseCase(
}
}
private fun getMigrationFromMaticToPolWarning(currency: CryptoCurrency): CryptoCurrencyWarning? {
return if (currency.symbol == MATIC_SYMBOL && !BlockchainUtils.isPolygonChain(currency.network.id.value)) {
CryptoCurrencyWarning.MigrationMaticToPol
} else {
null
}
}
private fun BigDecimal?.isZero(): Boolean {
return this?.signum() == 0
}
companion object {
private const val MATIC_SYMBOL = "MATIC"
}
}

View file

@ -49,6 +49,7 @@ internal class TokenDetailsNotificationsAnalyticsSender(
is TokenDetailsNotification.NetworkShutdown,
is TokenDetailsNotification.HederaAssociateWarning,
is TokenDetailsNotification.KoinosMana,
is TokenDetailsNotification.MigrationMaticToPol,
-> null
}
}

View file

@ -201,4 +201,9 @@ internal sealed class TokenDetailsNotification(val config: NotificationConfig) {
formatArgs = wrappedList(manaBalanceAmount, maxManaBalanceAmount),
),
)
data object MigrationMaticToPol : Warning(
title = resourceReference(id = R.string.warning_matic_migration_title),
subtitle = resourceReference(id = R.string.warning_matic_migration_message),
)
}

View file

@ -122,6 +122,7 @@ internal class TokenDetailsNotificationConverter(
""
},
)
is CryptoCurrencyWarning.MigrationMaticToPol -> MigrationMaticToPol
}
}

View file

@ -55,4 +55,10 @@ object BlockchainUtils {
val blockchain = Blockchain.fromId(networkId)
return blockchain == Blockchain.Binance || blockchain == Blockchain.BinanceTestnet
}
/** If current [networkId] is Polygon */
fun isPolygonChain(networkId: String): Boolean {
val blockchain = Blockchain.fromId(networkId)
return blockchain == Blockchain.Polygon || blockchain == Blockchain.PolygonTestnet
}
}