mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-05-06 11:32:13 +00:00
Cw 55 allow saving templateswith fiat amount (#343)
* added xhv logo * Added prefix icon widget * Added sending fiat template * template for sending selected fiat currency * fix issues
This commit is contained in:
parent
75da854121
commit
c08f2c1667
9 changed files with 135 additions and 39 deletions
BIN
assets/images/xhv_logo.png
Normal file
BIN
assets/images/xhv_logo.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 20 KiB |
|
@ -343,7 +343,8 @@ Future setup(
|
||||||
_transactionDescriptionBox));
|
_transactionDescriptionBox));
|
||||||
|
|
||||||
getIt.registerFactory(
|
getIt.registerFactory(
|
||||||
() => SendPage(sendViewModel: getIt.get<SendViewModel>()));
|
() => SendPage(sendViewModel: getIt.get<SendViewModel>(),
|
||||||
|
settingsViewModel: getIt.get<SettingsViewModel>()));
|
||||||
|
|
||||||
getIt.registerFactory(() => SendTemplatePage(
|
getIt.registerFactory(() => SendTemplatePage(
|
||||||
sendTemplateViewModel: getIt.get<SendTemplateViewModel>()));
|
sendTemplateViewModel: getIt.get<SendTemplateViewModel>()));
|
||||||
|
|
|
@ -4,7 +4,7 @@ part 'template.g.dart';
|
||||||
|
|
||||||
@HiveType(typeId: Template.typeId)
|
@HiveType(typeId: Template.typeId)
|
||||||
class Template extends HiveObject {
|
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 typeId = 6;
|
||||||
static const boxName = 'Template';
|
static const boxName = 'Template';
|
||||||
|
@ -20,4 +20,14 @@ class Template extends HiveObject {
|
||||||
|
|
||||||
@HiveField(3)
|
@HiveField(3)
|
||||||
String amount;
|
String amount;
|
||||||
}
|
|
||||||
|
@HiveField(4)
|
||||||
|
String fiatCurrency;
|
||||||
|
|
||||||
|
@HiveField(5)
|
||||||
|
bool isCurrencySelected;
|
||||||
|
|
||||||
|
@HiveField(6)
|
||||||
|
String amountFiat;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,8 @@ class CurrencyUtils {
|
||||||
return 'assets/images/xlm_icon.png';
|
return 'assets/images/xlm_icon.png';
|
||||||
case CryptoCurrency.xrp:
|
case CryptoCurrency.xrp:
|
||||||
return 'assets/images/xrp_icon.png';
|
return 'assets/images/xrp_icon.png';
|
||||||
|
case CryptoCurrency.xhv:
|
||||||
|
return 'assets/images/xhv_logo.png';
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import 'dart:ui';
|
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/dashboard/widgets/sync_indicator_icon.dart';
|
||||||
import 'package:cake_wallet/src/screens/send/widgets/send_card.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/alert_with_two_actions.dart';
|
||||||
import 'package:cake_wallet/src/widgets/picker.dart';
|
import 'package:cake_wallet/src/widgets/picker.dart';
|
||||||
import 'package:cake_wallet/src/widgets/template_tile.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/send/output.dart';
|
||||||
|
import 'package:cake_wallet/view_model/settings/settings_view_model.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_mobx/flutter_mobx.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';
|
import 'package:cw_core/crypto_currency.dart';
|
||||||
|
|
||||||
class SendPage extends BasePage {
|
class SendPage extends BasePage {
|
||||||
SendPage({@required this.sendViewModel}) : _formKey = GlobalKey<FormState>();
|
SendPage({@required this.sendViewModel,@required this.settingsViewModel }) : _formKey = GlobalKey<FormState>(),fiatFromSettings = settingsViewModel.fiatCurrency;
|
||||||
|
|
||||||
final SendViewModel sendViewModel;
|
final SendViewModel sendViewModel;
|
||||||
|
final SettingsViewModel settingsViewModel;
|
||||||
final GlobalKey<FormState> _formKey;
|
final GlobalKey<FormState> _formKey;
|
||||||
final controller = PageController(initialPage: 0);
|
final controller = PageController(initialPage: 0);
|
||||||
|
final FiatCurrency fiatFromSettings ;
|
||||||
|
|
||||||
bool _effectsInstalled = false;
|
bool _effectsInstalled = false;
|
||||||
|
|
||||||
|
@ -49,6 +53,12 @@ class SendPage extends BasePage {
|
||||||
@override
|
@override
|
||||||
AppBarStyle get appBarStyle => AppBarStyle.transparent;
|
AppBarStyle get appBarStyle => AppBarStyle.transparent;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onClose(BuildContext context) {
|
||||||
|
settingsViewModel.setFiatCurrency(fiatFromSettings);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget middle(BuildContext context) => Row(
|
Widget middle(BuildContext context) => Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
@ -212,12 +222,18 @@ class SendPage extends BasePage {
|
||||||
return TemplateTile(
|
return TemplateTile(
|
||||||
key: UniqueKey(),
|
key: UniqueKey(),
|
||||||
to: template.name,
|
to: template.name,
|
||||||
amount: template.amount,
|
amount: template.isCurrencySelected ? template.amount : template.amountFiat,
|
||||||
from: template.cryptoCurrency,
|
from: template.isCurrencySelected ? template.cryptoCurrency : template.fiatCurrency,
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
|
final fiatFromTemplate = FiatCurrency.all.singleWhere((element) => element.title == template.fiatCurrency);
|
||||||
final output = _defineCurrentOutput();
|
final output = _defineCurrentOutput();
|
||||||
output.address = template.address;
|
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();
|
output.resetParsedAddress();
|
||||||
await output.fetchParsedAddress(context);
|
await output.fetchParsedAddress(context);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'package:cake_wallet/utils/payment_request.dart';
|
import 'package:cake_wallet/utils/payment_request.dart';
|
||||||
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||||
import 'package:mobx/mobx.dart';
|
import 'package:mobx/mobx.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.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/keyboard_done_button.dart';
|
||||||
import 'package:cake_wallet/src/widgets/primary_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/widgets/scollable_with_bottom_section.dart';
|
||||||
|
import 'package:cake_wallet/src/screens/send/widgets/prefix_currency_icon_widget.dart';
|
||||||
|
|
||||||
class SendTemplatePage extends BasePage {
|
class SendTemplatePage extends BasePage {
|
||||||
SendTemplatePage({@required this.sendTemplateViewModel}) {
|
SendTemplatePage({@required this.sendTemplateViewModel}) {
|
||||||
|
@ -142,7 +144,13 @@ class SendTemplatePage extends BasePage {
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 20),
|
padding: const EdgeInsets.only(top: 20),
|
||||||
child: BaseTextFormField(
|
child: Focus(
|
||||||
|
onFocusChange: (hasFocus) {
|
||||||
|
if (hasFocus) {
|
||||||
|
sendTemplateViewModel.selectCurrency();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: BaseTextFormField(
|
||||||
focusNode: _cryptoAmountFocus,
|
focusNode: _cryptoAmountFocus,
|
||||||
controller: _cryptoAmountController,
|
controller: _cryptoAmountController,
|
||||||
keyboardType: TextInputType.numberWithOptions(
|
keyboardType: TextInputType.numberWithOptions(
|
||||||
|
@ -151,17 +159,14 @@ class SendTemplatePage extends BasePage {
|
||||||
FilteringTextInputFormatter.deny(
|
FilteringTextInputFormatter.deny(
|
||||||
RegExp('[\\-|\\ ]'))
|
RegExp('[\\-|\\ ]'))
|
||||||
],
|
],
|
||||||
prefixIcon: Padding(
|
prefixIcon: Observer(
|
||||||
padding: EdgeInsets.only(top: 9),
|
builder: (_) => PrefixCurrencyIcon(
|
||||||
child: Text(
|
title: sendTemplateViewModel
|
||||||
sendTemplateViewModel.currency.title +
|
.currency.title,
|
||||||
':',
|
isSelected:
|
||||||
style: TextStyle(
|
sendTemplateViewModel
|
||||||
fontSize: 16,
|
.isCurrencySelected,
|
||||||
fontWeight: FontWeight.w600,
|
)),
|
||||||
color: Colors.white,
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
hintText: '0.0000',
|
hintText: '0.0000',
|
||||||
borderColor: Theme.of(context)
|
borderColor: Theme.of(context)
|
||||||
.primaryTextTheme
|
.primaryTextTheme
|
||||||
|
@ -179,10 +184,16 @@ class SendTemplatePage extends BasePage {
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
fontSize: 14),
|
fontSize: 14),
|
||||||
validator:
|
validator:
|
||||||
sendTemplateViewModel.amountValidator)),
|
sendTemplateViewModel.amountValidator))),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(top: 20),
|
padding: const EdgeInsets.only(top: 20),
|
||||||
child: BaseTextFormField(
|
child: Focus(
|
||||||
|
onFocusChange: (hasFocus) {
|
||||||
|
if (hasFocus) {
|
||||||
|
sendTemplateViewModel.selectFiat();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: BaseTextFormField(
|
||||||
focusNode: _fiatAmountFocus,
|
focusNode: _fiatAmountFocus,
|
||||||
controller: _fiatAmountController,
|
controller: _fiatAmountController,
|
||||||
keyboardType: TextInputType.numberWithOptions(
|
keyboardType: TextInputType.numberWithOptions(
|
||||||
|
@ -191,16 +202,13 @@ class SendTemplatePage extends BasePage {
|
||||||
FilteringTextInputFormatter.deny(
|
FilteringTextInputFormatter.deny(
|
||||||
RegExp('[\\-|\\ ]'))
|
RegExp('[\\-|\\ ]'))
|
||||||
],
|
],
|
||||||
prefixIcon: Padding(
|
prefixIcon: Observer(
|
||||||
padding: EdgeInsets.only(top: 9),
|
builder: (_) => PrefixCurrencyIcon(
|
||||||
child: Text(
|
title: sendTemplateViewModel
|
||||||
sendTemplateViewModel.fiat.title + ':',
|
.fiat.title,
|
||||||
style: TextStyle(
|
isSelected: sendTemplateViewModel
|
||||||
fontSize: 16,
|
.isFiatSelected,
|
||||||
fontWeight: FontWeight.w600,
|
)),
|
||||||
color: Colors.white,
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
hintText: '0.00',
|
hintText: '0.00',
|
||||||
borderColor: Theme.of(context)
|
borderColor: Theme.of(context)
|
||||||
.primaryTextTheme
|
.primaryTextTheme
|
||||||
|
@ -217,7 +225,7 @@ class SendTemplatePage extends BasePage {
|
||||||
.decorationColor,
|
.decorationColor,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
fontSize: 14),
|
fontSize: 14),
|
||||||
)),
|
))),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -231,10 +239,13 @@ class SendTemplatePage extends BasePage {
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (_formKey.currentState.validate()) {
|
if (_formKey.currentState.validate()) {
|
||||||
sendTemplateViewModel.addTemplate(
|
sendTemplateViewModel.addTemplate(
|
||||||
|
isCurrencySelected: sendTemplateViewModel.isCurrencySelected,
|
||||||
name: _nameController.text,
|
name: _nameController.text,
|
||||||
address: _addressController.text,
|
address: _addressController.text,
|
||||||
cryptoCurrency: sendTemplateViewModel.currency.title,
|
cryptoCurrency:sendTemplateViewModel.currency.title,
|
||||||
amount: _cryptoAmountController.text);
|
fiatCurrency: sendTemplateViewModel.fiat.title,
|
||||||
|
amount: _cryptoAmountController.text,
|
||||||
|
amountFiat: _fiatAmountController.text);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -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,
|
||||||
|
)),
|
||||||
|
)
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,9 +23,9 @@ abstract class SendTemplateBase with Store {
|
||||||
templates.replaceRange(0, templates.length, templateSource.values.toList());
|
templates.replaceRange(0, templates.length, templateSource.values.toList());
|
||||||
|
|
||||||
@action
|
@action
|
||||||
Future addTemplate({String name, String address, String cryptoCurrency, String amount}) async {
|
Future addTemplate({String name,bool isCurrencySelected, String address, String cryptoCurrency, String fiatCurrency, String amount,String amountFiat}) async {
|
||||||
final template = Template(name: name, address: address,
|
final template = Template(name: name,isCurrencySelected: isCurrencySelected, address: address,
|
||||||
cryptoCurrency: cryptoCurrency, amount: amount);
|
cryptoCurrency: cryptoCurrency, fiatCurrency: fiatCurrency, amount: amount, amountFiat: amountFiat);
|
||||||
await templateSource.add(template);
|
await templateSource.add(template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,24 @@ abstract class SendTemplateViewModelBase with Store {
|
||||||
|
|
||||||
FiatCurrency get fiat => _settingsStore.fiatCurrency;
|
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
|
@computed
|
||||||
ObservableList<Template> get templates => _sendTemplateStore.templates;
|
ObservableList<Template> get templates => _sendTemplateStore.templates;
|
||||||
|
|
||||||
|
@ -48,14 +66,20 @@ abstract class SendTemplateViewModelBase with Store {
|
||||||
|
|
||||||
void addTemplate(
|
void addTemplate(
|
||||||
{String name,
|
{String name,
|
||||||
|
bool isCurrencySelected,
|
||||||
String address,
|
String address,
|
||||||
String cryptoCurrency,
|
String cryptoCurrency,
|
||||||
String amount}) {
|
String fiatCurrency,
|
||||||
|
String amount,
|
||||||
|
String amountFiat}) {
|
||||||
_sendTemplateStore.addTemplate(
|
_sendTemplateStore.addTemplate(
|
||||||
name: name,
|
name: name,
|
||||||
|
isCurrencySelected: isCurrencySelected,
|
||||||
address: address,
|
address: address,
|
||||||
cryptoCurrency: cryptoCurrency,
|
cryptoCurrency: cryptoCurrency,
|
||||||
amount: amount);
|
fiatCurrency: fiatCurrency,
|
||||||
|
amount: amount,
|
||||||
|
amountFiat: amountFiat);
|
||||||
updateTemplate();
|
updateTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue