From 45c8b74bf14578ffaa2b3499fe43512014317893 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Mon, 21 Sep 2020 22:01:45 +0300 Subject: [PATCH] CAKE-49 | refactored send page --- lib/di.dart | 4 +- lib/src/screens/send/send_page.dart | 1166 ++++++++++++++------------- pubspec.lock | 31 +- 3 files changed, 613 insertions(+), 588 deletions(-) diff --git a/lib/di.dart b/lib/di.dart index 5453010ca..48689d283 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -257,8 +257,8 @@ Future setup( getIt.registerFactory( () => SendPage(sendViewModel: getIt.get())); - // getIt.registerFactory( - // () => SendTemplatePage(sendViewModel: getIt.get())); + getIt.registerFactory( + () => SendTemplatePage(sendViewModel: getIt.get())); getIt.registerFactory(() => WalletListViewModel( walletInfoSource, getIt.get(), getIt.get())); diff --git a/lib/src/screens/send/send_page.dart b/lib/src/screens/send/send_page.dart index 187523de2..edbf1c2f5 100644 --- a/lib/src/screens/send/send_page.dart +++ b/lib/src/screens/send/send_page.dart @@ -1,4 +1,7 @@ import 'dart:ui'; +import 'package:cake_wallet/src/domain/common/transaction_priority.dart'; +import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; +import 'package:cake_wallet/src/widgets/picker.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -19,22 +22,22 @@ import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/src/screens/send/widgets/confirm_sending_alert.dart'; import 'package:cake_wallet/view_model/send/send_view_model_state.dart'; import 'package:cake_wallet/src/widgets/trail_button.dart'; - -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:cake_wallet/src/screens/base_page.dart'; -import 'package:cake_wallet/src/screens/send/widgets/base_send_widget.dart'; - -// FIXME: Refactor this screen. +import 'package:dotted_border/dotted_border.dart'; class SendPage extends BasePage { SendPage({@required this.sendViewModel}); final SendViewModel sendViewModel; + final _addressController = TextEditingController(); + final _cryptoAmountController = TextEditingController(); + final _fiatAmountController = TextEditingController(); + final _focusNode = FocusNode(); + final _formKey = GlobalKey(); + + bool _effectsInstalled = false; - // ??? @override - String get title => 'SEND'; + String get title => S.current.send; @override Color get titleColor => Colors.white; @@ -48,64 +51,9 @@ class SendPage extends BasePage { @override Widget trailing(context) => TrailButton( caption: S.of(context).clear, onPressed: () => sendViewModel.reset()); - Color get backgroundDarkColor => Colors.transparent; - - // @override - // State createState() => SendFormState(); - - final _addressController = TextEditingController(); - final _cryptoAmountController = TextEditingController(); - final _fiatAmountController = TextEditingController(); - - final _focusNode = FocusNode(); - - bool _effectsInstalled = false; - - final _formKey = GlobalKey(); - - // @override - // void initState() { - // _focusNode.addListener(() { - // if (!_focusNode.hasFocus && _addressController.text.isNotEmpty) { - // getOpenaliasRecord(context); - // } - // }); - - // super.initState(); - // } - - Future getOpenaliasRecord(BuildContext context) async { -// final sendStore = Provider.of(context); -// final isOpenalias = -// await sendStore.isOpenaliasRecord(_addressController.text); -// -// if (isOpenalias) { -// _addressController.text = sendStore.recordAddress; -// -// await showDialog( -// context: context, -// builder: (BuildContext context) { -// return AlertWithOneAction( -// alertTitle: S.of(context).openalias_alert_title, -// alertContent: -// S.of(context).openalias_alert_content(sendStore.recordName), -// buttonText: S.of(context).ok, -// buttonAction: () => Navigator.of(context).pop()); -// }); -// } - } - - // @override - // Widget body(BuildContext context) { - // return super.build(context); - // } @override - Widget body(BuildContext context) => BaseSendWidget( - sendViewModel: sendViewModel, - leading: leading(context), - middle: middle(context), - ); + Color get backgroundDarkColor => Colors.transparent; @override Widget build(BuildContext context) { @@ -115,529 +63,613 @@ class SendPage extends BasePage { color: Theme.of(context).backgroundColor, child: body(context))); } -// @override -// Widget build(BuildContext context) { -// _setEffects(context); + @override + Widget body(BuildContext context) { + _setEffects(context); -// return Container( -// color: Theme.of(context).backgroundColor, -// child: ScrollableWithBottomSection( -// contentPadding: EdgeInsets.only(bottom: 24), -// content: Column( -// children: [ -// TopPanel( -// color: Theme.of(context).accentTextTheme.title.backgroundColor, -// widget: Form( -// key: _formKey, -// child: Column(children: [ -// AddressTextField( -// controller: _addressController, -// placeholder: 'Address', -// //S.of(context).send_monero_address, FIXME: placeholder for btc and xmr address text field. -// focusNode: _focusNode, -// onURIScanned: (uri) { -// var address = ''; -// var amount = ''; + return ScrollableWithBottomSection( + contentPadding: EdgeInsets.only(bottom: 24), + content: Column( + children: [ + TopPanel( + edgeInsets: EdgeInsets.all(0), + gradient: LinearGradient(colors: [ + Theme.of(context).primaryTextTheme.subhead.color, + Theme.of(context).primaryTextTheme.subhead.decorationColor, + ], begin: Alignment.topLeft, end: Alignment.bottomRight), + widget: Form( + key: _formKey, + child: Column(children: [ + CupertinoNavigationBar( + leading: leading(context), + middle: middle(context), + trailing: trailing(context), + backgroundColor: Colors.transparent, + border: null, + ), + Padding( + padding: EdgeInsets.fromLTRB(24, 24, 24, 32), + child: Column( + children: [ + AddressTextField( + controller: _addressController, + focusNode: _focusNode, + onURIScanned: (uri) { + var address = ''; + var amount = ''; -// if (uri != null) { -// address = uri.path; -// amount = uri.queryParameters['tx_amount']; -// } else { -// address = uri.toString(); -// } + if (uri != null) { + address = uri.path; + amount = uri.queryParameters['tx_amount']; + } else { + address = uri.toString(); + } -// _addressController.text = address; -// _cryptoAmountController.text = amount; -// }, -// options: [ -// AddressTextFieldOption.qrCode, -// AddressTextFieldOption.addressBook -// ], -// buttonColor: Theme.of(context).accentTextTheme.title.color, -// validator: widget.sendViewModel.addressValidator, -// ), -// Padding( -// padding: const EdgeInsets.only(top: 20), -// child: TextFormField( -// onChanged: (value) => -// widget.sendViewModel.setCryptoAmount(value), -// style: TextStyle( -// fontSize: 16.0, -// color: -// Theme.of(context).primaryTextTheme.title.color), -// controller: _cryptoAmountController, -// keyboardType: TextInputType.numberWithOptions( -// signed: false, decimal: true), -// // inputFormatters: [ -// // BlacklistingTextInputFormatter( -// // RegExp('[\\-|\\ |\\,]')) -// // ], -// decoration: InputDecoration( -// prefixIcon: Padding( -// padding: EdgeInsets.only(top: 12), -// child: Text( -// '${widget.sendViewModel.currency.toString()}:', -// style: TextStyle( -// fontSize: 16, -// fontWeight: FontWeight.w500, -// color: Theme.of(context) -// .primaryTextTheme -// .title -// .color, -// )), -// ), -// suffixIcon: Padding( -// padding: EdgeInsets.only(bottom: 5), -// child: Container( -// height: 32, -// width: 32, -// margin: EdgeInsets.only( -// left: 12, bottom: 7, top: 4), -// decoration: BoxDecoration( -// color: Theme.of(context) -// .accentTextTheme -// .title -// .color, -// borderRadius: -// BorderRadius.all(Radius.circular(6))), -// child: InkWell( -// onTap: () => widget.sendViewModel.setAll(), -// child: Center( -// child: Text(S.of(context).all, -// textAlign: TextAlign.center, -// style: TextStyle( -// fontSize: 9, -// fontWeight: FontWeight.bold, -// color: Theme.of(context) -// .primaryTextTheme -// .caption -// .color)), -// ), -// ), -// )), -// hintStyle: TextStyle( -// fontSize: 16.0, -// color: Theme.of(context) -// .primaryTextTheme -// .title -// .color), -// hintText: '0.0000', -// focusedBorder: UnderlineInputBorder( -// borderSide: BorderSide( -// color: Theme.of(context).dividerColor, -// width: 1.0)), -// enabledBorder: UnderlineInputBorder( -// borderSide: BorderSide( -// color: Theme.of(context).dividerColor, -// width: 1.0))), -// validator: (String value) { -// if (widget.sendViewModel.all) { -// return null; -// } + _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), + validator: sendViewModel.addressValidator, + ), + Observer(builder: (_) { + return Padding( + padding: const EdgeInsets.only(top: 20), + child: BaseTextFormField( + 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, + )), + ), + suffixIcon: Container( + height: 32, + width: 32, + margin: EdgeInsets.only( + left: 14, top: 4, bottom: 10), + decoration: BoxDecoration( + color: Theme.of(context) + .primaryTextTheme + .display1 + .color, + borderRadius: BorderRadius.all( + Radius.circular(6))), + child: InkWell( + onTap: () => + sendViewModel.setSendAll(), + 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)), + ), + ), + ), + 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)); + }), + Observer( + builder: (_) => Padding( + padding: EdgeInsets.only(top: 10), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + 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( + controller: _fiatAmountController, + keyboardType: TextInputType.numberWithOptions( + signed: false, decimal: true), + inputFormatters: [ + BlacklistingTextInputFormatter( + 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), + )), + Observer( + builder: (_) => GestureDetector( + onTap: () => + _setTransactionPriority(context), + child: Container( + padding: EdgeInsets.only(top: 24), + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + 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( + children: [ + Text( + sendViewModel.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(left: 5), + child: Icon( + Icons.arrow_forward_ios, + size: 12, + color: Colors.white, + ), + ) + ], + ), + ) + ], + ), + ), + )) + ], + ), + ) + ]), + ), + ), + Padding( + padding: EdgeInsets.only(top: 30, left: 24, bottom: 24), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text( + S.of(context).send_templates, + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.w600, + color: Theme.of(context) + .primaryTextTheme + .display4 + .color), + ) + ], + ), + ), + Container( + height: 40, + width: double.infinity, + padding: EdgeInsets.only(left: 24), + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + children: [ + GestureDetector( + onTap: () => Navigator.of(context) + .pushNamed(Routes.sendTemplate), + child: Container( + padding: EdgeInsets.only(left: 1, right: 10), + child: DottedBorder( + borderType: BorderType.RRect, + dashPattern: [6, 4], + color: Theme.of(context) + .primaryTextTheme + .display2 + .decorationColor, + strokeWidth: 2, + radius: Radius.circular(20), + child: Container( + height: 34, + width: 75, + padding: EdgeInsets.only(left: 10, right: 10), + alignment: Alignment.center, + decoration: BoxDecoration( + borderRadius: + BorderRadius.all(Radius.circular(20)), + color: Colors.transparent, + ), + child: Text( + S.of(context).send_new, + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w600, + color: Theme.of(context) + .primaryTextTheme + .display3 + .color), + ), + )), + ), + ), + // Observer( + // builder: (_) { + // final templates = sendViewModel.templates; + // final itemCount = templates.length; -// return widget.sendViewModel.amountValidator -// .call(value); -// }), -// ), -// Padding( -// padding: const EdgeInsets.only(top: 20), -// child: TextFormField( -// onChanged: (value) => -// widget.sendViewModel.setFiatAmount(value), -// style: TextStyle( -// fontSize: 16.0, -// color: -// Theme.of(context).primaryTextTheme.title.color), -// controller: _fiatAmountController, -// keyboardType: TextInputType.numberWithOptions( -// signed: false, decimal: true), -// // inputFormatters: [ -// // BlacklistingTextInputFormatter( -// // RegExp('[\\-|\\ |\\,]')) -// // ], -// decoration: InputDecoration( -// prefixIcon: Padding( -// padding: EdgeInsets.only(top: 12), -// child: Text( -// '${widget.sendViewModel.fiat.toString()}:', -// style: TextStyle( -// fontSize: 16, -// fontWeight: FontWeight.w500, -// color: Theme.of(context) -// .primaryTextTheme -// .title -// .color, -// )), -// ), -// hintStyle: TextStyle( -// fontSize: 16.0, -// color: Theme.of(context) -// .primaryTextTheme -// .caption -// .color), -// hintText: '0.00', -// focusedBorder: UnderlineInputBorder( -// borderSide: BorderSide( -// color: Theme.of(context).dividerColor, -// width: 1.0)), -// enabledBorder: UnderlineInputBorder( -// borderSide: BorderSide( -// color: Theme.of(context).dividerColor, -// width: 1.0)))), -// ), -// Padding( -// padding: const EdgeInsets.only(top: 20), -// child: Row( -// mainAxisAlignment: MainAxisAlignment.spaceBetween, -// children: [ -// Text(S.of(context).send_estimated_fee, -// style: TextStyle( -// fontSize: 12, -// fontWeight: FontWeight.w600, -// color: Theme.of(context) -// .primaryTextTheme -// .title -// .color, -// )), -// Text( -// '${widget.sendViewModel.estimatedFee} ${widget.sendViewModel.currency.toString()}', -// style: TextStyle( -// fontSize: 12, -// fontWeight: FontWeight.w600, -// color: Theme.of(context) -// .primaryTextTheme -// .title -// .color, -// )) -// ], -// ), -// ) -// ]), -// ), -// ), -// // Padding( -// // padding: EdgeInsets.only(top: 32, left: 24, bottom: 24), -// // child: Row( -// // mainAxisAlignment: MainAxisAlignment.start, -// // children: [ -// // Text( -// // S.of(context).send_templates, -// // style: TextStyle( -// // fontSize: 18, -// // fontWeight: FontWeight.w600, -// // color: -// // Theme.of(context).primaryTextTheme.caption.color), -// // ) -// // ], -// // ), -// // ), -// // Container( -// // height: 40, -// // width: double.infinity, -// // padding: EdgeInsets.only(left: 24), -// // child: Observer(builder: (_) { -// // final itemCount = sendTemplateStore.templates.length + 1; -// // -// // return ListView.builder( -// // scrollDirection: Axis.horizontal, -// // itemCount: itemCount, -// // itemBuilder: (context, index) { -// // if (index == 0) { -// // return GestureDetector( -// // onTap: () => Navigator.of(context) -// // .pushNamed(Routes.sendTemplate), -// // child: Container( -// // padding: EdgeInsets.only(right: 10), -// // child: DottedBorder( -// // borderType: BorderType.RRect, -// // dashPattern: [8, 4], -// // color: Theme.of(context) -// // .accentTextTheme -// // .title -// // .backgroundColor, -// // strokeWidth: 2, -// // radius: Radius.circular(20), -// // child: Container( -// // height: 40, -// // width: 75, -// // padding: EdgeInsets.only(left: 10, right: 10), -// // alignment: Alignment.center, -// // decoration: BoxDecoration( -// // borderRadius: -// // BorderRadius.all(Radius.circular(20)), -// // color: Colors.transparent, -// // ), -// // child: Text( -// // S.of(context).send_new, -// // style: TextStyle( -// // fontSize: 14, -// // fontWeight: FontWeight.w600, -// // color: Theme.of(context) -// // .primaryTextTheme -// // .caption -// // .color), -// // ), -// // )), -// // ), -// // ); -// // } -// // -// // index -= 1; -// // -// // final template = sendTemplateStore.templates[index]; -// // -// // return TemplateTile( -// // to: template.name, -// // amount: template.amount, -// // from: template.cryptoCurrency, -// // onTap: () { -// // _addressController.text = template.address; -// // _cryptoAmountController.text = template.amount; -// // getOpenaliasRecord(context); -// // }); -// // }); -// // }), -// // ) -// ], -// ), -// bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24), -// bottomSection: Observer(builder: (_) { -// return LoadingPrimaryButton( -// onPressed: () async { -// FocusScope.of(context).requestFocus(FocusNode()); + // return ListView.builder( + // scrollDirection: Axis.horizontal, + // shrinkWrap: true, + // physics: NeverScrollableScrollPhysics(), + // itemCount: itemCount, + // itemBuilder: (context, index) { + // final template = templates[index]; -// if (!_formKey.currentState.validate()) { -// return; -// } + // return TemplateTile( + // key: UniqueKey(), + // to: template.name, + // amount: template.amount, + // from: template.cryptoCurrency, + // onTap: () { + // _addressController.text = template.address; + // _cryptoAmountController.text = template.amount; + // getOpenaliasRecord(context); + // }, + // onRemove: () { + // showDialog( + // context: context, + // builder: (dialogContext) { + // return AlertWithTwoActions( + // alertTitle: S.of(context).template, + // alertContent: S.of(context).confirm_delete_template, + // leftButtonText: S.of(context).delete, + // rightButtonText: S.of(context).cancel, + // actionLeftButton: () { + // Navigator.of(dialogContext).pop(); + // sendViewModel.sendTemplateStore.remove(template: template); + // sendViewModel.sendTemplateStore.update(); + // }, + // actionRightButton: () => Navigator.of(dialogContext).pop() + // ); + // } + // ); + // }, + // ); + // } + // ); + // } + // ) + ], + ), + ), + ) + ], + ), + bottomSectionPadding: EdgeInsets.only(left: 24, right: 24, bottom: 24), + bottomSection: Observer(builder: (_) { + return LoadingPrimaryButton( + onPressed: () { + if (_formKey.currentState.validate()) { + print('SENT!!!'); + } + }, + text: S.of(context).send, + color: Palette.blueCraiola, + textColor: Colors.white, + isLoading: sendViewModel.state is TransactionIsCreating || + sendViewModel.state is TransactionCommitting, + isDisabled: + false // FIXME !(syncStore.status is SyncedSyncStatus), + ); + }) + ); + } -// await showDialog( -// context: context, -// builder: (dialogContext) { -// return AlertWithTwoActions( -// alertTitle: S.of(context).send_creating_transaction, -// alertContent: S.of(context).confirm_sending, -// leftButtonText: S.of(context).send, -// rightButtonText: S.of(context).cancel, -// actionLeftButton: () async { -// await Navigator.of(dialogContext) -// .popAndPushNamed(Routes.auth, arguments: -// (bool isAuthenticatedSuccessfully, -// AuthPageState auth) { -// if (!isAuthenticatedSuccessfully) { -// return; -// } + void _setEffects(BuildContext context) { + if (_effectsInstalled) { + return; + } -// Navigator.of(auth.context).pop(); -// widget.sendViewModel.createTransaction(); -// }); -// }, -// actionRightButton: () => Navigator.of(context).pop()); -// }); -// }, -// text: S.of(context).send, -// color: Colors.blue, -// textColor: Colors.white, -// isLoading: widget.sendViewModel.state is TransactionIsCreating || -// widget.sendViewModel.state is TransactionCommitting, -// isDisabled: !widget.sendViewModel.isReadyForSend); -// }), -// ), -// ); -// } + reaction((_) => sendViewModel.sendAll, (bool all) { + if (all) { + _cryptoAmountController.text = S.current.all; + _fiatAmountController.text = null; + } + }); -// void _setEffects(BuildContext context) { -// if (_effectsInstalled) { -// return; -// } + reaction((_) => sendViewModel.fiatAmount, (String amount) { + if (amount != _fiatAmountController.text) { + _fiatAmountController.text = amount; + } + }); -// reaction((_) => widget.sendViewModel.all, (bool all) { -// if (all) { -// _cryptoAmountController.text = S.current.all; -// _fiatAmountController.text = null; -// } -// }); + reaction((_) => sendViewModel.cryptoAmount, (String amount) { + if (sendViewModel.sendAll && amount != S.current.all) { + sendViewModel.sendAll = false; + } -// reaction((_) => widget.sendViewModel.fiatAmount, (String amount) { -// if (amount != _fiatAmountController.text) { -// _fiatAmountController.text = amount; -// } -// }); + if (amount != _cryptoAmountController.text) { + _cryptoAmountController.text = amount; + } + }); -// reaction((_) => widget.sendViewModel.cryptoAmount, (String amount) { -// if (widget.sendViewModel.all && amount != S.current.all) { -// widget.sendViewModel.all = false; -// } + reaction((_) => sendViewModel.address, (String address) { + if (address != _addressController.text) { + _addressController.text = address; + } + }); -// if (amount != _cryptoAmountController.text) { -// _cryptoAmountController.text = amount; -// } -// }); + _addressController.addListener(() { + final address = _addressController.text; -// reaction((_) => widget.sendViewModel.address, (String address) { -// if (address != _addressController.text) { -// _addressController.text = address; -// } -// }); + if (sendViewModel.address != address) { + sendViewModel.address = address; + } + }); -// _addressController.addListener(() { -// final address = _addressController.text; + reaction((_) => sendViewModel.state, (SendViewModelState state) { + if (state is SendingFailed) { + WidgetsBinding.instance.addPostFrameCallback((_) { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertWithOneAction( + alertTitle: S.of(context).error, + alertContent: state.error, + buttonText: S.of(context).ok, + buttonAction: () => Navigator.of(context).pop()); + }); + }); + } -// if (widget.sendViewModel.address != address) { -// widget.sendViewModel.address = address; -// } -// }); + if (state is TransactionCreatedSuccessfully) { + WidgetsBinding.instance.addPostFrameCallback((_) { + showDialog( + context: context, + builder: (BuildContext context) { + return ConfirmSendingAlert( + alertTitle: S.of(context).confirm_sending, + amount: S.of(context).send_amount, + amountValue: + sendViewModel.pendingTransaction.amountFormatted, + fee: S.of(context).send_fee, + feeValue: sendViewModel.pendingTransaction.feeFormatted, + leftButtonText: S.of(context).ok, + rightButtonText: S.of(context).cancel, + actionLeftButton: () { + Navigator.of(context).pop(); + sendViewModel.commitTransaction(); + showDialog( + context: context, + builder: (BuildContext context) { + return Observer(builder: (_) { + final state = sendViewModel.state; -// reaction((_) => widget.sendViewModel.state, (SendViewModelState state) { -// if (state is SendingFailed) { -// WidgetsBinding.instance.addPostFrameCallback((_) { -// showDialog( -// context: context, -// builder: (BuildContext context) { -// return AlertWithOneAction( -// alertTitle: S.of(context).error, -// alertContent: state.error, -// buttonText: S.of(context).ok, -// buttonAction: () => Navigator.of(context).pop()); -// }); -// }); -// } + if (state is TransactionCommitted) { + return Stack( + children: [ + Container( + color: Theme.of(context).backgroundColor, + child: Center( + child: Image.asset( + 'assets/images/birthday_cake.png'), + ), + ), + Center( + child: Padding( + padding: EdgeInsets.only( + top: 220, left: 24, right: 24), + child: Text( + S.of(context).send_success, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + color: Theme.of(context) + .primaryTextTheme + .title + .color, + decoration: TextDecoration.none, + ), + ), + ), + ), + Positioned( + left: 24, + right: 24, + bottom: 24, + child: PrimaryButton( + onPressed: () => + Navigator.of(context).pop(), + text: S.of(context).send_got_it, + color: Colors.blue, + textColor: Colors.white)) + ], + ); + } -// if (state is TransactionCreatedSuccessfully) { -// WidgetsBinding.instance.addPostFrameCallback((_) { -// showDialog( -// context: context, -// builder: (BuildContext context) { -// return ConfirmSendingAlert( -// alertTitle: S.of(context).confirm_sending, -// amount: S.of(context).send_amount, -// amountValue: -// widget.sendViewModel.pendingTransaction.amountFormatted, -// fee: S.of(context).send_fee, -// feeValue: -// widget.sendViewModel.pendingTransaction.feeFormatted, -// leftButtonText: S.of(context).ok, -// rightButtonText: S.of(context).cancel, -// actionLeftButton: () { -// Navigator.of(context).pop(); -// widget.sendViewModel.commitTransaction(); -// showDialog( -// context: context, -// builder: (BuildContext context) { -// return Observer(builder: (_) { -// final state = widget.sendViewModel.state; + return Stack( + children: [ + Container( + color: Theme.of(context).backgroundColor, + child: Center( + child: Image.asset( + 'assets/images/birthday_cake.png'), + ), + ), + BackdropFilter( + filter: ImageFilter.blur( + sigmaX: 3.0, sigmaY: 3.0), + child: Container( + decoration: BoxDecoration( + color: Theme.of(context) + .backgroundColor + .withOpacity(0.25)), + child: Center( + child: Padding( + padding: EdgeInsets.only(top: 220), + child: Text( + S.of(context).send_sending, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + color: Theme.of(context) + .primaryTextTheme + .title + .color, + decoration: TextDecoration.none, + ), + ), + ), + ), + ), + ) + ], + ); + }); + }); + }, + actionRightButton: () => Navigator.of(context).pop()); + }); + }); + } -// if (state is TransactionCommitted) { -// return Stack( -// children: [ -// Container( -// color: Theme.of(context).backgroundColor, -// child: Center( -// child: Image.asset( -// 'assets/images/birthday_cake.png'), -// ), -// ), -// Center( -// child: Padding( -// padding: EdgeInsets.only( -// top: 220, left: 24, right: 24), -// child: Text( -// S.of(context).send_success, -// textAlign: TextAlign.center, -// style: TextStyle( -// fontSize: 22, -// fontWeight: FontWeight.bold, -// color: Theme.of(context) -// .primaryTextTheme -// .title -// .color, -// decoration: TextDecoration.none, -// ), -// ), -// ), -// ), -// Positioned( -// left: 24, -// right: 24, -// bottom: 24, -// child: PrimaryButton( -// onPressed: () => -// Navigator.of(context).pop(), -// text: S.of(context).send_got_it, -// color: Colors.blue, -// textColor: Colors.white)) -// ], -// ); -// } + if (state is TransactionCommitted) { + WidgetsBinding.instance.addPostFrameCallback((_) { + _addressController.text = ''; + _cryptoAmountController.text = ''; + }); + } + }); -// return Stack( -// children: [ -// Container( -// color: Theme.of(context).backgroundColor, -// child: Center( -// child: Image.asset( -// 'assets/images/birthday_cake.png'), -// ), -// ), -// BackdropFilter( -// filter: ImageFilter.blur( -// sigmaX: 3.0, sigmaY: 3.0), -// child: Container( -// decoration: BoxDecoration( -// color: Theme.of(context) -// .backgroundColor -// .withOpacity(0.25)), -// child: Center( -// child: Padding( -// padding: EdgeInsets.only(top: 220), -// child: Text( -// S.of(context).send_sending, -// textAlign: TextAlign.center, -// style: TextStyle( -// fontSize: 22, -// fontWeight: FontWeight.bold, -// color: Theme.of(context) -// .primaryTextTheme -// .title -// .color, -// decoration: TextDecoration.none, -// ), -// ), -// ), -// ), -// ), -// ) -// ], -// ); -// }); -// }); -// }, -// actionRightButton: () => Navigator.of(context).pop()); -// }); -// }); -// } + _effectsInstalled = true; + } -// if (state is TransactionCommitted) { -// WidgetsBinding.instance.addPostFrameCallback((_) { -// _addressController.text = ''; -// _cryptoAmountController.text = ''; -// }); -// } -// }); + Future getOpenaliasRecord(BuildContext context) async { + // final isOpenalias = + // await sendViewModel.isOpenaliasRecord(_addressController.text); -// _effectsInstalled = true; -// } + // if (isOpenalias) { + // _addressController.text = sendViewModel.recordAddress; -// Widget body(BuildContext context) => BaseSendWidget( -// sendViewModel: sendViewModel, -// leading: leading(context), -// middle: middle(context), -// ); + // await showDialog( + // context: context, + // builder: (BuildContext context) { + // return AlertWithOneAction( + // alertTitle: S.of(context).openalias_alert_title, + // alertContent: S + // .of(context) + // .openalias_alert_content(sendViewModel.recordName), + // buttonText: S.of(context).ok, + // buttonAction: () => Navigator.of(context).pop()); + // }); + // } + } -// @override -// Widget build(BuildContext context) { -// return Scaffold( -// resizeToAvoidBottomPadding: resizeToAvoidBottomPadding, -// body: Container( -// color: Theme.of(context).backgroundColor, child: body(context))); -// } + Future _setTransactionPriority(BuildContext context) async { + final items = TransactionPriority.all; + final selectedItem = items.indexOf(sendViewModel.transactionPriority); + + await showDialog( + builder: (_) => Picker( + items: items, + selectedAtIndex: selectedItem, + title: S.of(context).please_select, + mainAxisAlignment: MainAxisAlignment.center, + onItemSelected: (TransactionPriority priority) => null, + // sendViewModel.setTransactionPriority(priority), + isAlwaysShowScrollThumb: true, + ), + context: context); + } } diff --git a/pubspec.lock b/pubspec.lock index ab4e1d14e..158fdec7c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -42,7 +42,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.2" + version: "2.4.1" auto_size_text: dependency: "direct main" description: @@ -210,7 +210,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.13" + version: "1.14.12" convert: dependency: transitive description: @@ -224,7 +224,7 @@ packages: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" + version: "2.1.4" csslib: dependency: transitive description: @@ -302,13 +302,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" ffi: dependency: transitive description: @@ -475,7 +468,7 @@ packages: name: image url: "https://pub.dartlang.org" source: hosted - version: "2.1.14" + version: "2.1.12" intl: dependency: "direct main" description: @@ -524,7 +517,7 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.8" + version: "0.12.6" meta: dependency: transitive description: @@ -594,7 +587,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.6.4" path_drawing: dependency: transitive description: @@ -650,7 +643,7 @@ packages: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "3.0.4" + version: "2.4.0" platform: dependency: transitive description: @@ -830,7 +823,7 @@ packages: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.5" + version: "1.9.3" stream_channel: dependency: transitive description: @@ -865,7 +858,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.17" + version: "0.2.15" time: dependency: transitive description: @@ -886,7 +879,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.1.6" url_launcher: dependency: "direct main" description: @@ -963,7 +956,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "4.2.0" + version: "3.6.1" yaml: dependency: "direct main" description: @@ -972,5 +965,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.9.0-14.0.dev <3.0.0" + dart: ">=2.7.0 <3.0.0" flutter: ">=1.12.13+hotfix.5 <2.0.0"