111
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ class _TransferPageState extends State<TransferPage> {
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
LucideIcons.alertTriangle,
|
||||
LucideIcons.triangleAlert,
|
||||
size: 14,
|
||||
color: AppColorScheme.warning,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user