From 3da9eb38aa11542ca327ba0dda1e51fcda459914 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Wed, 31 Mar 2021 19:18:33 +0300 Subject: [PATCH 1/2] CAKE-288 | added possibility to see available and additional balance by pressing on hidden balance (balance_page.dart); fixed switch of display mode on order_list_item.dart and trade_list_item.dart --- .../dashboard/widgets/balance_page.dart | 176 +++++++++--------- lib/store/dashboard/orders_store.dart | 2 +- lib/store/dashboard/trades_store.dart | 3 +- .../dashboard/balance_view_model.dart | 14 +- lib/view_model/dashboard/order_list_item.dart | 11 +- lib/view_model/dashboard/trade_list_item.dart | 7 +- 6 files changed, 113 insertions(+), 100 deletions(-) diff --git a/lib/src/screens/dashboard/widgets/balance_page.dart b/lib/src/screens/dashboard/widgets/balance_page.dart index 415c3907c..aa8695dc7 100644 --- a/lib/src/screens/dashboard/widgets/balance_page.dart +++ b/lib/src/screens/dashboard/widgets/balance_page.dart @@ -13,97 +13,105 @@ class BalancePage extends StatelessWidget { return Container( color: Colors.transparent, padding: EdgeInsets.all(24), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Observer(builder: (_) { - return Text( - dashboardViewModel.balanceViewModel.currency.toString(), - style: TextStyle( - fontSize: 40, - fontWeight: FontWeight.bold, - color: Theme.of(context) - .accentTextTheme - .display2 - .backgroundColor, - height: 1), - ); - }), - SizedBox(height: 10), - Observer(builder: (_) { - return Row( - children: [ - Expanded( - child: Text( - '${dashboardViewModel.balanceViewModel.availableBalanceLabel} (${dashboardViewModel.balanceViewModel.availableFiatBalance.toString()})', - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w600, - color: Theme.of(context) - .accentTextTheme - .display2 - .backgroundColor, - height: 1), - ) - ) - ], - ); - }), - SizedBox(height: 10), - Observer(builder: (_) { - return AutoSizeText( - dashboardViewModel.balanceViewModel.availableBalance, + child: GestureDetector( + onLongPress: () => + dashboardViewModel.balanceViewModel.isReversing = + !dashboardViewModel.balanceViewModel.isReversing, + onLongPressUp: () => + dashboardViewModel.balanceViewModel.isReversing = + !dashboardViewModel.balanceViewModel.isReversing, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Observer(builder: (_) { + return Text( + dashboardViewModel.balanceViewModel.currency.toString(), style: TextStyle( - fontSize: 54, + fontSize: 40, fontWeight: FontWeight.bold, color: Theme.of(context) .accentTextTheme - .display3 + .display2 .backgroundColor, height: 1), - maxLines: 1, - textAlign: TextAlign.center); - }), - SizedBox(height: 10), - Observer(builder: (_) { - return Row( - children: [ - Expanded( - child: Text( - '${dashboardViewModel.balanceViewModel.additionalBalanceLabel} (${dashboardViewModel.balanceViewModel.additionalFiatBalance.toString()})', - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w600, - color: Theme.of(context) - .accentTextTheme - .display2 - .backgroundColor, - height: 1), + ); + }), + SizedBox(height: 10), + Observer(builder: (_) { + return Row( + children: [ + Expanded( + child: Text( + '${dashboardViewModel.balanceViewModel.availableBalanceLabel} (${dashboardViewModel.balanceViewModel.availableFiatBalance.toString()})', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: Theme.of(context) + .accentTextTheme + .display2 + .backgroundColor, + height: 1), + ) ) - ) - ], - ); - }), - SizedBox(height: 10), - Observer(builder: (_) { - return AutoSizeText( - dashboardViewModel.balanceViewModel.additionalBalance - .toString(), - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - color: Theme.of(context) - .accentTextTheme - .display3 - .backgroundColor, - height: 1), - maxLines: 1, - textAlign: TextAlign.center); - }), - ], + ], + ); + }), + SizedBox(height: 10), + Observer(builder: (_) { + return AutoSizeText( + dashboardViewModel.balanceViewModel.availableBalance, + style: TextStyle( + fontSize: 54, + fontWeight: FontWeight.bold, + color: Theme.of(context) + .accentTextTheme + .display3 + .backgroundColor, + height: 1), + maxLines: 1, + textAlign: TextAlign.center); + }), + SizedBox(height: 10), + Observer(builder: (_) { + return Row( + children: [ + Expanded( + child: Text( + '${dashboardViewModel.balanceViewModel.additionalBalanceLabel} (${dashboardViewModel.balanceViewModel.additionalFiatBalance.toString()})', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: Theme.of(context) + .accentTextTheme + .display2 + .backgroundColor, + height: 1), + ) + ) + ], + ); + }), + SizedBox(height: 10), + Observer(builder: (_) { + return AutoSizeText( + dashboardViewModel.balanceViewModel.additionalBalance + .toString(), + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + color: Theme.of(context) + .accentTextTheme + .display3 + .backgroundColor, + height: 1), + maxLines: 1, + textAlign: TextAlign.center); + }), + ], + ), ), ); } diff --git a/lib/store/dashboard/orders_store.dart b/lib/store/dashboard/orders_store.dart index 1aad9f5b8..01c2b13a9 100644 --- a/lib/store/dashboard/orders_store.dart +++ b/lib/store/dashboard/orders_store.dart @@ -41,5 +41,5 @@ abstract class OrdersStoreBase with Store { Future updateOrderList() async => orders = ordersSource.values.map((order) => OrderListItem( order: order, - displayMode: settingsStore.balanceDisplayMode)).toList(); + settingsStore: settingsStore)).toList(); } \ No newline at end of file diff --git a/lib/store/dashboard/trades_store.dart b/lib/store/dashboard/trades_store.dart index 6c8a0fd9c..a7ae6edac 100644 --- a/lib/store/dashboard/trades_store.dart +++ b/lib/store/dashboard/trades_store.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'package:cake_wallet/exchange/trade.dart'; import 'package:cake_wallet/view_model/dashboard/trade_list_item.dart'; -import 'package:flutter/cupertino.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/store/settings_store.dart'; @@ -37,5 +36,5 @@ abstract class TradesStoreBase with Store { Future updateTradeList() async => trades = tradesSource.values.map((trade) => TradeListItem( trade: trade, - displayMode: settingsStore.balanceDisplayMode)).toList(); + settingsStore: settingsStore)).toList(); } \ No newline at end of file diff --git a/lib/view_model/dashboard/balance_view_model.dart b/lib/view_model/dashboard/balance_view_model.dart index fa770c36f..fb9b07a27 100644 --- a/lib/view_model/dashboard/balance_view_model.dart +++ b/lib/view_model/dashboard/balance_view_model.dart @@ -69,9 +69,9 @@ abstract class BalanceViewModelBase with Store { @computed BalanceDisplayMode get displayMode => isReversing - ? (savedDisplayMode == BalanceDisplayMode.availableBalance - ? BalanceDisplayMode.fullBalance - : BalanceDisplayMode.availableBalance) + ? savedDisplayMode == BalanceDisplayMode.hiddenBalance + ? BalanceDisplayMode.displayableBalance + : savedDisplayMode : savedDisplayMode; @computed @@ -96,7 +96,7 @@ abstract class BalanceViewModelBase with Store { String get availableBalance { final walletBalance = _walletBalance; - if (settingsStore.balanceDisplayMode == BalanceDisplayMode.hiddenBalance) { + if (displayMode == BalanceDisplayMode.hiddenBalance) { return '---'; } @@ -107,7 +107,7 @@ abstract class BalanceViewModelBase with Store { String get additionalBalance { final walletBalance = _walletBalance; - if (settingsStore.balanceDisplayMode == BalanceDisplayMode.hiddenBalance) { + if (displayMode == BalanceDisplayMode.hiddenBalance) { return '---'; } @@ -119,7 +119,7 @@ abstract class BalanceViewModelBase with Store { final walletBalance = _walletBalance; final fiatCurrency = settingsStore.fiatCurrency; - if (settingsStore.balanceDisplayMode == BalanceDisplayMode.hiddenBalance) { + if (displayMode == BalanceDisplayMode.hiddenBalance) { return '---'; } @@ -135,7 +135,7 @@ abstract class BalanceViewModelBase with Store { final walletBalance = _walletBalance; final fiatCurrency = settingsStore.fiatCurrency; - if (settingsStore.balanceDisplayMode == BalanceDisplayMode.hiddenBalance) { + if (displayMode == BalanceDisplayMode.hiddenBalance) { return '---'; } diff --git a/lib/view_model/dashboard/order_list_item.dart b/lib/view_model/dashboard/order_list_item.dart index 46b33ef96..7eeff4bd1 100644 --- a/lib/view_model/dashboard/order_list_item.dart +++ b/lib/view_model/dashboard/order_list_item.dart @@ -1,18 +1,21 @@ import 'package:cake_wallet/entities/order.dart'; +import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/view_model/dashboard/action_list_item.dart'; import 'package:cake_wallet/entities/balance_display_mode.dart'; class OrderListItem extends ActionListItem { - OrderListItem({this.order, this.displayMode}); + OrderListItem({this.order, this.settingsStore}); final Order order; - final BalanceDisplayMode displayMode; + final SettingsStore settingsStore; + + BalanceDisplayMode get displayMode => settingsStore.balanceDisplayMode; String get orderFormattedAmount { return order.amount != null ? displayMode == BalanceDisplayMode.hiddenBalance - ? '---' - : order.amountFormatted() + ? '---' + : order.amountFormatted() : order.amount; } diff --git a/lib/view_model/dashboard/trade_list_item.dart b/lib/view_model/dashboard/trade_list_item.dart index ec9cca36e..1b3c17aa1 100644 --- a/lib/view_model/dashboard/trade_list_item.dart +++ b/lib/view_model/dashboard/trade_list_item.dart @@ -1,12 +1,15 @@ import 'package:cake_wallet/exchange/trade.dart'; +import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/view_model/dashboard/action_list_item.dart'; import 'package:cake_wallet/entities/balance_display_mode.dart'; class TradeListItem extends ActionListItem { - TradeListItem({this.trade, this.displayMode}); + TradeListItem({this.trade, this.settingsStore}); final Trade trade; - final BalanceDisplayMode displayMode; + final SettingsStore settingsStore; + + BalanceDisplayMode get displayMode => settingsStore.balanceDisplayMode; String get tradeFormattedAmount { return trade.amount != null From 5db97b6f02e45898c172a587339d91bb946c8920 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Wed, 31 Mar 2021 20:22:41 +0300 Subject: [PATCH 2/2] CAKE-288 | increased area of pressing on hidden balance; wrapped TradeRow and OrderRow by Observer --- .../dashboard/widgets/balance_page.dart | 20 +++++++++---------- .../dashboard/widgets/transactions_page.dart | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/src/screens/dashboard/widgets/balance_page.dart b/lib/src/screens/dashboard/widgets/balance_page.dart index aa8695dc7..1cd17d4c0 100644 --- a/lib/src/screens/dashboard/widgets/balance_page.dart +++ b/lib/src/screens/dashboard/widgets/balance_page.dart @@ -10,16 +10,16 @@ class BalancePage extends StatelessWidget { @override Widget build(BuildContext context) { - return Container( - color: Colors.transparent, - padding: EdgeInsets.all(24), - child: GestureDetector( - onLongPress: () => - dashboardViewModel.balanceViewModel.isReversing = - !dashboardViewModel.balanceViewModel.isReversing, - onLongPressUp: () => - dashboardViewModel.balanceViewModel.isReversing = - !dashboardViewModel.balanceViewModel.isReversing, + return GestureDetector( + onLongPress: () => + dashboardViewModel.balanceViewModel.isReversing = + !dashboardViewModel.balanceViewModel.isReversing, + onLongPressUp: () => + dashboardViewModel.balanceViewModel.isReversing = + !dashboardViewModel.balanceViewModel.isReversing, + child: Container( + color: Colors.transparent, + padding: EdgeInsets.all(24), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, diff --git a/lib/src/screens/dashboard/widgets/transactions_page.dart b/lib/src/screens/dashboard/widgets/transactions_page.dart index 2c72e419b..482d23a75 100644 --- a/lib/src/screens/dashboard/widgets/transactions_page.dart +++ b/lib/src/screens/dashboard/widgets/transactions_page.dart @@ -64,7 +64,7 @@ class TransactionsPage extends StatelessWidget { if (item is TradeListItem) { final trade = item.trade; - return TradeRow( + return Observer(builder: (_) => TradeRow( onTap: () => Navigator.of(context).pushNamed( Routes.tradeDetails, arguments: trade), @@ -74,13 +74,13 @@ class TransactionsPage extends StatelessWidget { createdAtFormattedDate: DateFormat('HH:mm').format(trade.createdAt), formattedAmount: item.tradeFormattedAmount - ); + )); } if (item is OrderListItem) { final order = item.order; - return OrderRow( + return Observer(builder: (_) => OrderRow( onTap: () => Navigator.of(context).pushNamed( Routes.orderDetails, arguments: order), @@ -89,7 +89,7 @@ class TransactionsPage extends StatelessWidget { createdAtFormattedDate: DateFormat('HH:mm').format(order.createdAt), formattedAmount: item.orderFormattedAmount, - ); + )); } return Container(