mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-21 06:18:42 +02:00
CW-143 cake pay custom tip amount (#492)
* Add custom tip logic * Fix euro currency
This commit is contained in:
@@ -156,7 +156,7 @@ class IoniaBuyGiftCardDetailPage extends BasePage {
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
padding: const EdgeInsets.fromLTRB(24.0, 24.0, 0, 24.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -174,6 +174,8 @@ class IoniaBuyGiftCardDetailPage extends BasePage {
|
||||
selectedTip: ioniaPurchaseViewModel.selectedTip.percentage,
|
||||
tipsList: ioniaPurchaseViewModel.tips,
|
||||
onSelect: (value) => ioniaPurchaseViewModel.addTip(value),
|
||||
amount: ioniaPurchaseViewModel.amount,
|
||||
merchant: ioniaPurchaseViewModel.ioniaMerchant,
|
||||
),
|
||||
)
|
||||
],
|
||||
@@ -372,13 +374,19 @@ class TipButtonGroup extends StatelessWidget {
|
||||
@required this.selectedTip,
|
||||
@required this.onSelect,
|
||||
@required this.tipsList,
|
||||
@required this.amount,
|
||||
@required this.merchant,
|
||||
}) : super(key: key);
|
||||
|
||||
final Function(IoniaTip) onSelect;
|
||||
final double selectedTip;
|
||||
final List<IoniaTip> tipsList;
|
||||
final double amount;
|
||||
final IoniaMerchant merchant;
|
||||
|
||||
bool _isSelected(double value) => selectedTip == value;
|
||||
Set<double> get filter => tipsList.map((e) => e.percentage).toSet();
|
||||
bool get _isCustomSelected => !filter.contains(selectedTip);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -392,10 +400,17 @@ class TipButtonGroup extends StatelessWidget {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(right: 5),
|
||||
child: TipButton(
|
||||
isSelected: _isSelected(tip.percentage),
|
||||
onTap: () => onSelect(tip),
|
||||
caption: '${tip.percentage.toStringAsFixed(0)}%',
|
||||
subTitle: '\$${tip.additionalAmount.toStringAsFixed(2)}',
|
||||
isSelected: tip.isCustom ? _isCustomSelected : _isSelected(tip.percentage),
|
||||
onTap: () async {
|
||||
IoniaTip ioniaTip = tip;
|
||||
if(tip.isCustom){
|
||||
final customTip = await Navigator.pushNamed(context, Routes.ioniaCustomTipPage, arguments: [amount, merchant, tip]) as IoniaTip;
|
||||
ioniaTip = customTip ?? tip;
|
||||
}
|
||||
onSelect(ioniaTip);
|
||||
},
|
||||
caption: tip.isCustom ? S.of(context).custom : '${tip.percentage.toStringAsFixed(0)}%',
|
||||
subTitle: tip.isCustom ? null : '\$${tip.additionalAmount.toStringAsFixed(2)}',
|
||||
));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ 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/themes/theme_base.dart';
|
||||
import 'package:cake_wallet/view_model/ionia/ionia_purchase_merch_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/ionia/ionia_custom_tip_view_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_mobx/flutter_mobx.dart';
|
||||
@@ -15,15 +15,15 @@ import 'package:cake_wallet/generated/i18n.dart';
|
||||
|
||||
class IoniaCustomTipPage extends BasePage {
|
||||
IoniaCustomTipPage(
|
||||
this.ioniaPurchaseViewModel,
|
||||
this.customTipViewModel,
|
||||
) : _amountFieldFocus = FocusNode(),
|
||||
_amountController = TextEditingController() {
|
||||
_amountController.addListener(() {
|
||||
// ioniaPurchaseViewModel.onTipChanged(_amountController.text);
|
||||
customTipViewModel.onTipChanged(_amountController.text);
|
||||
});
|
||||
}
|
||||
|
||||
final IoniaMerchPurchaseViewModel ioniaPurchaseViewModel;
|
||||
final IoniaCustomTipViewModel customTipViewModel;
|
||||
|
||||
|
||||
@override
|
||||
@@ -46,7 +46,7 @@ class IoniaCustomTipPage extends BasePage {
|
||||
@override
|
||||
Widget body(BuildContext context) {
|
||||
final _width = MediaQuery.of(context).size.width;
|
||||
final merchant = ioniaPurchaseViewModel.ioniaMerchant;
|
||||
final merchant = customTipViewModel.ioniaMerchant;
|
||||
return KeyboardActions(
|
||||
disableScroll: true,
|
||||
config: KeyboardActionsConfig(
|
||||
@@ -116,7 +116,7 @@ class IoniaCustomTipPage extends BasePage {
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Observer(builder: (_) {
|
||||
if (ioniaPurchaseViewModel.percentage == 0.0) {
|
||||
if (customTipViewModel.percentage == 0.0) {
|
||||
return SizedBox.shrink();
|
||||
}
|
||||
|
||||
@@ -129,8 +129,8 @@ class IoniaCustomTipPage extends BasePage {
|
||||
),
|
||||
children: [
|
||||
TextSpan(text: ' ${S.of(context).is_percentage} '),
|
||||
TextSpan(text: '${ioniaPurchaseViewModel.percentage}%'),
|
||||
TextSpan(text: ' ${S.of(context).percentageOf(ioniaPurchaseViewModel.amount.toString())} '),
|
||||
TextSpan(text: '${customTipViewModel.percentage.toStringAsFixed(2)}%'),
|
||||
TextSpan(text: ' ${S.of(context).percentageOf(customTipViewModel.amount.toStringAsFixed(2))} '),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -159,7 +159,7 @@ class IoniaCustomTipPage extends BasePage {
|
||||
padding: EdgeInsets.only(bottom: 12),
|
||||
child: PrimaryButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(_amountController.text);
|
||||
Navigator.of(context).pop(customTipViewModel.customTip);
|
||||
},
|
||||
text: S.of(context).add_tip,
|
||||
color: Theme.of(context).accentTextTheme.body2.color,
|
||||
|
||||
Reference in New Issue
Block a user