mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 03:49:22 +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: [
|
||||
AmountInputFormatter(
|
||||
decimals: coin.decimals,
|
||||
unit: ref.watch(pAmountUnit(coin)),
|
||||
locale: locale,
|
||||
),
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue