Fix Erc20 send all feature (#1030)

* Fix Erc20 send all feature

* Remove debug prints

* Add user connection issues and certificate issues to ignored errors [skip ci]
This commit is contained in:
Omar Hatem 2023-08-11 16:58:11 +03:00 committed by GitHub
parent 07844a6ef4
commit f4fad4d94d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 6 deletions

View file

@ -181,8 +181,15 @@ abstract class EthereumWalletBase
} }
} else { } else {
final output = outputs.first; final output = outputs.first;
final BigInt allAmount = // since the fees are taken from Ethereum
_erc20Balance.balance - BigInt.from(calculateEstimatedFee(_credentials.priority!, null)); // then no need to subtract the fees from the amount if send all
final BigInt allAmount;
if (transactionCurrency is Erc20Token) {
allAmount = _erc20Balance.balance;
} else {
allAmount = _erc20Balance.balance -
BigInt.from(calculateEstimatedFee(_credentials.priority!, null));
}
final totalOriginalAmount = final totalOriginalAmount =
EthereumFormatter.parseEthereumAmountToDouble(output.formattedCryptoAmount ?? 0); EthereumFormatter.parseEthereumAmountToDouble(output.formattedCryptoAmount ?? 0);
totalAmount = output.sendAll totalAmount = output.sendAll
@ -196,7 +203,9 @@ abstract class EthereumWalletBase
final pendingEthereumTransaction = await _client.signTransaction( final pendingEthereumTransaction = await _client.signTransaction(
privateKey: _privateKey, privateKey: _privateKey,
toAddress: _credentials.outputs.first.address, toAddress: _credentials.outputs.first.isParsedAddress
? _credentials.outputs.first.extractedAddress!
: _credentials.outputs.first.address,
amount: totalAmount.toString(), amount: totalAmount.toString(),
gas: _estimatedGas!, gas: _estimatedGas!,
priority: _credentials.priority!, priority: _credentials.priority!,

View file

@ -20,13 +20,19 @@ class PendingEthereumTransaction with PendingTransaction {
}); });
@override @override
String get amountFormatted => (BigInt.parse(amount) / BigInt.from(pow(10, exponent))).toString(); String get amountFormatted {
final _amount = BigInt.parse(amount) / BigInt.from(pow(10, exponent));
return _amount.toStringAsFixed(min(15, _amount.toString().length));
}
@override @override
Future<void> commit() async => await sendTransaction(); Future<void> commit() async => await sendTransaction();
@override @override
String get feeFormatted => (fee / BigInt.from(pow(10, 18))).toString(); String get feeFormatted {
final _fee = fee / BigInt.from(pow(10, 18));
return _fee.toStringAsFixed(min(15, _fee.toString().length));
}
@override @override
String get hex => bytesToHex(signedTransaction, include0x: true); String get hex => bytesToHex(signedTransaction, include0x: true);

View file

@ -144,7 +144,10 @@ class ExceptionHandler {
"Connection closed before full header was received", "Connection closed before full header was received",
"Connection terminated during handshake", "Connection terminated during handshake",
"PERMISSION_NOT_GRANTED", "PERMISSION_NOT_GRANTED",
"Failed host lookup: ", "Failed host lookup:",
"CERTIFICATE_VERIFY_FAILED",
"Handshake error in client",
"Error while launching http",
]; ];
static Future<void> _addDeviceInfo(File file) async { static Future<void> _addDeviceInfo(File file) async {