parseBalanceAmount function
Converts an exact base-unit amount without passing through floating point.
Implementation
BigInt parseBalanceAmount(Object value) {
if (value is! BigInt && value is! int && value is! String) {
throw ArgumentError.value(
value,
'amount',
'Use BigInt, int or decimal digits',
);
}
final text = value.toString();
if (!RegExp(r'^[0-9]+$').hasMatch(text)) {
throw ArgumentError.value(value, 'amount', 'Expected decimal digits');
}
final amount = BigInt.parse(text);
if (amount >= (BigInt.one << 64)) {
throw ArgumentError.value(value, 'amount', 'Exceeds u64');
}
return amount;
}