111
This commit is contained in:
Binary file not shown.
@@ -78,16 +78,30 @@ class AccountTrade {
|
|||||||
});
|
});
|
||||||
|
|
||||||
factory AccountTrade.fromJson(Map<String, dynamic> json) {
|
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(
|
return AccountTrade(
|
||||||
id: json['id'] as int? ?? 0,
|
id: json['id'] as int? ?? 0,
|
||||||
userId: json['userId'] as int? ?? 0,
|
userId: json['userId'] as int? ?? 0,
|
||||||
coinCode: json['coinCode'] as String? ?? '',
|
coinCode: json['coinCode'] as String? ?? '',
|
||||||
quantity: json['quantity']?.toString() ?? '0',
|
quantity: json['quantity']?.toString() ?? '0',
|
||||||
avgPrice: json['avgPrice']?.toString() ?? '0.00',
|
avgPrice: json['avgPrice']?.toString() ?? '0.00',
|
||||||
totalCost: json['totalCost']?.toString() ?? '0.00',
|
totalCost: totalCostNum.toStringAsFixed(2),
|
||||||
currentValue: json['currentValue']?.toString() ?? '0.00',
|
currentValue: currentValueNum.toStringAsFixed(2),
|
||||||
profit: json['profit']?.toString() ?? '0.00',
|
profit: profitNum.toStringAsFixed(2),
|
||||||
profitRate: (json['profitRate'] as num?)?.toDouble() ?? 0,
|
profitRate: profitRateNum,
|
||||||
updateTime: json['updateTime'] != null
|
updateTime: json['updateTime'] != null
|
||||||
? DateTime.tryParse(json['updateTime'])
|
? DateTime.tryParse(json['updateTime'])
|
||||||
: null,
|
: null,
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ class AssetService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (response.success && response.data != null) {
|
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() ?? [];
|
final accounts = list?.map((e) => AccountTrade.fromJson(e as Map<String, dynamic>)).toList() ?? [];
|
||||||
return ApiResponse.success(accounts, response.message);
|
return ApiResponse.success(accounts, response.message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ class _TransferPageState extends State<TransferPage> {
|
|||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
LucideIcons.alertTriangle,
|
LucideIcons.triangleAlert,
|
||||||
size: 14,
|
size: 14,
|
||||||
color: AppColorScheme.warning,
|
color: AppColorScheme.warning,
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user