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

OleksandrSobol committed Aug 11, 2021 at 15:20 UTC a8375321bc74355a62a45d61beb209011b9d133f
3 files changed +8 -28
cw_monero/lib/transaction_history.dart
+2 -2
@@ -205,7 +205,7 @@ PendingTransactionDescription _createTransactionMultDestSync(Map args) {
205
206 Future<PendingTransactionDescription> createTransaction(
207 {String address,
208 - String paymentId,
208 + String paymentId = '',
209 String amount,
210 int priorityRaw,
211 int accountIndex = 0}) =>
@@ -219,7 +219,7 @@ Future<PendingTransactionDescription> createTransaction(
219
220 Future<PendingTransactionDescription> createTransactionMultDest(
221 {List<MoneroOutput> outputs,
222 - String paymentId,
222 + String paymentId = '',
223 int priorityRaw,
224 int accountIndex = 0}) =>
225 compute(_createTransactionMultDestSync, {
lib/bitcoin/electrum_wallet.dart
+2 -10
@@ -186,16 +186,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
186 var fee = 0;
187
188 if (hasMultiDestination) {
189 - final sendAllItems = outputs.where((item) => item.sendAll).toList();
190 -
191 - if (sendAllItems?.isNotEmpty ?? false) {
192 - throw BitcoinTransactionWrongBalanceException(currency);
193 - }
194 -
195 - final nullAmountItems = outputs.where((item) =>
196 - item.formattedCryptoAmount <= 0).toList();
197 -
198 - if (nullAmountItems?.isNotEmpty ?? false) {
189 + if (outputs.any((item) => item.sendAll) ||
190 + outputs.any((item) => item.formattedCryptoAmount <= 0)) {
191 throw BitcoinTransactionWrongBalanceException(currency);
192 }
193
lib/monero/monero_wallet.dart
+4 -16
@@ -163,25 +163,15 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
163 }
164
165 if (hasMultiDestination) {
166 - final sendAllItems = outputs.where((item) => item.sendAll).toList();
167 -
168 - if (sendAllItems?.isNotEmpty ?? false) {
169 - throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.');
170 - }
171 -
172 - final nullAmountItems = outputs.where((item) =>
173 - item.formattedCryptoAmount <= 0).toList();
174 -
175 - if (nullAmountItems?.isNotEmpty ?? false) {
166 + if (outputs.any((item) => item.sendAll) ||
167 + outputs.any((item) => item.formattedCryptoAmount <= 0)) {
168 throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.');
169 }
170
179 - var credentialsAmount = 0;
180 -
181 - credentialsAmount = outputs.fold(0, (acc, value) =>
171 + final int totalAmount = outputs.fold(0, (acc, value) =>
172 acc + value.formattedCryptoAmount);
173
184 - if (unlockedBalance < credentialsAmount) {
174 + if (unlockedBalance < totalAmount) {
175 throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.');
176 }
177
@@ -194,7 +184,6 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
184 pendingTransactionDescription =
185 await transaction_history.createTransactionMultDest(
186 outputs: moneroOutputs,
197 - paymentId: '',
187 priorityRaw: _credentials.priority.serialize(),
188 accountIndex: walletAddresses.account.id);
189 } else {
@@ -218,7 +207,6 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
207 pendingTransactionDescription =
208 await transaction_history.createTransaction(
209 address: address,
221 - paymentId: '',
210 amount: amount,
211 priorityRaw: _credentials.priority.serialize(),
212 accountIndex: walletAddresses.account.id);