mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 17:40:43 +00:00
CAKE-359 | added text field for extracted (from Yat, Unstoppable Domains, OpenAlias) address to send_card.dart; added extractedAddress and isParsedAddress parameters to output.dart; applied extractedAddress to monero_wallet.dart and electrum_wallet.dart; added TextValidator to send_view_model.dart
This commit is contained in:
parent
9958f6c2e0
commit
3b649ef682
7 changed files with 116 additions and 69 deletions
|
@ -280,8 +280,12 @@ abstract class ElectrumWalletBase extends WalletBase<ElectrumBalance,
|
|||
? item.formattedCryptoAmount
|
||||
: amount;
|
||||
|
||||
final outputAddress = item.isParsedAddress
|
||||
? item.extractedAddress
|
||||
: item.address;
|
||||
|
||||
txb.addOutput(
|
||||
addressToOutputScript(item.address, networkType),
|
||||
addressToOutputScript(outputAddress, networkType),
|
||||
outputAmount);
|
||||
});
|
||||
|
||||
|
|
|
@ -175,11 +175,15 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
|||
throw MoneroTransactionCreationException('Wrong balance. Not enough XMR on your balance.');
|
||||
}
|
||||
|
||||
final moneroOutputs = outputs.map((output) =>
|
||||
MoneroOutput(
|
||||
address: output.address,
|
||||
amount: output.cryptoAmount.replaceAll(',', '.')))
|
||||
.toList();
|
||||
final moneroOutputs = outputs.map((output) {
|
||||
final outputAddress = output.isParsedAddress
|
||||
? output.extractedAddress
|
||||
: output.address;
|
||||
|
||||
return MoneroOutput(
|
||||
address: outputAddress,
|
||||
amount: output.cryptoAmount.replaceAll(',', '.'));
|
||||
}).toList();
|
||||
|
||||
pendingTransactionDescription =
|
||||
await transaction_history.createTransactionMultDest(
|
||||
|
@ -188,7 +192,9 @@ abstract class MoneroWalletBase extends WalletBase<MoneroBalance,
|
|||
accountIndex: walletAddresses.account.id);
|
||||
} else {
|
||||
final output = outputs.first;
|
||||
final address = output.address;
|
||||
final address = output.isParsedAddress
|
||||
? output.extractedAddress
|
||||
: output.address;
|
||||
final amount = output.sendAll
|
||||
? null
|
||||
: output.cryptoAmount.replaceAll(',', '.');
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'dart:ui';
|
||||
import 'package:cake_wallet/src/screens/send/widgets/parse_address_from_domain_alert.dart';
|
||||
import 'package:cake_wallet/src/screens/send/widgets/send_card.dart';
|
||||
import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart';
|
||||
import 'package:cake_wallet/src/widgets/template_tile.dart';
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'package:cake_wallet/entities/parsed_address.dart';
|
||||
import 'package:cake_wallet/palette.dart';
|
||||
import 'package:cake_wallet/view_model/send/output.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -274,16 +273,15 @@ class ConfirmSendingAlertContentState extends State<ConfirmSendingAlertContent>
|
|||
itemCount: itemCount,
|
||||
itemBuilder: (context, index) {
|
||||
final item = outputs[index];
|
||||
final _address = item.address;
|
||||
final _address = item.isParsedAddress
|
||||
? item.extractedAddress
|
||||
: item.address;
|
||||
final _amount =
|
||||
item.cryptoAmount.replaceAll(',', '.');
|
||||
final isParsedAddress =
|
||||
item.parsedAddress.parseFrom !=
|
||||
ParseFrom.notParsed;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
if (isParsedAddress) Padding(
|
||||
if (item.isParsedAddress) Padding(
|
||||
padding: EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
item.parsedAddress.name,
|
||||
|
@ -334,8 +332,7 @@ class ConfirmSendingAlertContentState extends State<ConfirmSendingAlertContent>
|
|||
})
|
||||
: Column(
|
||||
children: [
|
||||
if (outputs.first.parsedAddress.parseFrom !=
|
||||
ParseFrom.notParsed) Padding(
|
||||
if (outputs.first.isParsedAddress) Padding(
|
||||
padding: EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
outputs.first.parsedAddress.name,
|
||||
|
@ -352,7 +349,9 @@ class ConfirmSendingAlertContentState extends State<ConfirmSendingAlertContent>
|
|||
Padding(
|
||||
padding: EdgeInsets.only(top: 8),
|
||||
child: Text(
|
||||
outputs.first.address,
|
||||
outputs.first.isParsedAddress
|
||||
? outputs.first.extractedAddress
|
||||
: outputs.first.address,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.w600,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
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';
|
||||
|
@ -38,6 +37,7 @@ class SendCardState extends State<SendCard>
|
|||
cryptoAmountController = TextEditingController(),
|
||||
fiatAmountController = TextEditingController(),
|
||||
noteController = TextEditingController(),
|
||||
extractedAddressController = TextEditingController(),
|
||||
cryptoAmountFocus = FocusNode(),
|
||||
fiatAmountFocus = FocusNode(),
|
||||
addressFocusNode = FocusNode();
|
||||
|
@ -52,6 +52,7 @@ class SendCardState extends State<SendCard>
|
|||
final TextEditingController cryptoAmountController;
|
||||
final TextEditingController fiatAmountController;
|
||||
final TextEditingController noteController;
|
||||
final TextEditingController extractedAddressController;
|
||||
final FocusNode cryptoAmountFocus;
|
||||
final FocusNode fiatAmountFocus;
|
||||
final FocusNode addressFocusNode;
|
||||
|
@ -101,58 +102,80 @@ class SendCardState extends State<SendCard>
|
|||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(24, 100, 24, 32),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
child: Observer(builder: (_) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
AddressTextField(
|
||||
focusNode: addressFocusNode,
|
||||
controller: addressController,
|
||||
onURIScanned: (uri) {
|
||||
var address = '';
|
||||
var amount = '';
|
||||
Observer(builder: (_) {
|
||||
final validator = output.isParsedAddress
|
||||
? sendViewModel.textValidator
|
||||
: sendViewModel.addressValidator;
|
||||
|
||||
if (uri != null) {
|
||||
address = uri.path;
|
||||
amount = uri.queryParameters['tx_amount'] ??
|
||||
uri.queryParameters['amount'];
|
||||
} else {
|
||||
address = uri.toString();
|
||||
}
|
||||
return AddressTextField(
|
||||
focusNode: addressFocusNode,
|
||||
controller: addressController,
|
||||
onURIScanned: (uri) {
|
||||
var address = '';
|
||||
var amount = '';
|
||||
|
||||
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 {
|
||||
output.resetParsedAddress();
|
||||
await output.fetchParsedAddress(context);
|
||||
},
|
||||
onPushAddressBookButton: (context) =>
|
||||
output.resetParsedAddress(),
|
||||
validator: sendViewModel.addressValidator,
|
||||
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 {
|
||||
output.resetParsedAddress();
|
||||
await output.fetchParsedAddress(context);
|
||||
},
|
||||
onPushAddressBookButton: (context) =>
|
||||
output.resetParsedAddress(),
|
||||
validator: validator,
|
||||
);
|
||||
}),
|
||||
if (output.isParsedAddress) Padding(
|
||||
padding: const EdgeInsets.only(top: 20),
|
||||
child: BaseTextFormField(
|
||||
controller: extractedAddressController,
|
||||
readOnly: true,
|
||||
borderColor: Theme.of(context)
|
||||
.primaryTextTheme
|
||||
.headline
|
||||
.color,
|
||||
textStyle: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Colors.white),
|
||||
validator: sendViewModel.addressValidator
|
||||
)
|
||||
),
|
||||
Observer(
|
||||
builder: (_) => Padding(
|
||||
|
@ -440,7 +463,7 @@ class SendCardState extends State<SendCard>
|
|||
)
|
||||
)
|
||||
],
|
||||
)
|
||||
))
|
||||
),
|
||||
),
|
||||
)
|
||||
|
@ -453,6 +476,7 @@ class SendCardState extends State<SendCard>
|
|||
cryptoAmountController.text = output.cryptoAmount;
|
||||
fiatAmountController.text = output.fiatAmount;
|
||||
noteController.text = output.note;
|
||||
extractedAddressController.text = output.extractedAddress;
|
||||
|
||||
if (_effectsInstalled) {
|
||||
return;
|
||||
|
@ -520,6 +544,7 @@ class SendCardState extends State<SendCard>
|
|||
final address = addressController.text;
|
||||
|
||||
if (output.address != address) {
|
||||
output.resetParsedAddress();
|
||||
output.address = address;
|
||||
}
|
||||
});
|
||||
|
@ -532,11 +557,14 @@ class SendCardState extends State<SendCard>
|
|||
|
||||
addressFocusNode.addListener(() async {
|
||||
if (!addressFocusNode.hasFocus && addressController.text.isNotEmpty) {
|
||||
output.resetParsedAddress();
|
||||
await output.fetchParsedAddress(context);
|
||||
}
|
||||
});
|
||||
|
||||
reaction((_) => output.extractedAddress, (String extractedAddress) {
|
||||
extractedAddressController.text = extractedAddress;
|
||||
});
|
||||
|
||||
_effectsInstalled = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,8 +47,16 @@ abstract class OutputBase with Store {
|
|||
@observable
|
||||
bool sendAll;
|
||||
|
||||
@observable
|
||||
ParsedAddress parsedAddress;
|
||||
|
||||
@observable
|
||||
String extractedAddress;
|
||||
|
||||
@computed
|
||||
bool get isParsedAddress => parsedAddress.parseFrom != ParseFrom.notParsed
|
||||
&& parsedAddress.name.isNotEmpty;
|
||||
|
||||
@computed
|
||||
int get formattedCryptoAmount {
|
||||
int amount = 0;
|
||||
|
@ -134,6 +142,7 @@ abstract class OutputBase with Store {
|
|||
}
|
||||
|
||||
void resetParsedAddress() {
|
||||
extractedAddress = '';
|
||||
parsedAddress = ParsedAddress(addresses: []);
|
||||
}
|
||||
|
||||
|
@ -206,6 +215,6 @@ abstract class OutputBase with Store {
|
|||
final domain = address;
|
||||
final ticker = _wallet.currency.title.toLowerCase();
|
||||
parsedAddress = await parseAddressFromDomain(domain, ticker);
|
||||
address = await defineAddress(context, parsedAddress);
|
||||
extractedAddress = await defineAddress(context, parsedAddress);
|
||||
}
|
||||
}
|
|
@ -117,6 +117,8 @@ abstract class SendViewModelBase with Store {
|
|||
|
||||
Validator get addressValidator => AddressValidator(type: _wallet.currency);
|
||||
|
||||
Validator get textValidator => TextValidator();
|
||||
|
||||
@observable
|
||||
PendingTransaction pendingTransaction;
|
||||
|
||||
|
|
Loading…
Reference in a new issue