From a8375321bc74355a62a45d61beb209011b9d133f Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Wed, 11 Aug 2021 15:20:09 +0300 Subject: [PATCH] CAKE-345 | applied "any" method instead "where" and made single conditions in the createTransaction method (electrum and monero wallets); renamed credentialAmount on totalAmount and made it final in the monero_wallet.dart; made optional paymentId in createTransaction and createTransactionMultDest methods in the transaction_history.dart --- cw_monero/lib/transaction_history.dart | 4 ++-- lib/bitcoin/electrum_wallet.dart | 12 ++---------- lib/monero/monero_wallet.dart | 20 ++++---------------- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/cw_monero/lib/transaction_history.dart b/cw_monero/lib/transaction_history.dart index 58db9c8e3..0ca584778 100644 --- a/cw_monero/lib/transaction_history.dart +++ b/cw_monero/lib/transaction_history.dart @@ -205,7 +205,7 @@ PendingTransactionDescription _createTransactionMultDestSync(Map args) { Future createTransaction( {String address, - String paymentId, + String paymentId = '', String amount, int priorityRaw, int accountIndex = 0}) => @@ -219,7 +219,7 @@ Future createTransaction( Future createTransactionMultDest( {List outputs, - String paymentId, + String paymentId = '', int priorityRaw, int accountIndex = 0}) => compute(_createTransactionMultDestSync, { diff --git a/lib/bitcoin/electrum_wallet.dart b/lib/bitcoin/electrum_wallet.dart index 2df77951c..5b7970c3b 100644 --- a/lib/bitcoin/electrum_wallet.dart +++ b/lib/bitcoin/electrum_wallet.dart @@ -186,16 +186,8 @@ abstract class ElectrumWalletBase extends WalletBase item.sendAll).toList(); - - if (sendAllItems?.isNotEmpty ?? false) { - throw BitcoinTransactionWrongBalanceException(currency); - } - - final nullAmountItems = outputs.where((item) => - item.formattedCryptoAmount <= 0).toList(); - - if (nullAmountItems?.isNotEmpty ?? false) { + if (outputs.any((item) => item.sendAll) || + outputs.any((item) => item.formattedCryptoAmount <= 0)) { throw BitcoinTransactionWrongBalanceException(currency); } diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index 3acb67926..08c6d1ef3 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -163,25 +163,15 @@ abstract class MoneroWalletBase extends WalletBase item.sendAll).toList(); - - if (sendAllItems?.isNotEmpty ?? false) { + if (outputs.any((item) => item.sendAll) || + outputs.any((item) => item.formattedCryptoAmount <= 0)) { throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.'); } - final nullAmountItems = outputs.where((item) => - item.formattedCryptoAmount <= 0).toList(); - - if (nullAmountItems?.isNotEmpty ?? false) { - throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.'); - } - - var credentialsAmount = 0; - - credentialsAmount = outputs.fold(0, (acc, value) => + final int totalAmount = outputs.fold(0, (acc, value) => acc + value.formattedCryptoAmount); - if (unlockedBalance < credentialsAmount) { + if (unlockedBalance < totalAmount) { throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.'); } @@ -194,7 +184,6 @@ abstract class MoneroWalletBase extends WalletBase