mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-16 17:27:37 +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 Width: | Height: | Size: 20 KiB |
|
@ -343,7 +343,8 @@ Future setup(
|
|||
_transactionDescriptionBox));
|
||||
|
||||
getIt.registerFactory(
|
||||
() => SendPage(sendViewModel: getIt.get<SendViewModel>()));
|
||||
() => SendPage(sendViewModel: getIt.get<SendViewModel>(),
|
||||
settingsViewModel: getIt.get<SettingsViewModel>()));
|
||||
|
||||
getIt.registerFactory(() => SendTemplatePage(
|
||||
sendTemplateViewModel: getIt.get<SendTemplateViewModel>()));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
@HiveField(4)
|
||||
String fiatCurrency;
|
||||
|
||||
@HiveField(5)
|
||||
bool isCurrencySelected;
|
||||
|
||||
@HiveField(6)
|
||||
String amountFiat;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<FormState>();
|
||||
SendPage({@required this.sendViewModel,@required this.settingsViewModel }) : _formKey = GlobalKey<FormState>(),fiatFromSettings = settingsViewModel.fiatCurrency;
|
||||
|
||||
final SendViewModel sendViewModel;
|
||||
final SettingsViewModel settingsViewModel;
|
||||
final GlobalKey<FormState> _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);
|
||||
},
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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());
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Template> get templates => _sendTemplateStore.templates;
|
||||
|
||||
|
@ -48,14 +66,20 @@ abstract class SendTemplateViewModelBase with Store {
|
|||
|
||||
void addTemplate(
|
||||
{String name,
|
||||
bool isCurrencySelected,
|
||||
String address,
|
||||
String cryptoCurrency,
|
||||
String amount}) {
|
||||
String fiatCurrency,
|
||||
String amount,
|
||||
String amountFiat}) {
|
||||
_sendTemplateStore.addTemplate(
|
||||
name: name,
|
||||
isCurrencySelected: isCurrencySelected,
|
||||
address: address,
|
||||
cryptoCurrency: cryptoCurrency,
|
||||
amount: amount);
|
||||
fiatCurrency: fiatCurrency,
|
||||
amount: amount,
|
||||
amountFiat: amountFiat);
|
||||
updateTemplate();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue