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:
parent
2e91686a88
commit
b639b5d499
|
|
@ -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),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue