fix(trading): 流通池改为显示已挖矿产出总量,解决显示为0的问题

前端"流通池"原来读取 circulationPool(交易流通池),因系统尚无卖出交易故为 0。
现改为读取 totalMined(全网已挖矿产出的积分股总量 = 用户已挖 + 系统已挖)。

后端新增 getTotalMinedFromMiningService() 方法,调用 mining-service 的
GET /mining/progress 接口获取 totalDistributed。

注意:价格公式中的 circulationPool 保持不变,仍用交易流通池参与计算。
新增的 totalMined 字段仅用于前端展示。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-02-25 02:54:26 -08:00
parent 27db2a5aa2
commit a5a69645b4
4 changed files with 55 additions and 4 deletions

View File

@ -221,6 +221,38 @@ export class AssetService {
};
}
/**
* mining-service
*
* mining-service GET /mining/progress totalDistributed
* +
*
* "流通池"
* 使circulationPool
*/
private async getTotalMinedFromMiningService(): Promise<Money> {
try {
const response = await fetch(
`${this.miningServiceUrl}/api/v2/mining/progress`,
);
if (!response.ok) {
this.logger.warn(`Failed to fetch mining progress: HTTP ${response.status}`);
return Money.zero();
}
const result = await response.json();
// totalDistributed = 用户已挖总量 + 系统已挖总量
if (result?.totalDistributed) {
return new Money(result.totalDistributed);
}
return Money.zero();
} catch (error) {
this.logger.warn(`Failed to fetch total mined from mining-service: ${error}`);
return Money.zero();
}
}
/**
* "绿积分"
*/
@ -241,27 +273,37 @@ export class AssetService {
/**
*
*
*
* - circulationPool: 价格公式中的流通池/
* - totalMined: 全网已挖矿产出的积分股总量+"流通池"
*
* "流通池" totalMined circulationPool
* circulationPool 0
* "流通池" totalMined
*/
async getMarketOverview(): Promise<{
price: string;
greenPoints: string;
blackHoleAmount: string;
circulationPool: string;
totalMined: string;
effectiveDenominator: string;
burnMultiplier: string;
totalShares: string;
burnTarget: string;
burnProgress: string;
}> {
const [greenPoints, blackHole, circulationPool] = await Promise.all([
const [greenPoints, blackHole, circulationPool, totalMined] = await Promise.all([
this.getGreenPoints(),
this.blackHoleRepository.getBlackHole(),
this.circulationPoolRepository.getPool(),
this.getTotalMinedFromMiningService(),
]);
const blackHoleAmount = blackHole?.totalBurned || Money.zero();
const circulationPoolAmount = circulationPool?.totalShares || Money.zero();
// 计算价格
// 计算价格(使用交易流通池,非已挖总量)
const price = this.calculator.calculatePrice(greenPoints, blackHoleAmount, circulationPoolAmount);
// 计算有效分母
@ -285,6 +327,7 @@ export class AssetService {
greenPoints: greenPoints.toFixed(8),
blackHoleAmount: blackHoleAmount.toFixed(8),
circulationPool: circulationPoolAmount.toFixed(8),
totalMined: totalMined.toFixed(8),
effectiveDenominator: effectiveDenominator.toFixed(8),
burnMultiplier: burnMultiplier.toFixed(18),
totalShares: TradingCalculatorService.TOTAL_SHARES.toFixed(8),

View File

@ -6,6 +6,7 @@ class MarketOverviewModel extends MarketOverview {
required super.greenPoints,
required super.blackHoleAmount,
required super.circulationPool,
required super.totalMined,
required super.effectiveDenominator,
required super.burnMultiplier,
required super.totalShares,
@ -19,6 +20,7 @@ class MarketOverviewModel extends MarketOverview {
greenPoints: json['greenPoints']?.toString() ?? '0',
blackHoleAmount: json['blackHoleAmount']?.toString() ?? '0',
circulationPool: json['circulationPool']?.toString() ?? '0',
totalMined: json['totalMined']?.toString() ?? '0',
effectiveDenominator: json['effectiveDenominator']?.toString() ?? '0',
burnMultiplier: json['burnMultiplier']?.toString() ?? '0',
totalShares: json['totalShares']?.toString() ?? '0',

View File

@ -8,8 +8,10 @@ class MarketOverview extends Equatable {
final String greenPoints;
///
final String blackHoleAmount;
///
///
final String circulationPool;
/// +"流通池"
final String totalMined;
///
final String effectiveDenominator;
///
@ -26,6 +28,7 @@ class MarketOverview extends Equatable {
required this.greenPoints,
required this.blackHoleAmount,
required this.circulationPool,
required this.totalMined,
required this.effectiveDenominator,
required this.burnMultiplier,
required this.totalShares,
@ -39,6 +42,7 @@ class MarketOverview extends Equatable {
greenPoints,
blackHoleAmount,
circulationPool,
totalMined,
effectiveDenominator,
burnMultiplier,
totalShares,

View File

@ -363,9 +363,11 @@ class _TradingPageState extends ConsumerState<TradingPage> {
),
Container(width: 1, height: 24, color: bgGray),
const SizedBox(width: 16),
// totalMined
// circulationPool0
_buildMarketDataItem(
'流通池',
market != null ? formatCompact(market.circulationPool) : null,
market != null ? formatCompact(market.totalMined) : null,
_orange,
isLoading,
),