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]
Omar Hatem committed
Aug 11, 2023 at 16:58 UTC
f4fad4d94da5022b06290495bf73da47929ed8d2
3 files changed
+24
-6
cw_ethereum/lib/ethereum_wallet.dart
+12
-3
@@ -181,8 +181,15 @@ abstract class EthereumWalletBase
181
}
182
} else {
183
final output = outputs.first;
184
- final BigInt allAmount =
185
- _erc20Balance.balance - BigInt.from(calculateEstimatedFee(_credentials.priority!, null));
184
+ // since the fees are taken from Ethereum
185
+ // then no need to subtract the fees from the amount if send all
186
+ final BigInt allAmount;
187
+ if (transactionCurrency is Erc20Token) {
188
+ allAmount = _erc20Balance.balance;
189
+ } else {
190
+ allAmount = _erc20Balance.balance -
191
+ BigInt.from(calculateEstimatedFee(_credentials.priority!, null));
192
+ }
193
final totalOriginalAmount =
194
EthereumFormatter.parseEthereumAmountToDouble(output.formattedCryptoAmount ?? 0);
195
totalAmount = output.sendAll
@@ -196,7 +203,9 @@ abstract class EthereumWalletBase
203
204
final pendingEthereumTransaction = await _client.signTransaction(
205
privateKey: _privateKey,
199
- toAddress: _credentials.outputs.first.address,
206
+ toAddress: _credentials.outputs.first.isParsedAddress
207
+ ? _credentials.outputs.first.extractedAddress!
208
+ : _credentials.outputs.first.address,
209
amount: totalAmount.toString(),
210
gas: _estimatedGas!,
211
priority: _credentials.priority!,
cw_ethereum/lib/pending_ethereum_transaction.dart
+8
-2
@@ -20,13 +20,19 @@ class PendingEthereumTransaction with PendingTransaction {
20
});
21
22
@override
23
- String get amountFormatted => (BigInt.parse(amount) / BigInt.from(pow(10, exponent))).toString();
23
+ String get amountFormatted {
24
+ final _amount = BigInt.parse(amount) / BigInt.from(pow(10, exponent));
25
+ return _amount.toStringAsFixed(min(15, _amount.toString().length));
26
+ }
27
28
@override
29
Future<void> commit() async => await sendTransaction();
30
31
@override
29
- String get feeFormatted => (fee / BigInt.from(pow(10, 18))).toString();
32
+ String get feeFormatted {
33
+ final _fee = fee / BigInt.from(pow(10, 18));
34
+ return _fee.toStringAsFixed(min(15, _fee.toString().length));
35
+ }
36
37
@override
38
String get hex => bytesToHex(signedTransaction, include0x: true);
lib/utils/exception_handler.dart
+4
-1
@@ -144,7 +144,10 @@ class ExceptionHandler {
144
"Connection closed before full header was received",
145
"Connection terminated during handshake",
146
"PERMISSION_NOT_GRANTED",
147
- "Failed host lookup: ",
147
+ "Failed host lookup:",
148
+ "CERTIFICATE_VERIFY_FAILED",
149
+ "Handshake error in client",
150
+ "Error while launching http",
151
];
152
153
static Future<void> _addDeviceInfo(File file) async {