111
This commit is contained in:
@@ -56,8 +56,8 @@ class _DepositPageState extends State<DepositPage> {
|
||||
ToastUtils.showError('單筆最低充值 1000 USDT');
|
||||
return;
|
||||
}
|
||||
if (n % 1000 != 0) {
|
||||
ToastUtils.showError('充值金額必須為1000的整數倍');
|
||||
if (n > 8000) {
|
||||
ToastUtils.showError('單筆最高充值 8000 USDT');
|
||||
return;
|
||||
}
|
||||
if (_isSubmitting) return;
|
||||
@@ -273,7 +273,7 @@ class _DepositPageState extends State<DepositPage> {
|
||||
size: 13, color: colorScheme.onSurfaceVariant),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
'單筆最低充值 1000 USDT',
|
||||
'每人僅限充值一次,最低 1000 最高 8000 USDT',
|
||||
style: AppTextStyles.bodySmall(context).copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:lucide_icons_flutter/lucide_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../core/network/api_response.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../../../core/theme/app_spacing.dart';
|
||||
import '../../../core/utils/toast_utils.dart';
|
||||
@@ -82,6 +83,28 @@ class _WithdrawPageState extends State<WithdrawPage> {
|
||||
}
|
||||
if (_isSubmitting) return;
|
||||
|
||||
// 45天规则检查
|
||||
try {
|
||||
final checkResult = await context.read<AssetProvider>().withdrawCheck();
|
||||
if (checkResult != null && checkResult['isWithin45Days'] == true) {
|
||||
if (!mounted) return;
|
||||
final days = checkResult['depositDays'] ?? 0;
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('本金未滿45天提示'),
|
||||
content: Text('您的充值本金尚未滿45天(已$days天)。'
|
||||
'本金部分提現可能受到限制,是否繼續?'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消')),
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('確認提現')),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmed != true) return;
|
||||
}
|
||||
} catch (_) {}
|
||||
|
||||
setState(() => _isSubmitting = true);
|
||||
try {
|
||||
final response = await context.read<AssetProvider>().withdraw(
|
||||
|
||||
@@ -6,11 +6,12 @@ import '../../../core/theme/app_color_scheme.dart';
|
||||
import '../../../core/theme/app_theme_extension.dart';
|
||||
import '../../../core/theme/app_spacing.dart';
|
||||
import '../../../data/models/account_models.dart';
|
||||
import '../../../core/network/api_response.dart';
|
||||
import '../../../data/services/asset_service.dart';
|
||||
import '../../../data/services/bonus_service.dart';
|
||||
import '../../../providers/asset_provider.dart';
|
||||
import '../../components/coin_icon.dart';
|
||||
|
||||
/// 賬單頁面 — 代幣盈虧賬單 + 新人福利賬單 + 推廣福利賬單
|
||||
/// 賬單頁面 — 充提記錄 + 新人福利 + 推廣福利
|
||||
class BillsPage extends StatefulWidget {
|
||||
const BillsPage({super.key});
|
||||
|
||||
@@ -22,6 +23,7 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
late TabController _tabController;
|
||||
List<AccountTrade> _holdings = [];
|
||||
List<Map<String, dynamic>> _welfareRecords = [];
|
||||
List<AccountFlow> _flowRecords = [];
|
||||
bool _isLoading = true;
|
||||
|
||||
@override
|
||||
@@ -42,10 +44,16 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
try {
|
||||
final provider = context.read<AssetProvider>();
|
||||
final bonusService = context.read<BonusService>();
|
||||
final assetService = context.read<AssetService>();
|
||||
|
||||
// 並行加載持倉和福利記錄
|
||||
await provider.loadTradeAccount(force: true);
|
||||
final welfareResponse = await bonusService.getWelfareStatus();
|
||||
final results = await Future.wait([
|
||||
provider.loadTradeAccount(force: true),
|
||||
bonusService.getWelfareStatus(),
|
||||
assetService.getFlow(pageNum: 1, pageSize: 50),
|
||||
]);
|
||||
|
||||
final welfareResponse = results[1] as ApiResponse;
|
||||
final flowResponse = results[2] as ApiResponse<Map<String, dynamic>>;
|
||||
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
@@ -53,6 +61,12 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
if (welfareResponse.success && welfareResponse.data != null) {
|
||||
_welfareRecords = _parseWelfareRecords(welfareResponse.data!);
|
||||
}
|
||||
if (flowResponse.success && flowResponse.data != null) {
|
||||
final list = flowResponse.data!['list'] as List<dynamic>? ?? [];
|
||||
_flowRecords = list
|
||||
.map((e) => AccountFlow.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
@@ -69,12 +83,10 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
List<Map<String, dynamic>> _parseWelfareRecords(Map<String, dynamic> data) {
|
||||
final records = <Map<String, dynamic>>[];
|
||||
|
||||
// 新人福利
|
||||
final newUser = data['newUserBonus'] as Map<String, dynamic>?;
|
||||
if (newUser != null) {
|
||||
final claimed = newUser['claimed'] as bool? ?? false;
|
||||
final eligible = newUser['eligible'] as bool? ?? false;
|
||||
// 狀態: 1=已領取, 0=可領取(待領取), 2=不可用(未解鎖)
|
||||
final int status;
|
||||
if (claimed) {
|
||||
status = 1;
|
||||
@@ -92,7 +104,6 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
});
|
||||
}
|
||||
|
||||
// 推廣福利列表
|
||||
final referralRewards = data['referralRewards'] as List<dynamic>? ?? [];
|
||||
for (var r in referralRewards) {
|
||||
final map = r as Map<String, dynamic>;
|
||||
@@ -100,7 +111,6 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
final milestones = map['milestones'] as List<dynamic>? ?? [];
|
||||
final claimableCount = map['claimableCount'] as int? ?? 0;
|
||||
|
||||
// 每個 milestone 生成一條記錄
|
||||
for (var m in milestones) {
|
||||
final ms = m as Map<String, dynamic>;
|
||||
final earned = ms['earned'] as bool? ?? false;
|
||||
@@ -109,11 +119,11 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
|
||||
final int status;
|
||||
if (earned) {
|
||||
status = 1; // 已領取
|
||||
status = 1;
|
||||
} else if (claimable) {
|
||||
status = 0; // 可領取
|
||||
status = 0;
|
||||
} else {
|
||||
status = 2; // 未達標
|
||||
status = 2;
|
||||
}
|
||||
records.add({
|
||||
'type': 'referral',
|
||||
@@ -124,7 +134,6 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
});
|
||||
}
|
||||
|
||||
// 如果沒有 milestone 但有 claimableCount,也生成記錄
|
||||
if (milestones.isEmpty && claimableCount > 0) {
|
||||
records.add({
|
||||
'type': 'referral',
|
||||
@@ -158,13 +167,15 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
centerTitle: true,
|
||||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
isScrollable: true,
|
||||
labelColor: colorScheme.primary,
|
||||
unselectedLabelColor: colorScheme.onSurfaceVariant,
|
||||
indicatorColor: colorScheme.primary,
|
||||
labelStyle: AppTextStyles.headlineMedium(context).copyWith(fontWeight: FontWeight.w600),
|
||||
unselectedLabelStyle: AppTextStyles.headlineMedium(context),
|
||||
tabAlignment: TabAlignment.start,
|
||||
tabs: const [
|
||||
Tab(text: '代幣盈虧'),
|
||||
Tab(text: '充提記錄'),
|
||||
Tab(text: '新人福利'),
|
||||
Tab(text: '推廣福利'),
|
||||
],
|
||||
@@ -175,7 +186,7 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildCoinProfitTab(),
|
||||
_buildFlowTab(),
|
||||
_buildWelfareTab('new_user'),
|
||||
_buildWelfareTab('referral'),
|
||||
],
|
||||
@@ -184,161 +195,261 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// 代幣盈虧賬單
|
||||
// 充提記錄
|
||||
// ============================================
|
||||
Widget _buildCoinProfitTab() {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
|
||||
if (_holdings.isEmpty) {
|
||||
return _buildEmptyState(LucideIcons.wallet, '暫無持倉記錄');
|
||||
Widget _buildFlowTab() {
|
||||
if (_flowRecords.isEmpty) {
|
||||
return _buildEmptyState(LucideIcons.receipt, '暫無流水記錄');
|
||||
}
|
||||
|
||||
// 彙總統計
|
||||
double totalCost = 0;
|
||||
double totalValue = 0;
|
||||
double totalProfit = 0;
|
||||
for (var h in _holdings) {
|
||||
totalCost += double.tryParse(h.totalCost) ?? 0;
|
||||
totalValue += double.tryParse(h.currentValue) ?? 0;
|
||||
totalProfit += double.tryParse(h.profit) ?? 0;
|
||||
}
|
||||
final profitRate = totalCost > 0 ? (totalProfit / totalCost * 100) : 0.0;
|
||||
final isProfit = totalProfit >= 0;
|
||||
final profitColor = isProfit ? context.appColors.up : context.appColors.down;
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: _loadData,
|
||||
child: ListView(
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
children: [
|
||||
// 彙總卡片
|
||||
Container(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
decoration: BoxDecoration(
|
||||
color: _isDark ? AppColorScheme.darkSurfaceContainer : AppColorScheme.lightSurfaceLowest,
|
||||
borderRadius: BorderRadius.circular(AppRadius.xl),
|
||||
border: Border.all(
|
||||
color: _isDark
|
||||
? AppColorScheme.darkOutlineVariant.withValues(alpha: 0.15)
|
||||
: AppColorScheme.lightOutlineVariant.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Text('總盈虧 (USDT)', style: AppTextStyles.bodyMedium(context).copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
)),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
Text(
|
||||
'${isProfit ? '+' : ''}${totalProfit.toStringAsFixed(2)}',
|
||||
style: AppTextStyles.displaySmall(context).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: profitColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildSummaryItem('總成本', totalCost.toStringAsFixed(2)),
|
||||
Container(width: 1, height: 16, color: colorScheme.outlineVariant.withValues(alpha: 0.3)),
|
||||
_buildSummaryItem('總市值', totalValue.toStringAsFixed(2)),
|
||||
Container(width: 1, height: 16, color: colorScheme.outlineVariant.withValues(alpha: 0.3)),
|
||||
_buildSummaryItem('收益率', '${profitRate >= 0 ? '+' : ''}${profitRate.toStringAsFixed(2)}%'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
itemCount: _flowRecords.length,
|
||||
itemBuilder: (context, index) => _buildFlowCard(_flowRecords[index]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
IconData _flowIcon(String flowType) {
|
||||
switch (flowType) {
|
||||
case '1':
|
||||
return LucideIcons.arrowDownToLine;
|
||||
case '2':
|
||||
return LucideIcons.arrowUpFromLine;
|
||||
case '3':
|
||||
case '4':
|
||||
return LucideIcons.repeat;
|
||||
case '5':
|
||||
return LucideIcons.shoppingCart;
|
||||
case '6':
|
||||
return LucideIcons.tag;
|
||||
case '7':
|
||||
return LucideIcons.gift;
|
||||
default:
|
||||
return LucideIcons.circleDot;
|
||||
}
|
||||
}
|
||||
|
||||
Color _flowIconColor(String flowType) {
|
||||
switch (flowType) {
|
||||
case '1':
|
||||
case '3':
|
||||
case '6':
|
||||
return context.appColors.up;
|
||||
case '2':
|
||||
case '4':
|
||||
case '5':
|
||||
return context.appColors.down;
|
||||
case '7':
|
||||
return Theme.of(context).colorScheme.primary;
|
||||
default:
|
||||
return Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
}
|
||||
}
|
||||
|
||||
Color _flowAmountColor(bool isPositive) {
|
||||
return isPositive ? context.appColors.up : context.appColors.down;
|
||||
}
|
||||
|
||||
Widget _buildFlowCard(AccountFlow flow) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final amount = double.tryParse(flow.amount) ?? 0;
|
||||
final isPositive = amount >= 0;
|
||||
final iconColor = _flowIconColor(flow.flowType);
|
||||
final amountColor = _flowAmountColor(isPositive);
|
||||
final balanceBefore = double.tryParse(flow.balanceBefore) ?? 0;
|
||||
final balanceAfter = double.tryParse(flow.balanceAfter) ?? 0;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => _showFlowDetail(flow),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: _isDark ? AppColorScheme.darkSurfaceContainer : AppColorScheme.lightSurfaceLowest,
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
border: Border.all(
|
||||
color: _isDark
|
||||
? AppColorScheme.darkOutlineVariant.withValues(alpha: 0.15)
|
||||
: AppColorScheme.lightOutlineVariant.withValues(alpha: 0.5),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
|
||||
// 各幣種盈虧明細
|
||||
..._holdings.map((h) => _buildCoinProfitCard(h)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSummaryItem(String label, String value) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.md),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(label, style: AppTextStyles.bodySmall(context).copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
)),
|
||||
const SizedBox(height: 2),
|
||||
Text(value, style: AppTextStyles.labelMedium(context).copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCoinProfitCard(AccountTrade h) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final profit = double.tryParse(h.profit) ?? 0;
|
||||
final isProfit = profit >= 0;
|
||||
final profitColor = isProfit ? context.appColors.up : context.appColors.down;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.sm),
|
||||
padding: const EdgeInsets.all(AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: _isDark ? AppColorScheme.darkSurfaceContainer : AppColorScheme.lightSurfaceLowest,
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
border: Border.all(
|
||||
color: _isDark
|
||||
? AppColorScheme.darkOutlineVariant.withValues(alpha: 0.15)
|
||||
: AppColorScheme.lightOutlineVariant.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// 幣名 + 盈虧金額
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: iconColor.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(AppRadius.md),
|
||||
),
|
||||
child: Icon(_flowIcon(flow.flowType), size: 18, color: iconColor),
|
||||
),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
CoinIcon(symbol: h.coinCode, size: 32),
|
||||
const SizedBox(width: AppSpacing.sm),
|
||||
Text(h.coinCode, style: AppTextStyles.headlineMedium(context).copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
)),
|
||||
const SizedBox(width: AppSpacing.xs),
|
||||
Text('x ${double.tryParse(h.quantity)?.toStringAsFixed(4) ?? h.quantity}',
|
||||
style: AppTextStyles.bodySmall(context).copyWith(color: colorScheme.onSurfaceVariant),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
flow.flowTypeText,
|
||||
style: AppTextStyles.headlineMedium(context).copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${isPositive ? '+' : ''}${amount.toStringAsFixed(2)} ${flow.coinCode}',
|
||||
style: AppTextStyles.headlineMedium(context).copyWith(
|
||||
color: amountColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'餘額 ${balanceBefore.toStringAsFixed(2)} → ${balanceAfter.toStringAsFixed(2)}',
|
||||
style: AppTextStyles.bodySmall(context).copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
_formatTime(flow.createTime),
|
||||
style: AppTextStyles.bodySmall(context).copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
'${isProfit ? '+' : ''}${profit.toStringAsFixed(2)} USDT',
|
||||
style: AppTextStyles.headlineMedium(context).copyWith(
|
||||
color: profitColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Icon(
|
||||
LucideIcons.chevronRight,
|
||||
size: 16,
|
||||
color: colorScheme.onSurfaceVariant.withValues(alpha: 0.4),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showFlowDetail(AccountFlow flow) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
final amount = double.tryParse(flow.amount) ?? 0;
|
||||
final isPositive = amount >= 0;
|
||||
final amountColor = _flowAmountColor(isPositive);
|
||||
final iconColor = _flowIconColor(flow.flowType);
|
||||
final balanceBefore = double.tryParse(flow.balanceBefore) ?? 0;
|
||||
final balanceAfter = double.tryParse(flow.balanceAfter) ?? 0;
|
||||
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: _isDark ? AppColorScheme.darkSurfaceContainer : AppColorScheme.lightSurfaceLowest,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(AppRadius.xl)),
|
||||
),
|
||||
builder: (context) => SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(AppSpacing.lg),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Center(
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 4,
|
||||
margin: const EdgeInsets.only(bottom: AppSpacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.outlineVariant.withValues(alpha: 0.4),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: iconColor.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(AppRadius.lg),
|
||||
),
|
||||
child: Icon(_flowIcon(flow.flowType), size: 24, color: iconColor),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
Center(
|
||||
child: Text(
|
||||
'${isPositive ? '+' : ''}${amount.toStringAsFixed(2)} ${flow.coinCode}',
|
||||
style: AppTextStyles.displaySmall(context).copyWith(
|
||||
color: amountColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: Text(
|
||||
flow.flowTypeText,
|
||||
style: AppTextStyles.bodyMedium(context).copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.lg),
|
||||
_buildDetailRow('流水號', flow.flowNo.isNotEmpty ? flow.flowNo : '-'),
|
||||
_buildDetailRow('幣種', flow.coinCode),
|
||||
_buildDetailRow(
|
||||
'變動前餘額',
|
||||
'${balanceBefore.toStringAsFixed(2)} ${flow.coinCode}',
|
||||
),
|
||||
_buildDetailRow(
|
||||
'變動後餘額',
|
||||
'${balanceAfter.toStringAsFixed(2)} ${flow.coinCode}',
|
||||
),
|
||||
if (flow.relatedOrderNo.isNotEmpty)
|
||||
_buildDetailRow('關聯訂單', flow.relatedOrderNo),
|
||||
if (flow.remark.isNotEmpty)
|
||||
_buildDetailRow('備註', flow.remark),
|
||||
_buildDetailRow('時間', _formatTimeFull(flow.createTime)),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
// 明細行
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('均價: ${h.avgPrice}', style: AppTextStyles.bodySmall(context).copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
)),
|
||||
Text('市值: ${h.currentValue} USDT', style: AppTextStyles.bodySmall(context).copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
)),
|
||||
Text(h.formattedProfitRate, style: AppTextStyles.bodySmall(context).copyWith(
|
||||
color: profitColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailRow(String label, String value) {
|
||||
final colorScheme = Theme.of(context).colorScheme;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: AppSpacing.xs),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: AppTextStyles.bodyMedium(context).copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: Text(
|
||||
value,
|
||||
style: AppTextStyles.bodyMedium(context).copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -375,7 +486,6 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
final amount = double.tryParse(record['amount']?.toString() ?? '0') ?? 0;
|
||||
final status = record['status'] as int? ?? 0;
|
||||
|
||||
// status: 0=待領取, 1=已領取, 2=未達標
|
||||
String statusText;
|
||||
Color statusColor;
|
||||
switch (status) {
|
||||
@@ -477,9 +587,18 @@ class _BillsPageState extends State<BillsPage> with SingleTickerProviderStateMix
|
||||
String _formatTime(dynamic time) {
|
||||
if (time == null) return '-';
|
||||
if (time is DateTime) {
|
||||
return '${time.year}-${time.month.toString().padLeft(2, '0')}-${time.day.toString().padLeft(2, '0')} '
|
||||
return '${time.month.toString().padLeft(2, '0')}-${time.day.toString().padLeft(2, '0')} '
|
||||
'${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
return time.toString();
|
||||
}
|
||||
|
||||
String _formatTimeFull(dynamic time) {
|
||||
if (time == null) return '-';
|
||||
if (time is DateTime) {
|
||||
return '${time.year}-${time.month.toString().padLeft(2, '0')}-${time.day.toString().padLeft(2, '0')} '
|
||||
'${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}:${time.second.toString().padLeft(2, '0')}';
|
||||
}
|
||||
return time.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ class _WelfareCenterPageState extends State<WelfareCenterPage> {
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'+100 USDT',
|
||||
'+${newUserBonus?['amount'] ?? '100'} USDT',
|
||||
style: AppTextStyles.displayLarge(context).copyWith(
|
||||
fontWeight: FontWeight.w800,
|
||||
color: claimed ? Theme.of(context).colorScheme.onSurfaceVariant : profitGreen,
|
||||
@@ -809,7 +809,7 @@ class _WelfareCenterPageState extends State<WelfareCenterPage> {
|
||||
style: AppTextStyles.headlineSmall(context),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildRuleItem('新用戶首次充值完成後可領取 100 USDT(一次性)'),
|
||||
_buildRuleItem('充值金額每滿 1,000 USDT 獎勵 100 USDT(如充值 3,000 領取 300)'),
|
||||
_buildRuleItem('邀請好友累計充值每滿 1,000 USDT,獎勵 100 USDT(最多8次/人)'),
|
||||
_buildRuleItem('好友推廣的用戶充值每滿 1,000 USDT,額外獎勵 50 USDT(最多8次/人)'),
|
||||
_buildRuleItem('獎勵直接發放至資金賬戶'),
|
||||
@@ -843,7 +843,7 @@ class _WelfareCenterPageState extends State<WelfareCenterPage> {
|
||||
if (response.success) {
|
||||
context.read<AssetProvider>().refreshAll(force: true);
|
||||
context.read<AppEventBus>().fire(AppEventType.assetChanged);
|
||||
ToastUtils.showSuccess('領取成功!100 USDT 已到賬');
|
||||
ToastUtils.showSuccess('領取成功!獎勵已到賬');
|
||||
_loadData();
|
||||
} else {
|
||||
ToastUtils.showError(response.message ?? '領取失敗');
|
||||
@@ -865,7 +865,7 @@ class _WelfareCenterPageState extends State<WelfareCenterPage> {
|
||||
if (response.success) {
|
||||
context.read<AssetProvider>().refreshAll(force: true);
|
||||
context.read<AppEventBus>().fire(AppEventType.assetChanged);
|
||||
ToastUtils.showSuccess('領取成功!100 USDT 已到賬');
|
||||
ToastUtils.showSuccess('領取成功!獎勵已到賬');
|
||||
_loadData();
|
||||
} else {
|
||||
ToastUtils.showError(response.message ?? '領取失敗');
|
||||
|
||||
@@ -117,8 +117,7 @@ class PriceCard extends StatelessWidget {
|
||||
String _fmt(double? v) {
|
||||
if (v == null) return '--';
|
||||
if (v >= 1000) return v.toStringAsFixed(2);
|
||||
if (v >= 1) return v.toStringAsFixed(4);
|
||||
return v.toStringAsFixed(6);
|
||||
return v.toStringAsFixed(4);
|
||||
}
|
||||
|
||||
String _fmtVol(double? v) {
|
||||
|
||||
@@ -55,6 +55,15 @@ class SplitTradeForm extends StatefulWidget {
|
||||
class _SplitTradeFormState extends State<SplitTradeForm>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
double _currentPercent = 0.0;
|
||||
|
||||
String _fmtAvailable(String raw) {
|
||||
final v = double.tryParse(raw);
|
||||
if (v == null || v == 0) return '0';
|
||||
if (v >= 1) return v.toStringAsFixed(2);
|
||||
if (v >= 0.01) return v.toStringAsFixed(4);
|
||||
return v.toStringAsFixed(6);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -256,11 +265,21 @@ class _SplitTradeFormState extends State<SplitTradeForm>
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
|
||||
// 可用余额
|
||||
Text(
|
||||
'可用: $available ${_isBuy ? 'USDT' : (widget.coin?.code ?? '')}',
|
||||
style: AppTextStyles.bodySmall(context)
|
||||
.copyWith(color: context.colors.onSurfaceVariant),
|
||||
// 可用余额 + 手续费
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'可用: ${_fmtAvailable(available)} ${_isBuy ? 'USDT' : (widget.coin?.code ?? '')}',
|
||||
style: AppTextStyles.bodySmall(context)
|
||||
.copyWith(color: context.colors.onSurfaceVariant),
|
||||
),
|
||||
Text(
|
||||
'手续费: 0%',
|
||||
style: AppTextStyles.bodySmall(context)
|
||||
.copyWith(color: context.colors.onSurfaceVariant),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
|
||||
@@ -276,7 +295,29 @@ class _SplitTradeFormState extends State<SplitTradeForm>
|
||||
_pctBtn(context, '100%', 1.0, onFillPercent),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppSpacing.sm),
|
||||
const SizedBox(height: 2),
|
||||
|
||||
// 滑块选择仓位
|
||||
SliderTheme(
|
||||
data: SliderThemeData(
|
||||
trackHeight: 3,
|
||||
thumbShape: const RoundSliderThumbShape(enabledThumbRadius: 6),
|
||||
overlayShape: const RoundSliderOverlayShape(overlayRadius: 12),
|
||||
activeTrackColor: accentColor,
|
||||
inactiveTrackColor: context.colors.surfaceContainerHighest,
|
||||
thumbColor: accentColor,
|
||||
),
|
||||
child: Slider(
|
||||
value: _currentPercent.clamp(0.0, 1.0),
|
||||
onChanged: (v) {
|
||||
setState(() => _currentPercent = v);
|
||||
onFillPercent(v);
|
||||
},
|
||||
min: 0.0,
|
||||
max: 1.0,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppSpacing.xs),
|
||||
|
||||
// 提交按钮
|
||||
SizedBox(
|
||||
@@ -296,7 +337,7 @@ class _SplitTradeFormState extends State<SplitTradeForm>
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: Text(
|
||||
'${_isBuy ? '买入' : '卖出'} ${widget.coin?.code ?? ''}',
|
||||
'${_isBuy ? '買入' : '賣出'} ${widget.coin?.code ?? ''}',
|
||||
style: AppTextStyles.labelLarge(context)
|
||||
.copyWith(color: Colors.white, fontWeight: FontWeight.w700),
|
||||
),
|
||||
@@ -308,20 +349,26 @@ class _SplitTradeFormState extends State<SplitTradeForm>
|
||||
}
|
||||
|
||||
Widget _pctBtn(BuildContext context, String label, double pct, ValueChanged<double> onTap) {
|
||||
final isActive = (_currentPercent - pct).abs() < 0.01;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => onTap(pct),
|
||||
onTap: () {
|
||||
setState(() => _currentPercent = pct);
|
||||
onTap(pct);
|
||||
},
|
||||
child: Container(
|
||||
height: 28,
|
||||
height: 26,
|
||||
decoration: BoxDecoration(
|
||||
color: context.colors.surfaceContainerHighest.withValues(alpha: 0.4),
|
||||
color: isActive
|
||||
? context.colors.primary.withValues(alpha: 0.15)
|
||||
: context.colors.surfaceContainerHighest.withValues(alpha: 0.4),
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(label,
|
||||
style: AppTextStyles.bodySmall(context).copyWith(
|
||||
color: context.colors.onSurfaceVariant,
|
||||
fontWeight: FontWeight.w500)),
|
||||
color: isActive ? context.colors.primary : context.colors.onSurfaceVariant,
|
||||
fontWeight: isActive ? FontWeight.w600 : FontWeight.w500)),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -37,6 +37,7 @@ class _TradePageState extends State<TradePage>
|
||||
bool _isSellSubmitting = false;
|
||||
int _orderType = 1;
|
||||
double _realtimePrice = 0;
|
||||
double _currentBuyPercent = 0.0;
|
||||
|
||||
final _buyPriceController = TextEditingController();
|
||||
final _buyQuantityController = TextEditingController();
|
||||
@@ -695,10 +696,9 @@ class _TradePageState extends State<TradePage>
|
||||
if (_selectedCoin == null) return false;
|
||||
final qty = double.tryParse(_buyQuantityController.text) ?? 0;
|
||||
if (qty <= 0) return false;
|
||||
final price = double.tryParse(_buyPriceController.text) ?? 0;
|
||||
final amount = price * qty;
|
||||
// 只要有余额就可以买,后端会微调价格确保成交
|
||||
final available = double.tryParse(_availableUsdt) ?? 0;
|
||||
return amount <= available;
|
||||
return available > 0;
|
||||
}
|
||||
|
||||
bool _canSell() {
|
||||
@@ -710,13 +710,12 @@ class _TradePageState extends State<TradePage>
|
||||
}
|
||||
|
||||
void _buyFillPercent(double pct) {
|
||||
_currentBuyPercent = pct;
|
||||
final price = _orderType == 1 ? _realtimePrice : (double.tryParse(_buyPriceController.text) ?? 0);
|
||||
final available = double.tryParse(_availableUsdt) ?? 0;
|
||||
if (price <= 0) return;
|
||||
// 100%时留极小余量防精度误差
|
||||
final safePct = pct >= 1.0 ? 0.9999 : pct;
|
||||
final qty = (available / price) * safePct;
|
||||
_buyQuantityController.text = qty < 0.0001 ? '' : ((qty * 10000).truncateToDouble() / 10000).toStringAsFixed(4);
|
||||
final qty = (available / price * pct * 10000).truncateToDouble() / 10000;
|
||||
_buyQuantityController.text = qty < 0.0001 ? '' : qty.toStringAsFixed(4);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@@ -732,11 +731,24 @@ class _TradePageState extends State<TradePage>
|
||||
final priceController = isBuy ? _buyPriceController : _sellPriceController;
|
||||
final qtyController = isBuy ? _buyQuantityController : _sellQuantityController;
|
||||
|
||||
final price = priceController.text;
|
||||
String price = priceController.text;
|
||||
final quantity = qtyController.text;
|
||||
final coinCode = _selectedCoin!.code;
|
||||
final typeLabel = _orderType == 1 ? '市价单' : '限价单';
|
||||
|
||||
// 买入时:按所选仓位百分比重算价格,确保 价格×数量=仓位金额
|
||||
if (isBuy && _currentBuyPercent > 0) {
|
||||
final available = double.tryParse(_availableUsdt) ?? 0;
|
||||
final qty = double.tryParse(quantity) ?? 0;
|
||||
if (qty > 0 && available > 0) {
|
||||
final positionAmount = available * _currentBuyPercent;
|
||||
final adjustedPrice = positionAmount / qty;
|
||||
price = adjustedPrice.toStringAsFixed(8);
|
||||
}
|
||||
}
|
||||
|
||||
final displayAmount = ((double.tryParse(price) ?? 0) * (double.tryParse(quantity) ?? 0)).toStringAsFixed(2);
|
||||
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => ConfirmDialog(
|
||||
@@ -744,7 +756,7 @@ class _TradePageState extends State<TradePage>
|
||||
coinCode: coinCode,
|
||||
price: price,
|
||||
quantity: quantity,
|
||||
amount: ((double.tryParse(price) ?? 0) * (double.tryParse(quantity) ?? 0)).toStringAsFixed(2),
|
||||
amount: displayAmount,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -757,20 +769,39 @@ class _TradePageState extends State<TradePage>
|
||||
|
||||
try {
|
||||
final tradeService = context.read<TradeService>();
|
||||
final response = isBuy
|
||||
var response = isBuy
|
||||
? await tradeService.buy(coinCode: coinCode, price: price, quantity: quantity, orderType: _orderType)
|
||||
: await tradeService.sell(coinCode: coinCode, price: price, quantity: quantity, orderType: _orderType);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
// 买入次数用完 → 弹出交易码输入框重试
|
||||
if (isBuy && !response.success &&
|
||||
(response.message?.contains('次數') == true || response.message?.contains('交易碼') == true)) {
|
||||
final code = await _showTradeCodeDialog(response.message ?? '請輸入交易碼');
|
||||
if (code != null && code.isNotEmpty && mounted) {
|
||||
response = await tradeService.buy(
|
||||
coinCode: coinCode, price: price, quantity: quantity,
|
||||
orderType: _orderType, tradeCode: code,
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (response.success) {
|
||||
qtyController.clear();
|
||||
context.read<AssetProvider>().refreshAll(force: true);
|
||||
context.read<AppEventBus>().fire(AppEventType.assetChanged);
|
||||
_loadPendingOrders();
|
||||
final msg = _orderType == 2
|
||||
? '$typeLabel委托成功: $quantity $coinCode @ $price USDT'
|
||||
: '$typeLabel: $quantity $coinCode @ $price USDT';
|
||||
final resultAmount = response.data?['amount'];
|
||||
final resultQty = response.data?['quantity'];
|
||||
final resultPrice = response.data?['price'];
|
||||
final msg = isBuy
|
||||
? '買入 ${resultQty ?? quantity} $coinCode\n成交金額: ${resultAmount != null ? (double.tryParse(resultAmount.toString())?.toStringAsFixed(2) ?? displayAmount) : displayAmount} USDT'
|
||||
: '賣出 ${resultQty ?? quantity} $coinCode\n成交金額: ${resultAmount != null ? (double.tryParse(resultAmount.toString())?.toStringAsFixed(2) ?? displayAmount) : displayAmount} USDT';
|
||||
_showResultDialog(true, isBuy ? '買入成功' : '賣出成功', msg);
|
||||
} else {
|
||||
_showResultDialog(false, '交易失敗', response.message ?? '請稍後重試');
|
||||
@@ -787,6 +818,51 @@ class _TradePageState extends State<TradePage>
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> _showTradeCodeDialog(String hint) {
|
||||
final controller = TextEditingController();
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('需要交易碼'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(hint, style: AppTextStyles.bodySmall(ctx)),
|
||||
const SizedBox(height: AppSpacing.md),
|
||||
TextField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
textCapitalization: TextCapitalization.characters,
|
||||
style: AppTextStyles.headlineMedium(ctx),
|
||||
keyboardType: TextInputType.text,
|
||||
decoration: InputDecoration(
|
||||
hintText: '請輸入交易碼',
|
||||
filled: true,
|
||||
fillColor: ctx.colors.surfaceContainerHighest.withValues(alpha: 0.3),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppRadius.sm),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(null),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(controller.text.trim()),
|
||||
child: const Text('確認'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showResultDialog(bool success, String title, String message) {
|
||||
showDialog(
|
||||
context: context,
|
||||
|
||||
Reference in New Issue
Block a user