diff --git a/UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj b/UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj index 051e1c3841..410c4d86bc 100644 --- a/UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj +++ b/UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj @@ -12967,7 +12967,7 @@ repositoryURL = "https://github.com/horizontalsystems/EvmKit.Swift"; requirement = { kind = exactVersion; - version = 2.1.1; + version = 2.1.2; }; }; D3604E4828F02A8B0066C366 /* XCRemoteSwiftPackageReference "Eip20Kit" */ = { diff --git a/UnstoppableWallet/UnstoppableWallet/Core/App.swift b/UnstoppableWallet/UnstoppableWallet/Core/App.swift index ac683e3254..5b5a78463e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Core/App.swift +++ b/UnstoppableWallet/UnstoppableWallet/Core/App.swift @@ -343,9 +343,10 @@ class App { } func newSendEnabled(wallet: Wallet) -> Bool { - switch wallet.token.blockchainType { - case .ton: return true - default: return localStorage.newSendEnabled - } + true + // switch wallet.token.blockchainType { + // case .ton: return true + // default: return localStorage.newSendEnabled + // } } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmFeeEstimator.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmFeeEstimator.swift index 264027410a..0062eefab6 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmFeeEstimator.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmFeeEstimator.swift @@ -5,14 +5,19 @@ import MarketKit struct EvmFeeEstimator { private static let surchargePercent: Double = 10 - private func _estimateFee(evmKitWrapper: EvmKitWrapper, transactionData: TransactionData, gasPrice: GasPrice, predefinedGasLimit: Int? = nil) async throws -> EvmFeeData { + func estimateFee(evmKitWrapper: EvmKitWrapper, transactionData: TransactionData, gasPriceData: GasPriceData, predefinedGasLimit: Int? = nil) async throws -> EvmFeeData { let evmKit = evmKitWrapper.evmKit let gasLimit: Int + let gasPrice = gasPriceData.userDefined if let predefinedGasLimit { gasLimit = predefinedGasLimit } else { - gasLimit = try await evmKit.fetchEstimateGas(transactionData: transactionData, gasPrice: gasPrice) + do { + gasLimit = try await evmKit.fetchEstimateGas(transactionData: transactionData, gasPrice: gasPrice) + } catch { + gasLimit = try await evmKit.fetchEstimateGas(transactionData: transactionData) + } } let txAmount = transactionData.value @@ -48,16 +53,4 @@ struct EvmFeeEstimator { return .init(gasLimit: gasLimit, surchargedGasLimit: surchargedGasLimit, l1Fee: l1Fee) } - - func estimateFee(evmKitWrapper: EvmKitWrapper, transactionData: TransactionData, gasPriceData: GasPriceData, predefinedGasLimit _: Int? = nil) async throws -> EvmFeeData { - do { - return try await _estimateFee(evmKitWrapper: evmKitWrapper, transactionData: transactionData, gasPrice: gasPriceData.userDefined) - } catch { - if case let AppError.ethereum(reason: ethereumError) = error.convertedError, case .lowerThanBaseGasLimit = ethereumError { - return try await _estimateFee(evmKitWrapper: evmKitWrapper, transactionData: transactionData, gasPrice: gasPriceData.recommended) - } else { - throw error - } - } - } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmSendHandler.swift b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmSendHandler.swift index a129b15cda..9503fa9f61 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmSendHandler.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/SendNew/EvmSendHandler.swift @@ -38,8 +38,19 @@ extension EvmSendHandler: ISendHandler { evmFeeData = stubFeeData transactionData = TransactionData(to: transactionData.to, value: max(0, transactionData.value - totalFee), input: transactionData.input) + + if transactionData.value == 0 { + throw AppError.ethereum(reason: .insufficientBalanceWithFee) + } } else { - evmFeeData = try await evmFeeEstimator.estimateFee(evmKitWrapper: evmKitWrapper, transactionData: transactionData, gasPriceData: gasPriceData) + let _evmFeeData = try await evmFeeEstimator.estimateFee(evmKitWrapper: evmKitWrapper, transactionData: transactionData, gasPriceData: gasPriceData) + let totalFee = _evmFeeData.totalFee(gasPrice: gasPriceData.userDefined) + + evmFeeData = _evmFeeData + + if evmBalance < totalFee { + throw AppError.ethereum(reason: .insufficientBalanceWithFee) + } } } catch { transactionError = error