From 57b215722877c3829f79bd81aa6548a431c10c06 Mon Sep 17 00:00:00 2001 From: Lior Date: Tue, 17 Mar 2020 11:47:17 +0200 Subject: [PATCH] fixed pro mode remarks --- .../actions/pro_mode_wallet_actions.dart | 9 +- lib/screens/cash_home/dai_explained.dart | 104 ++++++++++++------ lib/screens/pro_mode/pro_drawer.dart | 11 +- lib/screens/pro_mode/pro_transactios.dart | 57 ++++++---- lib/screens/send/receive.dart | 69 ++++++------ lib/widgets/activate_pro_mode.dart | 20 ++-- lib/widgets/activate_pro_mode2.dart | 35 ++++-- lib/widgets/coming_soon.dart | 1 + lib/widgets/drawer.dart | 11 +- pubspec.lock | 2 +- pubspec.yaml | 2 +- 11 files changed, 197 insertions(+), 124 deletions(-) diff --git a/lib/redux/actions/pro_mode_wallet_actions.dart b/lib/redux/actions/pro_mode_wallet_actions.dart index e50b91006..d19a14301 100644 --- a/lib/redux/actions/pro_mode_wallet_actions.dart +++ b/lib/redux/actions/pro_mode_wallet_actions.dart @@ -4,7 +4,6 @@ import 'package:fusecash/models/pro/token.dart'; import 'package:fusecash/models/transactions/transfer.dart'; import 'package:fusecash/redux/state/store.dart'; import 'package:fusecash/services.dart'; -import 'package:fusecash/utils/addresses.dart'; import 'package:redux_thunk/redux_thunk.dart'; import 'package:redux/redux.dart'; import 'package:wallet_core/wallet_core.dart' as wallet_core; @@ -73,7 +72,6 @@ ThunkAction startListenToTransferEvents() { return (Store store) async { new Timer.periodic(Duration(seconds: 5), (Timer timer) async { store.dispatch(getAccountTokens()); - // store.dispatch(getForeignTransfersEvents(timer)); }); store.dispatch(new StartListenToTransferEventsSuccess()); }; @@ -84,13 +82,8 @@ ThunkAction getAccountTokens() { final logger = await AppFactory().getLogger('action'); try { - wallet_core.Web3 web3 = store.state.proWalletState.web3; - if (web3 == null) { - throw "Web3 is empty"; - } - String walletAddress = store.state.userState.walletAddress; - dynamic response = await graph.getAccountTokens(walletAddress, daiTokenAddress); + dynamic response = await graph.getAccountTokens(walletAddress); List accounts = List.from(response); if (accounts.isNotEmpty) { Map accountsBalances = Map.from(accounts[0]); diff --git a/lib/screens/cash_home/dai_explained.dart b/lib/screens/cash_home/dai_explained.dart index b4264f4e3..0a087f34c 100644 --- a/lib/screens/cash_home/dai_explained.dart +++ b/lib/screens/cash_home/dai_explained.dart @@ -1,14 +1,20 @@ import 'dart:core'; import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_segment/flutter_segment.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:fusecash/generated/i18n.dart'; +import 'package:fusecash/models/app_state.dart'; +import 'package:fusecash/models/community.dart'; import 'package:fusecash/screens/cash_home/webview_page.dart'; import 'package:fusecash/screens/routes.gr.dart'; +import 'package:fusecash/screens/send/send_amount_arguments.dart'; import 'package:fusecash/widgets/activate_pro_mode.dart'; import 'package:fusecash/widgets/bottombar.dart'; import 'package:fusecash/widgets/main_scaffold.dart'; import 'package:flushbar/flushbar.dart'; +import 'package:redux/redux.dart'; class DaiExplainedScreen extends StatefulWidget { @override @@ -244,40 +250,55 @@ class _DaiExplainedScreenState extends State { ], ), ), - InkWell( - onTap: () { - showDialog( - context: context, - builder: (BuildContext context) { - return ActivateProModeDialog(); - }); - Segment.track(eventName: "Wallet: Withdraw DAI clicked"); - }, - child: Align( - alignment: Alignment.centerLeft, - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - 'Withdraw DAI', - style: TextStyle( - fontSize: 16, - color: - Theme.of(context).textTheme.headline.color, - fontWeight: FontWeight.bold), - ), - SizedBox( - width: 5, - ), - Image.asset( - 'assets/images/arrow_black.png', - width: 15, - height: 12, + new StoreConnector( + converter: _DaiPointsViewModel.fromStore, + builder: (_, vm) { + return InkWell( + onTap: () { + if (vm.isProModeActivate) { + Router.navigator.pushNamed(Router.sendAmountScreen, + arguments: SendAmountArguments( + sendType: SendType.FUSE_ADDRESS, + accountAddress: + vm.daiPointsHomeBridgeAddress)); + } else { + showDialog( + context: context, + builder: (BuildContext context) { + return ActivateProModeDialog(); + }); + Segment.track(eventName: "Wallet: Withdraw DAI clicked"); + } + }, + child: Align( + alignment: Alignment.centerLeft, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'Withdraw DAI', + style: TextStyle( + fontSize: 16, + color: Theme.of(context) + .textTheme + .headline + .color, + fontWeight: FontWeight.bold), + ), + SizedBox( + width: 5, + ), + Image.asset( + 'assets/images/arrow_black.png', + width: 15, + height: 12, + ), + ], ), - ], - ), - ), + ), + ); + }, ) ], ), @@ -320,3 +341,20 @@ class _DaiExplainedScreenState extends State { ]); } } + +class _DaiPointsViewModel { + final bool isProModeActivate; + final String daiPointsHomeBridgeAddress; + _DaiPointsViewModel({this.isProModeActivate, this.daiPointsHomeBridgeAddress}); + + static _DaiPointsViewModel fromStore(Store store) { + String communityAddres = + DotEnv().env['DEFAULT_COMMUNITY_CONTRACT_ADDRESS'].toLowerCase(); + Community community = + store.state.cashWalletState.communities[communityAddres]; + return _DaiPointsViewModel( + daiPointsHomeBridgeAddress: community.homeBridgeAddress, + isProModeActivate: store.state.userState.isProModeActivated, + ); + } +} diff --git a/lib/screens/pro_mode/pro_drawer.dart b/lib/screens/pro_mode/pro_drawer.dart index f41c21327..1aa86d211 100644 --- a/lib/screens/pro_mode/pro_drawer.dart +++ b/lib/screens/pro_mode/pro_drawer.dart @@ -255,6 +255,7 @@ class _DrawerWidgetState extends State { return Column( children: [ Expanded( + flex: 5, child: ListView( padding: EdgeInsets.all(10), children: [ @@ -263,10 +264,12 @@ class _DrawerWidgetState extends State { ], ), ), - Padding( - child: switchToCashMode(viewModel), - padding: EdgeInsets.all(20), - ), + Flexible( + flex: 1, + child: Padding( + child: switchToCashMode(viewModel), + padding: EdgeInsets.all(20), + )), ], ); }, diff --git a/lib/screens/pro_mode/pro_transactios.dart b/lib/screens/pro_mode/pro_transactios.dart index 72612fb88..d1f3747f2 100644 --- a/lib/screens/pro_mode/pro_transactios.dart +++ b/lib/screens/pro_mode/pro_transactios.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:fusecash/generated/i18n.dart'; import 'package:fusecash/models/pro/token.dart'; import 'package:fusecash/models/pro/views/pro_wallet.dart'; +import 'package:fusecash/utils/addresses.dart'; class ProTransactios extends StatelessWidget { ProTransactios({this.viewModel}); @@ -98,30 +99,40 @@ class _TokenRow extends StatelessWidget { children: [ new RichText( text: new TextSpan(children: [ - new TextSpan( - text: - '\$' + token.amount.toStringAsFixed(3), - style: new TextStyle( - // color: deduceColor(transfer), - fontSize: 16.0, - fontWeight: FontWeight.bold, - color: Theme.of(context).colorScheme.secondary)), - // new TextSpan( - // text: " ${token.symbol}", - // style: new TextStyle( - // // color: deduceColor(transfer), - // fontSize: 10.0, - // fontWeight: FontWeight.normal, - // color: Theme.of(context).primaryColor)), + token.address.contains(daiTokenAddress) + ? new TextSpan( + text: '\$' + + token.amount.toStringAsFixed(2), + style: new TextStyle( + fontSize: 16.0, + fontWeight: FontWeight.bold, + color: Theme.of(context) + .colorScheme + .secondary)) + : new TextSpan( + text: token.amount.toStringAsFixed(2) + + ' ' + + token.symbol, + style: new TextStyle( + fontSize: 16.0, + fontWeight: FontWeight.bold, + color: Theme.of(context) + .colorScheme + .secondary)), ])), - Positioned( - bottom: -20, - child: Padding( - child: Text(token.amount.toStringAsFixed(3) + ' ' + token.symbol, - style: TextStyle( - color: Color(0xFF8D8D8D), - fontSize: 10)), - padding: EdgeInsets.only(top: 10))) + token.address.contains(daiTokenAddress) + ? Positioned( + bottom: -20, + child: Padding( + child: Text( + token.amount.toStringAsFixed(2) + + ' ' + + token.symbol, + style: TextStyle( + color: Color(0xFF8D8D8D), + fontSize: 10)), + padding: EdgeInsets.only(top: 10))) + : SizedBox.shrink() ], ) ], diff --git a/lib/screens/send/receive.dart b/lib/screens/send/receive.dart index cc0a080cf..cee3f010e 100644 --- a/lib/screens/send/receive.dart +++ b/lib/screens/send/receive.dart @@ -13,7 +13,6 @@ import 'package:qr_flutter/qr_flutter.dart'; import 'package:share/share.dart'; class ReceiveScreen extends StatelessWidget { - @override Widget build(BuildContext context) { return new StoreConnector( @@ -26,13 +25,14 @@ class ReceiveScreen extends StatelessWidget { withPadding: false, children: [ Container( + height: MediaQuery.of(context).size.height * 0.7, child: Column( - mainAxisAlignment: MainAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( padding: EdgeInsets.only( - left: 20.0, right: 20.0, bottom: 20.0, top: 20.0), + left: 20.0, right: 20.0, bottom: 20.0, top: 20), child: Text(I18n.of(context).scan_to_receive, textAlign: TextAlign.center, style: TextStyle( @@ -40,38 +40,43 @@ class ReceiveScreen extends StatelessWidget { fontSize: 16, fontWeight: FontWeight.normal)), ), - Center( - child: Container( - width: 200, - child: new QrImage( - data: 'fuse:${viewModel.walletAddress}', - )), - ), - const SizedBox(height: 20.0), - Container( - width: 220, - child: new Text(formatAddress(viewModel.walletAddress), - softWrap: true, - textAlign: TextAlign.center, - style: TextStyle( - color: Theme.of(context).primaryColor, - fontSize: 16, - fontWeight: FontWeight.normal)), - ), - const SizedBox(height: 20.0), - Container( - width: 250, - child: Opacity( - opacity: 0.5, - child: Center( - child: CopyToClipboard( - textColor: Color(0xFF0091ff), - content: viewModel.walletAddress, + Column( + children: [ + Center( + child: Container( + width: 200, + child: new QrImage( + data: 'fuse:${viewModel.walletAddress}', + )), + ), + const SizedBox(height: 20.0), + Container( + width: 220, + child: new Text( + formatAddress(viewModel.walletAddress), + softWrap: true, + textAlign: TextAlign.center, + style: TextStyle( + color: Theme.of(context).primaryColor, + fontSize: 16, + fontWeight: FontWeight.normal)), + ), + const SizedBox(height: 20.0), + Container( + width: 250, + child: Opacity( + opacity: 0.5, + child: Center( + child: CopyToClipboard( + textColor: Color(0xFF0091ff), + content: viewModel.walletAddress, + ), + ), ), ), - ), + ], ), - const SizedBox(height: 30.0), + // const SizedBox(height: 30.0), Center( child: PrimaryButton( fontSize: 15, diff --git a/lib/widgets/activate_pro_mode.dart b/lib/widgets/activate_pro_mode.dart index a89e3257b..bb3395db9 100644 --- a/lib/widgets/activate_pro_mode.dart +++ b/lib/widgets/activate_pro_mode.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:flutter_redux/flutter_redux.dart'; +import 'package:fusecash/models/community.dart'; import 'package:fusecash/redux/actions/user_actions.dart'; import 'package:fusecash/screens/routes.gr.dart'; import 'package:redux/redux.dart'; @@ -51,9 +53,9 @@ class ActivateProModeDialogState extends State borderRadius: BorderRadius.all(Radius.circular(12.0))), content: Stack( children: [ - new StoreConnector( + new StoreConnector( distinct: true, - converter: _ActivateViewModel.fromStore, + converter: ActivateProModeViewModel.fromStore, builder: (_, viewModel) { return Container( padding: EdgeInsets.only(top: 20, bottom: 20), @@ -119,14 +121,18 @@ class ActivateProModeDialogState extends State } } -class _ActivateViewModel { +class ActivateProModeViewModel { final Function activateProMode; - _ActivateViewModel({this.activateProMode}); + final String daiPointsHomeBridgeAddress; + ActivateProModeViewModel({this.activateProMode, this.daiPointsHomeBridgeAddress}); - static _ActivateViewModel fromStore(Store store) { - return _ActivateViewModel( + static ActivateProModeViewModel fromStore(Store store) { + String communityAddres = DotEnv().env['DEFAULT_COMMUNITY_CONTRACT_ADDRESS'].toLowerCase(); + Community community = store.state.cashWalletState.communities[communityAddres]; + return ActivateProModeViewModel( + daiPointsHomeBridgeAddress: community.homeBridgeAddress, activateProMode: () async { store.dispatch(activateProModeCall()); }); } -} +} \ No newline at end of file diff --git a/lib/widgets/activate_pro_mode2.dart b/lib/widgets/activate_pro_mode2.dart index 286784d28..49c9e8130 100644 --- a/lib/widgets/activate_pro_mode2.dart +++ b/lib/widgets/activate_pro_mode2.dart @@ -1,6 +1,10 @@ import 'package:flutter/material.dart'; +import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_svg/svg.dart'; +import 'package:fusecash/models/app_state.dart'; import 'package:fusecash/screens/routes.gr.dart'; +import 'package:fusecash/screens/send/send_amount_arguments.dart'; +import 'package:fusecash/widgets/activate_pro_mode.dart'; import 'dart:core'; import 'package:fusecash/widgets/primary_button.dart'; @@ -77,21 +81,30 @@ class ActivateProMode2DialogState extends State fontSize: 14, fontWeight: FontWeight.normal)), const SizedBox(height: 20.0), - Center( - child: PrimaryButton( - labelFontWeight: FontWeight.normal, - label: 'Close', - fontSize: 15, - onPressed: () { - Router.navigator.pushNamedAndRemoveUntil( - Router.cashHomeScreen, - (Route route) => false); - }, - )) + new StoreConnector( + distinct: true, + converter: ActivateProModeViewModel.fromStore, + builder: (_, viewModel) { + return Center( + child: PrimaryButton( + labelFontWeight: FontWeight.normal, + label: 'Choose amount to transfer', + fontSize: 15, + onPressed: () { + Router.navigator.pushNamed( + Router.sendAmountScreen, + arguments: SendAmountArguments( + sendType: SendType.FUSE_ADDRESS, + accountAddress: viewModel + .daiPointsHomeBridgeAddress)); + }, + )); + }) ], ), ) ], ))); + // }); } } diff --git a/lib/widgets/coming_soon.dart b/lib/widgets/coming_soon.dart index a49ac268a..477d6a61d 100644 --- a/lib/widgets/coming_soon.dart +++ b/lib/widgets/coming_soon.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; void comingSoon(context) { Flushbar( + margin: EdgeInsets.only(bottom: 80), flushbarPosition: FlushbarPosition.BOTTOM, duration: Duration(seconds: 2), messageText: new Text( diff --git a/lib/widgets/drawer.dart b/lib/widgets/drawer.dart index 261eea967..aad8959a5 100644 --- a/lib/widgets/drawer.dart +++ b/lib/widgets/drawer.dart @@ -243,6 +243,7 @@ class _DrawerWidgetState extends State { return Column( children: [ Expanded( + flex: 5, child: ListView( padding: EdgeInsets.all(10), children: [ @@ -253,10 +254,12 @@ class _DrawerWidgetState extends State { ), ), viewModel.isProModeActivate - ? Padding( - child: switchToProMode(viewModel), - padding: EdgeInsets.all(20), - ) + ? Flexible( + flex: 1, + child: Padding( + child: switchToProMode(viewModel), + padding: EdgeInsets.all(20), + )) : SizedBox.shrink(), ], ); diff --git a/pubspec.lock b/pubspec.lock index ccd132aa1..d72e098a5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1054,7 +1054,7 @@ packages: name: wallet_core url: "https://pub.dartlang.org" source: hosted - version: "0.1.2+1" + version: "0.1.2+3" watcher: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index b1234e713..540c7f549 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,7 +24,7 @@ dependencies: redux_logging: ^0.4.0 redux_persist: ^0.8.2 country_code_picker: ^1.2.4 - wallet_core: ^0.1.2+1 + wallet_core: ^0.1.2+3 # wallet_core: # path: ../wallet_core barcode_scan: ^2.0.1