CAKE-306 | reworked buy_list_item.dart and pre_order_page.dart; added clear button to pre_order_page.dart; fixed order_row.dart and order_details_view_model.dart; added MoonPay statuses to trade_state.dart

OleksandrSobol committed Apr 14, 2021 at 21:23 UTC 697fc7f5a59132a677c9af6b681a728a2640592e
10 files changed +148 -92
assets/images/moonpay-icon.png
Binary files /dev/null and b/assets/images/moonpay-icon.png differ
lib/buy/get_buy_provider_icon.dart
+2 -3
@@ -5,15 +5,14 @@ Image getBuyProviderIcon(BuyProviderDescription providerDescription) {
5 final _wyreIcon =
6 Image.asset('assets/images/wyre-icon.png', width: 36, height: 36);
7 final _moonPayIcon =
8 - Image.asset('assets/images/wyre-icon.png', width: 36, height: 36);
8 + Image.asset('assets/images/moonpay-icon.png', width: 36, height: 34);
9
10 if (providerDescription != null) {
11 switch (providerDescription) {
12 case BuyProviderDescription.wyre:
13 return _wyreIcon;
14 case BuyProviderDescription.moonPay:
15 - //return _moonPayIcon;
16 - return null;
15 + return _moonPayIcon;
16 default:
17 return null;
18 }
lib/buy/moonpay/moonpay_buy_provider.dart
+3 -2
@@ -94,8 +94,9 @@ class MoonPayBuyProvider extends BuyProvider {
94
95 final responseJSON = json.decode(response.body) as Map<String, dynamic>;
96 final status = responseJSON['status'] as String;
97 - final state = TradeState.deserialize(raw: status.toLowerCase());
98 - final createdAt = responseJSON['createdAt'] as DateTime;
97 + final state = TradeState.deserialize(raw: status);
98 + final createdAtRaw = responseJSON['createdAt'] as String;
99 + final createdAt = DateTime.parse(createdAtRaw).toLocal();
100 final amount = responseJSON['quoteCurrencyAmount'] as double;
101
102 return Order(
lib/exchange/trade_state.dart
+14
@@ -27,6 +27,12 @@ class TradeState extends EnumerableItem<String> with Serializable<String> {
27 static const finished = TradeState(raw: 'finished', title: 'Finished');
28 static const waiting = TradeState(raw: 'waiting', title: 'Waiting');
29 static const processing = TradeState(raw: 'processing', title: 'Processing');
30 + static const waitingPayment =
31 + TradeState(raw: 'waitingPayment', title: 'Waiting payment');
32 + static const waitingAuthorization =
33 + TradeState(raw: 'waitingAuthorization', title: 'Waiting authorization');
34 + static const failed = TradeState(raw: 'failed', title: 'Failed');
35 + static const completed = TradeState(raw: 'completed', title: 'Completed');
36
37 static TradeState deserialize({String raw}) {
38 switch (raw) {
@@ -62,6 +68,14 @@ class TradeState extends EnumerableItem<String> with Serializable<String> {
68 return waiting;
69 case 'processing':
70 return processing;
71 + case 'waitingPayment':
72 + return waitingPayment;
73 + case 'waitingAuthorization':
74 + return waitingAuthorization;
75 + case 'failed':
76 + return failed;
77 + case 'completed':
78 + return completed;
79 default:
80 return null;
81 }
lib/src/screens/buy/buy_webview_page.dart
+17 -1
@@ -92,7 +92,23 @@ class BuyWebViewPageBodyState extends State<BuyWebViewPageBody> {
92 }
93
94 if (_provider is MoonPayBuyProvider) {
95 - // FIXME: fetch orderId
95 + /*_timer?.cancel();
96 + _timer = Timer.periodic(Duration(seconds: 1), (timer) async {
97 +
98 + try {
99 + if (_webViewController == null || _isSaving) {
100 + return;
101 + }
102 +
103 + final url = await _webViewController.currentUrl();
104 + print('MoonPay Url = $url');
105 +
106 + timer.cancel();
107 + } catch (e) {
108 + _isSaving = false;
109 + print(e);
110 + }
111 + });*/
112 }
113 }
114
lib/src/screens/buy/pre_order_page.dart
+50 -36
@@ -14,6 +14,7 @@ import 'package:cake_wallet/src/widgets/primary_button.dart';
14 import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart';
15 import 'package:cake_wallet/generated/i18n.dart';
16 import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
17 +import 'package:cake_wallet/src/widgets/trail_button.dart';
18 import 'package:mobx/mobx.dart';
19
20 class PreOrderPage extends BasePage {
@@ -61,6 +62,13 @@ class PreOrderPage extends BasePage {
62 @override
63 AppBarStyle get appBarStyle => AppBarStyle.transparent;
64
65 + @override
66 + Widget trailing(context) => TrailButton(
67 + caption: S.of(context).clear,
68 + onPressed: () {
69 + buyViewModel.reset();
70 + });
71 +
72 @override
73 Widget body(BuildContext context) {
74 return KeyboardActions(
@@ -96,43 +104,49 @@ class PreOrderPage extends BasePage {
104 ], begin: Alignment.topLeft, end: Alignment.bottomRight),
105 ),
106 child: Padding(
99 - padding: EdgeInsets.fromLTRB(100, 100, 100, 65),
100 - child: BaseTextFormField(
101 - focusNode: _amountFocus,
102 - controller: _amountController,
103 - keyboardType:
104 - TextInputType.numberWithOptions(
105 - signed: false, decimal: true),
106 - inputFormatters: [
107 - FilteringTextInputFormatter
108 - .allow(RegExp(_amountPattern))
109 - ],
110 - prefixIcon: Padding(
111 - padding: EdgeInsets.only(top: 2),
112 - child:
113 - Text(buyViewModel.fiatCurrency.title + ': ',
114 - style: TextStyle(
115 - fontSize: 36,
116 - fontWeight: FontWeight.w600,
117 - color: Colors.white,
118 - )),
119 - ),
120 - hintText: '0.00',
121 - borderColor: Theme.of(context)
122 - .primaryTextTheme
123 - .headline
124 - .color,
125 - textStyle: TextStyle(
126 - fontSize: 36,
127 - fontWeight: FontWeight.w500,
128 - color: Colors.white),
129 - placeholderTextStyle: TextStyle(
130 - color: Theme.of(context)
107 + padding: EdgeInsets.only(top: 100, bottom: 65),
108 + child: Center(
109 + child: Container(
110 + width: 165,
111 + child: BaseTextFormField(
112 + focusNode: _amountFocus,
113 + controller: _amountController,
114 + keyboardType:
115 + TextInputType.numberWithOptions(
116 + signed: false, decimal: true),
117 + inputFormatters: [
118 + FilteringTextInputFormatter
119 + .allow(RegExp(_amountPattern))
120 + ],
121 + prefixIcon: Padding(
122 + padding: EdgeInsets.only(top: 2),
123 + child:
124 + Text(buyViewModel.fiatCurrency.title + ': ',
125 + style: TextStyle(
126 + fontSize: 36,
127 + fontWeight: FontWeight.w600,
128 + color: Colors.white,
129 + )),
130 + ),
131 + hintText: '0.00',
132 + borderColor: Theme.of(context)
133 .primaryTextTheme
132 - .headline
134 + .body2
135 .decorationColor,
134 - fontWeight: FontWeight.w500,
135 - fontSize: 36),
136 + borderWidth: 0.5,
137 + textStyle: TextStyle(
138 + fontSize: 36,
139 + fontWeight: FontWeight.w500,
140 + color: Colors.white),
141 + placeholderTextStyle: TextStyle(
142 + color: Theme.of(context)
143 + .primaryTextTheme
144 + .headline
145 + .decorationColor,
146 + fontWeight: FontWeight.w500,
147 + fontSize: 36),
148 + )
149 + )
150 )
151 )
152 ),
@@ -144,7 +158,7 @@ class PreOrderPage extends BasePage {
158 style: TextStyle(
159 color: Theme.of(context).primaryTextTheme.title.color,
160 fontSize: 18,
147 - fontWeight: FontWeight.w500
161 + fontWeight: FontWeight.bold
162 ),
163 )
164 ),
lib/src/screens/buy/widgets/buy_list_item.dart
+48 -43
@@ -52,62 +52,67 @@ class BuyListItem extends StatelessWidget {
52 height: 102,
53 padding: EdgeInsets.only(
54 left: 20,
55 + //top: 33,
56 right: 20
57 ),
58 decoration: BoxDecoration(
59 borderRadius: BorderRadius.all(Radius.circular(25)),
60 color: backgroundColor
61 ),
61 - child: Row(
62 - mainAxisAlignment: MainAxisAlignment.spaceBetween,
63 - mainAxisSize: MainAxisSize.max,
64 - crossAxisAlignment: CrossAxisAlignment.center,
62 + child: Stack(
63 children: [
66 - Row(
67 - mainAxisAlignment: MainAxisAlignment.start,
68 - mainAxisSize: MainAxisSize.min,
69 - children: [
70 - if (providerIcon != null) Padding(
71 - padding: EdgeInsets.only(right: 10),
72 - child: providerIcon
73 - ),
74 - Text(
75 - provider.description.title,
76 - style: TextStyle(
77 - color: primaryTextColor,
78 - fontSize: 24,
79 - fontWeight: FontWeight.w500
64 + Positioned(
65 + top: 33,
66 + left: 0,
67 + right: 0,
68 + child: Row(
69 + mainAxisAlignment: MainAxisAlignment.spaceBetween,
70 + mainAxisSize: MainAxisSize.max,
71 + crossAxisAlignment: CrossAxisAlignment.center,
72 + children: [
73 + Row(
74 + mainAxisAlignment: MainAxisAlignment.start,
75 + mainAxisSize: MainAxisSize.min,
76 + children: [
77 + if (providerIcon != null) Padding(
78 + padding: EdgeInsets.only(right: 10),
79 + child: providerIcon
80 + ),
81 + Text(
82 + provider.description.title,
83 + style: TextStyle(
84 + color: secondaryTextColor,
85 + fontSize: 20,
86 + fontWeight: FontWeight.bold
87 + ),
88 + )
89 + ],
90 ),
81 - )
82 - ],
83 - ),
84 - Column(
85 - mainAxisSize: MainAxisSize.min,
86 - crossAxisAlignment: CrossAxisAlignment.end,
87 - children: [
88 - Text(
89 - '${destAmount?.toString()} ${destCurrency.title}',
90 - style: TextStyle(
91 - color: secondaryTextColor,
92 - fontSize: 18,
93 - fontWeight: FontWeight.w500
94 - ),
95 - ),
96 - Padding(
97 - padding: EdgeInsets.only(top: 5),
98 - child: Text(
99 - '${sourceAmount?.toString()} ${sourceCurrency.title}',
91 + Text(
92 + '${destAmount?.toString()} ${destCurrency.title}',
93 style: TextStyle(
101 - color: primaryTextColor,
102 - fontSize: 18,
103 - fontWeight: FontWeight.w500
94 + color: secondaryTextColor,
95 + fontSize: 20,
96 + fontWeight: FontWeight.bold
97 ),
98 ),
106 - )
107 - ],
99 + ],
100 + )
101 + ),
102 + Positioned(
103 + top: 65,
104 + right: 0,
105 + child: Text(
106 + '${sourceAmount?.toString()} ${sourceCurrency.title}',
107 + style: TextStyle(
108 + color: primaryTextColor,
109 + fontSize: 16,
110 + fontWeight: FontWeight.bold
111 + ),
112 + ),
113 )
114 ],
110 - ),
115 + )
116 )
117 );
118 }
lib/src/screens/dashboard/widgets/order_row.dart
+4 -2
@@ -30,8 +30,10 @@ class OrderRow extends StatelessWidget {
30 mainAxisSize: MainAxisSize.max,
31 crossAxisAlignment: CrossAxisAlignment.center,
32 children: [
33 - providerIcon ?? Offstage(),
34 - SizedBox(width: 12),
33 + if (providerIcon != null) Padding(
34 + padding: EdgeInsets.only(right: 12),
35 + child: providerIcon,
36 + ),
37 Expanded(
38 child: Column(
39 mainAxisSize: MainAxisSize.min,
lib/src/widgets/base_text_form_field.dart
+6 -4
@@ -26,7 +26,8 @@ class BaseTextFormField extends StatelessWidget {
26 this.placeholderTextStyle,
27 this.maxLength,
28 this.focusNode,
29 - this.initialValue});
29 + this.initialValue,
30 + this.borderWidth = 1.0});
31
32 final TextEditingController controller;
33 final TextInputType keyboardType;
@@ -52,6 +53,7 @@ class BaseTextFormField extends StatelessWidget {
53 final bool readOnly;
54 final bool enableInteractiveSelection;
55 final String initialValue;
56 + final double borderWidth;
57
58 @override
59 Widget build(BuildContext context) {
@@ -88,17 +90,17 @@ class BaseTextFormField extends StatelessWidget {
90 borderSide: BorderSide(
91 color: borderColor ??
92 Theme.of(context).primaryTextTheme.title.backgroundColor,
91 - width: 1.0)),
93 + width: borderWidth)),
94 disabledBorder: UnderlineInputBorder(
95 borderSide: BorderSide(
96 color: borderColor ??
97 Theme.of(context).primaryTextTheme.title.backgroundColor,
96 - width: 1.0)),
98 + width: borderWidth)),
99 enabledBorder: UnderlineInputBorder(
100 borderSide: BorderSide(
101 color: borderColor ??
102 Theme.of(context).primaryTextTheme.title.backgroundColor,
101 - width: 1.0))),
103 + width: borderWidth))),
104 validator: validator,
105 );
106 }
lib/view_model/order_details_view_model.dart
+4 -1
@@ -58,6 +58,9 @@ abstract class OrderDetailsViewModelBase with Store {
58 final updatedOrder = await _provider.findOrderById(order.id);
59 updatedOrder.receiveAddress = order.receiveAddress;
60 updatedOrder.walletId = order.walletId;
61 + if (order.provider != null) {
62 + updatedOrder.providerRaw = order.provider.raw;
63 + }
64 order = updatedOrder;
65 _updateItems();
66 }
@@ -90,7 +93,7 @@ abstract class OrderDetailsViewModelBase with Store {
93 );
94 }
95
93 - if (_provider.trackUrl.isNotEmpty) {
96 + if (_provider?.trackUrl?.isNotEmpty ?? false) {
97 final buildURL = _provider.trackUrl + '${order.transferId}';
98 items.add(
99 TrackTradeListItem(