feat(trading): enable one-click settlement button

开放兑换页面的"一键结算"功能:

- 有可结算收益时:显示"一键结算",按钮可点击(金色)
- 无可结算收益时:显示"暂无可结算收益",按钮禁用(半透明)
- 结算中:显示加载动画,防止重复点击
- 使用 rewardService.settleToBalance() API 执行结算
- 结算成功后自动刷新页面数据

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-03 07:38:57 -08:00
parent dfdd8ed65a
commit d5fee8d8c6
1 changed files with 47 additions and 35 deletions

View File

@ -93,7 +93,7 @@ class _TradingPageState extends ConsumerState<TradingPage> {
builder: (context) => AlertDialog( builder: (context) => AlertDialog(
title: const Text('确认结算'), title: const Text('确认结算'),
content: Text( content: Text(
'确定将 ${_formatNumber(_settleableAmount)} 绿积分 结算${_getCurrencyName(_selectedCurrency)} 吗?', '确定将 ${_formatNumber(_settleableAmount)} 绿积分 结算到钱包余额吗?',
), ),
actions: [ actions: [
TextButton( TextButton(
@ -122,26 +122,27 @@ class _TradingPageState extends ConsumerState<TradingPage> {
try { try {
debugPrint('[TradingPage] 开始结算...'); debugPrint('[TradingPage] 开始结算...');
debugPrint('[TradingPage] 金额: $_settleableAmount USDT'); debugPrint('[TradingPage] 金额: $_settleableAmount 绿积分');
debugPrint('[TradingPage] 币种: ${_getCurrencyName(_selectedCurrency)}');
final walletService = ref.read(walletServiceProvider); // 使 reward-service settleToBalance API
final orderId = await walletService.settleRewards( final rewardService = ref.read(rewardServiceProvider);
usdtAmount: _settleableAmount, final result = await rewardService.settleToBalance();
settleCurrency: _getCurrencyName(_selectedCurrency),
);
debugPrint('[TradingPage] 结算成功: orderId=$orderId'); if (result.success) {
debugPrint('[TradingPage] 结算成功: settlementId=${result.settlementId}, amount=${result.settledUsdtAmount}');
if (mounted) { if (mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
const SnackBar( SnackBar(
content: Text('结算成功'), content: Text('结算成功,${result.settledUsdtAmount.toStringAsFixed(2)} 绿积分已转入钱包余额'),
backgroundColor: Color(0xFFD4AF37), backgroundColor: const Color(0xFFD4AF37),
), ),
); );
// //
_loadWalletData(); _loadWalletData();
}
} else {
throw Exception(result.error ?? '结算失败');
} }
} catch (e) { } catch (e) {
debugPrint('[TradingPage] 结算失败: $e'); debugPrint('[TradingPage] 结算失败: $e');
@ -371,33 +372,44 @@ class _TradingPageState extends ConsumerState<TradingPage> {
} }
/// ///
///
Widget _buildSettlementButton() { Widget _buildSettlementButton() {
// //
const bool canSettle = false; final bool canSettle = _settleableAmount > 0 && !_isSettling;
return Padding( return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16), padding: const EdgeInsets.symmetric(horizontal: 16),
child: GestureDetector( child: GestureDetector(
onTap: null, // onTap: canSettle ? _onSettlement : null,
child: Container( child: Container(
width: double.infinity, width: double.infinity,
height: 56, height: 56,
decoration: BoxDecoration( decoration: BoxDecoration(
color: const Color(0x80D4AF37), // color: canSettle
? const Color(0xFFD4AF37) //
: const Color(0x80D4AF37), //
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
), ),
child: const Center( child: Center(
child: Text( child: _isSettling
'一键结算(暂未开放)', ? const SizedBox(
style: TextStyle( width: 24,
fontSize: 16, height: 24,
fontFamily: 'Inter', child: CircularProgressIndicator(
fontWeight: FontWeight.w700, strokeWidth: 2,
height: 1.5, color: Colors.white,
letterSpacing: 0.24, ),
color: Colors.white, )
), : Text(
), canSettle ? '一键结算' : '暂无可结算收益',
style: const TextStyle(
fontSize: 16,
fontFamily: 'Inter',
fontWeight: FontWeight.w700,
height: 1.5,
letterSpacing: 0.24,
color: Colors.white,
),
),
), ),
), ),
), ),