2023-04-14 12:05:24 +00:00
|
|
|
import 'dart:math';
|
2023-03-16 17:24:21 +00:00
|
|
|
|
2023-07-22 00:39:10 +00:00
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
|
|
|
const ethereumAmountLength = 12;
|
|
|
|
const ethereumAmountDivider = 1000000000000;
|
|
|
|
final ethereumAmountFormat = NumberFormat()
|
|
|
|
..maximumFractionDigits = ethereumAmountLength
|
|
|
|
..minimumFractionDigits = 1;
|
|
|
|
|
2023-03-16 17:24:21 +00:00
|
|
|
class EthereumFormatter {
|
2023-07-22 00:39:10 +00:00
|
|
|
static int parseEthereumAmount(String amount) {
|
|
|
|
try {
|
|
|
|
return (double.parse(amount) * ethereumAmountDivider).round();
|
|
|
|
} catch (_) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int parseEthereumBigIntAmount(BigInt amount) {
|
|
|
|
try {
|
|
|
|
double result = amount / BigInt.from(pow(10, 18 - ethereumAmountLength));
|
|
|
|
return result.toInt();
|
|
|
|
} catch (_) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2023-04-14 12:05:24 +00:00
|
|
|
}
|