dev
dart 182 lines 6.38 KB
Raw
1 import 'package:cake_wallet/entities/bridge_transfer.dart';
2 import 'package:cake_wallet/evm/evm.dart';
3 import 'package:cake_wallet/src/widgets/cake_image_widget.dart';
4 import 'package:cake_wallet/themes/core/custom_theme_colors.dart';
5 import 'package:flutter/material.dart';
6 import 'package:intl/intl.dart';
7
8 class TransferHistoryRow extends StatelessWidget {
9 const TransferHistoryRow({
10 required this.transfer,
11 required this.onTap,
12 super.key,
13 });
14
15 final BridgeTransfer transfer;
16 final VoidCallback onTap;
17
18 String _statusLabel(String status) {
19 switch (status) {
20 case 'submitted':
21 return "Submitted";
22 case 'confirming':
23 return "Confirming on source";
24 case 'initiated':
25 return "Bridge initiated";
26 case 'completed':
27 return "Completed";
28 case 'failed':
29 return "Failed";
30 default:
31 return status;
32 }
33 }
34
35 Color _statusColor(BuildContext context, String status) {
36 switch (status) {
37 case 'completed':
38 return CustomThemeColors.syncGreen;
39 case 'failed':
40 return Theme.of(context).colorScheme.error;
41 case 'submitted':
42 case 'confirming':
43 case 'initiated':
44 default:
45 return CustomThemeColors.syncYellow;
46 }
47 }
48
49 @override
50 Widget build(BuildContext context) {
51 final sourceChainName = evm?.getChainInfoByChainId(transfer.sourceChainId)?.name;
52 final destChainName = evm?.getChainInfoByChainId(transfer.destinationChainId)?.name;
53 final formattedDate = DateFormat('HH:mm').format(transfer.createdAt);
54 final statusText = _statusLabel(transfer.status);
55
56 return InkWell(
57 onTap: onTap,
58 child: Container(
59 padding: const EdgeInsets.symmetric(horizontal: 16.0),
60 margin: const EdgeInsets.only(bottom: 16),
61 width: double.infinity,
62 height: 72,
63 decoration: BoxDecoration(
64 gradient: LinearGradient(
65 colors: [
66 Theme.of(context).colorScheme.surfaceContainerHigh,
67 Theme.of(context).colorScheme.surfaceContainer,
68 ],
69 begin: Alignment.topCenter,
70 end: Alignment.bottomCenter,
71 ),
72 borderRadius: BorderRadius.all(Radius.circular(20)),
73 border: Border.all(
74 color: Theme.of(context).colorScheme.surfaceContainerHighest,
75 width: 1,
76 ),
77 ),
78 child: Row(
79 mainAxisSize: MainAxisSize.max,
80 crossAxisAlignment: CrossAxisAlignment.center,
81 children: [
82 Container(
83 height: 42,
84 width: 42,
85 decoration: BoxDecoration(
86 borderRadius: BorderRadius.circular(16),
87 ),
88 child: Stack(
89 children: [
90 CakeImageWidget(
91 imageUrl:
92 'assets/new-ui/crypto_full_icons/${sourceChainName?.toLowerCase()}.svg',
93 width: 28,
94 height: 28,
95 ),
96 Positioned(
97 top: 14,
98 left: 12,
99 child: CakeImageWidget(
100 imageUrl:
101 'assets/new-ui/crypto_full_icons/${destChainName?.toLowerCase()}.svg',
102 width: 28,
103 height: 28,
104 ),
105 ),
106 ],
107 ),
108 ),
109 const SizedBox(width: 8),
110 Expanded(
111 child: Column(
112 mainAxisSize: MainAxisSize.min,
113 crossAxisAlignment: CrossAxisAlignment.start,
114 children: [
115 Row(
116 mainAxisAlignment: MainAxisAlignment.spaceBetween,
117 children: <Widget>[
118 Text(
119 '$sourceChainName$destChainName',
120 style: Theme.of(context).textTheme.bodyLarge?.copyWith(
121 fontSize: 16,
122 fontWeight: FontWeight.w500,
123 color: Theme.of(context).colorScheme.onSurface,
124 ),
125 ),
126 Text(
127 '${transfer.amount} ${transfer.tokenSymbol}',
128 style: Theme.of(context).textTheme.bodyLarge?.copyWith(
129 fontSize: 16,
130 fontWeight: FontWeight.w500,
131 color: Theme.of(context).colorScheme.onSurface,
132 ),
133 ),
134 ],
135 ),
136 const SizedBox(height: 8),
137 Row(
138 mainAxisAlignment: MainAxisAlignment.spaceBetween,
139 children: <Widget>[
140 Row(
141 children: [
142 Container(
143 height: 8,
144 width: 8,
145 decoration: BoxDecoration(
146 color: _statusColor(context, transfer.status),
147 borderRadius: BorderRadius.circular(12),
148 border: Border.all(
149 color: Theme.of(context).colorScheme.surface,
150 width: 1.5,
151 ),
152 ),
153 ),
154 SizedBox(width: 8),
155 Text(
156 statusText,
157 style: Theme.of(context).textTheme.bodyMedium?.copyWith(
158 fontWeight: FontWeight.w500,
159 color: Theme.of(context).colorScheme.onSurfaceVariant,
160 ),
161 overflow: TextOverflow.ellipsis,
162 ),
163 ],
164 ),
165 Text(
166 formattedDate,
167 style: Theme.of(context).textTheme.bodyMedium?.copyWith(
168 fontWeight: FontWeight.w500,
169 color: Theme.of(context).colorScheme.onSurfaceVariant,
170 ),
171 ),
172 ],
173 ),
174 ],
175 ),
176 ),
177 ],
178 ),
179 ),
180 );
181 }
182 }