mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 11:59:30 +00:00
account for units setting
This commit is contained in:
parent
c0eb85ce5a
commit
346a6a7a01
6 changed files with 18 additions and 2 deletions
|
@ -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,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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),
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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),
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue