2020-10-30 16:32:21 +00:00
|
|
|
import 'package:mobx/mobx.dart';
|
2020-05-08 16:22:56 +00:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-10-30 16:32:21 +00:00
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:keyboard_actions/keyboard_actions.dart';
|
2020-05-08 16:22:56 +00:00
|
|
|
import 'package:cake_wallet/src/screens/base_page.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
2021-07-16 09:32:36 +00:00
|
|
|
import 'package:cake_wallet/view_model/send/send_template_view_model.dart';
|
2020-10-30 16:32:21 +00:00
|
|
|
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';
|
|
|
|
import 'package:cake_wallet/src/widgets/primary_button.dart';
|
|
|
|
import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
|
2020-05-08 16:22:56 +00:00
|
|
|
|
|
|
|
class SendTemplatePage extends BasePage {
|
2021-07-16 09:32:36 +00:00
|
|
|
SendTemplatePage({@required this.sendTemplateViewModel}) {
|
2021-08-10 14:52:35 +00:00
|
|
|
sendTemplateViewModel.output.reset();
|
2021-07-16 09:32:36 +00:00
|
|
|
}
|
2020-05-08 16:22:56 +00:00
|
|
|
|
2021-07-16 09:32:36 +00:00
|
|
|
final SendTemplateViewModel sendTemplateViewModel;
|
2020-09-22 18:32:43 +00:00
|
|
|
final _addressController = TextEditingController();
|
|
|
|
final _cryptoAmountController = TextEditingController();
|
|
|
|
final _fiatAmountController = TextEditingController();
|
|
|
|
final _nameController = TextEditingController();
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
2020-10-30 16:32:21 +00:00
|
|
|
final FocusNode _cryptoAmountFocus = FocusNode();
|
|
|
|
final FocusNode _fiatAmountFocus = FocusNode();
|
2020-09-22 18:32:43 +00:00
|
|
|
|
|
|
|
bool _effectsInstalled = false;
|
2020-05-29 15:10:11 +00:00
|
|
|
|
|
|
|
@override
|
2020-07-29 16:55:42 +00:00
|
|
|
String get title => S.current.exchange_new_template;
|
2020-05-08 16:22:56 +00:00
|
|
|
|
|
|
|
@override
|
2020-08-20 17:43:54 +00:00
|
|
|
Color get titleColor => Colors.white;
|
2020-05-08 16:22:56 +00:00
|
|
|
|
2020-08-20 17:43:54 +00:00
|
|
|
@override
|
2020-09-22 18:32:43 +00:00
|
|
|
bool get extendBodyBehindAppBar => true;
|
2020-05-08 16:22:56 +00:00
|
|
|
|
|
|
|
@override
|
2020-09-22 18:32:43 +00:00
|
|
|
AppBarStyle get appBarStyle => AppBarStyle.transparent;
|
2020-05-08 16:22:56 +00:00
|
|
|
|
|
|
|
@override
|
2020-09-22 18:32:43 +00:00
|
|
|
Widget body(BuildContext context) {
|
|
|
|
_setEffects(context);
|
2020-08-20 17:43:54 +00:00
|
|
|
|
2020-10-30 16:32:21 +00:00
|
|
|
return KeyboardActions(
|
|
|
|
config: KeyboardActionsConfig(
|
|
|
|
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
|
2022-01-18 07:08:55 +00:00
|
|
|
keyboardBarColor:
|
|
|
|
Theme.of(context).accentTextTheme.body2.backgroundColor,
|
2020-10-30 16:32:21 +00:00
|
|
|
nextFocus: false,
|
|
|
|
actions: [
|
|
|
|
KeyboardActionsItem(
|
|
|
|
focusNode: _cryptoAmountFocus,
|
|
|
|
toolbarButtons: [(_) => KeyboardDoneButton()],
|
|
|
|
),
|
|
|
|
KeyboardActionsItem(
|
|
|
|
focusNode: _fiatAmountFocus,
|
|
|
|
toolbarButtons: [(_) => KeyboardDoneButton()],
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
child: Container(
|
|
|
|
height: 0,
|
|
|
|
color: Theme.of(context).backgroundColor,
|
|
|
|
child: ScrollableWithBottomSection(
|
|
|
|
contentPadding: EdgeInsets.only(bottom: 24),
|
|
|
|
content: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.only(
|
2022-01-18 07:08:55 +00:00
|
|
|
bottomLeft: Radius.circular(24),
|
|
|
|
bottomRight: Radius.circular(24),
|
|
|
|
),
|
2020-10-30 16:32:21 +00:00
|
|
|
gradient: LinearGradient(colors: [
|
|
|
|
Theme.of(context).primaryTextTheme.subhead.color,
|
|
|
|
Theme.of(context).primaryTextTheme.subhead.decorationColor,
|
|
|
|
], begin: Alignment.topLeft, end: Alignment.bottomRight),
|
|
|
|
),
|
|
|
|
child: Form(
|
|
|
|
key: _formKey,
|
2022-01-18 07:08:55 +00:00
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(24, 90, 24, 32),
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
BaseTextFormField(
|
|
|
|
controller: _nameController,
|
|
|
|
hintText: S.of(context).send_name,
|
2020-10-30 16:32:21 +00:00
|
|
|
borderColor: Theme.of(context)
|
2020-09-22 18:32:43 +00:00
|
|
|
.primaryTextTheme
|
|
|
|
.headline
|
2020-10-30 16:32:21 +00:00
|
|
|
.color,
|
|
|
|
textStyle: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
color: Colors.white),
|
2022-01-18 07:08:55 +00:00
|
|
|
placeholderTextStyle: TextStyle(
|
2020-10-30 16:32:21 +00:00
|
|
|
color: Theme.of(context)
|
|
|
|
.primaryTextTheme
|
|
|
|
.headline
|
2022-01-18 07:08:55 +00:00
|
|
|
.decorationColor,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
fontSize: 14),
|
|
|
|
validator: sendTemplateViewModel.templateValidator,
|
2020-10-30 16:32:21 +00:00
|
|
|
),
|
2022-01-18 07:08:55 +00:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.only(top: 20),
|
|
|
|
child: AddressTextField(
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
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(
|
|
|
|
focusNode: _fiatAmountFocus,
|
|
|
|
controller: _fiatAmountController,
|
2021-07-16 09:32:36 +00:00
|
|
|
keyboardType: TextInputType.numberWithOptions(
|
|
|
|
signed: false, decimal: true),
|
|
|
|
inputFormatters: [
|
2022-01-18 07:08:55 +00:00
|
|
|
FilteringTextInputFormatter.deny(
|
|
|
|
RegExp('[\\-|\\ ]'))
|
2021-07-16 09:32:36 +00:00
|
|
|
],
|
|
|
|
prefixIcon: Padding(
|
|
|
|
padding: EdgeInsets.only(top: 9),
|
2022-01-18 07:08:55 +00:00
|
|
|
child: Text(
|
|
|
|
sendTemplateViewModel.fiat.title + ':',
|
2021-07-16 09:32:36 +00:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
color: Colors.white,
|
|
|
|
)),
|
|
|
|
),
|
2022-01-18 07:08:55 +00:00
|
|
|
hintText: '0.00',
|
2021-07-16 09:32:36 +00: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),
|
2022-01-18 07:08:55 +00:00
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2020-10-30 16:32:21 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
bottomSectionPadding:
|
|
|
|
EdgeInsets.only(left: 24, right: 24, bottom: 24),
|
|
|
|
bottomSection: PrimaryButton(
|
|
|
|
onPressed: () {
|
|
|
|
if (_formKey.currentState.validate()) {
|
2021-07-16 09:32:36 +00:00
|
|
|
sendTemplateViewModel.addTemplate(
|
2020-10-30 16:32:21 +00:00
|
|
|
name: _nameController.text,
|
|
|
|
address: _addressController.text,
|
2021-07-16 09:32:36 +00:00
|
|
|
cryptoCurrency: sendTemplateViewModel.currency.title,
|
2020-10-30 16:32:21 +00:00
|
|
|
amount: _cryptoAmountController.text);
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
text: S.of(context).save,
|
2020-12-11 18:46:20 +00:00
|
|
|
color: Colors.green,
|
2020-12-18 13:21:30 +00:00
|
|
|
textColor: Colors.white,
|
2020-10-30 16:32:21 +00:00
|
|
|
),
|
2020-09-22 18:32:43 +00:00
|
|
|
),
|
2020-10-30 16:32:21 +00:00
|
|
|
));
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _setEffects(BuildContext context) {
|
|
|
|
if (_effectsInstalled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-10 14:52:35 +00:00
|
|
|
final output = sendTemplateViewModel.output;
|
2021-07-16 09:32:36 +00:00
|
|
|
|
2021-08-10 14:52:35 +00:00
|
|
|
reaction((_) => output.fiatAmount, (String amount) {
|
2020-09-22 18:32:43 +00:00
|
|
|
if (amount != _fiatAmountController.text) {
|
|
|
|
_fiatAmountController.text = amount;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-08-10 14:52:35 +00:00
|
|
|
reaction((_) => output.cryptoAmount, (String amount) {
|
2020-09-22 18:32:43 +00:00
|
|
|
if (amount != _cryptoAmountController.text) {
|
|
|
|
_cryptoAmountController.text = amount;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-08-10 14:52:35 +00:00
|
|
|
reaction((_) => output.address, (String address) {
|
2020-09-22 18:32:43 +00:00
|
|
|
if (address != _addressController.text) {
|
|
|
|
_addressController.text = address;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-10-07 05:58:22 +00:00
|
|
|
_cryptoAmountController.addListener(() {
|
|
|
|
final amount = _cryptoAmountController.text;
|
|
|
|
|
2021-08-10 14:52:35 +00:00
|
|
|
if (amount != output.cryptoAmount) {
|
|
|
|
output.setCryptoAmount(amount);
|
2020-10-07 05:58:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
_fiatAmountController.addListener(() {
|
|
|
|
final amount = _fiatAmountController.text;
|
|
|
|
|
2021-08-10 14:52:35 +00:00
|
|
|
if (amount != output.fiatAmount) {
|
|
|
|
output.setFiatAmount(amount);
|
2020-10-07 05:58:22 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-09-22 18:32:43 +00:00
|
|
|
_addressController.addListener(() {
|
|
|
|
final address = _addressController.text;
|
|
|
|
|
2021-08-10 14:52:35 +00:00
|
|
|
if (output.address != address) {
|
|
|
|
output.address = address;
|
2020-09-22 18:32:43 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
_effectsInstalled = true;
|
2020-08-20 17:43:54 +00:00
|
|
|
}
|
2020-09-02 08:47:41 +00:00
|
|
|
}
|