From 697fc7f5a59132a677c9af6b681a728a2640592e Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Wed, 14 Apr 2021 21:23:10 +0300 Subject: [PATCH] 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 --- assets/images/moonpay-icon.png | Bin 0 -> 2015 bytes lib/buy/get_buy_provider_icon.dart | 5 +- lib/buy/moonpay/moonpay_buy_provider.dart | 5 +- lib/exchange/trade_state.dart | 14 +++ lib/src/screens/buy/buy_webview_page.dart | 18 +++- lib/src/screens/buy/pre_order_page.dart | 86 ++++++++++------- .../screens/buy/widgets/buy_list_item.dart | 91 +++++++++--------- .../screens/dashboard/widgets/order_row.dart | 6 +- lib/src/widgets/base_text_form_field.dart | 10 +- lib/view_model/order_details_view_model.dart | 5 +- 10 files changed, 148 insertions(+), 92 deletions(-) create mode 100644 assets/images/moonpay-icon.png diff --git a/assets/images/moonpay-icon.png b/assets/images/moonpay-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..1fbc2b6fc67fbb9ceab8b7134328fe7416db7980 GIT binary patch literal 2015 zcmY*a3piWZ7C!N4Ns+cRG1U@jOi?7F7@3Gyij>5wLzGD*go*LUka~4|De4;P5uJ|e z)H~?IBdW$si!@%<2S(Milu||AGQBNTq%|k4Ywq3qTYLR`?SK7iuk)Sropg7qlPYvS z6aWBKvNOpO^k~pfN;|;S()V;K=oCWiD0TpFBWIVCsR-_ofzF;307&=}0M48RfORl* zW*z`eVF6$v008j$0D#~Y-1Z=V2WQzdaxjGg7=l;{P=xFS(jhX6jkGYqnqW~xC=!VzLEO;9^&OAL#bYqB zv9TtxW+stQAsACDD=Q2Zhr!{DL56X3d<2gfXB-iI=(EUwbx7>!z$gxv$BB$U%5<5m z$WuIP6iQZTdwjkpj}!b)rHJUQw!j84vJ;G{2^O=h4W<%gQM_9ehYePi=@U%}pP2s_ z+p0sr$cq2ZWj=TMDGIhqgc2~@kBtcZfh6yoOwt~pKf%f`n1ia3FR4h;S>KDoIe=@>dw z3LBHFuiUvVs;$+$@Xan?IV&5RIqS)ZiP=G0&6%mGR^pz62Prt#h)nd@&(TJW`%=Ze)a}n*@D1PiPd2d&Q*?eQf{zj=nyDH?Z6N^=!}O zoo-Q4^@7~8co!F!PN}qcC>}A;m7`-`{GzS0vXbVQ)`EN6+6pnZwDj`vK}4qIm8GK_-=!PgWZQirWx;H2jW<)WH=m7yXe2W z<@9Pci^ck=dO+ftH##|qSX*0b&gkxTrTWw9bo*J=skyn3w~(AnP2CUV^78V!?8Zh5 zx;Z`8c!j3*!8V;SvGL%+an-v$Jz0Nu zE8ILoLk;iqY|YHf2x*rFRngamhP<<{wzoSJj?>m*^nA@nX-bN!Fxbz_h@r?`7m~c- z=!3a}+;CH~=j!ynQ!z1)Q&Up|PoGk7R`m@vR!5Ox7me>8e)dOKLVP?~EEbQa3A-{g zM@M~Ut%$_gL`(I!g|8aPR;HmyGu*Q<9RGEUft^|DmFy!Aiwg?!GomgSK)jYFgWT71 zp|*|ih>or<^`F;RHk%mZV`DL2J$|D?=@vH`r`#<+N`2^)wABDJz=}GLb(d z3CzNDEeDsC+Rq^{^V8GGP9FCz<>uz)-6iN7Bc+zgLv}sVwYMRL1_q^9uj+gAhePw; zej%c_lx1WhG^B#}JO58`{=;ReGCf+&<0rDmoW7jAaJ4dM_fiqy*X2c>HC@f;n@;wjXD|t})zkK6ew}y3g6MTuDuBs8eiogk*0ohghli zACxXGF51%p-;4eCRllaM0!a)5$x{`6@zpjR$v_H9Td^gyiV>f`8>G?V6 QKeFEz`52W{YafvOH-BM2B>(^b literal 0 HcmV?d00001 diff --git a/lib/buy/get_buy_provider_icon.dart b/lib/buy/get_buy_provider_icon.dart index d58fe19d4..bbd599e24 100644 --- a/lib/buy/get_buy_provider_icon.dart +++ b/lib/buy/get_buy_provider_icon.dart @@ -5,15 +5,14 @@ Image getBuyProviderIcon(BuyProviderDescription providerDescription) { final _wyreIcon = Image.asset('assets/images/wyre-icon.png', width: 36, height: 36); final _moonPayIcon = - Image.asset('assets/images/wyre-icon.png', width: 36, height: 36); + Image.asset('assets/images/moonpay-icon.png', width: 36, height: 34); if (providerDescription != null) { switch (providerDescription) { case BuyProviderDescription.wyre: return _wyreIcon; case BuyProviderDescription.moonPay: - //return _moonPayIcon; - return null; + return _moonPayIcon; default: return null; } diff --git a/lib/buy/moonpay/moonpay_buy_provider.dart b/lib/buy/moonpay/moonpay_buy_provider.dart index 2fde667e4..5b2fd7326 100644 --- a/lib/buy/moonpay/moonpay_buy_provider.dart +++ b/lib/buy/moonpay/moonpay_buy_provider.dart @@ -94,8 +94,9 @@ class MoonPayBuyProvider extends BuyProvider { final responseJSON = json.decode(response.body) as Map; final status = responseJSON['status'] as String; - final state = TradeState.deserialize(raw: status.toLowerCase()); - final createdAt = responseJSON['createdAt'] as DateTime; + final state = TradeState.deserialize(raw: status); + final createdAtRaw = responseJSON['createdAt'] as String; + final createdAt = DateTime.parse(createdAtRaw).toLocal(); final amount = responseJSON['quoteCurrencyAmount'] as double; return Order( diff --git a/lib/exchange/trade_state.dart b/lib/exchange/trade_state.dart index 7095626b9..9f08b4df2 100644 --- a/lib/exchange/trade_state.dart +++ b/lib/exchange/trade_state.dart @@ -27,6 +27,12 @@ class TradeState extends EnumerableItem with Serializable { static const finished = TradeState(raw: 'finished', title: 'Finished'); static const waiting = TradeState(raw: 'waiting', title: 'Waiting'); static const processing = TradeState(raw: 'processing', title: 'Processing'); + static const waitingPayment = + TradeState(raw: 'waitingPayment', title: 'Waiting payment'); + static const waitingAuthorization = + TradeState(raw: 'waitingAuthorization', title: 'Waiting authorization'); + static const failed = TradeState(raw: 'failed', title: 'Failed'); + static const completed = TradeState(raw: 'completed', title: 'Completed'); static TradeState deserialize({String raw}) { switch (raw) { @@ -62,6 +68,14 @@ class TradeState extends EnumerableItem with Serializable { return waiting; case 'processing': return processing; + case 'waitingPayment': + return waitingPayment; + case 'waitingAuthorization': + return waitingAuthorization; + case 'failed': + return failed; + case 'completed': + return completed; default: return null; } diff --git a/lib/src/screens/buy/buy_webview_page.dart b/lib/src/screens/buy/buy_webview_page.dart index 91e93f902..d5ab59482 100644 --- a/lib/src/screens/buy/buy_webview_page.dart +++ b/lib/src/screens/buy/buy_webview_page.dart @@ -92,7 +92,23 @@ class BuyWebViewPageBodyState extends State { } if (_provider is MoonPayBuyProvider) { - // FIXME: fetch orderId + /*_timer?.cancel(); + _timer = Timer.periodic(Duration(seconds: 1), (timer) async { + + try { + if (_webViewController == null || _isSaving) { + return; + } + + final url = await _webViewController.currentUrl(); + print('MoonPay Url = $url'); + + timer.cancel(); + } catch (e) { + _isSaving = false; + print(e); + } + });*/ } } diff --git a/lib/src/screens/buy/pre_order_page.dart b/lib/src/screens/buy/pre_order_page.dart index 0cf6a1f88..44162d7ec 100644 --- a/lib/src/screens/buy/pre_order_page.dart +++ b/lib/src/screens/buy/pre_order_page.dart @@ -14,6 +14,7 @@ import 'package:cake_wallet/src/widgets/primary_button.dart'; import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; +import 'package:cake_wallet/src/widgets/trail_button.dart'; import 'package:mobx/mobx.dart'; class PreOrderPage extends BasePage { @@ -61,6 +62,13 @@ class PreOrderPage extends BasePage { @override AppBarStyle get appBarStyle => AppBarStyle.transparent; + @override + Widget trailing(context) => TrailButton( + caption: S.of(context).clear, + onPressed: () { + buyViewModel.reset(); + }); + @override Widget body(BuildContext context) { return KeyboardActions( @@ -96,43 +104,49 @@ class PreOrderPage extends BasePage { ], begin: Alignment.topLeft, end: Alignment.bottomRight), ), child: Padding( - padding: EdgeInsets.fromLTRB(100, 100, 100, 65), - child: BaseTextFormField( - focusNode: _amountFocus, - controller: _amountController, - keyboardType: - TextInputType.numberWithOptions( - signed: false, decimal: true), - inputFormatters: [ - FilteringTextInputFormatter - .allow(RegExp(_amountPattern)) - ], - prefixIcon: Padding( - padding: EdgeInsets.only(top: 2), - child: - Text(buyViewModel.fiatCurrency.title + ': ', - style: TextStyle( - fontSize: 36, - fontWeight: FontWeight.w600, - color: Colors.white, - )), - ), - hintText: '0.00', - borderColor: Theme.of(context) - .primaryTextTheme - .headline - .color, - textStyle: TextStyle( - fontSize: 36, - fontWeight: FontWeight.w500, - color: Colors.white), - placeholderTextStyle: TextStyle( - color: Theme.of(context) + padding: EdgeInsets.only(top: 100, bottom: 65), + child: Center( + child: Container( + width: 165, + child: BaseTextFormField( + focusNode: _amountFocus, + controller: _amountController, + keyboardType: + TextInputType.numberWithOptions( + signed: false, decimal: true), + inputFormatters: [ + FilteringTextInputFormatter + .allow(RegExp(_amountPattern)) + ], + prefixIcon: Padding( + padding: EdgeInsets.only(top: 2), + child: + Text(buyViewModel.fiatCurrency.title + ': ', + style: TextStyle( + fontSize: 36, + fontWeight: FontWeight.w600, + color: Colors.white, + )), + ), + hintText: '0.00', + borderColor: Theme.of(context) .primaryTextTheme - .headline + .body2 .decorationColor, - fontWeight: FontWeight.w500, - fontSize: 36), + borderWidth: 0.5, + textStyle: TextStyle( + fontSize: 36, + fontWeight: FontWeight.w500, + color: Colors.white), + placeholderTextStyle: TextStyle( + color: Theme.of(context) + .primaryTextTheme + .headline + .decorationColor, + fontWeight: FontWeight.w500, + fontSize: 36), + ) + ) ) ) ), @@ -144,7 +158,7 @@ class PreOrderPage extends BasePage { style: TextStyle( color: Theme.of(context).primaryTextTheme.title.color, fontSize: 18, - fontWeight: FontWeight.w500 + fontWeight: FontWeight.bold ), ) ), diff --git a/lib/src/screens/buy/widgets/buy_list_item.dart b/lib/src/screens/buy/widgets/buy_list_item.dart index 8ee3950aa..7c18893a6 100644 --- a/lib/src/screens/buy/widgets/buy_list_item.dart +++ b/lib/src/screens/buy/widgets/buy_list_item.dart @@ -52,62 +52,67 @@ class BuyListItem extends StatelessWidget { height: 102, padding: EdgeInsets.only( left: 20, + //top: 33, right: 20 ), decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(25)), color: backgroundColor ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.center, + child: Stack( children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - if (providerIcon != null) Padding( - padding: EdgeInsets.only(right: 10), - child: providerIcon - ), - Text( - provider.description.title, - style: TextStyle( - color: primaryTextColor, - fontSize: 24, - fontWeight: FontWeight.w500 + Positioned( + top: 33, + left: 0, + right: 0, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + if (providerIcon != null) Padding( + padding: EdgeInsets.only(right: 10), + child: providerIcon + ), + Text( + provider.description.title, + style: TextStyle( + color: secondaryTextColor, + fontSize: 20, + fontWeight: FontWeight.bold + ), + ) + ], ), - ) - ], - ), - Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - Text( - '${destAmount?.toString()} ${destCurrency.title}', - style: TextStyle( - color: secondaryTextColor, - fontSize: 18, - fontWeight: FontWeight.w500 - ), - ), - Padding( - padding: EdgeInsets.only(top: 5), - child: Text( - '${sourceAmount?.toString()} ${sourceCurrency.title}', + Text( + '${destAmount?.toString()} ${destCurrency.title}', style: TextStyle( - color: primaryTextColor, - fontSize: 18, - fontWeight: FontWeight.w500 + color: secondaryTextColor, + fontSize: 20, + fontWeight: FontWeight.bold ), ), - ) - ], + ], + ) + ), + Positioned( + top: 65, + right: 0, + child: Text( + '${sourceAmount?.toString()} ${sourceCurrency.title}', + style: TextStyle( + color: primaryTextColor, + fontSize: 16, + fontWeight: FontWeight.bold + ), + ), ) ], - ), + ) ) ); } diff --git a/lib/src/screens/dashboard/widgets/order_row.dart b/lib/src/screens/dashboard/widgets/order_row.dart index 49afa7a25..56a69122e 100644 --- a/lib/src/screens/dashboard/widgets/order_row.dart +++ b/lib/src/screens/dashboard/widgets/order_row.dart @@ -30,8 +30,10 @@ class OrderRow extends StatelessWidget { mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.center, children: [ - providerIcon ?? Offstage(), - SizedBox(width: 12), + if (providerIcon != null) Padding( + padding: EdgeInsets.only(right: 12), + child: providerIcon, + ), Expanded( child: Column( mainAxisSize: MainAxisSize.min, diff --git a/lib/src/widgets/base_text_form_field.dart b/lib/src/widgets/base_text_form_field.dart index b9148bf2c..385cba8cd 100644 --- a/lib/src/widgets/base_text_form_field.dart +++ b/lib/src/widgets/base_text_form_field.dart @@ -26,7 +26,8 @@ class BaseTextFormField extends StatelessWidget { this.placeholderTextStyle, this.maxLength, this.focusNode, - this.initialValue}); + this.initialValue, + this.borderWidth = 1.0}); final TextEditingController controller; final TextInputType keyboardType; @@ -52,6 +53,7 @@ class BaseTextFormField extends StatelessWidget { final bool readOnly; final bool enableInteractiveSelection; final String initialValue; + final double borderWidth; @override Widget build(BuildContext context) { @@ -88,17 +90,17 @@ class BaseTextFormField extends StatelessWidget { borderSide: BorderSide( color: borderColor ?? Theme.of(context).primaryTextTheme.title.backgroundColor, - width: 1.0)), + width: borderWidth)), disabledBorder: UnderlineInputBorder( borderSide: BorderSide( color: borderColor ?? Theme.of(context).primaryTextTheme.title.backgroundColor, - width: 1.0)), + width: borderWidth)), enabledBorder: UnderlineInputBorder( borderSide: BorderSide( color: borderColor ?? Theme.of(context).primaryTextTheme.title.backgroundColor, - width: 1.0))), + width: borderWidth))), validator: validator, ); } diff --git a/lib/view_model/order_details_view_model.dart b/lib/view_model/order_details_view_model.dart index 8e8ed3c18..328b0c93c 100644 --- a/lib/view_model/order_details_view_model.dart +++ b/lib/view_model/order_details_view_model.dart @@ -58,6 +58,9 @@ abstract class OrderDetailsViewModelBase with Store { final updatedOrder = await _provider.findOrderById(order.id); updatedOrder.receiveAddress = order.receiveAddress; updatedOrder.walletId = order.walletId; + if (order.provider != null) { + updatedOrder.providerRaw = order.provider.raw; + } order = updatedOrder; _updateItems(); } @@ -90,7 +93,7 @@ abstract class OrderDetailsViewModelBase with Store { ); } - if (_provider.trackUrl.isNotEmpty) { + if (_provider?.trackUrl?.isNotEmpty ?? false) { final buildURL = _provider.trackUrl + '${order.transferId}'; items.add( TrackTradeListItem(