fix(mining): correctly parse network-progress API response

The API returns {success: true, data: {...}} but code was accessing
progressResult.currentContributionPerTree directly instead of
progressResult.data.currentContributionPerTree.

This caused:
- totalTreeCount to be 0 (undefined → 0)
- networkTotalContribution to be 0
- No mining distributions happening

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-17 09:46:25 -08:00
parent 11ff3cc9bd
commit 416495a398
1 changed files with 11 additions and 9 deletions

View File

@ -145,24 +145,26 @@ export class NetworkSyncService {
throw new Error(`Failed to fetch network progress: ${progressResponse.status}`); throw new Error(`Failed to fetch network progress: ${progressResponse.status}`);
} }
const progressResult = await progressResponse.json(); const progressResult = await progressResponse.json();
// 从响应中提取 data 字段
const progressData = progressResult.data || progressResult;
// 防御性检查:确保必要字段存在 // 防御性检查:确保必要字段存在
if (!progressResult.currentContributionPerTree) { if (!progressData.currentContributionPerTree) {
this.logger.warn( this.logger.warn(
`Network progress missing currentContributionPerTree, response: ${JSON.stringify(progressResult)}`, `Network progress missing currentContributionPerTree, response: ${JSON.stringify(progressResult)}`,
); );
// 使用默认值继续 // 使用默认值继续
progressResult.currentContributionPerTree = '20'; progressData.currentContributionPerTree = '20';
} }
await this.handleNetworkProgressUpdated({ await this.handleNetworkProgressUpdated({
totalTreeCount: progressResult.totalTreeCount || 0, totalTreeCount: progressData.totalTreeCount || 0,
totalAdoptionOrders: progressResult.totalAdoptionOrders || 0, totalAdoptionOrders: progressData.totalAdoptionOrders || 0,
totalAdoptedUsers: progressResult.totalAdoptedUsers || 0, totalAdoptedUsers: progressData.totalAdoptedUsers || 0,
currentUnit: progressResult.currentUnit || 1, currentUnit: progressData.currentUnit || 1,
currentMultiplier: progressResult.currentMultiplier || '1', currentMultiplier: progressData.currentMultiplier || '1',
currentContributionPerTree: progressResult.currentContributionPerTree, currentContributionPerTree: progressData.currentContributionPerTree,
nextUnitTreeCount: progressResult.nextUnitTreeCount || 100000, nextUnitTreeCount: progressData.nextUnitTreeCount || 100000,
}); });
// 3. 获取最新的 MiningConfig 来返回结果 // 3. 获取最新的 MiningConfig 来返回结果