@@ -14,6 +14,7 @@ import '../../services/cakepay/src/models/order.dart';
1414import '../../themes/stack_colors.dart' ;
1515import '../../utilities/amount/amount.dart' ;
1616import '../../utilities/assets.dart' ;
17+ import '../../utilities/show_loading.dart' ;
1718import '../../utilities/text_styles.dart' ;
1819import '../../utilities/util.dart' ;
1920import '../../wallets/crypto_currency/crypto_currency.dart' ;
@@ -23,25 +24,24 @@ import '../../widgets/custom_buttons/app_bar_icon_button.dart';
2324import '../../widgets/desktop/desktop_dialog_close_button.dart' ;
2425import '../../widgets/desktop/primary_button.dart' ;
2526import '../../widgets/dialogs/s_dialog.dart' ;
26- import '../../widgets/loading_indicator.dart' ;
2727import '../../widgets/qr.dart' ;
2828import '../../widgets/rounded_white_container.dart' ;
29+ import '../wallet_view/transaction_views/transaction_details_view.dart' ;
2930import 'cakepay_send_from_view.dart' ;
3031
3132class CakePayOrderView extends ConsumerStatefulWidget {
32- const CakePayOrderView ({super .key, required this .orderId });
33+ const CakePayOrderView ({super .key, required this .order });
3334
3435 static const String routeName = "/cakePayOrder" ;
3536
36- final String orderId ;
37+ final CakePayOrder order ;
3738
3839 @override
3940 ConsumerState <CakePayOrderView > createState () => _CakePayOrderViewState ();
4041}
4142
4243class _CakePayOrderViewState extends ConsumerState <CakePayOrderView > {
43- CakePayOrder ? _order;
44- bool _loading = true ;
44+ late CakePayOrder _order;
4545 Timer ? _pollTimer;
4646 Timer ? _countdownTimer;
4747 Duration _timeRemaining = Duration .zero;
@@ -50,7 +50,11 @@ class _CakePayOrderViewState extends ConsumerState<CakePayOrderView> {
5050 @override
5151 void initState () {
5252 super .initState ();
53- _loadOrder ();
53+ _order = widget.order;
54+
55+ // TODO: _loadOrder already locked up the ui previously, this just puts a
56+ // nicer loading ui in place
57+ WidgetsBinding .instance.addPostFrameCallback ((_) => _loadOrder ());
5458 _pollTimer = Timer .periodic (
5559 const Duration (seconds: 15 ),
5660 (_) => _loadOrder (),
@@ -74,9 +78,9 @@ class _CakePayOrderViewState extends ConsumerState<CakePayOrderView> {
7478 }
7579
7680 void _updateTimeRemaining () {
77- if (_order? .expirationTime == null ) return ;
81+ if (_order.expirationTime == null ) return ;
7882 final expiresAt = DateTime .fromMillisecondsSinceEpoch (
79- _order! .expirationTime! ,
83+ _order.expirationTime! ,
8084 );
8185 final remaining = expiresAt.difference (DateTime .now ());
8286 if (mounted) {
@@ -107,7 +111,6 @@ class _CakePayOrderViewState extends ConsumerState<CakePayOrderView> {
107111 }) {
108112 final isDesktop = Util .isDesktop;
109113 if (isDesktop) {
110- Navigator .of (context, rootNavigator: true ).pop ();
111114 showDialog <void >(
112115 context: context,
113116 builder: (_) => CakePaySendFromView (
@@ -211,16 +214,26 @@ class _CakePayOrderViewState extends ConsumerState<CakePayOrderView> {
211214 }
212215
213216 Future <void > _loadOrder () async {
214- final resp = await CakePayService .instance.client.getOrder (widget.orderId);
217+ await showLoading (
218+ context: context,
219+ message: "Updating order..." ,
220+ whileFutureAlt: _loadOrderHelper,
221+ rootNavigator: Util .isDesktop,
222+ );
223+ }
224+
225+ Future <void > _loadOrderHelper () async {
226+ final resp = await CakePayService .instance.client.getOrder (
227+ widget.order.orderId,
228+ );
215229 if (mounted) {
216230 setState (() {
217- _loading = false ;
218231 if (! resp.hasError && resp.value != null ) {
219232 _order = resp.value! ;
220- if (_isTerminal (_order! .status)) {
233+ if (_isTerminal (_order.status)) {
221234 _pollTimer? .cancel ();
222235 _countdownTimer? .cancel ();
223- } else if (_order! .expirationTime != null ) {
236+ } else if (_order.expirationTime != null ) {
224237 _startCountdown ();
225238 }
226239 }
@@ -266,42 +279,34 @@ class _CakePayOrderViewState extends ConsumerState<CakePayOrderView> {
266279 return [
267280 // Copyable order ID.
268281 RoundedWhiteContainer (
269- child: GestureDetector (
270- onTap: () {
271- Clipboard .setData (ClipboardData (text: order.orderId));
272- showFloatingFlushBar (
273- type: FlushBarType .info,
274- message: "Order ID copied" ,
275- iconAsset: Assets .svg.copy,
276- context: context,
277- );
278- },
279- child: Row (
280- children: [
281- Expanded (
282- child: Column (
283- crossAxisAlignment: CrossAxisAlignment .start,
284- children: [
285- Text ("Order ID" , style: subtitleStyle),
286- const SizedBox (height: 4 ),
287- Text (
288- order.orderId,
289- style: isDesktop
290- ? STextStyles .desktopTextSmall (context)
291- : STextStyles .titleBold12 (context),
292- ),
293- ],
294- ),
295- ),
296- Icon (
297- Icons .copy,
298- size: 14 ,
299- color: Theme .of (
300- context,
301- ).extension < StackColors > ()! .accentColorBlue,
282+ onPressed: () {
283+ Clipboard .setData (ClipboardData (text: order.orderId));
284+ showFloatingFlushBar (
285+ type: FlushBarType .info,
286+ message: "Order ID copied" ,
287+ iconAsset: Assets .svg.copy,
288+ context: context,
289+ );
290+ },
291+ child: Row (
292+ children: [
293+ Expanded (
294+ child: Column (
295+ crossAxisAlignment: CrossAxisAlignment .start,
296+ children: [
297+ Text ("Order ID" , style: subtitleStyle),
298+ const SizedBox (height: 4 ),
299+ Text (
300+ order.orderId,
301+ style: isDesktop
302+ ? STextStyles .desktopTextSmall (context)
303+ : STextStyles .titleBold12 (context),
304+ ),
305+ ],
302306 ),
303- ],
304- ),
307+ ),
308+ IconCopyButton (data: order.orderId),
309+ ],
305310 ),
306311 ),
307312 // Created-at timestamp.
@@ -324,28 +329,7 @@ class _CakePayOrderViewState extends ConsumerState<CakePayOrderView> {
324329 Widget build (BuildContext context) {
325330 final isDesktop = Util .isDesktop;
326331
327- if (_loading) {
328- return _scaffold (
329- isDesktop: isDesktop,
330- child: const LoadingIndicator (width: 24 , height: 24 ),
331- );
332- }
333-
334- if (_order == null ) {
335- return _scaffold (
336- isDesktop: isDesktop,
337- child: Center (
338- child: Text (
339- "Failed to load order" ,
340- style: isDesktop
341- ? STextStyles .desktopTextSmall (context)
342- : STextStyles .itemSubtitle (context),
343- ),
344- ),
345- );
346- }
347-
348- final order = _order! ;
332+ final order = _order;
349333 final paymentOptions = order.paymentOptions;
350334
351335 final details = < Widget > [
@@ -377,46 +361,38 @@ class _CakePayOrderViewState extends ConsumerState<CakePayOrderView> {
377361 ),
378362 SizedBox (height: isDesktop ? 8 : 6 ),
379363 RoundedWhiteContainer (
380- child: GestureDetector (
381- onTap: () {
382- Clipboard .setData (ClipboardData (text: order.orderId));
383- showFloatingFlushBar (
384- type: FlushBarType .info,
385- message: "Order ID copied" ,
386- iconAsset: Assets .svg.copy,
387- context: context,
388- );
389- },
390- child: Row (
391- mainAxisAlignment: MainAxisAlignment .spaceBetween,
392- children: [
393- Text (
394- "Order ID" ,
395- style: isDesktop
396- ? STextStyles .desktopTextExtraExtraSmall (context)
397- : STextStyles .itemSubtitle12 (context),
398- ),
399- Row (
400- mainAxisSize: MainAxisSize .min,
401- children: [
402- SelectableText (
403- order.orderId,
404- style: isDesktop
405- ? STextStyles .desktopTextSmall (context)
406- : STextStyles .titleBold12 (context),
407- ),
408- const SizedBox (width: 6 ),
409- Icon (
410- Icons .copy,
411- size: 14 ,
412- color: Theme .of (
413- context,
414- ).extension < StackColors > ()! .accentColorBlue,
415- ),
416- ],
417- ),
418- ],
419- ),
364+ onPressed: () {
365+ Clipboard .setData (ClipboardData (text: order.orderId));
366+ showFloatingFlushBar (
367+ type: FlushBarType .info,
368+ message: "Order ID copied" ,
369+ iconAsset: Assets .svg.copy,
370+ context: context,
371+ );
372+ },
373+ child: Row (
374+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
375+ children: [
376+ Text (
377+ "Order ID" ,
378+ style: isDesktop
379+ ? STextStyles .desktopTextExtraExtraSmall (context)
380+ : STextStyles .itemSubtitle12 (context),
381+ ),
382+ Row (
383+ mainAxisSize: MainAxisSize .min,
384+ children: [
385+ SelectableText (
386+ order.orderId,
387+ style: isDesktop
388+ ? STextStyles .desktopTextSmall (context)
389+ : STextStyles .titleBold12 (context),
390+ ),
391+ const SizedBox (width: 6 ),
392+ IconCopyButton (data: order.orderId),
393+ ],
394+ ),
395+ ],
420396 ),
421397 ),
422398 SizedBox (height: isDesktop ? 16 : 12 ),
@@ -833,13 +809,7 @@ class _CakePayOrderViewState extends ConsumerState<CakePayOrderView> {
833809 : STextStyles .itemSubtitle12 (context),
834810 ),
835811 const Spacer (),
836- Icon (
837- Icons .copy,
838- size: 14 ,
839- color: Theme .of (
840- context,
841- ).extension < StackColors > ()! .accentColorBlue,
842- ),
812+ IconCopyButton (data: order.orderId),
843813 const SizedBox (width: 4 ),
844814 Text ("Copy" , style: STextStyles .link2 (context)),
845815 ],
0 commit comments