This commit is contained in:
sion
2026-03-28 18:21:33 +08:00
parent 0b43f7b310
commit a5d2ca1b5d
4 changed files with 21 additions and 6 deletions

View File

@@ -78,16 +78,30 @@ class AccountTrade {
});
factory AccountTrade.fromJson(Map<String, dynamic> json) {
// 后端返回 value当前价值前端用 currentValue
final quantityNum =
double.tryParse(json['quantity']?.toString() ?? '0') ?? 0;
final avgPriceNum =
double.tryParse(json['avgPrice']?.toString() ?? '0') ?? 0;
final currentValueNum =
double.tryParse(json['value']?.toString() ?? '0') ??
double.tryParse(json['currentValue']?.toString() ?? '0') ??
0;
final totalCostNum = quantityNum * avgPriceNum;
final profitNum = currentValueNum - totalCostNum;
final double profitRateNum =
totalCostNum > 0 ? (profitNum / totalCostNum) * 100.0 : 0.0;
return AccountTrade(
id: json['id'] as int? ?? 0,
userId: json['userId'] as int? ?? 0,
coinCode: json['coinCode'] as String? ?? '',
quantity: json['quantity']?.toString() ?? '0',
avgPrice: json['avgPrice']?.toString() ?? '0.00',
totalCost: json['totalCost']?.toString() ?? '0.00',
currentValue: json['currentValue']?.toString() ?? '0.00',
profit: json['profit']?.toString() ?? '0.00',
profitRate: (json['profitRate'] as num?)?.toDouble() ?? 0,
totalCost: totalCostNum.toStringAsFixed(2),
currentValue: currentValueNum.toStringAsFixed(2),
profit: profitNum.toStringAsFixed(2),
profitRate: profitRateNum,
updateTime: json['updateTime'] != null
? DateTime.tryParse(json['updateTime'])
: null,

View File

@@ -50,7 +50,8 @@ class AssetService {
);
if (response.success && response.data != null) {
final list = response.data!['list'] as List?;
// 后端返回格式: {"positions": [...]}
final list = response.data!['positions'] as List?;
final accounts = list?.map((e) => AccountTrade.fromJson(e as Map<String, dynamic>)).toList() ?? [];
return ApiResponse.success(accounts, response.message);
}

View File

@@ -265,7 +265,7 @@ class _TransferPageState extends State<TransferPage> {
child: Row(
children: [
Icon(
LucideIcons.alertTriangle,
LucideIcons.triangleAlert,
size: 14,
color: AppColorScheme.warning,
),