asset_staking_tab.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. import 'package:flutter/material.dart';
  2. import 'package:go_router/go_router.dart';
  3. import '../../../core/l10n/app_localizations.dart';
  4. import '../../../core/theme/app_colors.dart';
  5. import '../../../core/utils/number_format.dart';
  6. import '../../../data/models/finance/staking_order_item.dart';
  7. import '../../../providers/asset_provider.dart';
  8. import '../../widgets/common/app_refresh_indicator.dart';
  9. /// 锁仓账户 Tab — 对齐 Web AssetsView STAKING Tab
  10. class AssetStakingTab extends StatelessWidget {
  11. const AssetStakingTab({super.key, required this.state, required this.notifier});
  12. final AssetState state;
  13. final AssetNotifier notifier;
  14. @override
  15. Widget build(BuildContext context) {
  16. final cs = Theme.of(context).colorScheme;
  17. final l10n = AppLocalizations.of(context)!;
  18. final obscure = state.obscureBalance;
  19. final locked = double.tryParse(state.stakingOverviewLocked) ?? 0;
  20. final available = double.tryParse(state.stakingOverviewAvailable) ?? 0;
  21. final totalLocked = locked + available;
  22. final lockedDisplay =
  23. obscure ? '******' : formatPrice(locked, decimalPlaces: 2);
  24. final totalDisplay =
  25. obscure ? '******' : formatPrice(totalLocked, decimalPlaces: 2);
  26. return AppRefreshIndicator(
  27. onRefresh: notifier.refreshStakingTab,
  28. child: ListView(
  29. children: [
  30. Padding(
  31. padding: const EdgeInsets.fromLTRB(16, 20, 16, 0),
  32. child: Container(
  33. padding: const EdgeInsets.all(16),
  34. decoration: BoxDecoration(
  35. color: Theme.of(context).brightness == Brightness.dark
  36. ? AppColors.darkBgSecondary
  37. : AppColors.lightBgSecondary,
  38. borderRadius: BorderRadius.circular(12),
  39. border: Theme.of(context).brightness == Brightness.dark
  40. ? null
  41. : Border.all(color: AppColors.lightBorder, width: 0.5),
  42. ),
  43. child: Column(
  44. crossAxisAlignment: CrossAxisAlignment.start,
  45. children: [
  46. Row(
  47. children: [
  48. Text(
  49. l10n.assetsReleaseTotal,
  50. style: TextStyle(
  51. color: cs.onSurface.withAlpha(153),
  52. fontSize: 13,
  53. ),
  54. ),
  55. const SizedBox(width: 6),
  56. GestureDetector(
  57. onTap: notifier.toggleObscure,
  58. child: Icon(
  59. obscure
  60. ? Icons.visibility_off_outlined
  61. : Icons.visibility_outlined,
  62. size: 16,
  63. color: cs.onSurface.withAlpha(153),
  64. ),
  65. ),
  66. ],
  67. ),
  68. const SizedBox(height: 8),
  69. Row(
  70. crossAxisAlignment: CrossAxisAlignment.end,
  71. children: [
  72. Text(
  73. lockedDisplay,
  74. style: TextStyle(
  75. color: cs.onSurface,
  76. fontSize: 32,
  77. fontWeight: FontWeight.w700,
  78. letterSpacing: -0.5,
  79. ),
  80. ),
  81. const SizedBox(width: 6),
  82. Padding(
  83. padding: const EdgeInsets.only(bottom: 5),
  84. child: Text(
  85. l10n.assetsIbitUnit,
  86. style: TextStyle(
  87. color: cs.onSurface.withAlpha(153),
  88. fontSize: 14,
  89. ),
  90. ),
  91. ),
  92. ],
  93. ),
  94. const SizedBox(height: 8),
  95. Row(
  96. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  97. children: [
  98. Text(
  99. l10n.assetsTotalLockedBalance,
  100. style: TextStyle(
  101. color: cs.onSurface.withAlpha(153),
  102. fontSize: 13,
  103. ),
  104. ),
  105. Text(
  106. totalDisplay,
  107. style: TextStyle(
  108. color: cs.onSurface,
  109. fontSize: 13,
  110. fontWeight: FontWeight.w500,
  111. ),
  112. ),
  113. ],
  114. ),
  115. const SizedBox(height: 16),
  116. if (false) //先隐藏划转按钮
  117. Row(
  118. children: [
  119. Expanded(
  120. child: _StakingActionButton(
  121. label: l10n.depositCoin,
  122. primary: true,
  123. onTap: () => context.push('/asset/deposit'),
  124. ),
  125. ),
  126. const SizedBox(width: 8),
  127. Expanded(
  128. child: _StakingActionButton(
  129. label: l10n.withdrawCoin,
  130. onTap: () => context.push('/asset/withdraw'),
  131. ),
  132. ),
  133. const SizedBox(width: 8),
  134. Expanded(
  135. child: _StakingActionButton(
  136. label: l10n.transfer,
  137. onTap: () =>
  138. context.push('/asset/transfer?from=SPOT&to=SWAP'),
  139. ),
  140. ),
  141. ],
  142. ),
  143. ],
  144. ),
  145. ),
  146. ),
  147. Padding(
  148. padding: const EdgeInsets.fromLTRB(16, 20, 16, 8),
  149. child: Row(
  150. children: [
  151. Expanded(
  152. child: Text(
  153. l10n.assetsMyStakingOrders,
  154. style: TextStyle(
  155. color: cs.onSurface,
  156. fontSize: 15,
  157. fontWeight: FontWeight.w600,
  158. ),
  159. ),
  160. ),
  161. _StakingStatusFilter(
  162. value: state.stakingOrderStatusFilter,
  163. loading: state.stakingOrdersLoading,
  164. onChanged: notifier.setStakingOrderStatusFilter,
  165. ),
  166. ],
  167. ),
  168. ),
  169. if (state.stakingOrdersLoading && state.stakingOrders.isEmpty)
  170. Padding(
  171. padding: const EdgeInsets.symmetric(vertical: 32),
  172. child: Center(
  173. child: SizedBox(
  174. width: 24,
  175. height: 24,
  176. child: CircularProgressIndicator(
  177. strokeWidth: 2,
  178. color: cs.onSurface.withAlpha(120),
  179. ),
  180. ),
  181. ),
  182. )
  183. else if (state.stakingOrders.isEmpty)
  184. Padding(
  185. padding: const EdgeInsets.symmetric(vertical: 32),
  186. child: Center(
  187. child: Text(
  188. l10n.noData,
  189. style: TextStyle(
  190. color: cs.onSurface.withAlpha(120),
  191. fontSize: 14,
  192. ),
  193. ),
  194. ),
  195. )
  196. else
  197. ...state.stakingOrders.map(
  198. (order) => _StakingOrderCard(order: order, obscure: obscure),
  199. ),
  200. const SizedBox(height: 32),
  201. ],
  202. ),
  203. );
  204. }
  205. }
  206. class _StakingActionButton extends StatelessWidget {
  207. const _StakingActionButton({
  208. required this.label,
  209. required this.onTap,
  210. this.primary = false,
  211. });
  212. final String label;
  213. final VoidCallback onTap;
  214. final bool primary;
  215. @override
  216. Widget build(BuildContext context) {
  217. final cs = Theme.of(context).colorScheme;
  218. return GestureDetector(
  219. onTap: onTap,
  220. child: Container(
  221. height: 40,
  222. alignment: Alignment.center,
  223. decoration: BoxDecoration(
  224. color: primary ? AppColors.brand : cs.onSurface.withAlpha(20),
  225. borderRadius: BorderRadius.circular(20),
  226. ),
  227. child: Text(
  228. label,
  229. style: TextStyle(
  230. color: primary ? Colors.white : cs.onSurface,
  231. fontSize: 13,
  232. fontWeight: FontWeight.w600,
  233. ),
  234. ),
  235. ),
  236. );
  237. }
  238. }
  239. class _StakingStatusFilter extends StatelessWidget {
  240. const _StakingStatusFilter({
  241. required this.value,
  242. required this.loading,
  243. required this.onChanged,
  244. });
  245. final StakingOrderStatusFilter value;
  246. final bool loading;
  247. final ValueChanged<StakingOrderStatusFilter> onChanged;
  248. @override
  249. Widget build(BuildContext context) {
  250. final l10n = AppLocalizations.of(context)!;
  251. final cs = Theme.of(context).colorScheme;
  252. return Container(
  253. padding: const EdgeInsets.symmetric(horizontal: 10),
  254. decoration: BoxDecoration(
  255. border: Border.all(color: cs.outline.withAlpha(80)),
  256. borderRadius: BorderRadius.circular(8),
  257. ),
  258. child: DropdownButtonHideUnderline(
  259. child: DropdownButton<StakingOrderStatusFilter>(
  260. value: value,
  261. isDense: true,
  262. icon: Icon(Icons.expand_more, size: 18, color: cs.onSurface.withAlpha(153)),
  263. items: [
  264. DropdownMenuItem(
  265. value: StakingOrderStatusFilter.all,
  266. child: Text(l10n.all, style: const TextStyle(fontSize: 13)),
  267. ),
  268. DropdownMenuItem(
  269. value: StakingOrderStatusFilter.subscribing,
  270. child: Text(l10n.assetsSubscribing, style: const TextStyle(fontSize: 13)),
  271. ),
  272. DropdownMenuItem(
  273. value: StakingOrderStatusFilter.releasing,
  274. child: Text(l10n.assetsReleasing, style: const TextStyle(fontSize: 13)),
  275. ),
  276. DropdownMenuItem(
  277. value: StakingOrderStatusFilter.completed,
  278. child: Text(l10n.completed, style: const TextStyle(fontSize: 13)),
  279. ),
  280. ],
  281. onChanged: loading
  282. ? null
  283. : (next) {
  284. if (next != null) {
  285. onChanged(next);
  286. }
  287. },
  288. ),
  289. ),
  290. );
  291. }
  292. }
  293. class _StakingOrderCard extends StatelessWidget {
  294. const _StakingOrderCard({required this.order, required this.obscure});
  295. final StakingOrderItem order;
  296. final bool obscure;
  297. String _fmtAmount(double value) {
  298. if (obscure) {
  299. return '******';
  300. }
  301. return formatPrice(value, decimalPlaces: 2);
  302. }
  303. String _statusLabel(AppLocalizations l10n) {
  304. if (order.status == 0) {
  305. return l10n.assetsSubscribing;
  306. }
  307. if (order.status == 2) {
  308. return l10n.completed;
  309. }
  310. return l10n.assetsReleasing;
  311. }
  312. Color _statusColor() {
  313. if (order.status == 0) {
  314. return AppColors.brand;
  315. }
  316. if (order.status == 2) {
  317. return Colors.grey;
  318. }
  319. return Colors.orange;
  320. }
  321. @override
  322. Widget build(BuildContext context) {
  323. final cs = Theme.of(context).colorScheme;
  324. final l10n = AppLocalizations.of(context)!;
  325. final isDark = Theme.of(context).brightness == Brightness.dark;
  326. final coin = order.coinUnit.isNotEmpty ? order.coinUnit : l10n.assetsIbitUnit.toUpperCase();
  327. final amount = double.tryParse(order.amount) ?? 0;
  328. final released = double.tryParse(order.releasedAmount) ?? 0;
  329. return Container(
  330. margin: const EdgeInsets.fromLTRB(16, 0, 16, 10),
  331. padding: const EdgeInsets.all(16),
  332. decoration: BoxDecoration(
  333. color: isDark ? AppColors.darkBgSecondary : AppColors.lightBgSecondary,
  334. borderRadius: BorderRadius.circular(12),
  335. border: isDark ? null : Border.all(color: AppColors.lightBorder, width: 0.5),
  336. ),
  337. child: Column(
  338. crossAxisAlignment: CrossAxisAlignment.start,
  339. children: [
  340. Text(
  341. '${l10n.assetsStakingOrderNo}: ORD${order.id}',
  342. style: TextStyle(
  343. color: cs.onSurface.withAlpha(153),
  344. fontSize: 12,
  345. ),
  346. ),
  347. const SizedBox(height: 12),
  348. _StakingOrderRow(
  349. label: l10n.assetsStakingTotal,
  350. value: '${_fmtAmount(amount)} $coin',
  351. ),
  352. _StakingOrderRow(
  353. label: l10n.assetsReleased,
  354. value: '${_fmtAmount(released)} $coin',
  355. ),
  356. _StakingOrderRow(
  357. label: l10n.assetsPendingRelease,
  358. value: '${_fmtAmount(order.pendingAmount)} $coin',
  359. ),
  360. _StakingOrderRow(
  361. label: l10n.startTime,
  362. value: order.displayStartTime,
  363. ),
  364. _StakingOrderRow(
  365. label: l10n.statusLabel,
  366. value: _statusLabel(l10n),
  367. valueColor: _statusColor(),
  368. ),
  369. ],
  370. ),
  371. );
  372. }
  373. }
  374. class _StakingOrderRow extends StatelessWidget {
  375. const _StakingOrderRow({
  376. required this.label,
  377. required this.value,
  378. this.valueColor,
  379. });
  380. final String label;
  381. final String value;
  382. final Color? valueColor;
  383. @override
  384. Widget build(BuildContext context) {
  385. final cs = Theme.of(context).colorScheme;
  386. return Padding(
  387. padding: const EdgeInsets.only(bottom: 8),
  388. child: Row(
  389. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  390. children: [
  391. Text(
  392. label,
  393. style: TextStyle(color: cs.onSurface.withAlpha(153), fontSize: 13),
  394. ),
  395. Flexible(
  396. child: Text(
  397. value,
  398. textAlign: TextAlign.right,
  399. style: TextStyle(
  400. color: valueColor ?? cs.onSurface,
  401. fontSize: 13,
  402. fontWeight: FontWeight.w500,
  403. ),
  404. ),
  405. ),
  406. ],
  407. ),
  408. );
  409. }
  410. }