From a5831a25e76dbafcaccebf22c99daee40746fd68 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Mon, 16 Aug 2021 11:30:48 +0300 Subject: [PATCH] CAKE-345 | merged CAKE-349 branch into current --- lib/bitcoin/bitcoin_amount_format.dart | 20 ++++--------------- .../exchange/widgets/exchange_card.dart | 8 +++----- lib/src/screens/send/send_template_page.dart | 6 ++---- lib/src/screens/send/widgets/send_card.dart | 6 ++++++ 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/lib/bitcoin/bitcoin_amount_format.dart b/lib/bitcoin/bitcoin_amount_format.dart index fa00387f1..714fc5a97 100644 --- a/lib/bitcoin/bitcoin_amount_format.dart +++ b/lib/bitcoin/bitcoin_amount_format.dart @@ -16,24 +16,12 @@ double bitcoinAmountToDouble({int amount}) => cryptoAmountToDouble(amount: amount, divider: bitcoinAmountDivider); int stringDoubleToBitcoinAmount(String amount) { - final splitted = amount.split(''); - final dotIndex = amount.indexOf('.'); int result = 0; - - for (var i = 0; i < splitted.length; i++) { - try { - if (dotIndex == i) { - continue; - } - - final char = splitted[i]; - final multiplier = dotIndex < i - ? bitcoinAmountDivider ~/ pow(10, (i - dotIndex)) - : (bitcoinAmountDivider * pow(10, (dotIndex - i -1))).toInt(); - final num = int.parse(char) * multiplier; - result += num; - } catch (_) {} + try { + result = (double.parse(amount) * bitcoinAmountDivider).toInt(); + } catch (e) { + result = 0; } return result; diff --git a/lib/src/screens/exchange/widgets/exchange_card.dart b/lib/src/screens/exchange/widgets/exchange_card.dart index 8b93f1db8..23f235c65 100644 --- a/lib/src/screens/exchange/widgets/exchange_card.dart +++ b/lib/src/screens/exchange/widgets/exchange_card.dart @@ -165,11 +165,9 @@ class ExchangeCardState extends State { textAlign: TextAlign.left, keyboardType: TextInputType.numberWithOptions( signed: false, decimal: true), - // inputFormatters: [ - // LengthLimitingTextInputFormatter(15), - // BlacklistingTextInputFormatter( - // RegExp('[\\-|\\ |\\,]')) - // ], + inputFormatters: [ + FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]')) + ], hintText: '0.0000', borderColor: widget.borderColor, textStyle: TextStyle( diff --git a/lib/src/screens/send/send_template_page.dart b/lib/src/screens/send/send_template_page.dart index e35f7d71d..86eebc7bf 100644 --- a/lib/src/screens/send/send_template_page.dart +++ b/lib/src/screens/send/send_template_page.dart @@ -156,8 +156,7 @@ class SendTemplatePage extends BasePage { keyboardType: TextInputType.numberWithOptions( signed: false, decimal: true), inputFormatters: [ - BlacklistingTextInputFormatter( - RegExp('[\\-|\\ ]')) + FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]')) ], prefixIcon: Padding( padding: EdgeInsets.only(top: 9), @@ -196,8 +195,7 @@ class SendTemplatePage extends BasePage { keyboardType: TextInputType.numberWithOptions( signed: false, decimal: true), inputFormatters: [ - BlacklistingTextInputFormatter( - RegExp('[\\-|\\ ]')) + FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]')) ], prefixIcon: Padding( padding: EdgeInsets.only(top: 9), diff --git a/lib/src/screens/send/widgets/send_card.dart b/lib/src/screens/send/widgets/send_card.dart index 5db48567f..b33f29724 100644 --- a/lib/src/screens/send/widgets/send_card.dart +++ b/lib/src/screens/send/widgets/send_card.dart @@ -164,6 +164,9 @@ class SendCardState extends State keyboardType: TextInputType.numberWithOptions( signed: false, decimal: true), + inputFormatters: [ + FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]')) + ], prefixIcon: Padding( padding: EdgeInsets.only(top: 9), child: Text( @@ -273,6 +276,9 @@ class SendCardState extends State keyboardType: TextInputType.numberWithOptions( signed: false, decimal: true), + inputFormatters: [ + FilteringTextInputFormatter.deny(RegExp('[\\-|\\ ]')) + ], prefixIcon: Padding( padding: EdgeInsets.only(top: 9), child: