mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-08 03:49:43 +00:00
Fix fee check for erc20 transactions (#1915)
This commit is contained in:
parent
84cc0576d5
commit
a2cb994c09
1 changed files with 10 additions and 10 deletions
|
@ -29,7 +29,6 @@ import 'package:cw_evm/evm_chain_transaction_model.dart';
|
|||
import 'package:cw_evm/evm_chain_transaction_priority.dart';
|
||||
import 'package:cw_evm/evm_chain_wallet_addresses.dart';
|
||||
import 'package:cw_evm/evm_ledger_credentials.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hex/hex.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
|
@ -348,7 +347,7 @@ abstract class EVMChainWalletBase
|
|||
final CryptoCurrency transactionCurrency =
|
||||
balance.keys.firstWhere((element) => element.title == _credentials.currency.title);
|
||||
|
||||
final erc20Balance = balance[transactionCurrency]!;
|
||||
final currencyBalance = balance[transactionCurrency]!;
|
||||
BigInt totalAmount = BigInt.zero;
|
||||
BigInt estimatedFeesForTransaction = BigInt.zero;
|
||||
int exponent = transactionCurrency is Erc20Token ? transactionCurrency.decimal : 18;
|
||||
|
@ -385,7 +384,7 @@ abstract class EVMChainWalletBase
|
|||
estimatedGasUnitsForTransaction = gasFeesModel.estimatedGasUnits;
|
||||
maxFeePerGasForTransaction = gasFeesModel.maxFeePerGas;
|
||||
|
||||
if (erc20Balance.balance < totalAmount) {
|
||||
if (currencyBalance.balance < totalAmount) {
|
||||
throw EVMChainTransactionCreationException(transactionCurrency);
|
||||
}
|
||||
} else {
|
||||
|
@ -398,7 +397,7 @@ abstract class EVMChainWalletBase
|
|||
}
|
||||
|
||||
if (output.sendAll && transactionCurrency is Erc20Token) {
|
||||
totalAmount = erc20Balance.balance;
|
||||
totalAmount = currencyBalance.balance;
|
||||
}
|
||||
|
||||
final gasFeesModel = await calculateActualEstimatedFeeForCreateTransaction(
|
||||
|
@ -413,14 +412,15 @@ abstract class EVMChainWalletBase
|
|||
maxFeePerGasForTransaction = gasFeesModel.maxFeePerGas;
|
||||
|
||||
if (output.sendAll && transactionCurrency is! Erc20Token) {
|
||||
totalAmount = (erc20Balance.balance - estimatedFeesForTransaction);
|
||||
|
||||
if (estimatedFeesForTransaction > erc20Balance.balance) {
|
||||
throw EVMChainTransactionFeesException();
|
||||
}
|
||||
totalAmount = (currencyBalance.balance - estimatedFeesForTransaction);
|
||||
}
|
||||
|
||||
if (erc20Balance.balance < totalAmount) {
|
||||
// check the fees on the base currency (Eth/Polygon)
|
||||
if (estimatedFeesForTransaction > balance[currency]!.balance) {
|
||||
throw EVMChainTransactionFeesException();
|
||||
}
|
||||
|
||||
if (currencyBalance.balance < totalAmount) {
|
||||
throw EVMChainTransactionCreationException(transactionCurrency);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue