fix: crypto amount calculation logic with max decimals (#2697)

* fix: crypto amount calculation logic with max decimals

* refactor: remove `_setCryptoNumMaximumFractionDigits` and `_cryptoNumberFormat` to simplify `OutputBase` logic
This commit is contained in:
Konstantin Ullrich
2025-12-01 21:43:46 +01:00
committed by GitHub
parent ae81b11f99
commit 86f30a216c
2 changed files with 21 additions and 48 deletions
+14 -3
View File
@@ -1,6 +1,9 @@
import 'package:cw_core/currency.dart';
import 'package:cw_core/enumerable_item.dart';
import 'package:collection/collection.dart';
import 'package:cw_core/parse_fixed.dart';
import 'format_fixed.dart';
class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implements Currency {
const CryptoCurrency({
@@ -394,7 +397,15 @@ class CryptoCurrency extends EnumerableItem<int> with Serializable<int> implemen
@override
String toString() => title;
bool titleAndTagEqual(CryptoCurrency other) {
return title == other.title && tag == other.tag;
}
bool titleAndTagEqual(CryptoCurrency other) => title == other.title && tag == other.tag;
/// Format the raw amount into its decimal representation eg. turn Sats into Bitcoin
String formatAmount(BigInt amount, {int? fractionalDigits, bool trimZeros = true}) =>
formatFixed(amount, decimals, fractionalDigits: fractionalDigits, trimZeros: trimZeros);
/// Parse the [value] and turn it into the smallest denomination eg. turn Bitcoin into Sats
BigInt parseAmount(String value) => parseFixed(value, decimals);
/// Try parsing the [value] and turn it into the smallest denomination eg. turn Bitcoin into Sats
BigInt? tryParseAmount(String value) => tryParseFixed(value, decimals);
}