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: [ inputFormatters: [
AmountInputFormatter( AmountInputFormatter(
decimals: coin.decimals, decimals: coin.decimals,
unit: ref.watch(pAmountUnit(coin)),
locale: locale, locale: locale,
), ),

View file

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

View file

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

View file

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

View file

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

View file

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