Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

644 accept comma #650

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/models/currency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ class BitcoinCurrency extends Object {
RegExp get whitelistedPattern {
switch (tickerSymbol) {
case "BTC":
return RegExp("^\\d+\\.?\\d{0,8}");
return RegExp("^\\d+[.,]?\\d{0,8}");
case "SAT":
return RegExp(r'\d+');
default:
return RegExp("^\\d+\\.?\\d{0,8}");
return RegExp("^\\d+[.,]?\\d{0,8}");
}
}

Expand Down
4 changes: 4 additions & 0 deletions lib/utils/fiat_conversion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class FiatConversion {
return (fiatAmount / exchangeRate * 100000000).round();
}

RegExp get whitelistedPattern => currencyData.info.fractionSize == 0
? RegExp(r'\d+')
: RegExp("^\\d+[.,]?\\d{0,${currencyData.info.fractionSize}}");

double satToFiat(int satoshies) {
return satoshies.toDouble() / 100000000 * exchangeRate;
}
Expand Down
9 changes: 8 additions & 1 deletion lib/widgets/amount_form_field/amount_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ class AmountFormField extends TextFormField {
enabled: enabled,
controller: controller,
inputFormatters: bitcoinCurrency != BitcoinCurrency.SAT
? [FilteringTextInputFormatter.allow(RegExp(r'\d+\.?\d*'))]
? [
FilteringTextInputFormatter.allow(bitcoinCurrency.whitelistedPattern),
TextInputFormatter.withFunction(
(_, newValue) => newValue.copyWith(
text: newValue.text.replaceAll(',', '.'),
),
),
]
: [SatAmountFormFieldFormatter()],
onFieldSubmitted: onFieldSubmitted,
onSaved: onSaved,
Expand Down
9 changes: 6 additions & 3 deletions lib/widgets/amount_form_field/currency_converter_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ class CurrencyConverterDialogState extends State<CurrencyConverterDialog>
}

final fiatConversion = FiatConversion(fiatCurrency, fiatExchangeRate);
final int fractionSize = fiatCurrency.info.fractionSize;
final borderColor = themeData.isLightTheme ? Colors.red : themeData.colorScheme.error;

return Column(
Expand Down Expand Up @@ -212,10 +211,14 @@ class CurrencyConverterDialogState extends State<CurrencyConverterDialog>
style: themeData.dialogTheme.contentTextStyle,
),
),
// Do not allow '.' when fractionSize is 0 and only allow fiat currencies fractionSize number of digits after decimal point
inputFormatters: [
FilteringTextInputFormatter.allow(
fractionSize == 0 ? RegExp(r'\d+') : RegExp("^\\d+\\.?\\d{0,$fractionSize}"),
fiatConversion.whitelistedPattern,
),
TextInputFormatter.withFunction(
(_, newValue) => newValue.copyWith(
text: newValue.text.replaceAll(',', '.'),
),
),
],
keyboardType: const TextInputType.numberWithOptions(decimal: true),
Expand Down
Loading