From 3d8c2af4a2274ba14b852c82c3214518877c2dc2 Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 31 Mar 2023 00:24:05 +0200 Subject: [PATCH] Add missing configure for ethereum class --- cw_ethereum/lib/ethereum_wallet.dart | 110 +++++++++++++-------------- tool/configure.dart | 4 + 2 files changed, 59 insertions(+), 55 deletions(-) diff --git a/cw_ethereum/lib/ethereum_wallet.dart b/cw_ethereum/lib/ethereum_wallet.dart index 84c0b16de..a067a2975 100644 --- a/cw_ethereum/lib/ethereum_wallet.dart +++ b/cw_ethereum/lib/ethereum_wallet.dart @@ -130,61 +130,61 @@ abstract class EthereumWalletBase } - // if (hasMultiDestination) { - // if (outputs.any((item) => item.sendAll - // || (item.formattedCryptoAmount ?? 0) <= 0)) { - // throw EthereumTransactionCreationException(); - // } - // - // final BigInt totalAmount = outputs.fold(0, (acc, value) => - // acc + (value.formattedCryptoAmount ?? 0)); - // - // if (balance.getInWei < EtherAmount.inWei(totalAmount)) { - // throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.'); - // } - // - // final moneroOutputs = outputs.map((output) { - // final outputAddress = output.isParsedAddress - // ? output.extractedAddress - // : output.address; - // - // return MoneroOutput( - // address: outputAddress!, - // amount: output.cryptoAmount!.replaceAll(',', '.')); - // }).toList(); - // - // pendingTransactionDescription = - // await transaction_history.createTransactionMultDest( - // outputs: moneroOutputs, - // priorityRaw: _credentials.priority.serialize(), - // accountIndex: walletAddresses.account!.id); - // } else { - // final output = outputs.first; - // final address = output.isParsedAddress - // ? output.extractedAddress - // : output.address; - // final amount = output.sendAll - // ? null - // : output.cryptoAmount!.replaceAll(',', '.'); - // final formattedAmount = output.sendAll - // ? null - // : output.formattedCryptoAmount; - // - // if ((formattedAmount != null && unlockedBalance < formattedAmount) || - // (formattedAmount == null && unlockedBalance <= 0)) { - // final formattedBalance = moneroAmountToString(amount: unlockedBalance); - // - // throw MoneroTransactionCreationException( - // 'Incorrect unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${output.cryptoAmount}.'); - // } - // - // pendingTransactionDescription = - // await transaction_history.createTransaction( - // address: address!, - // amount: amount, - // priorityRaw: _credentials.priority.serialize(), - // accountIndex: walletAddresses.account!.id); - // } + if (hasMultiDestination) { + if (outputs.any((item) => item.sendAll + || (item.formattedCryptoAmount ?? 0) <= 0)) { + throw EthereumTransactionCreationException(); + } + + final BigInt totalAmount = outputs.fold(0, (acc, value) => + acc + (value.formattedCryptoAmount ?? 0)); + + if (balance.getInWei < EtherAmount.inWei(totalAmount)) { + throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.'); + } + + final moneroOutputs = outputs.map((output) { + final outputAddress = output.isParsedAddress + ? output.extractedAddress + : output.address; + + return MoneroOutput( + address: outputAddress!, + amount: output.cryptoAmount!.replaceAll(',', '.')); + }).toList(); + + pendingTransactionDescription = + await transaction_history.createTransactionMultDest( + outputs: moneroOutputs, + priorityRaw: _credentials.priority.serialize(), + accountIndex: walletAddresses.account!.id); + } else { + final output = outputs.first; + final address = output.isParsedAddress + ? output.extractedAddress + : output.address; + final amount = output.sendAll + ? null + : output.cryptoAmount!.replaceAll(',', '.'); + final formattedAmount = output.sendAll + ? null + : output.formattedCryptoAmount; + + if ((formattedAmount != null && unlockedBalance < formattedAmount) || + (formattedAmount == null && unlockedBalance <= 0)) { + final formattedBalance = moneroAmountToString(amount: unlockedBalance); + + throw MoneroTransactionCreationException( + 'Incorrect unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${output.cryptoAmount}.'); + } + + pendingTransactionDescription = + await transaction_history.createTransaction( + address: address!, + amount: amount, + priorityRaw: _credentials.priority.serialize(), + accountIndex: walletAddresses.account!.id); + } return PendingEthereumTransaction( client: _client, diff --git a/tool/configure.dart b/tool/configure.dart index aa9288d92..69cf8040b 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -484,7 +484,9 @@ import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_credentials.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:cw_core/wallet_service.dart'; +import 'package:cw_ethereum/ethereum_formatter.dart'; import 'package:cw_ethereum/ethereum_mnemonics.dart'; +import 'package:cw_ethereum/ethereum_transaction_credentials.dart'; import 'package:cw_ethereum/ethereum_wallet.dart'; import 'package:cw_ethereum/ethereum_wallet_creation_credentials.dart'; import 'package:cw_ethereum/ethereum_wallet_service.dart'; @@ -506,6 +508,8 @@ abstract class Ethereum { Object createEthereumTransactionCredentials(List outputs, {required TransactionPriority priority, int? feeRate}); Object createEthereumTransactionCredentialsRaw(List outputs, {TransactionPriority? priority, required int feeRate}); + + int formatterEthereumParseAmount(String amount); } """;