Merge pull request #181 from cake-tech/CAKE-345-batch-sending

Cake 345 batch sending
This commit is contained in:
M 2021-08-16 11:16:50 +02:00
commit cd45a2af7f
44 changed files with 1909 additions and 1168 deletions

View file

@ -495,6 +495,48 @@ extern "C"
return true;
}
bool transaction_create_mult_dest(char **addresses, char *payment_id, char **amounts, uint32_t size,
uint8_t priority_raw, uint32_t subaddr_account, Utf8Box &error, PendingTransactionRaw &pendingTransaction)
{
nice(19);
std::vector<std::string> _addresses;
std::vector<uint64_t> _amounts;
for (int i = 0; i < size; i++) {
_addresses.push_back(std::string(*addresses));
_amounts.push_back(Monero::Wallet::amountFromString(std::string(*amounts)));
addresses++;
amounts++;
}
auto priority = static_cast<Monero::PendingTransaction::Priority>(priority_raw);
std::string _payment_id;
Monero::PendingTransaction *transaction;
if (payment_id != nullptr)
{
_payment_id = std::string(payment_id);
}
transaction = m_wallet->createTransactionMultDest(_addresses, _payment_id, _amounts, m_wallet->defaultMixin(), priority, subaddr_account);
int status = transaction->status();
if (status == Monero::PendingTransaction::Status::Status_Error || status == Monero::PendingTransaction::Status::Status_Critical)
{
error = Utf8Box(strdup(transaction->errorString().c_str()));
return false;
}
if (m_listener != nullptr) {
m_listener->m_new_transaction = true;
}
pendingTransaction = PendingTransactionRaw(transaction);
return true;
}
bool transaction_commit(PendingTransactionRaw *transaction, Utf8Box &error)
{
bool committed = transaction->transaction->commit();

View file

@ -0,0 +1,8 @@
import 'package:flutter/foundation.dart';
class MoneroOutput {
MoneroOutput({@required this.address, @required this.amount});
final String address;
final String amount;
}

View file

@ -95,6 +95,16 @@ typedef transaction_create = Int8 Function(
Pointer<Utf8Box> error,
Pointer<PendingTransactionRaw> pendingTransaction);
typedef transaction_create_mult_dest = Int8 Function(
Pointer<Pointer<Utf8>> addresses,
Pointer<Utf8> paymentId,
Pointer<Pointer<Utf8>> amounts,
Int32 size,
Int8 priorityRaw,
Int32 subaddrAccount,
Pointer<Utf8Box> error,
Pointer<PendingTransactionRaw> pendingTransaction);
typedef transaction_commit = Int8 Function(Pointer<PendingTransactionRaw>, Pointer<Utf8Box>);
typedef secret_view_key = Pointer<Utf8> Function();

View file

@ -1,5 +1,6 @@
import 'dart:ffi';
import 'package:cw_monero/convert_utf8_to_string.dart';
import 'package:cw_monero/monero_output.dart';
import 'package:cw_monero/structs/ut8_box.dart';
import 'package:ffi/ffi.dart';
import 'package:flutter/foundation.dart';
@ -26,6 +27,10 @@ final transactionCreateNative = moneroApi
.lookup<NativeFunction<transaction_create>>('transaction_create')
.asFunction<TransactionCreate>();
final transactionCreateMultDestNative = moneroApi
.lookup<NativeFunction<transaction_create_mult_dest>>('transaction_create_mult_dest')
.asFunction<TransactionCreateMultDest>();
final transactionCommitNative = moneroApi
.lookup<NativeFunction<transaction_commit>>('transaction_commit')
.asFunction<TransactionCommit>();
@ -102,6 +107,59 @@ PendingTransactionDescription createTransactionSync(
pointerAddress: pendingTransactionRawPointer.address);
}
PendingTransactionDescription createTransactionMultDestSync(
{List<MoneroOutput> outputs,
String paymentId,
int priorityRaw,
int accountIndex = 0}) {
final int size = outputs.length;
final List<Pointer<Utf8>> addressesPointers = outputs.map((output) =>
Utf8.toUtf8(output.address)).toList();
final Pointer<Pointer<Utf8>> addressesPointerPointer = allocate(count: size);
final List<Pointer<Utf8>> amountsPointers = outputs.map((output) =>
Utf8.toUtf8(output.amount)).toList();
final Pointer<Pointer<Utf8>> amountsPointerPointer = allocate(count: size);
for (int i = 0; i < size; i++) {
addressesPointerPointer[i] = addressesPointers[i];
amountsPointerPointer[i] = amountsPointers[i];
}
final paymentIdPointer = Utf8.toUtf8(paymentId);
final errorMessagePointer = allocate<Utf8Box>();
final pendingTransactionRawPointer = allocate<PendingTransactionRaw>();
final created = transactionCreateMultDestNative(
addressesPointerPointer,
paymentIdPointer,
amountsPointerPointer,
size,
priorityRaw,
accountIndex,
errorMessagePointer,
pendingTransactionRawPointer) !=
0;
free(addressesPointerPointer);
free(amountsPointerPointer);
addressesPointers.forEach((element) => free(element));
amountsPointers.forEach((element) => free(element));
free(paymentIdPointer);
if (!created) {
final message = errorMessagePointer.ref.getValue();
free(errorMessagePointer);
throw CreationTransactionException(message: message);
}
return PendingTransactionDescription(
amount: pendingTransactionRawPointer.ref.amount,
fee: pendingTransactionRawPointer.ref.fee,
hash: pendingTransactionRawPointer.ref.getHash(),
pointerAddress: pendingTransactionRawPointer.address);
}
void commitTransactionFromPointerAddress({int address}) => commitTransaction(
transactionPointer: Pointer<PendingTransactionRaw>.fromAddress(address));
@ -132,9 +190,22 @@ PendingTransactionDescription _createTransactionSync(Map args) {
accountIndex: accountIndex);
}
PendingTransactionDescription _createTransactionMultDestSync(Map args) {
final outputs = args['outputs'] as List<MoneroOutput>;
final paymentId = args['paymentId'] as String;
final priorityRaw = args['priorityRaw'] as int;
final accountIndex = args['accountIndex'] as int;
return createTransactionMultDestSync(
outputs: outputs,
paymentId: paymentId,
priorityRaw: priorityRaw,
accountIndex: accountIndex);
}
Future<PendingTransactionDescription> createTransaction(
{String address,
String paymentId,
String paymentId = '',
String amount,
int priorityRaw,
int accountIndex = 0}) =>
@ -145,3 +216,15 @@ Future<PendingTransactionDescription> createTransaction(
'priorityRaw': priorityRaw,
'accountIndex': accountIndex
});
Future<PendingTransactionDescription> createTransactionMultDest(
{List<MoneroOutput> outputs,
String paymentId = '',
int priorityRaw,
int accountIndex = 0}) =>
compute(_createTransactionMultDestSync, {
'outputs': outputs,
'paymentId': paymentId,
'priorityRaw': priorityRaw,
'accountIndex': accountIndex
});

View file

@ -93,6 +93,16 @@ typedef TransactionCreate = int Function(
Pointer<Utf8Box> error,
Pointer<PendingTransactionRaw> pendingTransaction);
typedef TransactionCreateMultDest = int Function(
Pointer<Pointer<Utf8>> addresses,
Pointer<Utf8> paymentId,
Pointer<Pointer<Utf8>> amounts,
int size,
int priorityRaw,
int subaddrAccount,
Pointer<Utf8Box> error,
Pointer<PendingTransactionRaw> pendingTransaction);
typedef TransactionCommit = int Function(Pointer<PendingTransactionRaw>, Pointer<Utf8Box>);
typedef SecretViewKey = Pointer<Utf8> Function();

View file

@ -16,24 +16,12 @@ double bitcoinAmountToDouble({int amount}) =>
cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider);
int stringDoubleToBitcoinAmount(String amount) {
final splitted = amount.split('');
final dotIndex = amount.indexOf('.');
int result = 0;
for (var i = 0; i < splitted.length; i++) {
try {
if (dotIndex == i) {
continue;
}
final char = splitted[i];
final multiplier = dotIndex < i
? bitcoinAmountDivider ~/ pow(10, (i - dotIndex))
: (bitcoinAmountDivider * pow(10, (dotIndex - i -1))).toInt();
final num = int.parse(char) * multiplier;
result += num;
} catch (_) {}
try {
result = (double.parse(amount) * bitcoinAmountDivider).toInt();
} catch (e) {
result = 0;
}
return result;

View file

@ -1,9 +1,9 @@
import 'package:cake_wallet/bitcoin/bitcoin_transaction_priority.dart';
import 'package:cake_wallet/view_model/send/output.dart';
class BitcoinTransactionCredentials {
BitcoinTransactionCredentials(this.address, this.amount, this.priority);
BitcoinTransactionCredentials(this.outputs, this.priority);
final String address;
final String amount;
final List<Output> outputs;
BitcoinTransactionPriority priority;
}

View file

@ -158,9 +158,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
const minAmount = 546;
final transactionCredentials = credentials as BitcoinTransactionCredentials;
final inputs = <BitcoinUnspent>[];
final credentialsAmount = transactionCredentials.amount != null
? stringDoubleToBitcoinAmount(transactionCredentials.amount)
: 0;
final outputs = transactionCredentials.outputs;
final hasMultiDestination = outputs.length > 1;
var allInputsAmount = 0;
if (unspentCoins.isEmpty) {
@ -174,28 +173,60 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
}
}
if (inputs.isEmpty ||
(credentialsAmount > 0 && allInputsAmount < credentialsAmount)) {
if (inputs.isEmpty) {
throw BitcoinTransactionNoInputsException();
}
final allAmountFee =
feeAmountForPriority(transactionCredentials.priority, inputs.length, 1);
final allAmountFee = feeAmountForPriority(
transactionCredentials.priority, inputs.length, outputs.length);
final allAmount = allInputsAmount - allAmountFee;
final amount = transactionCredentials.amount == null ||
allAmount - credentialsAmount < minAmount
? allAmount
: credentialsAmount;
final fee = transactionCredentials.amount == null || amount == allAmount
? allAmountFee
: calculateEstimatedFee(transactionCredentials.priority, amount);
var credentialsAmount = 0;
var amount = 0;
var fee = 0;
if (hasMultiDestination) {
if (outputs.any((item) => item.sendAll
|| item.formattedCryptoAmount <= 0)) {
throw BitcoinTransactionWrongBalanceException(currency);
}
credentialsAmount = outputs.fold(0, (acc, value) =>
acc + value.formattedCryptoAmount);
if (allAmount - credentialsAmount < minAmount) {
throw BitcoinTransactionWrongBalanceException(currency);
}
amount = credentialsAmount;
fee = calculateEstimatedFee(transactionCredentials.priority, amount,
outputsCount: outputs.length + 1);
} else {
final output = outputs.first;
credentialsAmount = !output.sendAll
? output.formattedCryptoAmount
: 0;
if (credentialsAmount > allAmount) {
throw BitcoinTransactionWrongBalanceException(currency);
}
amount = output.sendAll || allAmount - credentialsAmount < minAmount
? allAmount
: credentialsAmount;
fee = output.sendAll || amount == allAmount
? allAmountFee
: calculateEstimatedFee(transactionCredentials.priority, amount);
}
if (fee == 0) {
throw BitcoinTransactionWrongBalanceException(currency);
}
final totalAmount = amount + fee;
final totalAmount = amount + fee;
if (totalAmount > balance.confirmed || totalAmount > allInputsAmount) {
throw BitcoinTransactionWrongBalanceException(currency);
@ -234,8 +265,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
if (input.isP2wpkh) {
final p2wpkh = bitcoin
.P2WPKH(
data: generatePaymentData(hd: hd, index: input.address.index),
network: networkType)
data: generatePaymentData(hd: hd, index: input.address.index),
network: networkType)
.data;
txb.addInput(input.hash, input.vout, null, p2wpkh.output);
@ -244,11 +275,18 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
}
});
txb.addOutput(
addressToOutputScript(transactionCredentials.address, networkType),
amount);
outputs.forEach((item) {
final outputAmount = hasMultiDestination
? item.formattedCryptoAmount
: amount;
final estimatedSize = estimatedTransactionSize(inputs.length, 2);
txb.addOutput(
addressToOutputScript(item.address, networkType),
outputAmount);
});
final estimatedSize =
estimatedTransactionSize(inputs.length, outputs.length + 1);
final feeAmount = feeRate(transactionCredentials.priority) * estimatedSize;
final changeValue = totalInputAmount - amount - feeAmount;
@ -293,7 +331,8 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
feeRate(priority) * estimatedTransactionSize(inputsCount, outputsCount);
@override
int calculateEstimatedFee(TransactionPriority priority, int amount) {
int calculateEstimatedFee(TransactionPriority priority, int amount,
{int outputsCount}) {
if (priority is BitcoinTransactionPriority) {
int inputsCount = 0;
@ -321,8 +360,10 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
}
// If send all, then we have no change value
final _outputsCount = outputsCount ?? (amount != null ? 2 : 1);
return feeAmountForPriority(
priority, inputsCount, amount != null ? 2 : 1);
priority, inputsCount, _outputsCount);
}
return 0;

View file

@ -75,6 +75,7 @@ import 'package:cake_wallet/view_model/node_list/node_create_or_edit_view_model.
import 'package:cake_wallet/view_model/order_details_view_model.dart';
import 'package:cake_wallet/view_model/rescan_view_model.dart';
import 'package:cake_wallet/view_model/restore_from_backup_view_model.dart';
import 'package:cake_wallet/view_model/send/send_template_view_model.dart';
import 'package:cake_wallet/view_model/setup_pin_code_view_model.dart';
import 'package:cake_wallet/view_model/support_view_model.dart';
import 'package:cake_wallet/view_model/transaction_details_view_model.dart';
@ -316,10 +317,17 @@ Future setup(
addressEditOrCreateViewModel:
getIt.get<WalletAddressEditOrCreateViewModel>(param1: item)));
getIt.registerFactory<SendViewModel>(() => SendViewModel(
getIt.registerFactory<SendTemplateViewModel>(() => SendTemplateViewModel(
getIt.get<AppStore>().wallet,
getIt.get<AppStore>().settingsStore,
getIt.get<SendTemplateStore>(),
getIt.get<FiatConversionStore>()
));
getIt.registerFactory<SendViewModel>(() => SendViewModel(
getIt.get<AppStore>().wallet,
getIt.get<AppStore>().settingsStore,
getIt.get<SendTemplateViewModel>(),
getIt.get<FiatConversionStore>(),
_transactionDescriptionBox));
@ -327,7 +335,8 @@ Future setup(
() => SendPage(sendViewModel: getIt.get<SendViewModel>()));
getIt.registerFactory(
() => SendTemplatePage(sendViewModel: getIt.get<SendViewModel>()));
() => SendTemplatePage(
sendTemplateViewModel: getIt.get<SendTemplateViewModel>()));
getIt.registerFactory(() => WalletListViewModel(
_walletInfoSource,

View file

@ -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/output.dart';
class MoneroTransactionCreationCredentials
extends TransactionCreationCredentials {
MoneroTransactionCreationCredentials(
{this.address, this.paymentId, this.priority, this.amount});
MoneroTransactionCreationCredentials({this.outputs, this.priority});
final String address;
final String paymentId;
final String amount;
final List<Output> outputs;
final MoneroTransactionPriority priority;
}

View file

@ -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'
@ -12,6 +13,7 @@ import 'package:cw_monero/transaction_history.dart'
import 'package:cw_monero/wallet.dart';
import 'package:cw_monero/wallet.dart' as monero_wallet;
import 'package:cw_monero/transaction_history.dart' as transaction_history;
import 'package:cw_monero/monero_output.dart';
import 'package:cake_wallet/monero/monero_transaction_creation_credentials.dart';
import 'package:cake_wallet/monero/pending_monero_transaction.dart';
import 'package:cake_wallet/monero/monero_wallet_keys.dart';
@ -149,31 +151,66 @@ 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 outputs = _credentials.outputs;
final hasMultiDestination = outputs.length > 1;
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 (hasMultiDestination) {
if (outputs.any((item) => item.sendAll
|| item.formattedCryptoAmount <= 0)) {
throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.');
}
final int totalAmount = outputs.fold(0, (acc, value) =>
acc + value.formattedCryptoAmount);
if (unlockedBalance < totalAmount) {
throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.');
}
final moneroOutputs = outputs.map((output) =>
MoneroOutput(
address: output.address,
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.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 PendingMoneroTransaction(pendingTransactionDescription);
}

View file

@ -786,22 +786,7 @@ class ExchangePage extends BasePage {
BuildContext context, String domain, String ticker) async {
final parsedAddress = await parseAddressFromDomain(domain, ticker);
switch (parsedAddress.parseFrom) {
case ParseFrom.unstoppableDomains:
showAddressAlert(
context,
S.of(context).address_detected,
S.of(context).address_from_domain(parsedAddress.name));
break;
case ParseFrom.openAlias:
showAddressAlert(
context,
S.of(context).openalias_alert_title,
S.of(context).openalias_alert_content(parsedAddress.name));
break;
case ParseFrom.notParsed:
break;
}
showAddressAlert(context, parsedAddress);
return parsedAddress.address;
}

View file

@ -165,11 +165,9 @@ class ExchangeCardState extends State<ExchangeCard> {
textAlign: TextAlign.left,
keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: true),
// inputFormatters: [
// LengthLimitingTextInputFormatter(15),
// BlacklistingTextInputFormatter(
// RegExp('[\\-|\\ |\\,]'))
// ],
inputFormatters: [
FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]'))
],
hintText: '0.0000',
borderColor: widget.borderColor,
textStyle: TextStyle(

View file

@ -385,9 +385,8 @@ class ExchangeTradeState extends State<ExchangeTradeForm> {
.pendingTransactionFiatAmount +
' ' +
widget.exchangeTradeViewModel.sendViewModel.fiat.title,
recipientTitle: S.of(context).recipient_address,
recipientAddress:
widget.exchangeTradeViewModel.sendViewModel.address);
outputs: widget.exchangeTradeViewModel.sendViewModel
.outputs);
});
});
}

File diff suppressed because it is too large Load diff

View file

@ -2,11 +2,10 @@ import 'package:mobx/mobx.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
import 'package:cake_wallet/src/screens/base_page.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/view_model/send/send_view_model.dart';
import 'package:cake_wallet/view_model/send/send_template_view_model.dart';
import 'package:cake_wallet/src/widgets/address_text_field.dart';
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
@ -14,9 +13,11 @@ import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
class SendTemplatePage extends BasePage {
SendTemplatePage({@required this.sendViewModel});
SendTemplatePage({@required this.sendTemplateViewModel}) {
sendTemplateViewModel.output.reset();
}
final SendViewModel sendViewModel;
final SendTemplateViewModel sendTemplateViewModel;
final _addressController = TextEditingController();
final _cryptoAmountController = TextEditingController();
final _fiatAmountController = TextEditingController();
@ -100,7 +101,7 @@ class SendTemplatePage extends BasePage {
.decorationColor,
fontWeight: FontWeight.w500,
fontSize: 14),
validator: sendViewModel.templateValidator,
validator: sendTemplateViewModel.templateValidator,
),
Padding(
padding: EdgeInsets.only(top: 20),
@ -145,49 +146,47 @@ class SendTemplatePage extends BasePage {
.primaryTextTheme
.headline
.decorationColor),
//validator: sendViewModel.addressValidator,
),
),
Observer(builder: (_) {
return Padding(
padding: const EdgeInsets.only(top: 20),
child: BaseTextFormField(
focusNode: _cryptoAmountFocus,
controller: _cryptoAmountController,
keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: true),
inputFormatters: [
BlacklistingTextInputFormatter(
RegExp('[\\-|\\ ]'))
],
prefixIcon: Padding(
padding: EdgeInsets.only(top: 9),
child:
Text(sendViewModel.currency.title + ':',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
)),
),
hintText: '0.0000',
borderColor: Theme.of(context)
.primaryTextTheme
.headline
.color,
textStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white),
placeholderTextStyle: TextStyle(
color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor,
fontWeight: FontWeight.w500,
fontSize: 14),
validator: sendViewModel.amountValidator));
}),
Padding(
padding: const EdgeInsets.only(top: 20),
child: BaseTextFormField(
focusNode: _cryptoAmountFocus,
controller: _cryptoAmountController,
keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: true),
inputFormatters: [
FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]'))
],
prefixIcon: Padding(
padding: EdgeInsets.only(top: 9),
child:
Text(sendTemplateViewModel
.currency.title + ':',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
)),
),
hintText: '0.0000',
borderColor: Theme.of(context)
.primaryTextTheme
.headline
.color,
textStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white),
placeholderTextStyle: TextStyle(
color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor,
fontWeight: FontWeight.w500,
fontSize: 14),
validator: sendTemplateViewModel
.amountValidator)),
Padding(
padding: const EdgeInsets.only(top: 20),
child: BaseTextFormField(
@ -196,12 +195,12 @@ class SendTemplatePage extends BasePage {
keyboardType: TextInputType.numberWithOptions(
signed: false, decimal: true),
inputFormatters: [
BlacklistingTextInputFormatter(
RegExp('[\\-|\\ ]'))
FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]'))
],
prefixIcon: Padding(
padding: EdgeInsets.only(top: 9),
child: Text(sendViewModel.fiat.title + ':',
child: Text(sendTemplateViewModel
.fiat.title + ':',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
@ -236,12 +235,11 @@ class SendTemplatePage extends BasePage {
bottomSection: PrimaryButton(
onPressed: () {
if (_formKey.currentState.validate()) {
sendViewModel.addTemplate(
sendTemplateViewModel.addTemplate(
name: _nameController.text,
address: _addressController.text,
cryptoCurrency: sendViewModel.currency.title,
cryptoCurrency: sendTemplateViewModel.currency.title,
amount: _cryptoAmountController.text);
sendViewModel.updateTemplate();
Navigator.of(context).pop();
}
},
@ -258,19 +256,21 @@ class SendTemplatePage extends BasePage {
return;
}
reaction((_) => sendViewModel.fiatAmount, (String amount) {
final output = sendTemplateViewModel.output;
reaction((_) => output.fiatAmount, (String amount) {
if (amount != _fiatAmountController.text) {
_fiatAmountController.text = amount;
}
});
reaction((_) => sendViewModel.cryptoAmount, (String amount) {
reaction((_) => output.cryptoAmount, (String amount) {
if (amount != _cryptoAmountController.text) {
_cryptoAmountController.text = amount;
}
});
reaction((_) => sendViewModel.address, (String address) {
reaction((_) => output.address, (String address) {
if (address != _addressController.text) {
_addressController.text = address;
}
@ -279,24 +279,24 @@ class SendTemplatePage extends BasePage {
_cryptoAmountController.addListener(() {
final amount = _cryptoAmountController.text;
if (amount != sendViewModel.cryptoAmount) {
sendViewModel.setCryptoAmount(amount);
if (amount != output.cryptoAmount) {
output.setCryptoAmount(amount);
}
});
_fiatAmountController.addListener(() {
final amount = _fiatAmountController.text;
if (amount != sendViewModel.fiatAmount) {
sendViewModel.setFiatAmount(amount);
if (amount != output.fiatAmount) {
output.setFiatAmount(amount);
}
});
_addressController.addListener(() {
final address = _addressController.text;
if (sendViewModel.address != address) {
sendViewModel.address = address;
if (output.address != address) {
output.address = address;
}
});

View file

@ -1,6 +1,9 @@
import 'package:cake_wallet/palette.dart';
import 'package:cake_wallet/view_model/send/output.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/src/widgets/base_alert_dialog.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/widgets/cake_scrollbar.dart';
class ConfirmSendingAlert extends BaseAlertDialog {
ConfirmSendingAlert({
@ -11,14 +14,12 @@ class ConfirmSendingAlert extends BaseAlertDialog {
@required this.fee,
@required this.feeValue,
@required this.feeFiatAmount,
@required this.recipientTitle,
@required this.recipientAddress,
@required this.outputs,
@required this.leftButtonText,
@required this.rightButtonText,
@required this.actionLeftButton,
@required this.actionRightButton,
this.alertBarrierDismissible = true
});
this.alertBarrierDismissible = true});
final String alertTitle;
final String amount;
@ -27,8 +28,7 @@ class ConfirmSendingAlert extends BaseAlertDialog {
final String fee;
final String feeValue;
final String feeFiatAmount;
final String recipientTitle;
final String recipientAddress;
final List<Output> outputs;
final String leftButtonText;
final String rightButtonText;
final VoidCallback actionLeftButton;
@ -57,128 +57,290 @@ class ConfirmSendingAlert extends BaseAlertDialog {
bool get barrierDismissible => alertBarrierDismissible;
@override
Widget content(BuildContext context) {
return Column(
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
amount,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.normal,
fontFamily: 'Lato',
color: Theme.of(context).primaryTextTheme.title.color,
decoration: TextDecoration.none,
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
amountValue,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: Theme.of(context).primaryTextTheme.title.color,
decoration: TextDecoration.none,
),
),
Text(
fiatAmountValue,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: PaletteDark.pigeonBlue,
decoration: TextDecoration.none,
),
Widget content(BuildContext context) => ConfirmSendingAlertContent(
amount: amount,
amountValue: amountValue,
fiatAmountValue: fiatAmountValue,
fee: fee,
feeValue: feeValue,
feeFiatAmount: feeFiatAmount,
outputs: outputs
);
}
class ConfirmSendingAlertContent extends StatefulWidget {
ConfirmSendingAlertContent({
@required this.amount,
@required this.amountValue,
@required this.fiatAmountValue,
@required this.fee,
@required this.feeValue,
@required this.feeFiatAmount,
@required this.outputs});
final String amount;
final String amountValue;
final String fiatAmountValue;
final String fee;
final String feeValue;
final String feeFiatAmount;
final List<Output> outputs;
@override
ConfirmSendingAlertContentState createState() => ConfirmSendingAlertContentState(
amount: amount,
amountValue: amountValue,
fiatAmountValue: fiatAmountValue,
fee: fee,
feeValue: feeValue,
feeFiatAmount: feeFiatAmount,
outputs: outputs
);
}
class ConfirmSendingAlertContentState extends State<ConfirmSendingAlertContent> {
ConfirmSendingAlertContentState({
@required this.amount,
@required this.amountValue,
@required this.fiatAmountValue,
@required this.fee,
@required this.feeValue,
@required this.feeFiatAmount,
@required this.outputs}) {
itemCount = outputs.length;
recipientTitle = itemCount > 1
? S.current.transaction_details_recipient_address
: S.current.recipient_address;
}
final String amount;
final String amountValue;
final String fiatAmountValue;
final String fee;
final String feeValue;
final String feeFiatAmount;
final List<Output> outputs;
final double backgroundHeight = 160;
final double thumbHeight = 72;
ScrollController controller = ScrollController();
double fromTop = 0;
String recipientTitle;
int itemCount;
@override
Widget build(BuildContext context) {
controller.addListener(() {
fromTop = controller.hasClients
? (controller.offset / controller.position.maxScrollExtent *
(backgroundHeight - thumbHeight))
: 0;
setState(() {});
});
return Stack(
alignment: Alignment.center,
clipBehavior: Clip.none,
children: [
Container(
height: 200,
child: SingleChildScrollView(
controller: controller,
child: Column(
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
amount,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.normal,
fontFamily: 'Lato',
color: Theme.of(context)
.primaryTextTheme
.title
.color,
decoration: TextDecoration.none,
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
amountValue,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: Theme.of(context)
.primaryTextTheme
.title
.color,
decoration: TextDecoration.none,
),
),
Text(
fiatAmountValue,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: PaletteDark.pigeonBlue,
decoration: TextDecoration.none,
),
)
],
)
],
),
Padding(
padding: EdgeInsets.only(top: 16),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
fee,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.normal,
fontFamily: 'Lato',
color: Theme.of(context)
.primaryTextTheme
.title
.color,
decoration: TextDecoration.none,
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
feeValue,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: Theme.of(context)
.primaryTextTheme
.title
.color,
decoration: TextDecoration.none,
),
),
Text(
feeFiatAmount,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: PaletteDark.pigeonBlue,
decoration: TextDecoration.none,
),
)
],
)
],
)
),
Padding(
padding: EdgeInsets.only(top: 16),
child: Column(
children: [
Text(
'$recipientTitle:',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.normal,
fontFamily: 'Lato',
color: Theme.of(context)
.primaryTextTheme
.title
.color,
decoration: TextDecoration.none,
),
),
itemCount > 1
? ListView.builder(
padding: EdgeInsets.only(top: 0),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: itemCount,
itemBuilder: (context, index) {
final item = outputs[index];
final _address = item.address;
final _amount =
item.cryptoAmount.replaceAll(',', '.');
return Column(
children: [
Padding(
padding: EdgeInsets.only(top: 8),
child: Text(
_address,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: PaletteDark.pigeonBlue,
decoration: TextDecoration.none,
),
)
),
Padding(
padding: EdgeInsets.only(top: 8),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Text(
_amount,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: PaletteDark.pigeonBlue,
decoration: TextDecoration.none,
),
)
],
)
)
],
);
})
: Padding(
padding: EdgeInsets.only(top: 8),
child: Text(
outputs.first.address,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: PaletteDark.pigeonBlue,
decoration: TextDecoration.none,
),
),
)
],
),
)
],
)
],
)
],
),
Padding(
padding: EdgeInsets.only(top: 16),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
fee,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.normal,
fontFamily: 'Lato',
color: Theme.of(context).primaryTextTheme.title.color,
decoration: TextDecoration.none,
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
feeValue,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: Theme.of(context).primaryTextTheme.title.color,
decoration: TextDecoration.none,
),
),
Text(
feeFiatAmount,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: PaletteDark.pigeonBlue,
decoration: TextDecoration.none,
),
)
],
)
],
if (itemCount > 1) CakeScrollbar(
backgroundHeight: backgroundHeight,
thumbHeight: thumbHeight,
fromTop: fromTop,
rightOffset: -15
)
),
Padding(
padding: EdgeInsets.fromLTRB(0, 16, 0, 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
'$recipientTitle:',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.normal,
fontFamily: 'Lato',
color: Theme.of(context).primaryTextTheme.title.color,
decoration: TextDecoration.none,
),
),
Padding(
padding: EdgeInsets.only(top: 8),
child: Text(
recipientAddress,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
fontFamily: 'Lato',
color: PaletteDark.pigeonBlue,
decoration: TextDecoration.none,
),
)
)
],
),
)
],
]
);
}
}

View file

@ -1,9 +1,26 @@
import 'package:cake_wallet/entities/parsed_address.dart';
import 'package:cake_wallet/src/widgets/alert_with_one_action.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/generated/i18n.dart';
void showAddressAlert(BuildContext context, String title, String content) async {
void showAddressAlert(BuildContext context, ParsedAddress parsedAddress) async {
var title = '';
var content = '';
switch (parsedAddress.parseFrom) {
case ParseFrom.unstoppableDomains:
title = S.of(context).address_detected;
content = S.of(context).address_from_domain(parsedAddress.name);
break;
case ParseFrom.openAlias:
title = S.of(context).openalias_alert_title;
content = S.of(context).openalias_alert_content(parsedAddress.name);
break;
case ParseFrom.notParsed:
return;
}
await showPopUp<void>(
context: context,
builder: (BuildContext context) {

View file

@ -0,0 +1,561 @@
import 'dart:ui';
import 'package:cake_wallet/entities/transaction_priority.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/send/widgets/parse_address_from_domain_alert.dart';
import 'package:cake_wallet/src/widgets/keyboard_done_button.dart';
import 'package:cake_wallet/src/widgets/picker.dart';
import 'package:cake_wallet/view_model/send/output.dart';
import 'package:cake_wallet/view_model/settings/settings_view_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:mobx/mobx.dart';
import 'package:keyboard_actions/keyboard_actions.dart';
import 'package:cake_wallet/view_model/send/send_view_model.dart';
import 'package:cake_wallet/utils/show_pop_up.dart';
import 'package:cake_wallet/src/widgets/address_text_field.dart';
import 'package:cake_wallet/generated/i18n.dart';
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
class SendCard extends StatefulWidget {
SendCard({Key key, @required this.output, @required this.sendViewModel}) : super(key: key);
final Output output;
final SendViewModel sendViewModel;
@override
SendCardState createState() => SendCardState(
output: output,
sendViewModel: sendViewModel
);
}
class SendCardState extends State<SendCard>
with AutomaticKeepAliveClientMixin<SendCard> {
SendCardState({@required this.output, @required this.sendViewModel})
: addressController = TextEditingController(),
cryptoAmountController = TextEditingController(),
fiatAmountController = TextEditingController(),
noteController = TextEditingController(),
cryptoAmountFocus = FocusNode(),
fiatAmountFocus = FocusNode(),
addressFocusNode = FocusNode();
static const prefixIconWidth = 34.0;
static const prefixIconHeight = 34.0;
final Output output;
final SendViewModel sendViewModel;
final TextEditingController addressController;
final TextEditingController cryptoAmountController;
final TextEditingController fiatAmountController;
final TextEditingController noteController;
final FocusNode cryptoAmountFocus;
final FocusNode fiatAmountFocus;
final FocusNode addressFocusNode;
bool _effectsInstalled = false;
@override
Widget build(BuildContext context) {
super.build(context);
_setEffects(context);
return Stack(
children: [
KeyboardActions(
config: KeyboardActionsConfig(
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
keyboardBarColor: Theme.of(context).accentTextTheme.body2
.backgroundColor,
nextFocus: false,
actions: [
KeyboardActionsItem(
focusNode: cryptoAmountFocus,
toolbarButtons: [(_) => KeyboardDoneButton()],
),
KeyboardActionsItem(
focusNode: fiatAmountFocus,
toolbarButtons: [(_) => KeyboardDoneButton()],
)
]),
child: Container(
height: 0,
color: Colors.transparent,
)),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(24),
bottomRight: Radius.circular(24)),
gradient: LinearGradient(colors: [
Theme.of(context).primaryTextTheme.subhead.color,
Theme.of(context)
.primaryTextTheme
.subhead
.decorationColor,
], begin: Alignment.topLeft, end: Alignment.bottomRight),
),
child: Padding(
padding: EdgeInsets.fromLTRB(24, 100, 24, 32),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
AddressTextField(
focusNode: addressFocusNode,
controller: addressController,
onURIScanned: (uri) {
var address = '';
var amount = '';
if (uri != null) {
address = uri.path;
amount = uri.queryParameters['tx_amount'] ??
uri.queryParameters['amount'];
} else {
address = uri.toString();
}
addressController.text = address;
cryptoAmountController.text = amount;
},
options: [
AddressTextFieldOption.paste,
AddressTextFieldOption.qrCode,
AddressTextFieldOption.addressBook
],
buttonColor: Theme.of(context)
.primaryTextTheme
.display1
.color,
borderColor: Theme.of(context)
.primaryTextTheme
.headline
.color,
textStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white),
hintStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor),
onPushPasteButton: (context) async {
final parsedAddress =
await output.applyOpenaliasOrUnstoppableDomains();
showAddressAlert(context, parsedAddress);
},
validator: sendViewModel.addressValidator,
),
Observer(
builder: (_) => Padding(
padding: const EdgeInsets.only(top: 20),
child: Stack(
children: [
BaseTextFormField(
focusNode: cryptoAmountFocus,
controller: cryptoAmountController,
keyboardType:
TextInputType.numberWithOptions(
signed: false, decimal: true),
inputFormatters: [
FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]'))
],
prefixIcon: Padding(
padding: EdgeInsets.only(top: 9),
child: Text(
sendViewModel.currency.title +
':',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
)),
),
suffixIcon: SizedBox(
width: prefixIconWidth,
),
hintText: '0.0000',
borderColor: Theme.of(context)
.primaryTextTheme
.headline
.color,
textStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white),
placeholderTextStyle: TextStyle(
color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor,
fontWeight: FontWeight.w500,
fontSize: 14),
validator: output.sendAll
? sendViewModel.allAmountValidator
: sendViewModel
.amountValidator),
if (!sendViewModel.isBatchSending) Positioned(
top: 2,
right: 0,
child: Container(
width: prefixIconWidth,
height: prefixIconHeight,
child: InkWell(
onTap: () async =>
output.setSendAll(),
child: Container(
decoration: BoxDecoration(
color: Theme.of(context)
.primaryTextTheme
.display1
.color,
borderRadius:
BorderRadius.all(
Radius.circular(6))),
child: Center(
child: Text(
S.of(context).all,
textAlign:
TextAlign.center,
style: TextStyle(
fontSize: 12,
fontWeight:
FontWeight.bold,
color:
Theme.of(context)
.primaryTextTheme
.display1
.decorationColor))),
))))])
)),
Observer(
builder: (_) => Padding(
padding: EdgeInsets.only(top: 10),
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: Text(
S.of(context).available_balance +
':',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor),
)),
Text(
sendViewModel.balance,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor),
)
],
),
)),
Padding(
padding: const EdgeInsets.only(top: 20),
child: BaseTextFormField(
focusNode: fiatAmountFocus,
controller: fiatAmountController,
keyboardType:
TextInputType.numberWithOptions(
signed: false, decimal: true),
inputFormatters: [
FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]'))
],
prefixIcon: Padding(
padding: EdgeInsets.only(top: 9),
child:
Text(sendViewModel.fiat.title + ':',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
)),
),
hintText: '0.00',
borderColor: Theme.of(context)
.primaryTextTheme
.headline
.color,
textStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white),
placeholderTextStyle: TextStyle(
color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor,
fontWeight: FontWeight.w500,
fontSize: 14),
)),
Padding(
padding: EdgeInsets.only(top: 20),
child: BaseTextFormField(
controller: noteController,
keyboardType: TextInputType.multiline,
maxLines: null,
borderColor: Theme.of(context)
.primaryTextTheme
.headline
.color,
textStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Colors.white),
hintText: S.of(context).note_optional,
placeholderTextStyle: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Theme.of(context)
.primaryTextTheme
.headline
.decorationColor),
),
),
Observer(
builder: (_) => GestureDetector(
onTap: () =>
_setTransactionPriority(context),
child: Container(
padding: EdgeInsets.only(top: 24),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
S
.of(context)
.send_estimated_fee,
style: TextStyle(
fontSize: 12,
fontWeight:
FontWeight.w500,
//color: Theme.of(context).primaryTextTheme.display2.color,
color: Colors.white)),
Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
output
.estimatedFee
.toString() +
' ' +
sendViewModel
.currency.title,
style: TextStyle(
fontSize: 12,
fontWeight:
FontWeight.w600,
//color: Theme.of(context).primaryTextTheme.display2.color,
color:
Colors.white)),
Padding(
padding:
EdgeInsets.only(top: 5),
child: Text(
output
.estimatedFeeFiatAmount
+ ' ' +
sendViewModel
.fiat.title,
style: TextStyle(
fontSize: 12,
fontWeight:
FontWeight.w600,
color: Theme
.of(context)
.primaryTextTheme
.headline
.decorationColor))
),
],
),
Padding(
padding: EdgeInsets.only(
top: 2,
left: 5),
child: Icon(
Icons.arrow_forward_ios,
size: 12,
color: Colors.white,
),
)
],
),
)
],
),
),
)),
if (sendViewModel.isElectrumWallet) Padding(
padding: EdgeInsets.only(top: 6),
child: GestureDetector(
onTap: () => Navigator.of(context)
.pushNamed(Routes.unspentCoinsList),
child: Container(
color: Colors.transparent,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
S.of(context).coin_control,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.white)),
Icon(
Icons.arrow_forward_ios,
size: 12,
color: Colors.white,
)
],
)
)
)
)
],
)
),
),
)
],
);
}
void _setEffects(BuildContext context) {
addressController.text = output.address;
cryptoAmountController.text = output.cryptoAmount;
fiatAmountController.text = output.fiatAmount;
noteController.text = output.note;
if (_effectsInstalled) {
return;
}
cryptoAmountController.addListener(() {
final amount = cryptoAmountController.text;
if (output.sendAll && amount != S.current.all) {
output.sendAll = false;
}
if (amount != output.cryptoAmount) {
output.setCryptoAmount(amount);
}
});
fiatAmountController.addListener(() {
final amount = fiatAmountController.text;
if (amount != output.fiatAmount) {
output.sendAll = false;
output.setFiatAmount(amount);
}
});
noteController.addListener(() {
final note = noteController.text ?? '';
if (note != output.note) {
output.note = note;
}
});
reaction((_) => output.sendAll, (bool all) {
if (all) {
cryptoAmountController.text = S.current.all;
fiatAmountController.text = null;
}
});
reaction((_) => output.fiatAmount, (String amount) {
if (amount != fiatAmountController.text) {
fiatAmountController.text = amount;
}
});
reaction((_) => output.cryptoAmount, (String amount) {
if (output.sendAll && amount != S.current.all) {
output.sendAll = false;
}
if (amount != cryptoAmountController.text) {
cryptoAmountController.text = amount;
}
});
reaction((_) => output.address, (String address) {
if (address != addressController.text) {
addressController.text = address;
}
});
addressController.addListener(() {
final address = addressController.text;
if (output.address != address) {
output.address = address;
}
});
reaction((_) => output.note, (String note) {
if (note != noteController.text) {
noteController.text = note;
}
});
addressFocusNode.addListener(() async {
if (!addressFocusNode.hasFocus && addressController.text.isNotEmpty) {
final parsedAddress = await output.applyOpenaliasOrUnstoppableDomains();
showAddressAlert(context, parsedAddress);
}
});
_effectsInstalled = true;
}
Future<void> _setTransactionPriority(BuildContext context) async {
final items = priorityForWalletType(sendViewModel.walletType);
final selectedItem = items.indexOf(sendViewModel.transactionPriority);
await showPopUp<void>(
builder: (_) => Picker(
items: items,
displayItem: sendViewModel.displayFeeRate,
selectedAtIndex: selectedItem,
title: S.of(context).please_select,
mainAxisAlignment: MainAxisAlignment.center,
onItemSelected: (TransactionPriority priority) =>
sendViewModel.setTransactionPriority(priority),
),
context: context);
}
@override
bool get wantKeepAlive => true;
}

View file

@ -4,17 +4,19 @@ class CakeScrollbar extends StatelessWidget {
CakeScrollbar({
@required this.backgroundHeight,
@required this.thumbHeight,
@required this.fromTop
@required this.fromTop,
this.rightOffset = 6
});
final double backgroundHeight;
final double thumbHeight;
final double fromTop;
final double rightOffset;
@override
Widget build(BuildContext context) {
return Positioned(
right: 6,
right: rightOffset,
child: Container(
height: backgroundHeight,
width: 6,

View file

@ -1,3 +1,4 @@
import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@ -8,18 +9,22 @@ class PrimaryButton extends StatelessWidget {
@required this.color,
@required this.textColor,
this.isDisabled = false,
this.isDottedBorder = false,
this.borderColor = Colors.black,
this.onDisabledPressed});
final VoidCallback onPressed;
final VoidCallback onDisabledPressed;
final Color color;
final Color textColor;
final Color borderColor;
final String text;
final bool isDisabled;
final bool isDottedBorder;
@override
Widget build(BuildContext context) {
return ButtonTheme(
final content = ButtonTheme(
minWidth: double.infinity,
height: 52.0,
child: FlatButton(
@ -27,6 +32,8 @@ class PrimaryButton extends StatelessWidget {
? (onDisabledPressed != null ? onDisabledPressed : null)
: onPressed,
color: isDisabled ? color.withOpacity(0.5) : color,
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
disabledColor: color.withOpacity(0.5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(26.0),
@ -40,6 +47,16 @@ class PrimaryButton extends StatelessWidget {
? textColor.withOpacity(0.5)
: textColor)),
));
return isDottedBorder
? DottedBorder(
borderType: BorderType.RRect,
dashPattern: [6, 4],
color: borderColor,
strokeWidth: 2,
radius: Radius.circular(26),
child: content)
: content;
}
}

View file

@ -105,10 +105,12 @@ class BrightTheme extends ThemeBase {
),
display2: TextStyle(
color: Colors.white.withOpacity(0.5), // estimated fee (send page)
backgroundColor: PaletteDark.darkCyanBlue.withOpacity(0.67), // dot color for indicator on send page
decorationColor: Palette.shadowWhite // template dotted border (send page)
),
display3: TextStyle(
color: Palette.darkBlueCraiola, // template new text (send page)
backgroundColor: PaletteDark.darkNightBlue, // active dot color for indicator on send page
decorationColor: Palette.shadowWhite // template background color (send page)
),
display4: TextStyle(

View file

@ -104,10 +104,12 @@ class DarkTheme extends ThemeBase {
),
display2: TextStyle(
color: Colors.white, // estimated fee (send page)
backgroundColor: PaletteDark.cyanBlue, // dot color for indicator on send page
decorationColor: PaletteDark.darkCyanBlue // template dotted border (send page)
),
display3: TextStyle(
color: PaletteDark.darkCyanBlue, // template new text (send page)
backgroundColor: Colors.white, // active dot color for indicator on send page
decorationColor: PaletteDark.darkVioletBlue // template background color (send page)
),
display4: TextStyle(

View file

@ -105,10 +105,12 @@ class LightTheme extends ThemeBase {
),
display2: TextStyle(
color: Colors.white.withOpacity(0.5), // estimated fee (send page)
backgroundColor: PaletteDark.darkCyanBlue.withOpacity(0.67), // dot color for indicator on send page
decorationColor: Palette.moderateLavender // template dotted border (send page)
),
display3: TextStyle(
color: Palette.darkBlueCraiola, // template new text (send page)
backgroundColor: PaletteDark.darkNightBlue, // active dot color for indicator on send page
decorationColor: Palette.blueAlice // template background color (send page)
),
display4: TextStyle(

View file

@ -79,8 +79,11 @@ abstract class ExchangeTradeViewModelBase with Store {
return;
}
sendViewModel.address = trade.inputAddress;
sendViewModel.setCryptoAmount(trade.amount);
sendViewModel.clearOutputs();
final output = sendViewModel.outputs.first;
output.address = trade.inputAddress;
output.setCryptoAmount(trade.amount);
await sendViewModel.createTransaction();
}

View file

@ -0,0 +1,206 @@
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/parse_address_from_domain.dart';
import 'package:cake_wallet/entities/parsed_address.dart';
import 'package:cake_wallet/monero/monero_amount_format.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/core/wallet_base.dart';
import 'package:cake_wallet/monero/monero_wallet.dart';
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/generated/i18n.dart';
part 'output.g.dart';
const String cryptoNumberPattern = '0.0';
class Output = OutputBase with _$Output;
abstract class OutputBase with Store {
OutputBase(this._wallet, this._settingsStore, this._fiatConversationStore)
:_cryptoNumberFormat = NumberFormat(cryptoNumberPattern) {
reset();
_setCryptoNumMaximumFractionDigits();
key = UniqueKey();
}
Key key;
@observable
String fiatAmount;
@observable
String cryptoAmount;
@observable
String address;
@observable
String note;
@observable
bool sendAll;
@computed
int get formattedCryptoAmount {
int amount = 0;
try {
if (cryptoAmount?.isNotEmpty ?? false) {
final _cryptoAmount = cryptoAmount.replaceAll(',', '.');
int _amount = 0;
switch (walletType) {
case WalletType.monero:
_amount = moneroParseAmount(amount: _cryptoAmount);
break;
case WalletType.bitcoin:
_amount = stringDoubleToBitcoinAmount(_cryptoAmount);
break;
case WalletType.litecoin:
_amount = stringDoubleToBitcoinAmount(_cryptoAmount);
break;
default:
break;
}
if (_amount > 0) {
amount = _amount;
}
}
} catch(e) {
amount = 0;
}
return amount;
}
@computed
double get estimatedFee {
try {
final fee = _wallet.calculateEstimatedFee(
_settingsStore.priority[_wallet.type], formattedCryptoAmount);
if (_wallet is ElectrumWallet) {
return bitcoinAmountToDouble(amount: fee);
}
if (_wallet is MoneroWallet) {
return moneroAmountToDouble(amount: fee);
}
} catch (e) {
print(e.toString());
}
return 0;
}
@computed
String get estimatedFeeFiatAmount {
try {
final fiat = calculateFiatAmountRaw(
price: _fiatConversationStore.prices[_wallet.currency],
cryptoAmount: estimatedFee);
return fiat;
} catch (_) {
return '0.00';
}
}
WalletType get walletType => _wallet.type;
final WalletBase _wallet;
final SettingsStore _settingsStore;
final FiatConversionStore _fiatConversationStore;
final NumberFormat _cryptoNumberFormat;
@action
void setSendAll() => sendAll = true;
@action
void reset() {
sendAll = false;
cryptoAmount = '';
fiatAmount = '';
address = '';
note = '';
}
@action
void setCryptoAmount(String amount) {
if (amount.toUpperCase() != S.current.all) {
sendAll = false;
}
cryptoAmount = amount;
_updateFiatAmount();
}
@action
void setFiatAmount(String amount) {
fiatAmount = amount;
_updateCryptoAmount();
}
@action
void _updateFiatAmount() {
try {
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[_wallet.currency],
cryptoAmount: cryptoAmount.replaceAll(',', '.'));
if (fiatAmount != fiat) {
fiatAmount = fiat;
}
} catch (_) {
fiatAmount = '';
}
}
@action
void _updateCryptoAmount() {
try {
final crypto = double.parse(fiatAmount.replaceAll(',', '.')) /
_fiatConversationStore.prices[_wallet.currency];
final cryptoAmountTmp = _cryptoNumberFormat.format(crypto);
if (cryptoAmount != cryptoAmountTmp) {
cryptoAmount = cryptoAmountTmp;
}
} catch (e) {
cryptoAmount = '';
}
}
void _setCryptoNumMaximumFractionDigits() {
var maximumFractionDigits = 0;
switch (_wallet.type) {
case WalletType.monero:
maximumFractionDigits = 12;
break;
case WalletType.bitcoin:
maximumFractionDigits = 8;
break;
case WalletType.litecoin:
maximumFractionDigits = 8;
break;
default:
break;
}
_cryptoNumberFormat.maximumFractionDigits = maximumFractionDigits;
}
Future<ParsedAddress> applyOpenaliasOrUnstoppableDomains() async {
final domain = address;
final ticker = _wallet.currency.title.toLowerCase();
final parsedAddress = await parseAddressFromDomain(domain, ticker);
address = parsedAddress.address;
return parsedAddress;
}
}

View file

@ -0,0 +1,66 @@
import 'package:cake_wallet/view_model/send/output.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/entities/template.dart';
import 'package:cake_wallet/store/templates/send_template_store.dart';
import 'package:cake_wallet/core/template_validator.dart';
import 'package:cake_wallet/core/address_validator.dart';
import 'package:cake_wallet/core/amount_validator.dart';
import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/core/wallet_base.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
import 'package:cake_wallet/entities/fiat_currency.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cake_wallet/store/settings_store.dart';
part 'send_template_view_model.g.dart';
class SendTemplateViewModel = SendTemplateViewModelBase
with _$SendTemplateViewModel;
abstract class SendTemplateViewModelBase with Store {
SendTemplateViewModelBase(this._wallet, this._settingsStore,
this._sendTemplateStore, this._fiatConversationStore) {
output = Output(_wallet, _settingsStore, _fiatConversationStore);
}
Output output;
Validator get amountValidator => AmountValidator(type: _wallet.type);
Validator get addressValidator => AddressValidator(type: _wallet.currency);
Validator get templateValidator => TemplateValidator();
CryptoCurrency get currency => _wallet.currency;
FiatCurrency get fiat => _settingsStore.fiatCurrency;
@computed
ObservableList<Template> get templates => _sendTemplateStore.templates;
final WalletBase _wallet;
final SettingsStore _settingsStore;
final SendTemplateStore _sendTemplateStore;
final FiatConversionStore _fiatConversationStore;
void updateTemplate() => _sendTemplateStore.update();
void addTemplate(
{String name,
String address,
String cryptoCurrency,
String amount}) {
_sendTemplateStore.addTemplate(
name: name,
address: address,
cryptoCurrency: cryptoCurrency,
amount: amount);
updateTemplate();
}
void removeTemplate({Template template}) {
_sendTemplateStore.remove(template: template);
updateTemplate();
}
}

View file

@ -1,17 +1,13 @@
import 'package:cake_wallet/bitcoin/bitcoin_amount_format.dart';
import 'package:cake_wallet/bitcoin/bitcoin_transaction_priority.dart';
import 'package:cake_wallet/bitcoin/electrum_wallet.dart';
import 'package:cake_wallet/entities/calculate_fiat_amount_raw.dart';
import 'package:cake_wallet/entities/transaction_description.dart';
import 'package:cake_wallet/entities/transaction_priority.dart';
import 'package:cake_wallet/monero/monero_amount_format.dart';
import 'package:cake_wallet/view_model/send/output.dart';
import 'package:cake_wallet/view_model/send/send_template_view_model.dart';
import 'package:cake_wallet/view_model/settings/settings_view_model.dart';
import 'package:hive/hive.dart';
import 'package:intl/intl.dart';
import 'package:mobx/mobx.dart';
import 'package:cake_wallet/entities/template.dart';
import 'package:cake_wallet/store/templates/send_template_store.dart';
import 'package:cake_wallet/core/template_validator.dart';
import 'package:cake_wallet/core/address_validator.dart';
import 'package:cake_wallet/core/amount_validator.dart';
import 'package:cake_wallet/core/pending_transaction.dart';
@ -19,7 +15,6 @@ import 'package:cake_wallet/core/validator.dart';
import 'package:cake_wallet/core/wallet_base.dart';
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/bitcoin/bitcoin_transaction_credentials.dart';
import 'package:cake_wallet/monero/monero_wallet.dart';
import 'package:cake_wallet/monero/monero_transaction_creation_credentials.dart';
import 'package:cake_wallet/entities/sync_status.dart';
import 'package:cake_wallet/entities/crypto_currency.dart';
@ -30,21 +25,16 @@ import 'package:cake_wallet/entities/wallet_type.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/view_model/send/send_view_model_state.dart';
import 'package:cake_wallet/generated/i18n.dart';
part 'send_view_model.g.dart';
const String cryptoNumberPattern = '0.0';
class SendViewModel = SendViewModelBase with _$SendViewModel;
abstract class SendViewModelBase with Store {
SendViewModelBase(this._wallet, this._settingsStore, this._sendTemplateStore,
this._fiatConversationStore, this.transactionDescriptionBox)
: state = InitialExecutionState(),
_cryptoNumberFormat = NumberFormat(cryptoNumberPattern),
note = '',
sendAll = false {
SendViewModelBase(this._wallet, this._settingsStore,
this.sendTemplateViewModel, this._fiatConversationStore,
this.transactionDescriptionBox)
: state = InitialExecutionState() {
final priority = _settingsStore.priority[_wallet.type];
final priorities = priorityForWalletType(_wallet.type);
@ -52,84 +42,35 @@ abstract class SendViewModelBase with Store {
_settingsStore.priority[_wallet.type] = priorities.first;
}
isElectrumWallet = _wallet is ElectrumWallet;
_setCryptoNumMaximumFractionDigits();
outputs = ObservableList<Output>()
..add(Output(_wallet, _settingsStore, _fiatConversationStore));
}
@observable
ExecutionState state;
@observable
String fiatAmount;
ObservableList<Output> outputs;
@observable
String cryptoAmount;
@action
void addOutput() {
outputs.add(Output(_wallet, _settingsStore, _fiatConversationStore));
}
@observable
String address;
@observable
String note;
@observable
bool sendAll;
@computed
double get estimatedFee {
int amount;
try {
if (cryptoAmount?.isNotEmpty ?? false) {
final _cryptoAmount = cryptoAmount.replaceAll(',', '.');
int _amount = 0;
switch (walletType) {
case WalletType.monero:
_amount = moneroParseAmount(amount: _cryptoAmount);
break;
case WalletType.bitcoin:
_amount = stringDoubleToBitcoinAmount(_cryptoAmount);
break;
case WalletType.litecoin:
_amount = stringDoubleToBitcoinAmount(_cryptoAmount);
break;
default:
break;
}
if (_amount > 0) {
amount = _amount;
}
}
final fee = _wallet.calculateEstimatedFee(
_settingsStore.priority[_wallet.type], amount);
if (_wallet is ElectrumWallet) {
return bitcoinAmountToDouble(amount: fee);
}
if (_wallet is MoneroWallet) {
return moneroAmountToDouble(amount: fee);
}
} catch (e) {
print(e.toString());
@action
void removeOutput(Output output) {
if (isBatchSending) {
outputs.remove(output);
}
}
return 0;
@action
void clearOutputs() {
outputs.clear();
addOutput();
}
@computed
String get estimatedFeeFiatAmount {
try {
final fiat = calculateFiatAmountRaw(
price: _fiatConversationStore.prices[_wallet.currency],
cryptoAmount: estimatedFee);
return fiat;
} catch (_) {
return '0.00';
}
}
bool get isBatchSending => outputs.length > 1;
@computed
String get pendingTransactionFiatAmount {
@ -176,14 +117,9 @@ abstract class SendViewModelBase with Store {
Validator get addressValidator => AddressValidator(type: _wallet.currency);
Validator get templateValidator => TemplateValidator();
@observable
PendingTransaction pendingTransaction;
@observable
bool isElectrumWallet;
@computed
String get balance => _wallet.balance.formattedAvailableBalance ?? '0.0';
@ -191,28 +127,18 @@ abstract class SendViewModelBase with Store {
bool get isReadyForSend => _wallet.syncStatus is SyncedSyncStatus;
@computed
ObservableList<Template> get templates => _sendTemplateStore.templates;
ObservableList<Template> get templates => sendTemplateViewModel.templates;
@computed
bool get isElectrumWallet => _wallet is ElectrumWallet;
WalletType get walletType => _wallet.type;
final WalletBase _wallet;
final SettingsStore _settingsStore;
final SendTemplateStore _sendTemplateStore;
final SendTemplateViewModel sendTemplateViewModel;
final FiatConversionStore _fiatConversationStore;
final NumberFormat _cryptoNumberFormat;
final Box<TransactionDescription> transactionDescriptionBox;
@action
void setSendAll() => sendAll = true;
@action
void reset() {
sendAll = false;
cryptoAmount = '';
fiatAmount = '';
address = '';
note = '';
}
@action
Future<void> createTransaction() async {
try {
@ -226,6 +152,18 @@ abstract class SendViewModelBase with Store {
@action
Future<void> commitTransaction() async {
String address = outputs.fold('', (acc, value) {
return acc + value.address + '\n\n';
});
address = address.trim();
String note = outputs.fold('', (acc, value) {
return acc + value.note + '\n';
});
note = note.trim();
try {
state = TransactionCommitting();
await pendingTransaction.commit();
@ -246,121 +184,33 @@ abstract class SendViewModelBase with Store {
}
}
@action
void setCryptoAmount(String amount) {
if (amount.toUpperCase() != S.current.all) {
sendAll = false;
}
cryptoAmount = amount;
_updateFiatAmount();
}
@action
void setFiatAmount(String amount) {
fiatAmount = amount;
_updateCryptoAmount();
}
@action
void setTransactionPriority(TransactionPriority priority) =>
_settingsStore.priority[_wallet.type] = priority;
@action
void _updateFiatAmount() {
try {
final fiat = calculateFiatAmount(
price: _fiatConversationStore.prices[_wallet.currency],
cryptoAmount: cryptoAmount.replaceAll(',', '.'));
if (fiatAmount != fiat) {
fiatAmount = fiat;
}
} catch (_) {
fiatAmount = '';
}
}
@action
void _updateCryptoAmount() {
try {
final crypto = double.parse(fiatAmount.replaceAll(',', '.')) /
_fiatConversationStore.prices[_wallet.currency];
final cryptoAmountTmp = _cryptoNumberFormat.format(crypto);
if (cryptoAmount != cryptoAmountTmp) {
cryptoAmount = cryptoAmountTmp;
}
} catch (e) {
cryptoAmount = '';
}
}
Object _credentials() {
final _amount = cryptoAmount.replaceAll(',', '.');
switch (_wallet.type) {
case WalletType.bitcoin:
final amount = !sendAll ? _amount : null;
final priority = _settingsStore.priority[_wallet.type];
return BitcoinTransactionCredentials(
address, amount, priority as BitcoinTransactionPriority);
outputs, priority as BitcoinTransactionPriority);
case WalletType.litecoin:
final amount = !sendAll ? _amount : null;
final priority = _settingsStore.priority[_wallet.type];
return BitcoinTransactionCredentials(
address, amount, priority as BitcoinTransactionPriority);
outputs, priority as BitcoinTransactionPriority);
case WalletType.monero:
final amount = !sendAll ? _amount : null;
final priority = _settingsStore.priority[_wallet.type];
return MoneroTransactionCreationCredentials(
address: address,
paymentId: '',
priority: priority as MoneroTransactionPriority,
amount: amount);
outputs: outputs,
priority: priority as MoneroTransactionPriority);
default:
return null;
}
}
void _setCryptoNumMaximumFractionDigits() {
var maximumFractionDigits = 0;
switch (_wallet.type) {
case WalletType.monero:
maximumFractionDigits = 12;
break;
case WalletType.bitcoin:
maximumFractionDigits = 8;
break;
case WalletType.litecoin:
maximumFractionDigits = 8;
break;
default:
break;
}
_cryptoNumberFormat.maximumFractionDigits = maximumFractionDigits;
}
void updateTemplate() => _sendTemplateStore.update();
void addTemplate(
{String name,
String address,
String cryptoCurrency,
String amount}) =>
_sendTemplateStore.addTemplate(
name: name,
address: address,
cryptoCurrency: cryptoCurrency,
amount: amount);
void removeTemplate({Template template}) =>
_sendTemplateStore.remove(template: template);
String displayFeeRate(dynamic priority) {
final _priority = priority as TransactionPriority;
final wallet = _wallet;

View file

@ -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) {

View file

@ -11,7 +11,7 @@ description: Cake Wallet.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 4.2.3+53
version: 4.2.4+57
environment:
sdk: ">=2.7.0 <3.0.0"

View file

@ -284,7 +284,7 @@
"transaction_details_amount" : "Betrag",
"transaction_details_fee" : "Gebühr",
"transaction_details_copied" : "${title} in die Zwischenablage kopiert",
"transaction_details_recipient_address" : "Empfängeradresse",
"transaction_details_recipient_address" : "Empfängeradressen",
"wallet_list_title" : "Monero-Wallet",
@ -492,5 +492,7 @@
"coin_control" : "Münzkontrolle (optional)",
"address_detected" : "Adresse erkannt",
"address_from_domain" : "Sie haben die Adresse von der unaufhaltsamen Domain ${domain} erhalten"
"address_from_domain" : "Diese Adresse ist von ${domain} auf Unstoppable Domains",
"add_receiver" : "Fügen Sie einen weiteren Empfänger hinzu (optional)"
}

View file

@ -284,7 +284,7 @@
"transaction_details_amount" : "Amount",
"transaction_details_fee" : "Fee",
"transaction_details_copied" : "${title} copied to Clipboard",
"transaction_details_recipient_address" : "Recipient address",
"transaction_details_recipient_address" : "Recipient addresses",
"wallet_list_title" : "Monero Wallet",
@ -492,5 +492,7 @@
"coin_control" : "Coin control (optional)",
"address_detected" : "Address detected",
"address_from_domain" : "You got address from unstoppable domain ${domain}"
"address_from_domain" : "This address is from ${domain} on Unstoppable Domains",
"add_receiver" : "Add another receiver (optional)"
}

View file

@ -284,7 +284,7 @@
"transaction_details_amount" : "Cantidad",
"transaction_details_fee" : "Cuota",
"transaction_details_copied" : "${title} Copiado al portapapeles",
"transaction_details_recipient_address" : "Dirección del receptor",
"transaction_details_recipient_address" : "Direcciones de destinatarios",
"wallet_list_title" : "Monedero Monero",
@ -492,5 +492,7 @@
"coin_control" : "Control de monedas (opcional)",
"address_detected" : "Dirección detectada",
"address_from_domain" : "Tienes la dirección de unstoppable domain ${domain}"
"address_from_domain" : "Esta dirección es de ${domain} en Unstoppable Domains",
"add_receiver" : "Agregar otro receptor (opcional)"
}

View file

@ -284,7 +284,7 @@
"transaction_details_amount" : "रकम",
"transaction_details_fee" : "शुल्क",
"transaction_details_copied" : "${title} क्लिपबोर्ड पर नकल",
"transaction_details_recipient_address" : "प्राप्तकर्ता का पता",
"transaction_details_recipient_address" : "प्राप्तकर्ता के पते",
"wallet_list_title" : "Monero बटुआ",
@ -492,5 +492,7 @@
"coin_control" : "सिक्का नियंत्रण (वैकल्पिक)",
"address_detected" : "पता लग गया",
"address_from_domain" : "आपको अजेय डोमेन ${domain} से पता मिला है"
"address_from_domain" : "यह पता ${domain} से है Unstoppable Domains",
"add_receiver" : "एक और रिसीवर जोड़ें (वैकल्पिक)"
}

View file

@ -284,7 +284,7 @@
"transaction_details_amount" : "Iznos",
"transaction_details_fee" : "Naknada",
"transaction_details_copied" : "${title} kopiran u međuspremnik",
"transaction_details_recipient_address" : "Primateljeva adresa",
"transaction_details_recipient_address" : "Adrese primatelja",
"wallet_list_title" : "Monero novčanik",
@ -492,5 +492,7 @@
"coin_control" : "Kontrola novca (nije obavezno)",
"address_detected" : "Adresa je otkrivena",
"address_from_domain" : "Dobili ste adresu od unstoppable domain ${domain}"
"address_from_domain" : "To je adresa od ${domain} na Unstoppable Domains",
"add_receiver" : "Dodajte drugi prijemnik (izborno)"
}

View file

@ -284,7 +284,7 @@
"transaction_details_amount" : "Ammontare",
"transaction_details_fee" : "Commissione",
"transaction_details_copied" : "${title} copiati negli Appunti",
"transaction_details_recipient_address" : "Indirizzo destinatario",
"transaction_details_recipient_address" : "Indirizzi dei destinatari",
"wallet_list_title" : "Portafoglio Monero",
@ -492,5 +492,7 @@
"coin_control" : "Controllo monete (opzionale)",
"address_detected" : "Indirizzo rilevato",
"address_from_domain" : "Hai l'indirizzo da unstoppable domain ${domain}"
"address_from_domain" : "Questo indirizzo è da ${domain} in poi Unstoppable Domains",
"add_receiver" : "Aggiungi un altro ricevitore (opzionale)"
}

View file

@ -284,7 +284,7 @@
"transaction_details_amount" : "量",
"transaction_details_fee" : "費用",
"transaction_details_copied" : "${title} クリップボードにコピーしました",
"transaction_details_recipient_address" : "受取人の住所",
"transaction_details_recipient_address" : "受信者のアドレス",
"wallet_list_title" : "Monero 財布",
@ -492,5 +492,7 @@
"coin_control" : "コインコントロール(オプション)",
"address_detected" : "アドレスが検出されました",
"address_from_domain" : "あなたはからアドレスを得ました unstoppable domain ${domain}"
"address_from_domain" : "このアドレスは ${domain} からのものです Unstoppable Domains",
"add_receiver" : "別のレシーバーを追加します(オプション)"
}

View file

@ -492,5 +492,7 @@
"coin_control" : "코인 제어 (옵션)",
"address_detected" : "주소 감지",
"address_from_domain" : "주소는 unstoppable domain ${domain}"
"address_from_domain" : "이 주소는 ${domain} 의 주소입니다 Unstoppable Domains",
"add_receiver" : "다른 수신기 추가(선택 사항)"
}

View file

@ -284,7 +284,7 @@
"transaction_details_amount" : "Bedrag",
"transaction_details_fee" : "Vergoeding",
"transaction_details_copied" : "${title} gekopieerd naar het klembord",
"transaction_details_recipient_address" : "Adres van de ontvanger",
"transaction_details_recipient_address" : "Adressen van ontvangers",
"wallet_list_title" : "Monero portemonnee",
@ -492,5 +492,7 @@
"coin_control" : "Muntcontrole (optioneel)",
"address_detected" : "Adres gedetecteerd",
"address_from_domain" : "Je adres is van unstoppable domain ${domain}"
"address_from_domain" : "Dit adres is van ${domain} op Unstoppable Domains",
"add_receiver" : "Nog een ontvanger toevoegen (optioneel)"
}

View file

@ -284,7 +284,7 @@
"transaction_details_amount" : "Ilość",
"transaction_details_fee" : "Opłata",
"transaction_details_copied" : "${title} skopiowane do schowka",
"transaction_details_recipient_address" : "Adres odbiorcy",
"transaction_details_recipient_address" : "Adresy odbiorców",
"wallet_list_title" : "Portfel Monero",
@ -492,5 +492,7 @@
"coin_control" : "Kontrola monet (opcjonalnie)",
"address_detected" : "Wykryto adres",
"address_from_domain" : "Dostałeś adres od unstoppable domain ${domain}"
"address_from_domain" : "Ten adres jest od ${domain} na Unstoppable Domains",
"add_receiver" : "Dodaj kolejny odbiornik (opcjonalnie)"
}

View file

@ -284,7 +284,7 @@
"transaction_details_amount" : "Quantia",
"transaction_details_fee" : "Taxa",
"transaction_details_copied" : "${title} copiados para a área de transferência",
"transaction_details_recipient_address" : "Endereço do destinatário",
"transaction_details_recipient_address" : "Endereços de destinatários",
"wallet_list_title" : "Carteira Monero",
@ -492,5 +492,7 @@
"coin_control" : "Controle de moedas (opcional)",
"address_detected" : "Endereço detectado",
"address_from_domain" : "Você obteve o endereço de unstoppable domain ${domain}"
"address_from_domain" : "Este endereço é de ${domain} em Unstoppable Domains",
"add_receiver" : "Adicione outro receptor (opcional)"
}

View file

@ -284,7 +284,7 @@
"transaction_details_amount" : "Сумма",
"transaction_details_fee" : "Комиссия",
"transaction_details_copied" : "${title} скопировано в буфер обмена",
"transaction_details_recipient_address" : "Адрес получателя",
"transaction_details_recipient_address" : "Адреса получателей",
"wallet_list_title" : "Monero Кошелёк",
@ -492,5 +492,7 @@
"coin_control" : "Контроль монет (необязательно)",
"address_detected" : "Обнаружен адрес",
"address_from_domain" : "Вы получили адрес из unstoppable domain ${domain}"
"address_from_domain" : "Этот адрес от ${domain} на Unstoppable Domains",
"add_receiver" : "Добавить получателя (необязательно)"
}

View file

@ -284,7 +284,7 @@
"transaction_details_amount" : "Сума",
"transaction_details_fee" : "Комісія",
"transaction_details_copied" : "${title} скопійовано в буфер обміну",
"transaction_details_recipient_address" : "Адреса отримувача",
"transaction_details_recipient_address" : "Адреси одержувачів",
"wallet_list_title" : "Monero Гаманець",
@ -492,5 +492,7 @@
"coin_control" : "Контроль монет (необов’язково)",
"address_detected" : "Виявлено адресу",
"address_from_domain" : "Ви отримали адресу від unstoppable domain ${domain}"
"address_from_domain" : "Ця адреса від ${domain} на Unstoppable Domains",
"add_receiver" : "Додати одержувача (необов'язково)"
}

View file

@ -492,5 +492,7 @@
"coin_control" : "硬幣控制(可選)",
"address_detected" : "檢測到地址",
"address_from_domain" : "您有以下地址 unstoppable domain ${domain}"
"address_from_domain" : "此地址來自 Unstoppable Domains 上的 ${domain}",
"add_receiver" : "添加另一個接收器(可選)"
}