import '../../core/constants/api_endpoints.dart'; import '../../core/network/api_response.dart'; import '../../core/network/dio_client.dart'; import '../models/order_models.dart'; /// 充提服务 class FundService { final DioClient _client; FundService(this._client); /// 获取默认钱包地址 Future> getDefaultWallet() async { final response = await _client.get>( ApiEndpoints.defaultWallet, ); if (response.success && response.data != null) { return ApiResponse.success( ColdWallet.fromJson(response.data!), response.message, ); } return ApiResponse.fail(response.message ?? '获取钱包地址失败'); } /// 申请充值 /// 返回包含 orderNo, amount, status, walletAddress, walletNetwork 的信息 Future>> deposit({ required String amount, String? remark, }) async { return _client.post>( ApiEndpoints.deposit, data: { 'amount': amount, if (remark != null) 'remark': remark, }, ); } /// 用户确认已打款 Future> confirmPay(String orderNo) async { return _client.post( ApiEndpoints.confirmPay, data: {'orderNo': orderNo}, ); } /// 申请提现 Future>> withdraw({ required String amount, required String withdrawAddress, String? withdrawContact, String? remark, }) async { return _client.post>( ApiEndpoints.withdraw, data: { 'amount': amount, 'withdrawAddress': withdrawAddress, if (withdrawContact != null) 'withdrawContact': withdrawContact, if (remark != null) 'remark': remark, }, ); } /// 取消订单 Future> cancelOrder(String orderNo) async { return _client.post( ApiEndpoints.cancelOrder, data: {'orderNo': orderNo}, ); } /// 获取充提记录 Future>> getOrders({ int? type, int pageNum = 1, int pageSize = 20, }) async { final params = { 'pageNum': pageNum, 'pageSize': pageSize, }; if (type != null) params['type'] = type; return _client.get>( ApiEndpoints.fundOrders, queryParameters: params, ); } /// 解析充提记录列表 List parseOrderList(List? list) { if (list == null) return []; return list.map((e) => OrderFund.fromJson(e as Map)).toList(); } }