fix(mining-app): 价格显示优化 + 涨跌幅精度再提升

- 兑换页顶部价格改用 formatPriceFull 显示完整零(不再用 0.0{n} 缩写)
- K线纵坐标有效数字从7位精简为4位,节省空间更简洁
- 涨跌幅精度再提升:后端 toFixed(8)→toFixed(12),前端 6位→10位小数

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-04 20:43:48 -08:00
parent 2e91686a88
commit b639b5d499
5 changed files with 36 additions and 9 deletions

View File

@ -104,8 +104,8 @@ export class PriceService {
burnMultiplier: burnMultiplier.toFixed(18), burnMultiplier: burnMultiplier.toFixed(18),
minuteBurnRate: minuteBurnRate.toFixed(18), minuteBurnRate: minuteBurnRate.toFixed(18),
snapshotTime: new Date(), snapshotTime: new Date(),
// 保留8位小数,确保每分钟销毁带来的微小涨幅在前端可见 // 保留12位小数,确保每分钟销毁带来的微小涨幅在前端可见
priceChangePercent: priceChangePercent.toFixed(8), priceChangePercent: priceChangePercent.toFixed(12),
initialPrice: initialPrice.toFixed(18), initialPrice: initialPrice.toFixed(18),
}; };
} }
@ -265,8 +265,8 @@ export class PriceService {
burnMultiplier: burnMultiplier.toFixed(18), burnMultiplier: burnMultiplier.toFixed(18),
minuteBurnRate: snapshot.minuteBurnRate.toFixed(18), minuteBurnRate: snapshot.minuteBurnRate.toFixed(18),
snapshotTime: snapshot.snapshotTime, snapshotTime: snapshot.snapshotTime,
// 保留8位小数,确保每分钟销毁带来的微小涨幅在前端可见 // 保留12位小数,确保每分钟销毁带来的微小涨幅在前端可见
priceChangePercent: priceChangePercent.toFixed(8), priceChangePercent: priceChangePercent.toFixed(12),
initialPrice: initialPrice.toFixed(18), initialPrice: initialPrice.toFixed(18),
}; };
} }

View File

@ -70,6 +70,33 @@ String formatPrice(String? value) {
} }
} }
/// formatPrice 使 0.0{n} 0
String formatPriceFull(String? value) {
if (value == null || value.isEmpty) return '0';
try {
final decimal = Decimal.parse(value);
if (decimal >= Decimal.one) return decimal.toStringAsFixed(4);
if (decimal >= Decimal.parse('0.0001')) return decimal.toStringAsFixed(6);
if (decimal <= Decimal.zero) return '0';
final str = decimal.toStringAsFixed(18);
final dotIndex = str.indexOf('.');
int zeroCount = 0;
for (int i = dotIndex + 1; i < str.length; i++) {
if (str[i] == '0') {
zeroCount++;
} else {
break;
}
}
// + 7
final sigEnd = dotIndex + 1 + zeroCount + 7;
final end = sigEnd > str.length ? str.length : sigEnd;
return str.substring(0, end);
} catch (e) {
return '0';
}
}
String formatAmount(String? value) { String formatAmount(String? value) {
return formatDecimal(value, 4); return formatDecimal(value, 4);
} }

View File

@ -179,7 +179,7 @@ class _TradingPageState extends ConsumerState<TradingPage> {
textBaseline: TextBaseline.alphabetic, textBaseline: TextBaseline.alphabetic,
children: [ children: [
AmountText( AmountText(
amount: priceInfo != null ? formatPrice(price) : null, amount: priceInfo != null ? formatPriceFull(price) : null,
isLoading: isLoading, isLoading: isLoading,
style: const TextStyle( style: const TextStyle(
fontSize: 30, fontSize: 30,
@ -219,8 +219,8 @@ class _TradingPageState extends ConsumerState<TradingPage> {
), ),
const SizedBox(width: 4), const SizedBox(width: 4),
DataText( DataText(
// 6 // 10
data: isLoading ? null : '$sign${changePercent.toStringAsFixed(6)}%', data: isLoading ? null : '$sign${changePercent.toStringAsFixed(10)}%',
isLoading: isLoading, isLoading: isLoading,
placeholder: '+--.--%', placeholder: '+--.--%',
style: TextStyle( style: TextStyle(

View File

@ -743,7 +743,7 @@ class _KlineChartWidgetState extends State<KlineChartWidget> {
} }
} }
final sigStart = dotIndex + 1 + zeroCount; final sigStart = dotIndex + 1 + zeroCount;
final sigEnd = math.min(sigStart + 7, str.length); final sigEnd = math.min(sigStart + 4, str.length);
final significant = str.substring(sigStart, sigEnd); final significant = str.substring(sigStart, sigEnd);
return '0.0{$zeroCount}$significant'; return '0.0{$zeroCount}$significant';
} }

View File

@ -567,7 +567,7 @@ class KlinePainter extends CustomPainter {
} }
} }
final sigStart = dotIndex + 1 + zeroCount; final sigStart = dotIndex + 1 + zeroCount;
final sigEnd = math.min(sigStart + 7, str.length); final sigEnd = math.min(sigStart + 4, str.length);
final significant = str.substring(sigStart, sigEnd); final significant = str.substring(sigStart, sigEnd);
return '0.0{$zeroCount}$significant'; return '0.0{$zeroCount}$significant';
} }