mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-01 12:04:21 +01:00
CAKE-345 | applied batch sending to monero wallet
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
import 'package:cake_wallet/entities/transaction_creation_credentials.dart';
|
||||
import 'package:cake_wallet/entities/monero_transaction_priority.dart';
|
||||
import 'package:cake_wallet/view_model/send/send_item.dart';
|
||||
|
||||
class MoneroTransactionCreationCredentials
|
||||
extends TransactionCreationCredentials {
|
||||
MoneroTransactionCreationCredentials(
|
||||
{this.address, this.paymentId, this.priority, this.amount});
|
||||
MoneroTransactionCreationCredentials({this.sendItemList, this.priority});
|
||||
|
||||
final String address;
|
||||
final String paymentId;
|
||||
final String amount;
|
||||
final List<SendItem> sendItemList;
|
||||
final MoneroTransactionPriority priority;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:cake_wallet/monero/monero_transaction_creation_exception.dart';
|
||||
import 'package:cake_wallet/monero/monero_transaction_info.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet_addresses.dart';
|
||||
import 'package:cake_wallet/monero/monero_wallet_utils.dart';
|
||||
import 'package:cw_monero/structs/pending_transaction.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cw_monero/transaction_history.dart'
|
||||
@@ -149,31 +150,80 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
||||
@override
|
||||
Future<PendingTransaction> createTransaction(Object credentials) async {
|
||||
final _credentials = credentials as MoneroTransactionCreationCredentials;
|
||||
final amount = _credentials.amount != null
|
||||
? moneroParseAmount(amount: _credentials.amount)
|
||||
: null;
|
||||
final sendItemList = _credentials.sendItemList;
|
||||
final listSize = sendItemList.length;
|
||||
final unlockedBalance =
|
||||
monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account.id);
|
||||
monero_wallet.getUnlockedBalance(accountIndex: walletAddresses.account.id);
|
||||
|
||||
if ((amount != null && unlockedBalance < amount) ||
|
||||
(amount == null && unlockedBalance <= 0)) {
|
||||
final formattedBalance = moneroAmountToString(amount: unlockedBalance);
|
||||
|
||||
throw MoneroTransactionCreationException(
|
||||
'Incorrect unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${_credentials.amount}.');
|
||||
}
|
||||
PendingTransactionDescription pendingTransactionDescription;
|
||||
|
||||
if (!(syncStatus is SyncedSyncStatus)) {
|
||||
throw MoneroTransactionCreationException('The wallet is not synced.');
|
||||
}
|
||||
|
||||
final pendingTransactionDescription =
|
||||
await transaction_history.createTransaction(
|
||||
address: _credentials.address,
|
||||
paymentId: _credentials.paymentId,
|
||||
amount: _credentials.amount,
|
||||
priorityRaw: _credentials.priority.serialize(),
|
||||
accountIndex: walletAddresses.account.id);
|
||||
if (listSize > 1) {
|
||||
final sendAllItems = sendItemList.where((item) => item.sendAll).toList();
|
||||
|
||||
if (sendAllItems?.isNotEmpty ?? false) {
|
||||
throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.');
|
||||
}
|
||||
|
||||
final nullAmountItems = sendItemList.where((item) =>
|
||||
moneroParseAmount(amount: item.cryptoAmount.replaceAll(',', '.')) <= 0)
|
||||
.toList();
|
||||
|
||||
if (nullAmountItems?.isNotEmpty ?? false) {
|
||||
throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.');
|
||||
}
|
||||
|
||||
var credentialsAmount = 0;
|
||||
|
||||
credentialsAmount = sendItemList.fold(0, (previousValue, element) =>
|
||||
previousValue + moneroParseAmount(
|
||||
amount: element.cryptoAmount.replaceAll(',', '.')));
|
||||
|
||||
if (unlockedBalance < credentialsAmount) {
|
||||
throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.');
|
||||
}
|
||||
|
||||
final addresses = sendItemList.map((e) => e.address).toList();
|
||||
final amounts = sendItemList.map((e) =>
|
||||
e.cryptoAmount.replaceAll(',', '.')).toList();
|
||||
|
||||
pendingTransactionDescription =
|
||||
await transaction_history.createTransactionMultDest(
|
||||
addresses: addresses,
|
||||
paymentId: '',
|
||||
amounts: amounts,
|
||||
size: listSize,
|
||||
priorityRaw: _credentials.priority.serialize(),
|
||||
accountIndex: walletAddresses.account.id);
|
||||
} else {
|
||||
final item = sendItemList.first;
|
||||
final address = item.address;
|
||||
final amount = item.sendAll
|
||||
? null
|
||||
: item.cryptoAmount.replaceAll(',', '.');
|
||||
final formattedAmount = item.sendAll
|
||||
? null
|
||||
: moneroParseAmount(amount: amount);
|
||||
|
||||
if ((formattedAmount != null && unlockedBalance < formattedAmount) ||
|
||||
(formattedAmount == null && unlockedBalance <= 0)) {
|
||||
final formattedBalance = moneroAmountToString(amount: unlockedBalance);
|
||||
|
||||
throw MoneroTransactionCreationException(
|
||||
'Incorrect unlocked balance. Unlocked: $formattedBalance. Transaction amount: ${item.cryptoAmount}.');
|
||||
}
|
||||
|
||||
pendingTransactionDescription =
|
||||
await transaction_history.createTransaction(
|
||||
address: address,
|
||||
paymentId: '',
|
||||
amount: amount,
|
||||
priorityRaw: _credentials.priority.serialize(),
|
||||
accountIndex: walletAddresses.account.id);
|
||||
}
|
||||
|
||||
return PendingMoneroTransaction(pendingTransactionDescription);
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ class SendPage extends BasePage {
|
||||
EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
||||
bottomSection: Column(
|
||||
children: [
|
||||
if (sendViewModel.isElectrumWallet) Padding(
|
||||
Padding(
|
||||
padding: EdgeInsets.only(bottom: 12),
|
||||
child: PrimaryButton(
|
||||
onPressed: () {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
|
||||
import 'package:cake_wallet/bitcoin/electrum_wallet.dart';
|
||||
import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
|
||||
import 'package:cake_wallet/entities/openalias_record.dart';
|
||||
import 'package:cake_wallet/entities/parse_address_from_domain.dart';
|
||||
import 'package:cake_wallet/entities/parsed_address.dart';
|
||||
import 'package:cake_wallet/monero/monero_amount_format.dart';
|
||||
|
||||
@@ -199,18 +199,11 @@ abstract class SendViewModelBase with Store {
|
||||
return BitcoinTransactionCredentials(
|
||||
sendItemList, priority as BitcoinTransactionPriority);
|
||||
case WalletType.monero:
|
||||
final _item = sendItemList.first;
|
||||
final address = _item.address;
|
||||
final amount = _item.sendAll
|
||||
? null
|
||||
: _item.cryptoAmount.replaceAll(',', '.');
|
||||
final priority = _settingsStore.priority[_wallet.type];
|
||||
|
||||
return MoneroTransactionCreationCredentials(
|
||||
address: address,
|
||||
paymentId: '',
|
||||
priority: priority as MoneroTransactionPriority,
|
||||
amount: amount);
|
||||
sendItemList: sendItemList,
|
||||
priority: priority as MoneroTransactionPriority);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ abstract class TransactionDetailsViewModelBase with Store {
|
||||
this.settingsStore})
|
||||
: items = [] {
|
||||
showRecipientAddress = settingsStore?.shouldSaveRecipientAddress ?? false;
|
||||
isRecipientAddressShown = false;
|
||||
|
||||
final dateFormat = DateFormatter.withCurrentLocal();
|
||||
final tx = transactionInfo;
|
||||
@@ -64,6 +65,7 @@ abstract class TransactionDetailsViewModelBase with Store {
|
||||
final address =
|
||||
_wallet.getTransactionAddress(accountIndex, addressIndex);
|
||||
if (address?.isNotEmpty ?? false) {
|
||||
isRecipientAddressShown = true;
|
||||
_items.add(
|
||||
StandartListItem(
|
||||
title: S.current.transaction_details_recipient_address,
|
||||
@@ -101,7 +103,7 @@ abstract class TransactionDetailsViewModelBase with Store {
|
||||
items.addAll(_items);
|
||||
}
|
||||
|
||||
if (showRecipientAddress) {
|
||||
if (showRecipientAddress && !isRecipientAddressShown) {
|
||||
final recipientAddress = transactionDescriptionBox.values
|
||||
.firstWhere((val) => val.id == transactionInfo.id, orElse: () => null)
|
||||
?.recipientAddress;
|
||||
@@ -151,6 +153,7 @@ abstract class TransactionDetailsViewModelBase with Store {
|
||||
|
||||
final List<TransactionDetailsListItem> items;
|
||||
bool showRecipientAddress;
|
||||
bool isRecipientAddressShown;
|
||||
|
||||
String _explorerUrl(WalletType type, String txId) {
|
||||
switch (type) {
|
||||
|
||||
Reference in New Issue
Block a user