account for units setting

This commit is contained in:
julian 2023-06-16 17:04:39 -06:00
parent c0eb85ce5a
commit 346a6a7a01
6 changed files with 18 additions and 2 deletions

View file

@ -1539,6 +1539,7 @@ class _SendViewState extends ConsumerState<SendView> {
inputFormatters: [
AmountInputFormatter(
decimals: coin.decimals,
unit: ref.watch(pAmountUnit(coin)),
locale: locale,
),

View file

@ -938,6 +938,7 @@ class _TokenSendViewState extends ConsumerState<TokenSendView> {
inputFormatters: [
AmountInputFormatter(
decimals: tokenContract.decimals,
unit: ref.watch(pAmountUnit(coin)),
locale: locale,
),
// // regex to validate a crypto amount with 8 decimal places

View file

@ -760,6 +760,7 @@ class _TransactionSearchViewState
inputFormatters: [
AmountInputFormatter(
decimals: widget.coin.decimals,
unit: ref.watch(pAmountUnit(widget.coin)),
locale: ref.watch(
localeServiceChangeNotifierProvider
.select((value) => value.locale),

View file

@ -1043,6 +1043,7 @@ class _DesktopSendState extends ConsumerState<DesktopSend> {
inputFormatters: [
AmountInputFormatter(
decimals: coin.decimals,
unit: ref.watch(pAmountUnit(coin)),
locale: locale,
),
// // regex to validate a crypto amount with 8 decimal places

View file

@ -720,6 +720,7 @@ class _DesktopTokenSendState extends ConsumerState<DesktopTokenSend> {
inputFormatters: [
AmountInputFormatter(
decimals: tokenContract.decimals,
unit: ref.watch(pAmountUnit(coin)),
locale: ref.watch(
localeServiceChangeNotifierProvider
.select((value) => value.locale),

View file

@ -1,12 +1,20 @@
import 'dart:math';
import 'package:flutter/services.dart';
import 'package:intl/number_symbols.dart';
import 'package:intl/number_symbols_data.dart';
import 'package:stackwallet/utilities/amount/amount_unit.dart';
class AmountInputFormatter extends TextInputFormatter {
final int decimals;
final String locale;
final AmountUnit? unit;
AmountInputFormatter({required this.decimals, required this.locale});
AmountInputFormatter({
required this.decimals,
required this.locale,
this.unit,
});
@override
TextEditingValue formatEditUpdate(
@ -46,7 +54,10 @@ class AmountInputFormatter extends TextInputFormatter {
fraction = "";
}
if (fraction.length > decimals) {
final fractionDigits =
unit == null ? decimals : max(decimals - unit!.shift, 0);
if (fraction.length > fractionDigits) {
return oldValue;
}
}