mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-24 06:48:38 +02:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user