diff --git a/assets/images/xhv_logo.png b/assets/images/xhv_logo.png new file mode 100644 index 000000000..118c920fd Binary files /dev/null and b/assets/images/xhv_logo.png differ diff --git a/lib/di.dart b/lib/di.dart index dc6ec367d..c066b6cf1 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -343,7 +343,8 @@ Future setup( _transactionDescriptionBox)); getIt.registerFactory( - () => SendPage(sendViewModel: getIt.get())); + () => SendPage(sendViewModel: getIt.get(), + settingsViewModel: getIt.get())); getIt.registerFactory(() => SendTemplatePage( sendTemplateViewModel: getIt.get())); diff --git a/lib/entities/template.dart b/lib/entities/template.dart index b64910699..c37197e91 100644 --- a/lib/entities/template.dart +++ b/lib/entities/template.dart @@ -4,7 +4,7 @@ part 'template.g.dart'; @HiveType(typeId: Template.typeId) class Template extends HiveObject { - Template({this.name, this.address, this.cryptoCurrency, this.amount}); + Template({this.name,this.isCurrencySelected, this.address, this.cryptoCurrency, this.amount, this.fiatCurrency, this.amountFiat}); static const typeId = 6; static const boxName = 'Template'; @@ -20,4 +20,14 @@ class Template extends HiveObject { @HiveField(3) String amount; -} \ No newline at end of file + + @HiveField(4) + String fiatCurrency; + + @HiveField(5) + bool isCurrencySelected; + + @HiveField(6) + String amountFiat; +} + diff --git a/lib/src/screens/exchange/widgets/currency_utils.dart b/lib/src/screens/exchange/widgets/currency_utils.dart index aaf9ea57c..83c6d0af9 100644 --- a/lib/src/screens/exchange/widgets/currency_utils.dart +++ b/lib/src/screens/exchange/widgets/currency_utils.dart @@ -48,6 +48,8 @@ class CurrencyUtils { return 'assets/images/xlm_icon.png'; case CryptoCurrency.xrp: return 'assets/images/xrp_icon.png'; + case CryptoCurrency.xhv: + return 'assets/images/xhv_logo.png'; default: return null; } diff --git a/lib/src/screens/send/send_page.dart b/lib/src/screens/send/send_page.dart index 070e452f1..791548f3d 100644 --- a/lib/src/screens/send/send_page.dart +++ b/lib/src/screens/send/send_page.dart @@ -1,10 +1,12 @@ import 'dart:ui'; +import 'package:cake_wallet/entities/fiat_currency.dart'; import 'package:cake_wallet/src/screens/dashboard/widgets/sync_indicator_icon.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/picker.dart'; import 'package:cake_wallet/src/widgets/template_tile.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_mobx/flutter_mobx.dart'; @@ -26,11 +28,13 @@ import 'package:smooth_page_indicator/smooth_page_indicator.dart'; import 'package:cw_core/crypto_currency.dart'; class SendPage extends BasePage { - SendPage({@required this.sendViewModel}) : _formKey = GlobalKey(); + SendPage({@required this.sendViewModel,@required this.settingsViewModel }) : _formKey = GlobalKey(),fiatFromSettings = settingsViewModel.fiatCurrency; final SendViewModel sendViewModel; + final SettingsViewModel settingsViewModel; final GlobalKey _formKey; final controller = PageController(initialPage: 0); + final FiatCurrency fiatFromSettings ; bool _effectsInstalled = false; @@ -49,6 +53,12 @@ class SendPage extends BasePage { @override AppBarStyle get appBarStyle => AppBarStyle.transparent; + @override + void onClose(BuildContext context) { + settingsViewModel.setFiatCurrency(fiatFromSettings); + Navigator.of(context).pop(); + } + @override Widget middle(BuildContext context) => Row( mainAxisAlignment: MainAxisAlignment.center, @@ -212,12 +222,18 @@ class SendPage extends BasePage { return TemplateTile( key: UniqueKey(), to: template.name, - amount: template.amount, - from: template.cryptoCurrency, + amount: template.isCurrencySelected ? template.amount : template.amountFiat, + from: template.isCurrencySelected ? template.cryptoCurrency : template.fiatCurrency, onTap: () async { + final fiatFromTemplate = FiatCurrency.all.singleWhere((element) => element.title == template.fiatCurrency); final output = _defineCurrentOutput(); output.address = template.address; - output.setCryptoAmount(template.amount); + if(template.isCurrencySelected){ + output.setCryptoAmount(template.amount); + }else{ + settingsViewModel.setFiatCurrency(fiatFromTemplate); + output.setFiatAmount(template.amountFiat); + } output.resetParsedAddress(); await output.fetchParsedAddress(context); }, diff --git a/lib/src/screens/send/send_template_page.dart b/lib/src/screens/send/send_template_page.dart index a3e0b8928..9170bccfe 100644 --- a/lib/src/screens/send/send_template_page.dart +++ b/lib/src/screens/send/send_template_page.dart @@ -1,4 +1,5 @@ import 'package:cake_wallet/utils/payment_request.dart'; +import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:mobx/mobx.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -12,6 +13,7 @@ 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'; +import 'package:cake_wallet/src/screens/send/widgets/prefix_currency_icon_widget.dart'; class SendTemplatePage extends BasePage { SendTemplatePage({@required this.sendTemplateViewModel}) { @@ -142,7 +144,13 @@ class SendTemplatePage extends BasePage { ), Padding( padding: const EdgeInsets.only(top: 20), - child: BaseTextFormField( + child: Focus( + onFocusChange: (hasFocus) { + if (hasFocus) { + sendTemplateViewModel.selectCurrency(); + } + }, + child: BaseTextFormField( focusNode: _cryptoAmountFocus, controller: _cryptoAmountController, keyboardType: TextInputType.numberWithOptions( @@ -151,17 +159,14 @@ class SendTemplatePage extends BasePage { 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, - )), - ), + prefixIcon: Observer( + builder: (_) => PrefixCurrencyIcon( + title: sendTemplateViewModel + .currency.title, + isSelected: + sendTemplateViewModel + .isCurrencySelected, + )), hintText: '0.0000', borderColor: Theme.of(context) .primaryTextTheme @@ -179,10 +184,16 @@ class SendTemplatePage extends BasePage { fontWeight: FontWeight.w500, fontSize: 14), validator: - sendTemplateViewModel.amountValidator)), + sendTemplateViewModel.amountValidator))), Padding( padding: const EdgeInsets.only(top: 20), - child: BaseTextFormField( + child: Focus( + onFocusChange: (hasFocus) { + if (hasFocus) { + sendTemplateViewModel.selectFiat(); + } + }, + child: BaseTextFormField( focusNode: _fiatAmountFocus, controller: _fiatAmountController, keyboardType: TextInputType.numberWithOptions( @@ -191,16 +202,13 @@ class SendTemplatePage extends BasePage { FilteringTextInputFormatter.deny( RegExp('[\\-|\\ ]')) ], - prefixIcon: Padding( - padding: EdgeInsets.only(top: 9), - child: Text( - sendTemplateViewModel.fiat.title + ':', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - color: Colors.white, - )), - ), + prefixIcon: Observer( + builder: (_) => PrefixCurrencyIcon( + title: sendTemplateViewModel + .fiat.title, + isSelected: sendTemplateViewModel + .isFiatSelected, + )), hintText: '0.00', borderColor: Theme.of(context) .primaryTextTheme @@ -217,7 +225,7 @@ class SendTemplatePage extends BasePage { .decorationColor, fontWeight: FontWeight.w500, fontSize: 14), - )), + ))), ], ), ) @@ -231,10 +239,13 @@ class SendTemplatePage extends BasePage { onPressed: () { if (_formKey.currentState.validate()) { sendTemplateViewModel.addTemplate( + isCurrencySelected: sendTemplateViewModel.isCurrencySelected, name: _nameController.text, address: _addressController.text, - cryptoCurrency: sendTemplateViewModel.currency.title, - amount: _cryptoAmountController.text); + cryptoCurrency:sendTemplateViewModel.currency.title, + fiatCurrency: sendTemplateViewModel.fiat.title, + amount: _cryptoAmountController.text, + amountFiat: _fiatAmountController.text); Navigator.of(context).pop(); } }, diff --git a/lib/src/screens/send/widgets/prefix_currency_icon_widget.dart b/lib/src/screens/send/widgets/prefix_currency_icon_widget.dart new file mode 100644 index 000000000..030c1e652 --- /dev/null +++ b/lib/src/screens/send/widgets/prefix_currency_icon_widget.dart @@ -0,0 +1,32 @@ +import 'package:flutter/material.dart'; + +class PrefixCurrencyIcon extends StatelessWidget { + PrefixCurrencyIcon({ + @required this.isSelected, + @required this.title, + }); + + final bool isSelected; + final String title; + + @override + Widget build(BuildContext context) { + return Padding( + padding: EdgeInsets.fromLTRB(0, 6.0, 8.0, 0), + child: Column(children: [ + Container( + padding: EdgeInsets.symmetric(vertical: 4, horizontal: 8), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(26), + color: isSelected ? Colors.green : Colors.transparent, + ), + child: Text(title + ':', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + color: Colors.white, + )), + ) + ])); + } +} diff --git a/lib/store/templates/send_template_store.dart b/lib/store/templates/send_template_store.dart index b65362a1c..46d0dc451 100644 --- a/lib/store/templates/send_template_store.dart +++ b/lib/store/templates/send_template_store.dart @@ -23,9 +23,9 @@ abstract class SendTemplateBase with Store { templates.replaceRange(0, templates.length, templateSource.values.toList()); @action - Future addTemplate({String name, String address, String cryptoCurrency, String amount}) async { - final template = Template(name: name, address: address, - cryptoCurrency: cryptoCurrency, amount: amount); + Future addTemplate({String name,bool isCurrencySelected, String address, String cryptoCurrency, String fiatCurrency, String amount,String amountFiat}) async { + final template = Template(name: name,isCurrencySelected: isCurrencySelected, address: address, + cryptoCurrency: cryptoCurrency, fiatCurrency: fiatCurrency, amount: amount, amountFiat: amountFiat); await templateSource.add(template); } diff --git a/lib/view_model/send/send_template_view_model.dart b/lib/view_model/send/send_template_view_model.dart index e52022f8d..7ca2f39b4 100644 --- a/lib/view_model/send/send_template_view_model.dart +++ b/lib/view_model/send/send_template_view_model.dart @@ -36,6 +36,24 @@ abstract class SendTemplateViewModelBase with Store { FiatCurrency get fiat => _settingsStore.fiatCurrency; + @observable + bool isCurrencySelected = true; + + @observable + bool isFiatSelected = false; + + @action + void selectCurrency () { + isCurrencySelected = true; + isFiatSelected = false; + } + + @action + void selectFiat () { + isFiatSelected = true; + isCurrencySelected = false; + } + @computed ObservableList