From 835694f7acbbb8a24b66091e67177e028320f901 Mon Sep 17 00:00:00 2001 From: Rafael Date: Tue, 19 Nov 2024 12:58:35 +0600 Subject: [PATCH] Improve fee estimation logic for insufficient balance case --- app/build.gradle | 2 +- .../modules/evmfee/EvmCommonGasDataService.kt | 20 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 9c6e829861..7154210727 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -283,7 +283,7 @@ dependencies { // Wallet kits implementation 'com.github.horizontalsystems:ton-kit-android:763a5c3' implementation 'com.github.horizontalsystems:bitcoin-kit-android:ced5801' - implementation 'com.github.horizontalsystems:ethereum-kit-android:a5eff38' + implementation 'com.github.horizontalsystems:ethereum-kit-android:0c770e3' implementation 'com.github.horizontalsystems:blockchain-fee-rate-kit-android:1d3bd49' implementation 'com.github.horizontalsystems:binance-chain-kit-android:c1509a2' implementation 'com.github.horizontalsystems:market-kit-android:4201f8f' diff --git a/app/src/main/java/io/horizontalsystems/bankwallet/modules/evmfee/EvmCommonGasDataService.kt b/app/src/main/java/io/horizontalsystems/bankwallet/modules/evmfee/EvmCommonGasDataService.kt index 4b4c59b0a9..feca8f1bd4 100644 --- a/app/src/main/java/io/horizontalsystems/bankwallet/modules/evmfee/EvmCommonGasDataService.kt +++ b/app/src/main/java/io/horizontalsystems/bankwallet/modules/evmfee/EvmCommonGasDataService.kt @@ -27,14 +27,18 @@ open class EvmCommonGasDataService( } return evmKit.estimateGas(stubTransactionData, gasPrice) - .map { estimatedGasLimit -> - val gasLimit = if (surchargeRequired) EvmFeeModule.surcharged(estimatedGasLimit) else estimatedGasLimit - GasData( - gasLimit = gasLimit, - estimatedGasLimit = estimatedGasLimit, - gasPrice = gasPrice - ) - } + .onErrorResumeNext { + evmKit.estimateGas(stubTransactionData) + } + .map { estimatedGasLimit -> + val gasLimit = + if (surchargeRequired) EvmFeeModule.surcharged(estimatedGasLimit) else estimatedGasLimit + GasData( + gasLimit = gasLimit, + estimatedGasLimit = estimatedGasLimit, + gasPrice = gasPrice + ) + } } companion object {