From 9d3e2653928f16001a051c50428920607e692aeb Mon Sep 17 00:00:00 2001 From: M Date: Tue, 19 Jul 2022 14:42:20 +0100 Subject: [PATCH] Fixes for fiat amounts for ionia. --- lib/ionia/ionia_tip.dart | 2 +- lib/src/screens/ionia/cards/ionia_buy_gift_card.dart | 4 +++- lib/view_model/ionia/ionia_buy_card_view_model.dart | 2 +- lib/view_model/ionia/ionia_purchase_merch_view_model.dart | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/ionia/ionia_tip.dart b/lib/ionia/ionia_tip.dart index fbd6e4e4c..340c6226f 100644 --- a/lib/ionia/ionia_tip.dart +++ b/lib/ionia/ionia_tip.dart @@ -2,7 +2,7 @@ class IoniaTip { const IoniaTip({this.originalAmount, this.percentage}); final double originalAmount; final double percentage; - double get additionalAmount => originalAmount * percentage / 100; + double get additionalAmount => double.parse((originalAmount * percentage / 100).toStringAsFixed(2)); static const tipList = [ IoniaTip(originalAmount: 0, percentage: 0), diff --git a/lib/src/screens/ionia/cards/ionia_buy_gift_card.dart b/lib/src/screens/ionia/cards/ionia_buy_gift_card.dart index e7c6dabf8..882dfdc88 100644 --- a/lib/src/screens/ionia/cards/ionia_buy_gift_card.dart +++ b/lib/src/screens/ionia/cards/ionia_buy_gift_card.dart @@ -85,7 +85,9 @@ class IoniaBuyGiftCardPage extends BasePage { controller: _amountController, focusNode: _amountFieldFocus, keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true), - inputFormatters: [FilteringTextInputFormatter.deny(RegExp('[\-|\ ]'))], + inputFormatters: [ + FilteringTextInputFormatter.deny(RegExp('[\-|\ ]')), + WhitelistingTextInputFormatter(RegExp(r'^\d+(\.|\,)?\d{0,2}'))], hintText: '1000', placeholderTextStyle: TextStyle( color: Theme.of(context).primaryTextTheme.headline.color, diff --git a/lib/view_model/ionia/ionia_buy_card_view_model.dart b/lib/view_model/ionia/ionia_buy_card_view_model.dart index ed5411f49..b6314be80 100644 --- a/lib/view_model/ionia/ionia_buy_card_view_model.dart +++ b/lib/view_model/ionia/ionia_buy_card_view_model.dart @@ -22,7 +22,7 @@ abstract class IoniaBuyCardViewModelBase with Store { @action void onAmountChanged(String input) { if (input.isEmpty) return; - amount = double.parse(input); + amount = double.parse(input.replaceAll(',', '.')); final min = ioniaMerchant.minimumCardPurchase; final max = ioniaMerchant.maximumCardPurchase; diff --git a/lib/view_model/ionia/ionia_purchase_merch_view_model.dart b/lib/view_model/ionia/ionia_purchase_merch_view_model.dart index 1e537ac37..10e7c1f5e 100644 --- a/lib/view_model/ionia/ionia_purchase_merch_view_model.dart +++ b/lib/view_model/ionia/ionia_purchase_merch_view_model.dart @@ -55,7 +55,7 @@ abstract class IoniaMerchPurchaseViewModelBase with Store { double percentage; @computed - double get giftCardAmount => amount + tipAmount; + double get giftCardAmount => double.parse((amount + tipAmount).toStringAsFixed(2)); @observable double tipAmount;