From f4fad4d94da5022b06290495bf73da47929ed8d2 Mon Sep 17 00:00:00 2001 From: Omar Hatem Date: Fri, 11 Aug 2023 16:58:11 +0300 Subject: [PATCH] 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] --- cw_ethereum/lib/ethereum_wallet.dart | 15 ++++++++++++--- cw_ethereum/lib/pending_ethereum_transaction.dart | 10 ++++++++-- lib/utils/exception_handler.dart | 5 ++++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/cw_ethereum/lib/ethereum_wallet.dart b/cw_ethereum/lib/ethereum_wallet.dart index 967a116e6..404b78ca2 100644 --- a/cw_ethereum/lib/ethereum_wallet.dart +++ b/cw_ethereum/lib/ethereum_wallet.dart @@ -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!, diff --git a/cw_ethereum/lib/pending_ethereum_transaction.dart b/cw_ethereum/lib/pending_ethereum_transaction.dart index 23dfa3b87..35b0123cc 100644 --- a/cw_ethereum/lib/pending_ethereum_transaction.dart +++ b/cw_ethereum/lib/pending_ethereum_transaction.dart @@ -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 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); diff --git a/lib/utils/exception_handler.dart b/lib/utils/exception_handler.dart index 6a33c842d..9d9328879 100644 --- a/lib/utils/exception_handler.dart +++ b/lib/utils/exception_handler.dart @@ -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 _addDeviceInfo(File file) async {