mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-09 12:29:31 +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_transaction_priority.dart';
|
||||||
import 'package:cw_evm/evm_chain_wallet_addresses.dart';
|
import 'package:cw_evm/evm_chain_wallet_addresses.dart';
|
||||||
import 'package:cw_evm/evm_ledger_credentials.dart';
|
import 'package:cw_evm/evm_ledger_credentials.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:hex/hex.dart';
|
import 'package:hex/hex.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
|
@ -348,7 +347,7 @@ abstract class EVMChainWalletBase
|
||||||
final CryptoCurrency transactionCurrency =
|
final CryptoCurrency transactionCurrency =
|
||||||
balance.keys.firstWhere((element) => element.title == _credentials.currency.title);
|
balance.keys.firstWhere((element) => element.title == _credentials.currency.title);
|
||||||
|
|
||||||
final erc20Balance = balance[transactionCurrency]!;
|
final currencyBalance = balance[transactionCurrency]!;
|
||||||
BigInt totalAmount = BigInt.zero;
|
BigInt totalAmount = BigInt.zero;
|
||||||
BigInt estimatedFeesForTransaction = BigInt.zero;
|
BigInt estimatedFeesForTransaction = BigInt.zero;
|
||||||
int exponent = transactionCurrency is Erc20Token ? transactionCurrency.decimal : 18;
|
int exponent = transactionCurrency is Erc20Token ? transactionCurrency.decimal : 18;
|
||||||
|
@ -385,7 +384,7 @@ abstract class EVMChainWalletBase
|
||||||
estimatedGasUnitsForTransaction = gasFeesModel.estimatedGasUnits;
|
estimatedGasUnitsForTransaction = gasFeesModel.estimatedGasUnits;
|
||||||
maxFeePerGasForTransaction = gasFeesModel.maxFeePerGas;
|
maxFeePerGasForTransaction = gasFeesModel.maxFeePerGas;
|
||||||
|
|
||||||
if (erc20Balance.balance < totalAmount) {
|
if (currencyBalance.balance < totalAmount) {
|
||||||
throw EVMChainTransactionCreationException(transactionCurrency);
|
throw EVMChainTransactionCreationException(transactionCurrency);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -398,7 +397,7 @@ abstract class EVMChainWalletBase
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output.sendAll && transactionCurrency is Erc20Token) {
|
if (output.sendAll && transactionCurrency is Erc20Token) {
|
||||||
totalAmount = erc20Balance.balance;
|
totalAmount = currencyBalance.balance;
|
||||||
}
|
}
|
||||||
|
|
||||||
final gasFeesModel = await calculateActualEstimatedFeeForCreateTransaction(
|
final gasFeesModel = await calculateActualEstimatedFeeForCreateTransaction(
|
||||||
|
@ -413,14 +412,15 @@ abstract class EVMChainWalletBase
|
||||||
maxFeePerGasForTransaction = gasFeesModel.maxFeePerGas;
|
maxFeePerGasForTransaction = gasFeesModel.maxFeePerGas;
|
||||||
|
|
||||||
if (output.sendAll && transactionCurrency is! Erc20Token) {
|
if (output.sendAll && transactionCurrency is! Erc20Token) {
|
||||||
totalAmount = (erc20Balance.balance - estimatedFeesForTransaction);
|
totalAmount = (currencyBalance.balance - estimatedFeesForTransaction);
|
||||||
|
}
|
||||||
|
|
||||||
if (estimatedFeesForTransaction > erc20Balance.balance) {
|
// check the fees on the base currency (Eth/Polygon)
|
||||||
|
if (estimatedFeesForTransaction > balance[currency]!.balance) {
|
||||||
throw EVMChainTransactionFeesException();
|
throw EVMChainTransactionFeesException();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (erc20Balance.balance < totalAmount) {
|
if (currencyBalance.balance < totalAmount) {
|
||||||
throw EVMChainTransactionCreationException(transactionCurrency);
|
throw EVMChainTransactionCreationException(transactionCurrency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue