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 {
final output = outputs.first;
final BigInt allAmount =
_erc20Balance.balance - BigInt.from(calculateEstimatedFee(_credentials.priority!, null));
// since the fees are taken from Ethereum
// 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 =
EthereumFormatter.parseEthereumAmountToDouble(output.formattedCryptoAmount ?? 0);
totalAmount = output.sendAll
@ -196,7 +203,9 @@ abstract class EthereumWalletBase
final pendingEthereumTransaction = await _client.signTransaction(
privateKey: _privateKey,
toAddress: _credentials.outputs.first.address,
toAddress: _credentials.outputs.first.isParsedAddress
? _credentials.outputs.first.extractedAddress!
: _credentials.outputs.first.address,
amount: totalAmount.toString(),
gas: _estimatedGas!,
priority: _credentials.priority!,

View file

@ -20,13 +20,19 @@ class PendingEthereumTransaction with PendingTransaction {
});
@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
Future<void> commit() async => await sendTransaction();
@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
String get hex => bytesToHex(signedTransaction, include0x: true);

View file

@ -144,7 +144,10 @@ class ExceptionHandler {
"Connection closed before full header was received",
"Connection terminated during handshake",
"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 {