- Clean architecture with feature-based organization - Riverpod state management, Dio HTTP, GoRouter navigation - Dashboard, blocks, wallet, transactions, mining screens - Dark crypto theme with JetBrains Mono font
32 lines
969 B
Dart
32 lines
969 B
Dart
import 'package:intl/intl.dart';
|
|
|
|
class Formatters {
|
|
/// Format a hash for display (first 8 + ... + last 8).
|
|
static String truncateHash(String hash, {int chars = 8}) {
|
|
if (hash.length <= chars * 2) return hash;
|
|
return '${hash.substring(0, chars)}...${hash.substring(hash.length - chars)}';
|
|
}
|
|
|
|
/// Format amount from smallest unit to display unit.
|
|
/// 50_000_000 -> "50.000000"
|
|
static String formatAmount(int amount, {int decimals = 6}) {
|
|
final value = amount / 1000000;
|
|
return value.toStringAsFixed(decimals);
|
|
}
|
|
|
|
/// Format a timestamp string to readable date.
|
|
static String formatTimestamp(String timestamp) {
|
|
try {
|
|
final dt = DateTime.parse(timestamp);
|
|
return DateFormat('yyyy-MM-dd HH:mm:ss').format(dt.toLocal());
|
|
} catch (_) {
|
|
return timestamp;
|
|
}
|
|
}
|
|
|
|
/// Format large numbers with comma separators.
|
|
static String formatNumber(int number) {
|
|
return NumberFormat('#,###').format(number);
|
|
}
|
|
}
|