From 757d48f793126b59103ea9d5505df072019fd300 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Wed, 23 Sep 2020 22:31:39 +0300 Subject: [PATCH 1/9] CAKE-45 | created wallet menu item and wallet menu alert; deleted wallet tile; added menuItems to wallet menu; reworked wallet list page (removed slider menu on wallet list screen and used alert instead of this) --- .../screens/wallet_list/wallet_list_page.dart | 151 ++++++++---------- lib/src/screens/wallet_list/wallet_menu.dart | 106 ++++-------- .../screens/wallet_list/wallet_menu_item.dart | 16 ++ .../widgets/wallet_menu_alert.dart | 112 +++++++++++++ .../wallet_list/widgets/wallet_tile.dart | 151 ------------------ 5 files changed, 230 insertions(+), 306 deletions(-) create mode 100644 lib/src/screens/wallet_list/wallet_menu_item.dart create mode 100644 lib/src/screens/wallet_list/widgets/wallet_menu_alert.dart delete mode 100644 lib/src/screens/wallet_list/widgets/wallet_tile.dart diff --git a/lib/src/screens/wallet_list/wallet_list_page.dart b/lib/src/screens/wallet_list/wallet_list_page.dart index 0e743e1c9..4e78642c7 100644 --- a/lib/src/screens/wallet_list/wallet_list_page.dart +++ b/lib/src/screens/wallet_list/wallet_list_page.dart @@ -1,8 +1,8 @@ +import 'package:cake_wallet/src/screens/wallet_list/widgets/wallet_menu_alert.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:cake_wallet/routes.dart'; -import 'package:cake_wallet/palette.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/entities/wallet_type.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart'; @@ -10,7 +10,6 @@ import 'package:cake_wallet/src/widgets/primary_button.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart'; import 'package:cake_wallet/src/screens/wallet_list/wallet_menu.dart'; -import 'package:cake_wallet/src/screens/wallet_list/widgets/wallet_tile.dart'; class WalletListPage extends BasePage { WalletListPage({this.walletListViewModel}); @@ -65,95 +64,83 @@ class WalletListBodyState extends State { itemCount: widget.walletListViewModel.wallets.length, itemBuilder: (__, index) { final wallet = widget.walletListViewModel.wallets[index]; - final screenWidth = MediaQuery.of(context).size.width; final walletMenu = WalletMenu(context, widget.walletListViewModel); final items = walletMenu.generateItemsForWalletMenu(wallet.isCurrent); - final colors = walletMenu - .generateColorsForWalletMenu(wallet.isCurrent); - final images = walletMenu - .generateImagesForWalletMenu(wallet.isCurrent); + final currentColor = wallet.isCurrent + ? Theme.of(context).accentTextTheme.subtitle.decorationColor + : Theme.of(context).backgroundColor; - return Container( - height: tileHeight, - width: double.infinity, - child: CustomScrollView( - scrollDirection: Axis.horizontal, - controller: scrollController, - slivers: [ - SliverPersistentHeader( - pinned: false, - floating: true, - delegate: WalletTile( - min: screenWidth - 170, - max: screenWidth, - image: _imageFor(type: wallet.type), - walletName: wallet.name, - walletAddress: '', //shortAddress, - isCurrent: wallet.isCurrent), - ), - SliverList( - delegate: - SliverChildBuilderDelegate((context, index) { - final item = items[index]; - final image = images[index]; - final firstColor = colors[index*2]; - final secondColor = colors[index*2 + 1]; - - final radius = index == 0 ? 10.0 : 0.0; - - return GestureDetector( - onTap: () { - scrollController.animateTo(0.0, - duration: Duration(milliseconds: 500), - curve: Curves.fastOutSlowIn); - walletMenu.action( - walletMenu.listItems.indexOf(item), - wallet, - wallet.isCurrent); - }, - child: Container( - height: tileHeight, - width: 80, - color: Theme.of(context).backgroundColor, + return GestureDetector( + onTap: () { + showDialog( + context: context, + builder: (dialogContext) { + return WalletMenuAlert( + wallet: wallet, + walletMenu: walletMenu, + items: items); + } + ); + }, + child: Container( + height: tileHeight, + width: double.infinity, + child: Row( + children: [ + Container( + height: tileHeight, + width: 4, + decoration: BoxDecoration( + borderRadius: BorderRadius.only( + topRight: Radius.circular(4), + bottomRight: Radius.circular(4)), + color: currentColor + ), + ), + Expanded( child: Container( - padding: EdgeInsets.only(left: 5, right: 5), - decoration: BoxDecoration( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(radius), - bottomLeft: Radius.circular(radius)), - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - firstColor, - secondColor - ] + height: tileHeight, + padding: EdgeInsets.only(left: 20, right: 20), + color: Theme.of(context).backgroundColor, + alignment: Alignment.centerLeft, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + _imageFor(type: wallet.type), + SizedBox(width: 10), + Text( + wallet.name, + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.w600, + color: Theme.of(context).primaryTextTheme.title.color + ), ) - ), - child: Center( - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - image, - SizedBox(height: 2), - Text( - item, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 7, - fontWeight: FontWeight.w500, - color: Colors.white), - ) - ], - ), + ], ), ), + ), + Container( + height: tileHeight, + width: 10, + decoration: BoxDecoration( + borderRadius: BorderRadius.only( + topLeft: Radius.circular(10), + bottomLeft: Radius.circular(10)), + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [ + Theme.of(context).accentTextTheme.headline.color, + Theme.of(context).accentTextTheme.headline.backgroundColor + ] + ) ), - ); - }, childCount: items.length)) - ], - ), + ), + ], + ), + ) ); }), ), diff --git a/lib/src/screens/wallet_list/wallet_menu.dart b/lib/src/screens/wallet_list/wallet_menu.dart index a508541bd..e5745ccd8 100644 --- a/lib/src/screens/wallet_list/wallet_menu.dart +++ b/lib/src/screens/wallet_list/wallet_menu.dart @@ -1,10 +1,9 @@ +import 'package:cake_wallet/src/screens/wallet_list/wallet_menu_item.dart'; import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/routes.dart'; -import 'package:provider/provider.dart'; import 'package:cake_wallet/generated/i18n.dart'; -// import 'package:cake_wallet/src/stores/wallet_list/wallet_list_store.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart'; import 'package:cake_wallet/src/screens/auth/auth_page.dart'; import 'package:cake_wallet/palette.dart'; @@ -15,85 +14,46 @@ class WalletMenu { final WalletListViewModel walletListViewModel; final BuildContext context; - final List listItems = [ - S.current.wallet_list_load_wallet, - S.current.show_seed, - S.current.remove, - S.current.rescan + final List menuItems = [ + WalletMenuItem( + title: S.current.wallet_list_load_wallet, + firstGradientColor: Palette.cornflower, + secondGradientColor: Palette.royalBlue, + image: Image.asset('assets/images/load.png', + height: 24, width: 24, color: Colors.white)), + WalletMenuItem( + title: S.current.show_seed, + firstGradientColor: Palette.moderateOrangeYellow, + secondGradientColor: Palette.moderateOrange, + image: Image.asset('assets/images/eye_action.png', + height: 24, width: 24, color: Colors.white)), + WalletMenuItem( + title: S.current.remove, + firstGradientColor: Palette.lightRed, + secondGradientColor: Palette.persianRed, + image: Image.asset('assets/images/trash.png', + height: 24, width: 24, color: Colors.white)), + WalletMenuItem( + title: S.current.rescan, + firstGradientColor: Palette.shineGreen, + secondGradientColor: Palette.moderateGreen, + image: Image.asset('assets/images/scanner.png', + height: 24, width: 24, color: Colors.white)) ]; - final List firstColors = [ - Palette.cornflower, - Palette.moderateOrangeYellow, - Palette.lightRed, - Palette.shineGreen - ]; + List generateItemsForWalletMenu(bool isCurrentWallet) { + final items = List(); - final List secondColors = [ - Palette.royalBlue, - Palette.moderateOrange, - Palette.persianRed, - Palette.moderateGreen - ]; - - final List listImages = [ - Image.asset('assets/images/load.png', - height: 24, width: 24, color: Colors.white), - Image.asset('assets/images/eye_action.png', - height: 24, width: 24, color: Colors.white), - Image.asset('assets/images/trash.png', - height: 24, width: 24, color: Colors.white), - Image.asset('assets/images/scanner.png', - height: 24, width: 24, color: Colors.white) - ]; - - List generateItemsForWalletMenu(bool isCurrentWallet) { - final items = List(); - - if (!isCurrentWallet) items.add(listItems[0]); - if (isCurrentWallet) items.add(listItems[1]); - if (!isCurrentWallet) items.add(listItems[2]); - if (isCurrentWallet) items.add(listItems[3]); + if (!isCurrentWallet) items.add(menuItems[0]); + if (isCurrentWallet) items.add(menuItems[1]); + if (!isCurrentWallet) items.add(menuItems[2]); + if (isCurrentWallet) items.add(menuItems[3]); return items; } - List generateColorsForWalletMenu(bool isCurrentWallet) { - final colors = []; - - if (!isCurrentWallet) { - colors.add(firstColors[0]); - colors.add(secondColors[0]); - } - if (isCurrentWallet) { - colors.add(firstColors[1]); - colors.add(secondColors[1]); - } - if (!isCurrentWallet) { - colors.add(firstColors[2]); - colors.add(secondColors[2]); - } - if (isCurrentWallet) { - colors.add(firstColors[3]); - colors.add(secondColors[3]); - } - - return colors; - } - - List generateImagesForWalletMenu(bool isCurrentWallet) { - final images = []; - - if (!isCurrentWallet) images.add(listImages[0]); - if (isCurrentWallet) images.add(listImages[1]); - if (!isCurrentWallet) images.add(listImages[2]); - if (isCurrentWallet) images.add(listImages[3]); - - return images; - } - Future action( - int index, WalletListItem wallet, bool isCurrentWallet) async { + int index, WalletListItem wallet) async { switch (index) { case 0: await Navigator.of(context).pushNamed(Routes.auth, arguments: diff --git a/lib/src/screens/wallet_list/wallet_menu_item.dart b/lib/src/screens/wallet_list/wallet_menu_item.dart new file mode 100644 index 000000000..55e7189c5 --- /dev/null +++ b/lib/src/screens/wallet_list/wallet_menu_item.dart @@ -0,0 +1,16 @@ +import 'dart:ui'; +import 'package:flutter/cupertino.dart'; + +class WalletMenuItem { + WalletMenuItem({ + @required this.title, + @required this.firstGradientColor, + @required this.secondGradientColor, + @required this.image + }); + + final String title; + final Color firstGradientColor; + final Color secondGradientColor; + final Image image; +} \ No newline at end of file diff --git a/lib/src/screens/wallet_list/widgets/wallet_menu_alert.dart b/lib/src/screens/wallet_list/widgets/wallet_menu_alert.dart new file mode 100644 index 000000000..cafb27516 --- /dev/null +++ b/lib/src/screens/wallet_list/widgets/wallet_menu_alert.dart @@ -0,0 +1,112 @@ +import 'dart:ui'; +import 'package:cake_wallet/palette.dart'; +import 'package:cake_wallet/src/screens/wallet_list/wallet_menu.dart'; +import 'package:cake_wallet/src/screens/wallet_list/wallet_menu_item.dart'; +import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:cake_wallet/src/widgets/alert_background.dart'; +import 'package:cake_wallet/src/widgets/alert_close_button.dart'; + +class WalletMenuAlert extends StatelessWidget { + WalletMenuAlert({ + @required this.wallet, + @required this.walletMenu, + @required this.items + }); + + final WalletListItem wallet; + final WalletMenu walletMenu; + final List items; + final closeButton = Image.asset('assets/images/close.png', + color: Palette.darkBlueCraiola, + ); + + @override + Widget build(BuildContext context) { + return AlertBackground( + child: Stack( + alignment: Alignment.center, + children: [ + Padding( + padding: EdgeInsets.only( + left: 24, + right: 24, + ), + child: ClipRRect( + borderRadius: BorderRadius.all(Radius.circular(14)), + child: Container( + color: Theme.of(context).textTheme.body2.decorationColor, + padding: EdgeInsets.only(left: 24), + child: ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemCount: items.length, + separatorBuilder: (context, _) => Container( + height: 1, + color: Theme.of(context).accentTextTheme.subhead.backgroundColor, + ), + itemBuilder: (_, index) { + final item = items[index]; + + return GestureDetector( + onTap: () { + Navigator.of(context).pop(); + walletMenu.action( + walletMenu.menuItems.indexOf(item), + wallet); + }, + child: Container( + padding: EdgeInsets.only(top: 12, bottom: 12), + child: Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + height: 56, + width: 56, + decoration: BoxDecoration( + borderRadius: BorderRadius.all( + Radius.circular(12)), + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [ + item.firstGradientColor, + item.secondGradientColor + ] + ) + ), + child: Center( + child: item.image, + ), + ), + SizedBox(width: 12), + Expanded( + child: Text( + item.title, + style: TextStyle( + color: Theme.of(context).primaryTextTheme.title.color, + fontSize: 18, + fontFamily: 'Poppins', + fontWeight: FontWeight.w500, + decoration: TextDecoration.none + ), + ) + ) + ], + ), + ), + ); + }, + ), + ), + ), + ), + AlertCloseButton(image: closeButton) + ], + ), + ); + } +} \ No newline at end of file diff --git a/lib/src/screens/wallet_list/widgets/wallet_tile.dart b/lib/src/screens/wallet_list/widgets/wallet_tile.dart deleted file mode 100644 index 4e4165341..000000000 --- a/lib/src/screens/wallet_list/widgets/wallet_tile.dart +++ /dev/null @@ -1,151 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter/cupertino.dart'; - -class WalletTile extends SliverPersistentHeaderDelegate { - WalletTile({ - @required this.min, - @required this.max, - @required this.image, - @required this.walletName, - @required this.walletAddress, - @required this.isCurrent - }); - - final double min; - final double max; - final Image image; - final String walletName; - final String walletAddress; - final bool isCurrent; - final double tileHeight = 60; - - @override - Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) { - var opacity = 1 - shrinkOffset / (max - min); - opacity = opacity >= 0 ? opacity : 0; - - var panelWidth = 10 * opacity; - panelWidth = panelWidth < 10 ? 0 : 10; - - final currentColor = isCurrent - ? Theme.of(context).accentTextTheme.subtitle.decorationColor - : Theme.of(context).backgroundColor; - - return Stack( - fit: StackFit.expand, - overflow: Overflow.visible, - children: [ - Positioned( - top: 0, - right: max - 4, - child: Container( - height: tileHeight, - width: 4, - decoration: BoxDecoration( - borderRadius: BorderRadius.only(topRight: Radius.circular(4), bottomRight: Radius.circular(4)), - color: currentColor - ), - ), - ), - Positioned( - top: 0, - right: 10, - child: Container( - height: tileHeight, - width: max - 14, - padding: EdgeInsets.only(left: 20, right: 20), - color: Theme.of(context).backgroundColor, - alignment: Alignment.centerLeft, - child: Row( - //mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - image, - SizedBox(width: 10), - Text( - walletName, - style: TextStyle( - fontSize: 22, - fontWeight: FontWeight.w600, - color: Theme.of(context).primaryTextTheme.title.color - ), - ) - ], - ), - /*Column( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - image, - SizedBox(width: 10), - Text( - walletName, - style: TextStyle( - fontSize: 22, - fontWeight: FontWeight.bold, - color: Theme.of(context).primaryTextTheme.title.color - ), - ) - ], - ), - isCurrent ? SizedBox(height: 5) : Offstage(), - isCurrent - ? Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - SizedBox(width: 34), - Text( - walletAddress, - style: TextStyle( - fontSize: 12, - color: Theme.of(context).primaryTextTheme.caption.color - ), - ) - ], - ) - : Offstage() - ], - ),*/ - ), - ), - Positioned( - top: 0, - right: 0, - child: Opacity( - opacity: opacity, - child: Container( - height: tileHeight, - width: panelWidth, - decoration: BoxDecoration( - borderRadius: BorderRadius.only(topLeft: Radius.circular(10), bottomLeft: Radius.circular(10)), - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - Theme.of(context).accentTextTheme.headline.color, - Theme.of(context).accentTextTheme.headline.backgroundColor - ] - ) - ), - ), - ) - ), - ], - ); - } - - @override - double get maxExtent => max; - - @override - double get minExtent => min; - - @override - bool shouldRebuild(SliverPersistentHeaderDelegate oldDelegate) => true; - -} \ No newline at end of file From 83ef5c179db0352516caff7be118806fcc9ca422 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Thu, 24 Sep 2020 20:46:48 +0300 Subject: [PATCH 2/9] CAKE-45 | changed wallet list tile (wallet list page); changed wallet menu tile (wallet menu alert) --- .../screens/wallet_list/wallet_list_page.dart | 17 ----------------- .../wallet_list/widgets/wallet_menu_alert.dart | 8 ++++---- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/lib/src/screens/wallet_list/wallet_list_page.dart b/lib/src/screens/wallet_list/wallet_list_page.dart index 4e78642c7..694c338e4 100644 --- a/lib/src/screens/wallet_list/wallet_list_page.dart +++ b/lib/src/screens/wallet_list/wallet_list_page.dart @@ -121,23 +121,6 @@ class WalletListBodyState extends State { ), ), ), - Container( - height: tileHeight, - width: 10, - decoration: BoxDecoration( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(10), - bottomLeft: Radius.circular(10)), - gradient: LinearGradient( - begin: Alignment.topCenter, - end: Alignment.bottomCenter, - colors: [ - Theme.of(context).accentTextTheme.headline.color, - Theme.of(context).accentTextTheme.headline.backgroundColor - ] - ) - ), - ), ], ), ) diff --git a/lib/src/screens/wallet_list/widgets/wallet_menu_alert.dart b/lib/src/screens/wallet_list/widgets/wallet_menu_alert.dart index cafb27516..e5f68597f 100644 --- a/lib/src/screens/wallet_list/widgets/wallet_menu_alert.dart +++ b/lib/src/screens/wallet_list/widgets/wallet_menu_alert.dart @@ -57,18 +57,18 @@ class WalletMenuAlert extends StatelessWidget { wallet); }, child: Container( - padding: EdgeInsets.only(top: 12, bottom: 12), + height: 60, child: Row( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( - height: 56, - width: 56, + height: 32, + width: 32, decoration: BoxDecoration( borderRadius: BorderRadius.all( - Radius.circular(12)), + Radius.circular(4)), gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, From 9c1f726c43cd739906f9aa0e7aa3c0ee01dff969 Mon Sep 17 00:00:00 2001 From: M Date: Fri, 25 Sep 2020 13:26:08 +0300 Subject: [PATCH 3/9] Changed to closable auth screens. Added alert with confirmation for new wallet's seed have written. --- lib/di.dart | 6 +- lib/router.dart | 6 +- lib/src/screens/auth/auth_page.dart | 10 +- lib/src/screens/seed/wallet_seed_page.dart | 192 +++++++++++++-------- 4 files changed, 132 insertions(+), 82 deletions(-) diff --git a/lib/di.dart b/lib/di.dart index 697e40e22..2010a6158 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -195,9 +195,9 @@ Future setup( instanceName: 'login'); getIt - .registerFactoryParam( - (onAuthFinished, _) => AuthPage(getIt.get(), - onAuthenticationFinished: onAuthFinished, closable: false)); + .registerFactoryParam( + (onAuthFinished, closable) => AuthPage(getIt.get(), + onAuthenticationFinished: onAuthFinished, closable: closable ?? false)); getIt.registerFactory(() => DashboardPage( walletViewModel: getIt.get(), diff --git a/lib/router.dart b/lib/router.dart index e7f9330d8..5ae418395 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -215,13 +215,15 @@ class Router { return MaterialPageRoute( fullscreenDialog: true, builder: (_) => getIt.get( - param1: settings.arguments as OnAuthenticationFinished)); + param1: settings.arguments as OnAuthenticationFinished, + param2: true)); case Routes.unlock: return MaterialPageRoute( fullscreenDialog: true, builder: (_) => getIt.get( - param1: settings.arguments as OnAuthenticationFinished)); + param1: settings.arguments as OnAuthenticationFinished, + param2: false)); case Routes.nodeList: return CupertinoPageRoute( diff --git a/lib/src/screens/auth/auth_page.dart b/lib/src/screens/auth/auth_page.dart index 13c74f6e1..37f03f5c3 100644 --- a/lib/src/screens/auth/auth_page.dart +++ b/lib/src/screens/auth/auth_page.dart @@ -27,7 +27,7 @@ class AuthPageState extends State { final _key = GlobalKey(); final _pinCodeKey = GlobalKey(); final _backArrowImageDarkTheme = - Image.asset('assets/images/back_arrow_dark_theme.png'); + Image.asset('assets/images/close_button.png'); ReactionDisposer _reaction; @override @@ -122,9 +122,11 @@ class AuthPageState extends State { key: _key, appBar: CupertinoNavigationBar( leading: widget.closable - ? SizedBox( + ? Container( + padding: EdgeInsets.only(top: 10), + child: SizedBox( height: 37, - width: 20, + width: 37, child: ButtonTheme( minWidth: double.minPositive, child: FlatButton( @@ -134,7 +136,7 @@ class AuthPageState extends State { onPressed: () => Navigator.of(context).pop(), child: _backArrowImageDarkTheme), ), - ) + )) : Container(), backgroundColor: Theme.of(context).backgroundColor, border: null), diff --git a/lib/src/screens/seed/wallet_seed_page.dart b/lib/src/screens/seed/wallet_seed_page.dart index ed5746d55..6e6088bdd 100644 --- a/lib/src/screens/seed/wallet_seed_page.dart +++ b/lib/src/screens/seed/wallet_seed_page.dart @@ -1,5 +1,6 @@ import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/palette.dart'; +import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/store/settings_store.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -24,9 +25,28 @@ class WalletSeedPage extends BasePage { final WalletSeedViewModel walletSeedViewModel; @override - void onClose(BuildContext context) => isNewWalletCreated - ? Navigator.of(context).popUntil((route) => route.isFirst) - : Navigator.of(context).pop(); + void onClose(BuildContext context) async { + if (isNewWalletCreated) { + final confirmed = await showDialog(context: context, builder: (BuildContext context) { + // FIXME: add translations + return AlertWithTwoActions( + alertTitle: 'Attention', + alertContent: 'Have you written it down? The seed is the only way to recover your wallet.', + leftButtonText: 'Not yet', + rightButtonText: 'Yes, I have', + actionLeftButton: () => Navigator.of(context).pop(false), + actionRightButton: () => Navigator.of(context).pop(true)); + }) ?? false; + + if (confirmed) { + Navigator.of(context).popUntil((route) => route.isFirst); + } + + return; + } + + Navigator.of(context).pop(); + } @override Widget leading(BuildContext context) => @@ -36,31 +56,39 @@ class WalletSeedPage extends BasePage { Widget trailing(BuildContext context) { return isNewWalletCreated ? GestureDetector( - onTap: () => onClose(context), - child: Container( - width: 100, - height: 32, - alignment: Alignment.center, - margin: EdgeInsets.only(left: 10), - decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(16)), - color: Theme.of(context).accentTextTheme.caption.color), - child: Text( - S.of(context).seed_language_next, - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w600, - color: Palette.blueCraiola), - ), - ), - ) + onTap: () => onClose(context), + child: Container( + width: 100, + height: 32, + alignment: Alignment.center, + margin: EdgeInsets.only(left: 10), + decoration: BoxDecoration( + borderRadius: BorderRadius.all(Radius.circular(16)), + color: Theme + .of(context) + .accentTextTheme + .caption + .color), + child: Text( + S + .of(context) + .seed_language_next, + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w600, + color: Palette.blueCraiola), + ), + ), + ) : Offstage(); } @override Widget body(BuildContext context) { final image = - getIt.get().isDarkTheme ? imageDark : imageLight; + getIt + .get() + .isDarkTheme ? imageDark : imageLight; return Container( padding: EdgeInsets.all(24), @@ -87,21 +115,23 @@ class WalletSeedPage extends BasePage { style: TextStyle( fontSize: 20, fontWeight: FontWeight.w600, - color: Theme.of(context) + color: Theme + .of(context) .primaryTextTheme .title .color), ), Padding( padding: - EdgeInsets.only(top: 20, left: 16, right: 16), + EdgeInsets.only(top: 20, left: 16, right: 16), child: Text( walletSeedViewModel.seed, textAlign: TextAlign.center, style: TextStyle( fontSize: 14, fontWeight: FontWeight.normal, - color: Theme.of(context) + color: Theme + .of(context) .primaryTextTheme .caption .color), @@ -115,62 +145,78 @@ class WalletSeedPage extends BasePage { children: [ isNewWalletCreated ? Padding( - padding: EdgeInsets.only( - bottom: 52, left: 43, right: 43), - child: Text( - S.of(context).seed_reminder, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.normal, - color: Theme.of(context) - .primaryTextTheme - .overline - .color), - ), - ) + padding: EdgeInsets.only( + bottom: 52, left: 43, right: 43), + child: Text( + S + .of(context) + .seed_reminder, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.normal, + color: Theme + .of(context) + .primaryTextTheme + .overline + .color), + ), + ) : Offstage(), Row( mainAxisSize: MainAxisSize.max, children: [ Flexible( child: Container( - padding: EdgeInsets.only(right: 8.0), - child: PrimaryButton( - onPressed: () => Share.text( - S.of(context).seed_share, - walletSeedViewModel.seed, - 'text/plain'), - text: S.of(context).save, - color: Colors.green, - textColor: Colors.white), - )), + padding: EdgeInsets.only(right: 8.0), + child: PrimaryButton( + onPressed: () => + Share.text( + S + .of(context) + .seed_share, + walletSeedViewModel.seed, + 'text/plain'), + text: S + .of(context) + .save, + color: Colors.green, + textColor: Colors.white), + )), Flexible( child: Container( - padding: EdgeInsets.only(left: 8.0), - child: Builder( - builder: (context) => PrimaryButton( - onPressed: () { - Clipboard.setData(ClipboardData( - text: walletSeedViewModel.seed)); - Scaffold.of(context).showSnackBar( - SnackBar( - content: Text(S - .of(context) - .copied_to_clipboard), - backgroundColor: Colors.green, - duration: - Duration(milliseconds: 1500), - ), - ); - }, - text: S.of(context).copy, - color: Theme.of(context) - .accentTextTheme - .body2 - .color, - textColor: Colors.white)), - )) + padding: EdgeInsets.only(left: 8.0), + child: Builder( + builder: (context) => + PrimaryButton( + onPressed: () { + Clipboard.setData(ClipboardData( + text: walletSeedViewModel + .seed)); + Scaffold.of(context) + .showSnackBar( + SnackBar( + content: Text(S + .of(context) + .copied_to_clipboard), + backgroundColor: Colors + .green, + duration: + Duration( + milliseconds: 1500), + ), + ); + }, + text: S + .of(context) + .copy, + color: Theme + .of(context) + .accentTextTheme + .body2 + .color, + textColor: Colors.white)), + )) ], ) ], From dcbaf01118cdd0dc6198617feebbd024368738b9 Mon Sep 17 00:00:00 2001 From: M Date: Fri, 25 Sep 2020 14:25:08 +0300 Subject: [PATCH 4/9] Fixes mergina and peddings for actions button on dashboard screen --- lib/src/screens/dashboard/dashboard_page.dart | 31 +++++++------------ .../dashboard/widgets/action_button.dart | 2 -- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/lib/src/screens/dashboard/dashboard_page.dart b/lib/src/screens/dashboard/dashboard_page.dart index fc538834a..16cce7518 100644 --- a/lib/src/screens/dashboard/dashboard_page.dart +++ b/lib/src/screens/dashboard/dashboard_page.dart @@ -103,28 +103,21 @@ class DashboardPage extends BasePage { activeDotColor: Colors.white), )), Container( - width: double.infinity, - padding: EdgeInsets.only( - left: 45, - right: 45, - bottom: 24 - ), + padding: EdgeInsets.only(left: 45, right: 45, bottom: 24), child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Flexible( - child: ActionButton( - image: sendImage, - title: S.of(context).send, - route: Routes.send, - alignment: Alignment.centerLeft, - ), + ActionButton( + image: sendImage, + title: S.of(context).send, + route: Routes.send, + alignment: Alignment.centerLeft, ), - Flexible( - child: ActionButton( - image: exchangeImage, - title: S.of(context).exchange, - route: Routes.exchange - ), + ActionButton( + image: sendImage, + title: S.of(context).send, + route: Routes.send, + alignment: Alignment.centerLeft, ), ], ), diff --git a/lib/src/screens/dashboard/widgets/action_button.dart b/lib/src/screens/dashboard/widgets/action_button.dart index 3cf1d6ded..dc9a64bbf 100644 --- a/lib/src/screens/dashboard/widgets/action_button.dart +++ b/lib/src/screens/dashboard/widgets/action_button.dart @@ -15,8 +15,6 @@ class ActionButton extends StatelessWidget { @override Widget build(BuildContext context) { return Container( - width: double.infinity, - height: 93, alignment: alignment, child: Column( mainAxisSize: MainAxisSize.max, From 34aa7fdc7667bc53fdc12ef21e562eb87d7c70c2 Mon Sep 17 00:00:00 2001 From: M Date: Fri, 25 Sep 2020 18:32:44 +0300 Subject: [PATCH 5/9] Fixes pre release. --- lib/monero/monero_wallet.dart | 2 +- .../screens/contact/contact_list_page.dart | 5 +- lib/src/screens/contact/contact_page.dart | 5 +- lib/src/screens/dashboard/wallet_menu.dart | 3 +- .../screens/dashboard/widgets/header_row.dart | 3 +- .../screens/disclaimer/disclaimer_page.dart | 3 +- lib/src/screens/exchange/exchange_page.dart | 5 +- .../exchange/widgets/exchange_card.dart | 3 +- .../widgets/present_provider_picker.dart | 3 +- .../exchange_trade/exchange_trade_page.dart | 9 +- .../screens/new_wallet/new_wallet_page.dart | 3 +- lib/src/screens/nodes/nodes_list_page.dart | 7 +- lib/src/screens/pin_code/pin_code_widget.dart | 2 +- lib/src/screens/receive/receive_page.dart | 85 ++++++++++--------- .../restore_wallet_from_keys_page.dart | 2 +- .../restore_wallet_from_seed_details.dart | 3 +- lib/src/screens/seed/wallet_seed_page.dart | 7 +- lib/src/screens/send/send_page.dart | 13 +-- lib/src/screens/settings/change_language.dart | 2 +- .../widgets/settings_picker_cell.dart | 3 +- .../setup_pin_code/setup_pin_code.dart | 7 +- lib/src/screens/wallet_list/wallet_menu.dart | 3 +- lib/src/widgets/seed_language_selector.dart | 3 +- lib/utils/show_pop_up.dart | 22 +++++ .../wallet_list/wallet_list_view_model.dart | 2 +- 25 files changed, 124 insertions(+), 81 deletions(-) create mode 100644 lib/utils/show_pop_up.dart diff --git a/lib/monero/monero_wallet.dart b/lib/monero/monero_wallet.dart index 6f0ea6d79..4a053b788 100644 --- a/lib/monero/monero_wallet.dart +++ b/lib/monero/monero_wallet.dart @@ -191,7 +191,7 @@ abstract class MoneroWalletBase extends WalletBase with Store { @override Future rescan({int height}) async { - // FIXME: Unimplemented + monero_wallet.rescanBlockchainAsync(); } void _setListeners() { diff --git a/lib/src/screens/contact/contact_list_page.dart b/lib/src/screens/contact/contact_list_page.dart index dc1d14b72..8cae22f85 100644 --- a/lib/src/screens/contact/contact_list_page.dart +++ b/lib/src/screens/contact/contact_list_page.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; @@ -246,7 +247,7 @@ class ContactListPage extends BasePage { } Future showAlertDialog(BuildContext context) async { - return await showDialog( + return await showPopUp( context: context, builder: (BuildContext context) { return AlertWithTwoActions( @@ -261,7 +262,7 @@ class ContactListPage extends BasePage { Future showNameAndAddressDialog( BuildContext context, String name, String address) async { - return await showDialog( + return await showPopUp( context: context, builder: (BuildContext context) { return AlertWithTwoActions( diff --git a/lib/src/screens/contact/contact_page.dart b/lib/src/screens/contact/contact_page.dart index e73760ce1..a65a86e29 100644 --- a/lib/src/screens/contact/contact_page.dart +++ b/lib/src/screens/contact/contact_page.dart @@ -1,4 +1,5 @@ import 'package:cake_wallet/palette.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; @@ -138,7 +139,7 @@ class ContactPage extends BasePage { } void _presentCurrencyPicker(BuildContext context) { - showDialog( + showPopUp( builder: (_) => CurrencyPicker( selectedAtIndex: contactViewModel.currencies.indexOf(contactViewModel.currency), @@ -150,7 +151,7 @@ class ContactPage extends BasePage { } void _onContactSavingFailure(BuildContext context, String error) { - showDialog( + showPopUp( context: context, builder: (BuildContext context) { return AlertWithOneAction( diff --git a/lib/src/screens/dashboard/wallet_menu.dart b/lib/src/screens/dashboard/wallet_menu.dart index 1eb3864d0..d06068c89 100644 --- a/lib/src/screens/dashboard/wallet_menu.dart +++ b/lib/src/screens/dashboard/wallet_menu.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/routes.dart'; import 'package:provider/provider.dart'; @@ -72,7 +73,7 @@ class WalletMenu { } Future _presentReconnectAlert(BuildContext context) async { - await showDialog( + await showPopUp( context: context, builder: (BuildContext context) { return AlertWithTwoActions( diff --git a/lib/src/screens/dashboard/widgets/header_row.dart b/lib/src/screens/dashboard/widgets/header_row.dart index a878ff11f..5b63f7a0e 100644 --- a/lib/src/screens/dashboard/widgets/header_row.dart +++ b/lib/src/screens/dashboard/widgets/header_row.dart @@ -1,4 +1,5 @@ import 'package:cake_wallet/src/screens/dashboard/widgets/filter_widget.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; @@ -31,7 +32,7 @@ class HeaderRow extends StatelessWidget { ), GestureDetector( onTap: () { - showDialog( + showPopUp( context: context, builder: (context) => FilterWidget(dashboardViewModel: dashboardViewModel) ); diff --git a/lib/src/screens/disclaimer/disclaimer_page.dart b/lib/src/screens/disclaimer/disclaimer_page.dart index fde5677e7..b80a7a1fe 100644 --- a/lib/src/screens/disclaimer/disclaimer_page.dart +++ b/lib/src/screens/disclaimer/disclaimer_page.dart @@ -1,5 +1,6 @@ import 'dart:ui'; import 'package:cake_wallet/palette.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; @@ -51,7 +52,7 @@ class DisclaimerBodyState extends State { } Future _showAlertDialog(BuildContext context) async { - await showDialog( + await showPopUp( context: context, builder: (BuildContext context) { return AlertWithOneAction( diff --git a/lib/src/screens/exchange/exchange_page.dart b/lib/src/screens/exchange/exchange_page.dart index 1cabcc448..a602fc995 100644 --- a/lib/src/screens/exchange/exchange_page.dart +++ b/lib/src/screens/exchange/exchange_page.dart @@ -4,6 +4,7 @@ import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/src/widgets/template_tile.dart'; import 'package:cake_wallet/src/widgets/trail_button.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:dotted_border/dotted_border.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -293,7 +294,7 @@ class ExchangePage extends BasePage { exchangeViewModel, template); }, onRemove: () { - showDialog( + showPopUp( context: context, builder: (dialogContext) { return AlertWithTwoActions( @@ -492,7 +493,7 @@ class ExchangePage extends BasePage { // reaction((_) => exchangeViewModel.tradeState, (ExchangeTradeState state) { // if (state is TradeIsCreatedFailure) { // WidgetsBinding.instance.addPostFrameCallback((_) { - // showDialog( + // showPopUp( // context: context, // builder: (BuildContext context) { // return AlertWithOneAction( diff --git a/lib/src/screens/exchange/widgets/exchange_card.dart b/lib/src/screens/exchange/widgets/exchange_card.dart index 1836ec912..28c7980f8 100644 --- a/lib/src/screens/exchange/widgets/exchange_card.dart +++ b/lib/src/screens/exchange/widgets/exchange_card.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/generated/i18n.dart'; @@ -303,7 +304,7 @@ class ExchangeCardState extends State { } void _presentPicker(BuildContext context) { - showDialog( + showPopUp( builder: (_) => CurrencyPicker( selectedAtIndex: widget.currencies.indexOf(_selectedCurrency), items: widget.currencies, diff --git a/lib/src/screens/exchange/widgets/present_provider_picker.dart b/lib/src/screens/exchange/widgets/present_provider_picker.dart index b8154632e..f4cc7abf1 100644 --- a/lib/src/screens/exchange/widgets/present_provider_picker.dart +++ b/lib/src/screens/exchange/widgets/present_provider_picker.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/exchange/exchange_provider_description.dart'; import 'package:cake_wallet/exchange/exchange_provider.dart'; @@ -72,7 +73,7 @@ class PresentProviderPicker extends StatelessWidget { } } - showDialog( + showPopUp( builder: (_) => Picker( items: items, images: images, diff --git a/lib/src/screens/exchange_trade/exchange_trade_page.dart b/lib/src/screens/exchange_trade/exchange_trade_page.dart index 545492e09..945bb298d 100644 --- a/lib/src/screens/exchange_trade/exchange_trade_page.dart +++ b/lib/src/screens/exchange_trade/exchange_trade_page.dart @@ -4,6 +4,7 @@ import 'package:cake_wallet/exchange/exchange_provider_description.dart'; import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_item.dart'; import 'package:cake_wallet/src/screens/exchange_trade/information_page.dart'; import 'package:cake_wallet/src/widgets/standart_list_row.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/view_model/exchange/exchange_trade_view_model.dart'; import 'package:mobx/mobx.dart'; import 'package:provider/provider.dart'; @@ -37,7 +38,7 @@ void showInformation(ExchangeTradeViewModel exchangeTradeViewModel, BuildContext : S.current.exchange_result_description( trade.amount ?? fetchingLabel, trade.from.toString()); - showDialog( + showPopUp( context: context, builder: (_) => InformationPage(information: information) ); @@ -255,7 +256,7 @@ class ExchangeTradeState extends State { reaction((_) => sendStore.state, (SendingState state) { if (state is SendingFailed) { WidgetsBinding.instance.addPostFrameCallback((_) { - showDialog( + showPopUp( context: context, builder: (BuildContext context) { return AlertWithOneAction( @@ -270,7 +271,7 @@ class ExchangeTradeState extends State { if (state is TransactionCreatedSuccessfully) { WidgetsBinding.instance.addPostFrameCallback((_) { - showDialog( + showPopUp( context: context, builder: (BuildContext context) { return AlertWithTwoActions( @@ -292,7 +293,7 @@ class ExchangeTradeState extends State { if (state is TransactionCommitted) { WidgetsBinding.instance.addPostFrameCallback((_) { - showDialog( + showPopUp( context: context, builder: (BuildContext context) { return AlertWithOneAction( diff --git a/lib/src/screens/new_wallet/new_wallet_page.dart b/lib/src/screens/new_wallet/new_wallet_page.dart index 9512a3753..9300b9c3a 100644 --- a/lib/src/screens/new_wallet/new_wallet_page.dart +++ b/lib/src/screens/new_wallet/new_wallet_page.dart @@ -1,6 +1,7 @@ import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/store/settings_store.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:mobx/mobx.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:flutter/material.dart'; @@ -60,7 +61,7 @@ class _WalletNameFormState extends State { if (state is FailureState) { WidgetsBinding.instance.addPostFrameCallback((_) { - showDialog( + showPopUp( context: context, builder: (_) { return AlertWithOneAction( diff --git a/lib/src/screens/nodes/nodes_list_page.dart b/lib/src/screens/nodes/nodes_list_page.dart index dd713d430..84e87a3a5 100644 --- a/lib/src/screens/nodes/nodes_list_page.dart +++ b/lib/src/screens/nodes/nodes_list_page.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; @@ -29,7 +30,7 @@ class NodeListPage extends BasePage { minWidth: double.minPositive, child: FlatButton( onPressed: () async { - await showDialog( + await showPopUp( context: context, builder: (BuildContext context) { return AlertWithTwoActions( @@ -83,7 +84,7 @@ class NodeListPage extends BasePage { return; } - await showDialog( + await showPopUp( context: context, builder: (BuildContext context) { return AlertDialog( @@ -110,7 +111,7 @@ class NodeListPage extends BasePage { final dismissibleRow = Dismissible( key: Key('${node.keyIndex}'), confirmDismiss: (direction) async { - return await showDialog( + return await showPopUp( context: context, builder: (BuildContext context) { return AlertWithTwoActions( diff --git a/lib/src/screens/pin_code/pin_code_widget.dart b/lib/src/screens/pin_code/pin_code_widget.dart index e4e17dae3..6cb0a9714 100644 --- a/lib/src/screens/pin_code/pin_code_widget.dart +++ b/lib/src/screens/pin_code/pin_code_widget.dart @@ -266,7 +266,7 @@ class PinCodeState extends State { return; } - pin.substring(0, pin.length - 1); + setState(() => pin = pin.substring(0, pin.length - 1)); } String _changePinLengthText() { diff --git a/lib/src/screens/receive/receive_page.dart b/lib/src/screens/receive/receive_page.dart index fbae17324..b7b06fcdb 100644 --- a/lib/src/screens/receive/receive_page.dart +++ b/lib/src/screens/receive/receive_page.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; @@ -34,21 +35,19 @@ class ReceivePage extends BasePage { @override Widget Function(BuildContext, Widget) get rootWrapper => - (BuildContext context, Widget scaffold) => Container( + (BuildContext context, Widget scaffold) => Container( decoration: BoxDecoration( gradient: LinearGradient(colors: [ - Theme.of(context).accentColor, - Theme.of(context).scaffoldBackgroundColor, - Theme.of(context).primaryColor, - ], - begin: Alignment.topRight, - end: Alignment.bottomLeft)), + Theme.of(context).accentColor, + Theme.of(context).scaffoldBackgroundColor, + Theme.of(context).primaryColor, + ], begin: Alignment.topRight, end: Alignment.bottomLeft)), child: scaffold); @override Widget trailing(BuildContext context) { - final shareImage = Image.asset('assets/images/share.png', - color: Colors.white); + final shareImage = + Image.asset('assets/images/share.png', color: Colors.white); return SizedBox( height: 20.0, @@ -56,12 +55,12 @@ class ReceivePage extends BasePage { child: ButtonTheme( minWidth: double.minPositive, child: FlatButton( - highlightColor: Colors.transparent, - splashColor: Colors.transparent, - padding: EdgeInsets.all(0), - onPressed: () => Share.text(S.current.share_address, - addressListViewModel.address.address, 'text/plain'), - child: shareImage), + highlightColor: Colors.transparent, + splashColor: Colors.transparent, + padding: EdgeInsets.all(0), + onPressed: () => Share.text(S.current.share_address, + addressListViewModel.address.address, 'text/plain'), + child: shareImage), ), ); } @@ -80,10 +79,9 @@ class ReceivePage extends BasePage { ), Observer( builder: (_) => ListView.separated( - separatorBuilder: (context, _) => - Container( - height: 1, - color: Theme.of(context).dividerColor), + padding: EdgeInsets.all(0), + separatorBuilder: (context, _) => Container( + height: 1, color: Theme.of(context).dividerColor), shrinkWrap: true, physics: NeverScrollableScrollPhysics(), itemCount: addressListViewModel.items.length, @@ -93,9 +91,10 @@ class ReceivePage extends BasePage { if (item is WalletAccountListHeader) { cell = HeaderTile( - onTap: () async => await showDialog( + onTap: () async => await showPopUp( context: context, - builder: (_) => getIt.get()), + builder: (_) => + getIt.get()), title: addressListViewModel.accountLabel, icon: Icon( Icons.arrow_forward_ios, @@ -117,27 +116,31 @@ class ReceivePage extends BasePage { } if (item is WalletAddressListItem) { - cell = Observer( - builder: (_) { - final isCurrent = item.address == - addressListViewModel.address.address; - final backgroundColor = isCurrent - ? Theme.of(context).textTheme.display3.decorationColor - : Theme.of(context).textTheme.display2.decorationColor; - final textColor = isCurrent - ? Theme.of(context).textTheme.display3.color - : Theme.of(context).textTheme.display2.color; + cell = Observer(builder: (_) { + final isCurrent = item.address == + addressListViewModel.address.address; + final backgroundColor = isCurrent + ? Theme.of(context) + .textTheme + .display3 + .decorationColor + : Theme.of(context) + .textTheme + .display2 + .decorationColor; + final textColor = isCurrent + ? Theme.of(context).textTheme.display3.color + : Theme.of(context).textTheme.display2.color; - return AddressCell.fromItem(item, - isCurrent: isCurrent, - backgroundColor: backgroundColor, - textColor: textColor, - onTap: (_) => addressListViewModel.address = item, - onEdit: () => Navigator.of(context).pushNamed( - Routes.newSubaddress, - arguments: item)); - } - ); + return AddressCell.fromItem(item, + isCurrent: isCurrent, + backgroundColor: backgroundColor, + textColor: textColor, + onTap: (_) => addressListViewModel.address = item, + onEdit: () => Navigator.of(context).pushNamed( + Routes.newSubaddress, + arguments: item)); + }); } return index != 0 diff --git a/lib/src/screens/restore/restore_wallet_from_keys_page.dart b/lib/src/screens/restore/restore_wallet_from_keys_page.dart index f0e17ccf0..fa5efdff6 100644 --- a/lib/src/screens/restore/restore_wallet_from_keys_page.dart +++ b/lib/src/screens/restore/restore_wallet_from_keys_page.dart @@ -80,7 +80,7 @@ class _RestoreFromKeysFromState extends State { if (state is WalletRestorationFailure) { WidgetsBinding.instance.addPostFrameCallback((_) { - showDialog( + showPopUp( context: context, builder: (BuildContext context) { return AlertWithOneAction( diff --git a/lib/src/screens/restore/restore_wallet_from_seed_details.dart b/lib/src/screens/restore/restore_wallet_from_seed_details.dart index 5469a9f58..6a245884d 100644 --- a/lib/src/screens/restore/restore_wallet_from_seed_details.dart +++ b/lib/src/screens/restore/restore_wallet_from_seed_details.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:mobx/mobx.dart'; import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; @@ -53,7 +54,7 @@ class _RestoreFromSeedDetailsFormState if (state is FailureState) { WidgetsBinding.instance.addPostFrameCallback((_) { - showDialog( + showPopUp( context: context, builder: (BuildContext context) { return AlertWithOneAction( diff --git a/lib/src/screens/seed/wallet_seed_page.dart b/lib/src/screens/seed/wallet_seed_page.dart index 6e6088bdd..92d3b8504 100644 --- a/lib/src/screens/seed/wallet_seed_page.dart +++ b/lib/src/screens/seed/wallet_seed_page.dart @@ -2,6 +2,7 @@ import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/palette.dart'; import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/store/settings_store.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -27,12 +28,12 @@ class WalletSeedPage extends BasePage { @override void onClose(BuildContext context) async { if (isNewWalletCreated) { - final confirmed = await showDialog(context: context, builder: (BuildContext context) { + final confirmed = await showPopUp(context: context, builder: (BuildContext context) { // FIXME: add translations return AlertWithTwoActions( alertTitle: 'Attention', - alertContent: 'Have you written it down? The seed is the only way to recover your wallet.', - leftButtonText: 'Not yet', + alertContent: 'The seed is the only way to recover your wallet. Have you written it down?', + leftButtonText: 'Go back', rightButtonText: 'Yes, I have', actionLeftButton: () => Navigator.of(context).pop(false), actionRightButton: () => Navigator.of(context).pop(true)); diff --git a/lib/src/screens/send/send_page.dart b/lib/src/screens/send/send_page.dart index 0beddd831..d62b14ead 100644 --- a/lib/src/screens/send/send_page.dart +++ b/lib/src/screens/send/send_page.dart @@ -6,6 +6,7 @@ import 'package:cake_wallet/src/widgets/picker.dart'; import 'package:cake_wallet/src/widgets/primary_button.dart'; import 'package:cake_wallet/src/widgets/scollable_with_bottom_section.dart'; import 'package:cake_wallet/src/widgets/trail_button.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/view_model/send/send_view_model_state.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -397,7 +398,7 @@ class SendPage extends BasePage { // getOpenaliasRecord(context); // }, // onRemove: () { - // showDialog( + // showPopUp( // context: context, // builder: (dialogContext) { // return AlertWithTwoActions( @@ -492,7 +493,7 @@ class SendPage extends BasePage { reaction((_) => sendViewModel.state, (ExecutionState state) { if (state is FailureState) { WidgetsBinding.instance.addPostFrameCallback((_) { - showDialog( + showPopUp( context: context, builder: (BuildContext context) { return AlertWithOneAction( @@ -506,7 +507,7 @@ class SendPage extends BasePage { if (state is ExecutedSuccessfullyState) { WidgetsBinding.instance.addPostFrameCallback((_) { - showDialog( + showPopUp( context: context, builder: (BuildContext context) { return ConfirmSendingAlert( @@ -521,7 +522,7 @@ class SendPage extends BasePage { actionLeftButton: () { Navigator.of(context).pop(); sendViewModel.commitTransaction(); - showDialog( + showPopUp( context: context, builder: (BuildContext context) { return Observer(builder: (_) { @@ -635,7 +636,7 @@ class SendPage extends BasePage { // if (isOpenalias) { // _addressController.text = sendViewModel.recordAddress; - // await showDialog( + // await showPopUp( // context: context, // builder: (BuildContext context) { // return AlertWithOneAction( @@ -653,7 +654,7 @@ class SendPage extends BasePage { // final items = TransactionPriority.all; // final selectedItem = items.indexOf(sendViewModel.transactionPriority); // - // await showDialog( + // await showPopUp( // builder: (_) => Picker( // items: items, // selectedAtIndex: selectedItem, diff --git a/lib/src/screens/settings/change_language.dart b/lib/src/screens/settings/change_language.dart index 78e6f09fb..3b06aefa8 100644 --- a/lib/src/screens/settings/change_language.dart +++ b/lib/src/screens/settings/change_language.dart @@ -39,7 +39,7 @@ class ChangeLanguage extends BasePage { // isSelected: isCurrent, // handler: (context) async { // if (!isCurrent) { - // await showDialog( + // await showPopUp( // context: context, // builder: (BuildContext context) { // return AlertWithTwoActions( diff --git a/lib/src/screens/settings/widgets/settings_picker_cell.dart b/lib/src/screens/settings/widgets/settings_picker_cell.dart index a77e76efd..e2c949683 100644 --- a/lib/src/screens/settings/widgets/settings_picker_cell.dart +++ b/lib/src/screens/settings/widgets/settings_picker_cell.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/src/widgets/picker.dart'; import 'package:cake_wallet/src/widgets/standard_list.dart'; @@ -16,7 +17,7 @@ class SettingsPickerCell extends StandardListRow { onTap: (BuildContext context) async { final selectedAtIndex = items.indexOf(selectedItem); - await showDialog( + await showPopUp( context: context, builder: (_) => Picker( items: items, diff --git a/lib/src/screens/setup_pin_code/setup_pin_code.dart b/lib/src/screens/setup_pin_code/setup_pin_code.dart index dad0c0f2f..6cd54625d 100644 --- a/lib/src/screens/setup_pin_code/setup_pin_code.dart +++ b/lib/src/screens/setup_pin_code/setup_pin_code.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:cake_wallet/generated/i18n.dart'; @@ -26,7 +27,7 @@ class SetupPinCodePage extends BasePage { } if (!pinCodeViewModel.isPinCodeCorrect) { - await showDialog( + await showPopUp( context: context, builder: (BuildContext context) { return AlertWithOneAction( @@ -43,7 +44,7 @@ class SetupPinCodePage extends BasePage { try { await pinCodeViewModel.setupPinCode(); - await showDialog( + await showPopUp( context: context, builder: (BuildContext context) { return AlertWithOneAction( @@ -60,7 +61,7 @@ class SetupPinCodePage extends BasePage { }); } catch (e) { // FIXME: Add translation for alert content text. - await showDialog( + await showPopUp( context: context, builder: (BuildContext context) { return AlertWithOneAction( diff --git a/lib/src/screens/wallet_list/wallet_menu.dart b/lib/src/screens/wallet_list/wallet_menu.dart index a508541bd..aa83d56e2 100644 --- a/lib/src/screens/wallet_list/wallet_menu.dart +++ b/lib/src/screens/wallet_list/wallet_menu.dart @@ -1,4 +1,5 @@ import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/routes.dart'; @@ -126,7 +127,7 @@ class WalletMenu { }); break; case 2: - final isComfirmed = await showDialog( + final isComfirmed = await showPopUp( context: context, builder: (BuildContext context) { return AlertWithTwoActions( diff --git a/lib/src/widgets/seed_language_selector.dart b/lib/src/widgets/seed_language_selector.dart index 74420d370..57011f323 100644 --- a/lib/src/widgets/seed_language_selector.dart +++ b/lib/src/widgets/seed_language_selector.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/src/screens/new_wallet/widgets/select_button.dart'; @@ -35,7 +36,7 @@ class SeedLanguageSelectorState extends State { image: null, text: seedLocales[seedLanguages.indexOf(selected)], onTap: () async { - final selected = await showDialog( + final selected = await showPopUp( context: context, builder: (BuildContext context) => SeedLanguagePicker(key: _pickerKey, selected: this.selected)); diff --git a/lib/utils/show_pop_up.dart b/lib/utils/show_pop_up.dart new file mode 100644 index 000000000..a97fb3762 --- /dev/null +++ b/lib/utils/show_pop_up.dart @@ -0,0 +1,22 @@ +import 'package:flutter/material.dart'; + +Future showPopUp({ + @required BuildContext context, + WidgetBuilder builder, + bool barrierDismissible = true, + Color barrierColor, + bool useSafeArea = false, + bool useRootNavigator = true, + RouteSettings routeSettings, + Widget child, +}) { + return showDialog( + context: context, + builder: builder, + barrierDismissible: barrierDismissible, + barrierColor: barrierColor, + useSafeArea: useSafeArea, + useRootNavigator: useRootNavigator, + routeSettings: routeSettings, + child: child); +} diff --git a/lib/view_model/wallet_list/wallet_list_view_model.dart b/lib/view_model/wallet_list/wallet_list_view_model.dart index 3be5d164c..8bb102620 100644 --- a/lib/view_model/wallet_list/wallet_list_view_model.dart +++ b/lib/view_model/wallet_list/wallet_list_view_model.dart @@ -35,7 +35,7 @@ abstract class WalletListViewModelBase with Store { @action Future remove(WalletListItem wallet) async { - final walletService = getIt.get(); + final walletService = getIt.get(param1: wallet.type); await walletService.remove(wallet.name); await _walletInfoSource.delete(wallet.key); _updateList(); From 162e9e5712934d98671441a1d75b58aa27933841 Mon Sep 17 00:00:00 2001 From: M Date: Sat, 26 Sep 2020 14:17:39 +0300 Subject: [PATCH 6/9] Design fixes. --- .../dashboard/widgets/action_button.dart | 1 + .../dashboard/widgets/balance_page.dart | 68 ++++------ .../dashboard/widgets/transaction_raw.dart | 128 +++++++++--------- .../settings/settings_view_model.dart | 5 +- 4 files changed, 96 insertions(+), 106 deletions(-) diff --git a/lib/src/screens/dashboard/widgets/action_button.dart b/lib/src/screens/dashboard/widgets/action_button.dart index dc9a64bbf..9f9fbc418 100644 --- a/lib/src/screens/dashboard/widgets/action_button.dart +++ b/lib/src/screens/dashboard/widgets/action_button.dart @@ -36,6 +36,7 @@ class ActionButton extends StatelessWidget { child: image, ), ), + SizedBox(height: 15), Text( title, style: TextStyle(fontSize: 14, color: Colors.white), diff --git a/lib/src/screens/dashboard/widgets/balance_page.dart b/lib/src/screens/dashboard/widgets/balance_page.dart index 4cd3fe2a0..519f21960 100644 --- a/lib/src/screens/dashboard/widgets/balance_page.dart +++ b/lib/src/screens/dashboard/widgets/balance_page.dart @@ -18,45 +18,34 @@ class BalancePage extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ - Observer( - builder: (_) { - return Text( - dashboardViewModel.wallet.currency.toString(), - style: TextStyle( - fontSize: 40, - fontWeight: FontWeight.bold, - color: Theme.of(context).indicatorColor, - height: 1 - ), - ); - } - ), - Observer( - builder: (_) { - return Text( - dashboardViewModel.balanceViewModel.cryptoBalance, - style: TextStyle( - fontSize: 54, - fontWeight: FontWeight.bold, - color: Colors.white, - height: 1 - ), - ); - } - ), - Observer( - builder: (_) { - return Text( - dashboardViewModel.balanceViewModel.fiatBalance, - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.w500, - color: Theme.of(context).indicatorColor, - height: 1 - ), - ); - } - ), + Observer(builder: (_) { + return Text( + dashboardViewModel.wallet.currency.toString(), + style: TextStyle( + fontSize: 40, + fontWeight: FontWeight.bold, + color: Theme.of(context).indicatorColor, + height: 1), + ); + }), + Observer(builder: (_) { + return Text(dashboardViewModel.balanceViewModel.cryptoBalance, + style: TextStyle( + fontSize: 54, + fontWeight: FontWeight.bold, + color: Colors.white, + height: 1), + textAlign: TextAlign.center); + }), + Observer(builder: (_) { + return Text(dashboardViewModel.balanceViewModel.fiatBalance, + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.w500, + color: Theme.of(context).indicatorColor, + height: 1), + textAlign: TextAlign.center); + }), ], ), ), @@ -64,4 +53,3 @@ class BalancePage extends StatelessWidget { ); } } - diff --git a/lib/src/screens/dashboard/widgets/transaction_raw.dart b/lib/src/screens/dashboard/widgets/transaction_raw.dart index 13e3bd2be..14d07a9fc 100644 --- a/lib/src/screens/dashboard/widgets/transaction_raw.dart +++ b/lib/src/screens/dashboard/widgets/transaction_raw.dart @@ -3,13 +3,13 @@ import 'package:cake_wallet/entities/transaction_direction.dart'; import 'package:cake_wallet/generated/i18n.dart'; class TransactionRow extends StatelessWidget { - TransactionRow({ - this.direction, - this.formattedDate, - this.formattedAmount, - this.formattedFiatAmount, - this.isPending, - @required this.onTap}); + TransactionRow( + {this.direction, + this.formattedDate, + this.formattedAmount, + this.formattedFiatAmount, + this.isPending, + @required this.onTap}); final VoidCallback onTap; final TransactionDirection direction; @@ -23,75 +23,73 @@ class TransactionRow extends StatelessWidget { return InkWell( onTap: onTap, child: Container( - height: 52, + height: 62, color: Colors.transparent, padding: EdgeInsets.only(left: 24, right: 24), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ - Container( - height: 36, - width: 36, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Theme.of(context).textTheme.overline.decorationColor - ), - child: Image.asset( - direction == TransactionDirection.incoming - ? 'assets/images/down_arrow.png' - : 'assets/images/up_arrow.png'), - ), Expanded( - child: Padding( - padding: const EdgeInsets.only(left: 12), - child: Container( - height: 46, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - mainAxisSize: MainAxisSize.max, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - (direction == TransactionDirection.incoming + child: Container( + height: 56, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisSize: MainAxisSize.max, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + (direction == TransactionDirection.incoming ? S.of(context).received : S.of(context).sent) + - (isPending ? S.of(context).pending : ''), + (isPending ? S.of(context).pending : ''), + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w500, + color: Colors.white)), + Container( + decoration: BoxDecoration( + borderRadius: + BorderRadius.all(Radius.circular(10)), + color: (direction == + TransactionDirection.incoming + ? Colors.green.withOpacity(0.8) + : Theme.of(context) + .accentTextTheme + .body2 + .decorationColor + .withOpacity(0.8))), + padding: EdgeInsets.only( + top: 3, bottom: 3, left: 10, right: 10), + child: Text(formattedAmount, style: TextStyle( fontSize: 16, fontWeight: FontWeight.w500, - color: Colors.white - )), - Text(direction == TransactionDirection.incoming - ? formattedAmount - : '- ' + formattedAmount, - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w500, - color: Colors.white - )) - ]), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text(formattedDate, - style: TextStyle( - fontSize: 14, - color: Theme.of(context).textTheme - .overline.backgroundColor)), - Text(direction == TransactionDirection.incoming - ? formattedFiatAmount - : '- ' + formattedFiatAmount, - style: TextStyle( - fontSize: 14, - color: Theme.of(context).textTheme - .overline.backgroundColor)) - ]), - ], - ), - ), - )) + color: Colors.white))) + ]), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(formattedDate, + style: TextStyle( + fontSize: 14, + color: Theme.of(context) + .textTheme + .overline + .backgroundColor)), + Text(formattedFiatAmount, + style: TextStyle( + fontSize: 14, + color: Theme.of(context) + .textTheme + .overline + .backgroundColor)) + ]), + ], + ), + ), + ) ]), )); } diff --git a/lib/view_model/settings/settings_view_model.dart b/lib/view_model/settings/settings_view_model.dart index 61ffda19b..bac456e79 100644 --- a/lib/view_model/settings/settings_view_model.dart +++ b/lib/view_model/settings/settings_view_model.dart @@ -40,7 +40,9 @@ abstract class SettingsViewModelBase with Store { PickerListItem( title: S.current.settings_display_balance_as, items: BalanceDisplayMode.all, - selectedItem: () => balanceDisplayMode), + selectedItem: () => balanceDisplayMode, + onItemSelected: (BalanceDisplayMode mode) => + _settingsStore.balanceDisplayMode = mode), PickerListItem( title: S.current.settings_currency, items: FiatCurrency.all, @@ -204,6 +206,7 @@ abstract class SettingsViewModelBase with Store { @action void setFiatCurrency(FiatCurrency value) => _settingsStore.fiatCurrency = value; + @action void setShouldSaveRecipientAddress(bool value) => _settingsStore.shouldSaveRecipientAddress = value; From dcdc411d41a281d85501177a99b4453b5f946322 Mon Sep 17 00:00:00 2001 From: M Date: Sat, 26 Sep 2020 15:19:33 +0300 Subject: [PATCH 7/9] Fixes --- lib/router.dart | 4 ++-- lib/src/screens/dashboard/dashboard_page.dart | 16 +++++-------- .../dashboard/widgets/balance_page.dart | 2 +- .../screens/wallet_list/wallet_list_page.dart | 3 ++- lib/src/screens/welcome/welcome_page.dart | 4 ++-- .../dashboard/balance_view_model.dart | 4 ++++ pubspec.lock | 23 ++++++++++++------- 7 files changed, 32 insertions(+), 24 deletions(-) diff --git a/lib/router.dart b/lib/router.dart index 5ae418395..5213758f2 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -67,7 +67,7 @@ class Router { .pushNamed(Routes.newWallet, arguments: type))); case Routes.newWallet: - final type = settings.arguments as WalletType; + final type = WalletType.monero; // settings.arguments as WalletType; final walletNewVM = getIt.get(param1: type); return CupertinoPageRoute( @@ -97,7 +97,7 @@ class Router { builder: (_) => RestoreOptionsPage(type: type)); case Routes.restoreWalletOptions: - final type = settings.arguments as WalletType; + final type = WalletType.monero; //settings.arguments as WalletType; return CupertinoPageRoute( builder: (_) => RestoreWalletOptionsPage( diff --git a/lib/src/screens/dashboard/dashboard_page.dart b/lib/src/screens/dashboard/dashboard_page.dart index 16cce7518..fecaec430 100644 --- a/lib/src/screens/dashboard/dashboard_page.dart +++ b/lib/src/screens/dashboard/dashboard_page.dart @@ -108,17 +108,13 @@ class DashboardPage extends BasePage { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ ActionButton( - image: sendImage, - title: S.of(context).send, - route: Routes.send, - alignment: Alignment.centerLeft, - ), + image: sendImage, + title: S.of(context).send, + route: Routes.send), ActionButton( - image: sendImage, - title: S.of(context).send, - route: Routes.send, - alignment: Alignment.centerLeft, - ), + image: exchangeImage, + title: S.of(context).exchange, + route: Routes.exchange), ], ), ) diff --git a/lib/src/screens/dashboard/widgets/balance_page.dart b/lib/src/screens/dashboard/widgets/balance_page.dart index 519f21960..e6c0ccef7 100644 --- a/lib/src/screens/dashboard/widgets/balance_page.dart +++ b/lib/src/screens/dashboard/widgets/balance_page.dart @@ -20,7 +20,7 @@ class BalancePage extends StatelessWidget { children: [ Observer(builder: (_) { return Text( - dashboardViewModel.wallet.currency.toString(), + dashboardViewModel.balanceViewModel.currency.toString(), style: TextStyle( fontSize: 40, fontWeight: FontWeight.bold, diff --git a/lib/src/screens/wallet_list/wallet_list_page.dart b/lib/src/screens/wallet_list/wallet_list_page.dart index 694c338e4..0b845f3ed 100644 --- a/lib/src/screens/wallet_list/wallet_list_page.dart +++ b/lib/src/screens/wallet_list/wallet_list_page.dart @@ -1,4 +1,5 @@ import 'package:cake_wallet/src/screens/wallet_list/widgets/wallet_menu_alert.dart'; +import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; @@ -73,7 +74,7 @@ class WalletListBodyState extends State { return GestureDetector( onTap: () { - showDialog( + showPopUp( context: context, builder: (dialogContext) { return WalletMenuAlert( diff --git a/lib/src/screens/welcome/welcome_page.dart b/lib/src/screens/welcome/welcome_page.dart index 78cd04835..aa0d5b80c 100644 --- a/lib/src/screens/welcome/welcome_page.dart +++ b/lib/src/screens/welcome/welcome_page.dart @@ -103,7 +103,7 @@ class WelcomePage extends BasePage { Padding( padding: EdgeInsets.only(top: 24), child: PrimaryImageButton( - onPressed: () => Navigator.pushNamed(context, Routes.newWalletFromWelcome), + onPressed: () => Navigator.pushNamed(context, Routes.newWallet), image: newWalletImage, text: S.of(context).create_new, color: Theme.of(context).accentTextTheme.subtitle.decorationColor, @@ -113,7 +113,7 @@ class WelcomePage extends BasePage { Padding( padding: EdgeInsets.only(top: 10), child: PrimaryImageButton( - onPressed: () => Navigator.pushNamed(context, Routes.restoreWalletOptionsFromWelcome), + onPressed: () => Navigator.pushNamed(context, Routes.restoreWalletOptions), image: restoreWalletImage, text: S.of(context).restore_wallet, color: Theme.of(context).accentTextTheme.caption.color, diff --git a/lib/view_model/dashboard/balance_view_model.dart b/lib/view_model/dashboard/balance_view_model.dart index 23fd578f1..58978c946 100644 --- a/lib/view_model/dashboard/balance_view_model.dart +++ b/lib/view_model/dashboard/balance_view_model.dart @@ -1,5 +1,6 @@ import 'package:cake_wallet/bitcoin/bitcoin_wallet.dart'; import 'package:cake_wallet/core/wallet_base.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; import 'package:cake_wallet/monero/monero_wallet.dart'; import 'package:cake_wallet/entities/balance_display_mode.dart'; import 'package:cake_wallet/entities/calculate_fiat_amount.dart'; @@ -92,6 +93,9 @@ abstract class BalanceViewModelBase with Store { return null; } + @computed + CryptoCurrency get currency => appStore.wallet.currency; + String _getFiatBalance({double price, String cryptoAmount}) { if (cryptoAmount == null) { return '0.00'; diff --git a/pubspec.lock b/pubspec.lock index df34727ee..612b1ac91 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -42,7 +42,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.1" + version: "2.4.2" auto_size_text: dependency: "direct main" description: @@ -210,7 +210,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.12" + version: "1.14.13" connectivity: dependency: "direct main" description: @@ -330,6 +330,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" ffi: dependency: transitive description: @@ -547,7 +554,7 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.8" meta: dependency: transitive description: @@ -617,7 +624,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.7.0" path_drawing: dependency: transitive description: @@ -867,7 +874,7 @@ packages: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.9.5" stream_channel: dependency: transitive description: @@ -902,7 +909,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.15" + version: "0.2.17" time: dependency: transitive description: @@ -923,7 +930,7 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.2.0" url_launcher: dependency: "direct main" description: @@ -1023,5 +1030,5 @@ packages: source: hosted version: "2.2.1" sdks: - dart: ">=2.7.0 <3.0.0" + dart: ">=2.9.0-14.0.dev <3.0.0" flutter: ">=1.12.13+hotfix.5 <2.0.0" From 51cf11127c54149022b22c626cb3ba2207b5c742 Mon Sep 17 00:00:00 2001 From: M Date: Sat, 26 Sep 2020 22:17:31 +0300 Subject: [PATCH 8/9] Fixes --- lib/core/contact_service.dart | 4 +- lib/di.dart | 17 +- lib/entities/contact_record.dart | 40 ++++ lib/entities/node.dart | 3 + lib/entities/record.dart | 35 ++++ lib/reactions/bootstrap.dart | 2 + lib/reactions/on_current_node_change.dart | 17 ++ lib/router.dart | 3 +- .../screens/contact/contact_list_page.dart | 12 +- .../monero_accounts/widgets/account_tile.dart | 2 +- lib/src/screens/nodes/nodes_list_page.dart | 153 ++++++++------- lib/store/contact_list_store.dart | 6 +- lib/store/node_list_store.dart | 10 +- lib/store/settings_store.dart | 13 +- lib/utils/item_cell.dart | 11 +- lib/utils/mobx.dart | 178 +++++++++++------- .../contact_list/contact_list_view_model.dart | 9 +- .../contact_list/contact_view_model.dart | 12 +- .../node_list/node_list_view_model.dart | 52 +---- pubspec.lock | 35 ++-- pubspec.yaml | 2 +- 21 files changed, 362 insertions(+), 254 deletions(-) create mode 100644 lib/entities/contact_record.dart create mode 100644 lib/entities/record.dart create mode 100644 lib/reactions/on_current_node_change.dart diff --git a/lib/core/contact_service.dart b/lib/core/contact_service.dart index c7027fa8f..3f2a46203 100644 --- a/lib/core/contact_service.dart +++ b/lib/core/contact_service.dart @@ -22,7 +22,7 @@ class ContactService { if (index >= 0) { _forceUpdateContactListStore(); } else { - contactListStore.contacts.add(contact); + // contactListStore.contacts.add(contact); } } @@ -33,6 +33,6 @@ class ContactService { void _forceUpdateContactListStore() { contactListStore.contacts.clear(); - contactListStore.contacts.addAll(contactSource.values); + // contactListStore.contacts.addAll(contactSource.values); } } diff --git a/lib/di.dart b/lib/di.dart index 2010a6158..d6ccde3cc 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -2,6 +2,7 @@ import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart'; import 'package:cake_wallet/core/contact_service.dart'; import 'package:cake_wallet/core/wallet_service.dart'; import 'package:cake_wallet/entities/biometric_auth.dart'; +import 'package:cake_wallet/entities/contact_record.dart'; import 'package:cake_wallet/monero/monero_wallet_service.dart'; import 'package:cake_wallet/entities/contact.dart'; import 'package:cake_wallet/entities/node.dart'; @@ -197,7 +198,8 @@ Future setup( getIt .registerFactoryParam( (onAuthFinished, closable) => AuthPage(getIt.get(), - onAuthenticationFinished: onAuthFinished, closable: closable ?? false)); + onAuthenticationFinished: onAuthFinished, + closable: closable ?? false)); getIt.registerFactory(() => DashboardPage( walletViewModel: getIt.get(), @@ -282,8 +284,8 @@ Future setup( getIt.registerFactory(() => WalletKeysPage(getIt.get())); - getIt.registerFactoryParam( - (Contact contact, _) => ContactViewModel( + getIt.registerFactoryParam( + (ContactRecord contact, _) => ContactViewModel( contactSource, getIt.get().wallet, contact: contact)); @@ -296,13 +298,14 @@ Future setup( (bool isEditable, _) => ContactListPage(getIt.get(), isEditable: isEditable)); - getIt.registerFactoryParam((Contact contact, _) => - ContactPage(getIt.get(param1: contact))); + getIt.registerFactoryParam( + (ContactRecord contact, _) => + ContactPage(getIt.get(param1: contact))); getIt.registerFactory(() { final appStore = getIt.get(); - return NodeListViewModel(appStore.nodeListStore, nodeSource, - appStore.wallet, appStore.settingsStore); + return NodeListViewModel( + nodeSource, appStore.wallet, appStore.settingsStore); }); getIt.registerFactory(() => NodeListPage(getIt.get())); diff --git a/lib/entities/contact_record.dart b/lib/entities/contact_record.dart new file mode 100644 index 000000000..c4f55cc5a --- /dev/null +++ b/lib/entities/contact_record.dart @@ -0,0 +1,40 @@ +import 'package:hive/hive.dart'; +import 'package:mobx/mobx.dart'; +import 'package:cake_wallet/entities/contact.dart'; +import 'package:cake_wallet/entities/crypto_currency.dart'; +import 'package:cake_wallet/entities/record.dart'; + +part 'contact_record.g.dart'; + +class ContactRecord = ContactRecordBase with _$ContactRecord; + +abstract class ContactRecordBase extends Record with Store { + ContactRecordBase(Box source, Contact original) + : super(source, original); + + @observable + String name; + + @observable + String address; + + @observable + CryptoCurrency type; + + @override + void toBind(Contact original) { + reaction((_) => name, (String name) => original.name = name); + reaction((_) => address, (String address) => original.address = address); + reaction( + (_) => type, + (CryptoCurrency currency) => + original.updateCryptoCurrency(currency: currency)); + } + + @override + void fromBind(Contact original) { + name = original.name; + address = original.address; + type = original.type; + } +} diff --git a/lib/entities/node.dart b/lib/entities/node.dart index 74643112a..f79b8b2e0 100644 --- a/lib/entities/node.dart +++ b/lib/entities/node.dart @@ -38,6 +38,9 @@ class Node extends HiveObject with Keyable { @HiveField(3) int typeRaw; + @override + dynamic get keyIndex => key; + WalletType get type => deserializeFromInt(typeRaw); set type(WalletType type) => typeRaw = serializeToInt(type); diff --git a/lib/entities/record.dart b/lib/entities/record.dart new file mode 100644 index 000000000..3c21441cc --- /dev/null +++ b/lib/entities/record.dart @@ -0,0 +1,35 @@ +import 'dart:async'; + +import 'package:cake_wallet/utils/mobx.dart'; +import 'package:hive/hive.dart'; + +abstract class Record with Keyable { + Record(this._source, this.original) { + _listener?.cancel(); + _listener = _source.watch(key: original.key).listen((event) { + if (!event.deleted) { + fromBind(event.value as T); + } + }); + + fromBind(original); + toBind(original); + } + + dynamic get key => original.key; + + @override + dynamic get keyIndex => key; + + final T original; + + final Box _source; + + StreamSubscription _listener; + + void fromBind(T original); + + void toBind(T original); + + Future save() => original.save(); +} diff --git a/lib/reactions/bootstrap.dart b/lib/reactions/bootstrap.dart index 2ffb5d376..fef73c46f 100644 --- a/lib/reactions/bootstrap.dart +++ b/lib/reactions/bootstrap.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'package:cake_wallet/reactions/on_current_node_change.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -31,4 +32,5 @@ Future bootstrap(GlobalKey navigatorKey) async { startCurrentWalletChangeReaction( appStore, settingsStore, fiatConversionStore); startCurrentFiatChangeReaction(appStore, settingsStore); + startOnCurrentNodeChangeReaction(appStore); } diff --git a/lib/reactions/on_current_node_change.dart b/lib/reactions/on_current_node_change.dart new file mode 100644 index 000000000..c03bbac21 --- /dev/null +++ b/lib/reactions/on_current_node_change.dart @@ -0,0 +1,17 @@ +import 'package:mobx/mobx.dart'; +import 'package:cake_wallet/entities/node.dart'; +import 'package:cake_wallet/store/app_store.dart'; + +ReactionDisposer _onCurrentNodeChangeReaction; + +void startOnCurrentNodeChangeReaction(AppStore appStore) { + _onCurrentNodeChangeReaction?.reaction?.dispose(); + _onCurrentNodeChangeReaction = + reaction((_) => appStore.settingsStore.currentNode, (Node node) async { + try { + await appStore.wallet.connectToNode(node: node); + } catch (e) { + print(e.toString()); + } + }); +} diff --git a/lib/router.dart b/lib/router.dart index 5213758f2..cc660d9a0 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/entities/contact_record.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/routes.dart'; @@ -252,7 +253,7 @@ class Router { case Routes.addressBookAddContact: return CupertinoPageRoute( builder: (_) => - getIt.get(param1: settings.arguments as Contact)); + getIt.get(param1: settings.arguments as ContactRecord)); case Routes.showKeys: return MaterialPageRoute( diff --git a/lib/src/screens/contact/contact_list_page.dart b/lib/src/screens/contact/contact_list_page.dart index 044484f49..37c37876f 100644 --- a/lib/src/screens/contact/contact_list_page.dart +++ b/lib/src/screens/contact/contact_list_page.dart @@ -164,17 +164,17 @@ class ContactListPage extends BasePage { final isDelete = await showAlertDialog(context) ?? false; - if (isDelete) { - await contactListViewModel - .delete(contact); - } + // if (isDelete) { + // await contactListViewModel + // .delete(contact); + // } }, ), ], dismissal: SlidableDismissal( child: SlidableDrawerDismissal(), - onDismissed: (actionType) async => - await contactListViewModel.delete(contact), + onDismissed: (actionType) async => null, + // await contactListViewModel.delete(contact), onWillDismiss: (actionType) async => showAlertDialog(context), ), diff --git a/lib/src/screens/monero_accounts/widgets/account_tile.dart b/lib/src/screens/monero_accounts/widgets/account_tile.dart index c39758bd5..50238a67c 100644 --- a/lib/src/screens/monero_accounts/widgets/account_tile.dart +++ b/lib/src/screens/monero_accounts/widgets/account_tile.dart @@ -31,7 +31,7 @@ class AccountTile extends StatelessWidget { accountName, style: TextStyle( fontSize: 18, - fontWeight: FontWeight.bold, + fontWeight: FontWeight.w600, fontFamily: 'Poppins', color: textColor, decoration: TextDecoration.none, diff --git a/lib/src/screens/nodes/nodes_list_page.dart b/lib/src/screens/nodes/nodes_list_page.dart index 84e87a3a5..b0bc8c15f 100644 --- a/lib/src/screens/nodes/nodes_list_page.dart +++ b/lib/src/screens/nodes/nodes_list_page.dart @@ -67,87 +67,86 @@ class NodeListPage extends BasePage { sectionCount: 2, context: context, itemBuilder: (_, sectionIndex, index) { - if (sectionIndex == 0) { - return NodeHeaderListRow( - title: S.of(context).add_new_node, - onTap: (_) async => - await Navigator.of(context).pushNamed(Routes.newNode)); - } + return Observer(builder: (_) { + if (sectionIndex == 0) { + return NodeHeaderListRow( + title: S.of(context).add_new_node, + onTap: (_) async => await Navigator.of(context) + .pushNamed(Routes.newNode)); + } - final node = nodeListViewModel.nodes[index]; - final nodeListRow = NodeListRow( - title: node.value.uri, - isSelected: node.isSelected, - isAlive: node.value.requestNode(), - onTap: (_) async { - if (node.isSelected) { - return; - } + final node = nodeListViewModel.nodes[index]; + final isSelected = node.keyIndex == + nodeListViewModel.settingsStore.currentNode.keyIndex; + final nodeListRow = NodeListRow( + title: node.uri, + isSelected: isSelected, + isAlive: node.requestNode(), + onTap: (_) async { + if (isSelected) { + return; + } - await showPopUp( - context: context, - builder: (BuildContext context) { - return AlertDialog( - content: Text( - S.of(context).change_current_node(node.value.uri), - textAlign: TextAlign.center, + await showPopUp( + context: context, + builder: (BuildContext context) { + // FIXME: Add translation. + return AlertWithTwoActions( + alertTitle: 'Change current node', + alertContent: + S.of(context).change_current_node(node.uri), + leftButtonText: S.of(context).cancel, + rightButtonText: S.of(context).change, + actionLeftButton: () => + Navigator.of(context).pop(), + actionRightButton: () async { + await nodeListViewModel.setAsCurrent(node); + Navigator.of(context).pop(); + }); + }); + }); + + final dismissibleRow = Dismissible( + key: Key('${node.keyIndex}'), + confirmDismiss: (direction) async { + return await showPopUp( + context: context, + builder: (BuildContext context) { + return AlertWithTwoActions( + alertTitle: S.of(context).remove_node, + alertContent: S.of(context).remove_node_message, + rightButtonText: S.of(context).remove, + leftButtonText: S.of(context).cancel, + actionRightButton: () => + Navigator.pop(context, true), + actionLeftButton: () => + Navigator.pop(context, false)); + }); + }, + onDismissed: (direction) async => + nodeListViewModel.delete(node), + direction: DismissDirection.endToStart, + background: Container( + padding: EdgeInsets.only(right: 10.0), + alignment: AlignmentDirectional.centerEnd, + color: Palette.red, + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + const Icon( + CupertinoIcons.delete, + color: Colors.white, ), - actions: [ - FlatButton( - onPressed: () => Navigator.pop(context), - child: Text(S.of(context).cancel)), - FlatButton( - onPressed: () async { - Navigator.of(context).pop(); - await nodeListViewModel - .setAsCurrent(node.value); - }, - child: Text(S.of(context).change)), - ], - ); - }); - }); + Text( + S.of(context).delete, + style: TextStyle(color: Colors.white), + ) + ], + )), + child: nodeListRow); - final dismissibleRow = Dismissible( - key: Key('${node.keyIndex}'), - confirmDismiss: (direction) async { - return await showPopUp( - context: context, - builder: (BuildContext context) { - return AlertWithTwoActions( - alertTitle: S.of(context).remove_node, - alertContent: S.of(context).remove_node_message, - rightButtonText: S.of(context).remove, - leftButtonText: S.of(context).cancel, - actionRightButton: () => - Navigator.pop(context, true), - actionLeftButton: () => - Navigator.pop(context, false)); - }); - }, - onDismissed: (direction) async => - nodeListViewModel.delete(node.value), - direction: DismissDirection.endToStart, - background: Container( - padding: EdgeInsets.only(right: 10.0), - alignment: AlignmentDirectional.centerEnd, - color: Palette.red, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - const Icon( - CupertinoIcons.delete, - color: Colors.white, - ), - Text( - S.of(context).delete, - style: TextStyle(color: Colors.white), - ) - ], - )), - child: nodeListRow); - - return node.isSelected ? nodeListRow : dismissibleRow; + return isSelected ? nodeListRow : dismissibleRow; + }); }, itemCounter: (int sectionIndex) { if (sectionIndex == 0) { diff --git a/lib/store/contact_list_store.dart b/lib/store/contact_list_store.dart index ca3d0bcf0..85194e0d6 100644 --- a/lib/store/contact_list_store.dart +++ b/lib/store/contact_list_store.dart @@ -1,12 +1,12 @@ import 'package:mobx/mobx.dart'; -import 'package:cake_wallet/entities/contact.dart'; +import 'package:cake_wallet/entities/contact_record.dart'; part 'contact_list_store.g.dart'; class ContactListStore = ContactListStoreBase with _$ContactListStore; abstract class ContactListStoreBase with Store { - ContactListStoreBase() : contacts = ObservableList(); + ContactListStoreBase() : contacts = ObservableList(); - final ObservableList contacts; + final ObservableList contacts; } diff --git a/lib/store/node_list_store.dart b/lib/store/node_list_store.dart index 0ff958e3f..56fe0333a 100644 --- a/lib/store/node_list_store.dart +++ b/lib/store/node_list_store.dart @@ -22,17 +22,13 @@ abstract class NodeListStoreBase with Store { final nodeSource = getIt.get>(); _instance = NodeListStore(); - _instance.replaceValues(nodeSource.values); + _instance.nodes.clear(); + _instance.nodes.addAll(nodeSource.values); _onNodesSourceChange?.cancel(); - _onNodesSourceChange = bindBox(nodeSource, _instance.nodes); + _onNodesSourceChange = nodeSource.bindToList(_instance.nodes); return _instance; } final ObservableList nodes; - - void replaceValues(Iterable newNodes) { - nodes.clear(); - nodes.addAll(newNodes); - } } diff --git a/lib/store/settings_store.dart b/lib/store/settings_store.dart index e17ce2de9..d4f6bf95a 100644 --- a/lib/store/settings_store.dart +++ b/lib/store/settings_store.dart @@ -21,7 +21,6 @@ class SettingsStore = SettingsStoreBase with _$SettingsStore; abstract class SettingsStoreBase with Store { SettingsStoreBase( {@required SharedPreferences sharedPreferences, - @required Box nodeSource, @required FiatCurrency initialFiatCurrency, @required TransactionPriority initialTransactionPriority, @required BalanceDisplayMode initialBalanceDisplayMode, @@ -43,10 +42,9 @@ abstract class SettingsStoreBase with Store { pinCodeLength = initialPinLength; languageCode = initialLanguageCode; currentLocale = initialCurrentLocale; - itemHeaders = {}; + currentNode = nodes[WalletType.monero]; this.nodes = ObservableMap.of(nodes); _sharedPreferences = sharedPreferences; - _nodeSource = nodeSource; reaction( (_) => allowBiometricalAuthentication, @@ -58,6 +56,9 @@ abstract class SettingsStoreBase with Store { (_) => pinCodeLength, (int pinLength) => sharedPreferences.setInt( PreferencesKey.currentPinLength, pinLength)); + + reaction((_) => currentNode, + (Node node) => _saveCurrentNode(node, WalletType.monero)); } static const defaultPinLength = 4; @@ -88,7 +89,7 @@ abstract class SettingsStoreBase with Store { int pinCodeLength; @observable - Map itemHeaders; + Node currentNode; String languageCode; @@ -97,7 +98,6 @@ abstract class SettingsStoreBase with Store { String appVersion; SharedPreferences _sharedPreferences; - Box _nodeSource; ObservableMap nodes; @@ -150,7 +150,6 @@ abstract class SettingsStoreBase with Store { WalletType.monero: moneroNode, WalletType.bitcoin: bitcoinElectrumServer }, - nodeSource: nodeSource, appVersion: packageInfo.version, initialFiatCurrency: currentFiatCurrency, initialTransactionPriority: currentTransactionPriority, @@ -164,7 +163,7 @@ abstract class SettingsStoreBase with Store { initialCurrentLocale: initialCurrentLocale); } - Future setCurrentNode(Node node, WalletType walletType) async { + Future _saveCurrentNode(Node node, WalletType walletType) async { switch (walletType) { case WalletType.bitcoin: await _sharedPreferences.setInt( diff --git a/lib/utils/item_cell.dart b/lib/utils/item_cell.dart index 4aca57b46..150df6d50 100644 --- a/lib/utils/item_cell.dart +++ b/lib/utils/item_cell.dart @@ -1,11 +1,18 @@ import 'package:flutter/foundation.dart'; +import 'package:mobx/mobx.dart'; import 'package:cake_wallet/utils/mobx.dart'; +// part 'node_list_view_model.g.dart'; +// +// class NodeListViewModel = NodeListViewModelBase with _$NodeListViewModel; + class ItemCell with Keyable { - ItemCell(this.value, {@required this.isSelected, @required dynamic key}) { + ItemCell(this.value, {this.isSelectedBuilder, @required dynamic key}) { keyIndex = key; } final Item value; - final bool isSelected; + + bool get isSelected => isSelectedBuilder(value); + bool Function(Item item) isSelectedBuilder; } diff --git a/lib/utils/mobx.dart b/lib/utils/mobx.dart index cb2d810e5..b11922f8e 100644 --- a/lib/utils/mobx.dart +++ b/lib/utils/mobx.dart @@ -6,36 +6,6 @@ mixin Keyable { dynamic keyIndex; } -void connectWithTransform( - ObservableList source, ObservableList dest, Y Function(T) transform, - {bool Function(T) filter}) { - source.observe((ListChange change) { - change.elementChanges.forEach((change) { - switch (change.type) { - case OperationType.add: - if (filter?.call(change.newValue as T) ?? true) { - dest.add(transform(change.newValue as T)); - } - break; - case OperationType.remove: - // Hive could has equal index and key - dest.removeWhere( - (elem) => elem.keyIndex == (change.oldValue.key ?? change.index)); - break; - case OperationType.update: - for (var i = 0; i < dest.length; i++) { - final item = dest[i]; - - if (item.keyIndex == change.newValue.key) { - dest[i] = transform(change.newValue as T); - } - } - break; - } - }); - }); -} - void connectMapToListWithTransform( ObservableMap source, ObservableList dest, @@ -50,8 +20,8 @@ void connectMapToListWithTransform( break; case OperationType.remove: // Hive could has equal index and key - dest.removeWhere( - (elem) => elem.keyIndex == (change.key ?? change.newValue.keyIndex)); + dest.removeWhere((elem) => + elem.keyIndex == (change.key ?? change.newValue.keyIndex)); break; case OperationType.update: for (var i = 0; i < dest.length; i++) { @@ -66,54 +36,124 @@ void connectMapToListWithTransform( }); } -void connect( - ObservableList source, ObservableList dest) { - source.observe((ListChange change) { - source.observe((ListChange change) { - change.elementChanges.forEach((change) { - switch (change.type) { - case OperationType.add: - // if (filter?.call(change.newValue as T) ?? true) { - dest.add(change.newValue as T); - // } - break; - case OperationType.remove: - // Hive could has equal index and key - dest.removeWhere((elem) => - elem.keyIndex == (change.oldValue.key ?? change.index)); - break; - case OperationType.update: - for (var i = 0; i < dest.length; i++) { - final item = dest[i]; +typedef Filter = bool Function(T); +typedef Transform = Y Function(T); - if (item.keyIndex == change.newValue.key) { - dest[i] = change.newValue as T; - } - } - break; - } - }); - }); - }); +enum ChangeType { update, delete, add } + +class EntityChange { + EntityChange(this.value, this.type, {dynamic key}) : _key = key; + + dynamic get key => _key ?? value.keyIndex; + final T value; + final ChangeType type; + final dynamic _key; } -StreamSubscription bindBox( - Box source, ObservableList dest) { - return source.watch().listen((event) { +extension MobxBindable on Box { + StreamSubscription bindToList( + ObservableList dest, { + bool initialFire = false, + Filter filter, + }) { + if (initialFire) { + dest.addAll(values); + } + + return watch().listen((event) { + if (filter != null && !filter(event.value as T)) { + return; + } + + dest.acceptBoxChange(event); + }); + } + + StreamSubscription bindToListWithTransform( + ObservableList dest, + Transform transform, { + bool initialFire = false, + Filter filter, + }) { + if (initialFire) { + dest.addAll(values.map((value) => transform(value))); + } + + return watch().listen((event) { + if (filter != null && !filter(event.value as T)) { + return; + } + + dest.acceptBoxChange(event, transformed: transform(event.value as T)); + }); + } +} + +extension HiveBindable on ObservableList { + Stream> listen() { + // ignore: close_sinks + final controller = StreamController>(); + + observe((ListChange change) { + change.elementChanges.forEach((change) { + ChangeType type; + + switch (change.type) { + case OperationType.add: + type = ChangeType.add; + break; + case OperationType.remove: + type = ChangeType.delete; + break; + case OperationType.update: + type = ChangeType.update; + break; + } + + final value = change.newValue as T; + controller.add(EntityChange(value, type)); + }); + }); + + return controller.stream; + } + + StreamSubscription> bindToList(ObservableList dest) => + listen().listen((event) => dest.acceptEntityChange(event)); + + void acceptBoxChange(BoxEvent event, {T transformed}) { if (event.deleted) { - dest.removeWhere((el) => el.keyIndex == event.key); + removeWhere((el) => el.keyIndex == event.key); + } + + final dynamic value = transformed ?? event.value; + + if (value is T) { + final index = indexWhere((el) => el.keyIndex == value.keyIndex); + + if (index > -1) { + this.setAll(index, [value]); // FIXME: fixme + } else { + add(value); + } + } + } + + void acceptEntityChange(EntityChange event) { + if (event.type == ChangeType.delete) { + removeWhere((el) => el.keyIndex == event.key); } final dynamic value = event.value; if (value is T) { - final elIndex = dest.indexWhere((el) => el.keyIndex == value.keyIndex); + final index = indexWhere((el) => el.keyIndex == value.keyIndex); - if (elIndex > -1) { - dest[elIndex] = value; + if (index > -1) { + this.setAll(index, [value]); // FIXME: fixme } else { - dest.add(value); + add(value); } } - }); + } } diff --git a/lib/view_model/contact_list/contact_list_view_model.dart b/lib/view_model/contact_list/contact_list_view_model.dart index d222cb6dd..aa3a5e2c7 100644 --- a/lib/view_model/contact_list/contact_list_view_model.dart +++ b/lib/view_model/contact_list/contact_list_view_model.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'package:cake_wallet/entities/contact_record.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/core/contact_service.dart'; @@ -14,19 +15,21 @@ class ContactListViewModel = ContactListViewModelBase abstract class ContactListViewModelBase with Store { ContactListViewModelBase( this.addressBookStore, this.contactService, this.contactSource) { - _subscription = bindBox(contactSource, addressBookStore.contacts); + _subscription = contactSource.bindToListWithTransform(addressBookStore.contacts, + (Contact contact) => ContactRecord(contactSource, contact), + initialFire: true); } final ContactListStore addressBookStore; final ContactService contactService; final Box contactSource; - ObservableList get contacts => addressBookStore.contacts; + ObservableList get contacts => addressBookStore.contacts; StreamSubscription _subscription; void dispose() { - _subscription.cancel(); + // _subscription.cancel(); } Future delete(Contact contact) async => contactService.delete(contact); diff --git a/lib/view_model/contact_list/contact_view_model.dart b/lib/view_model/contact_list/contact_view_model.dart index 059b6a210..cb48260b5 100644 --- a/lib/view_model/contact_list/contact_view_model.dart +++ b/lib/view_model/contact_list/contact_view_model.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/entities/contact_record.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/core/execution_state.dart'; @@ -11,7 +12,7 @@ part 'contact_view_model.g.dart'; class ContactViewModel = ContactViewModelBase with _$ContactViewModel; abstract class ContactViewModelBase with Store { - ContactViewModelBase(this._contacts, this._wallet, {Contact contact}) + ContactViewModelBase(this._contacts, this._wallet, {ContactRecord contact}) : state = InitialExecutionState(), currencies = CryptoCurrency.all, _contact = contact { @@ -41,7 +42,7 @@ abstract class ContactViewModelBase with Store { final List currencies; final WalletBase _wallet; final Box _contacts; - final Contact _contact; + final ContactRecord _contact; @action void reset() { @@ -57,9 +58,12 @@ abstract class ContactViewModelBase with Store { if (_contact != null) { _contact.name = name; _contact.address = address; - _contact.updateCryptoCurrency(currency: currency); - await _contacts.put(_contact.key, _contact); + _contact.type = currency; + await _contact.save(); + // await _contacts.put(_contact.key, _contact); } else { + // final contact = ContactRecordBase.create(_contacts, name, address, currency); + // await contact.save(); await _contacts .add(Contact(name: name, address: address, type: currency)); } diff --git a/lib/view_model/node_list/node_list_view_model.dart b/lib/view_model/node_list/node_list_view_model.dart index 4ca46c9fc..2231ff7c9 100644 --- a/lib/view_model/node_list/node_list_view_model.dart +++ b/lib/view_model/node_list/node_list_view_model.dart @@ -1,45 +1,29 @@ import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/core/wallet_base.dart'; +import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/entities/node.dart'; import 'package:cake_wallet/entities/node_list.dart'; -import 'package:cake_wallet/store/node_list_store.dart'; -import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/entities/default_settings_migration.dart'; import 'package:cake_wallet/entities/wallet_type.dart'; import 'package:cake_wallet/utils/mobx.dart'; -import 'package:cake_wallet/utils/item_cell.dart'; part 'node_list_view_model.g.dart'; class NodeListViewModel = NodeListViewModelBase with _$NodeListViewModel; abstract class NodeListViewModelBase with Store { - NodeListViewModelBase( - this._nodeListStore, this._nodeSource, this._wallet, this._settingsStore) - : nodes = ObservableList>() { - final currentNode = _settingsStore.getCurrentNode(_wallet.type); - final values = _nodeListStore.nodes; - nodes.clear(); - nodes.addAll(values.where((Node node) => node.type == _wallet.type).map( - (Node val) => ItemCell(val, - isSelected: val.key == currentNode.key, key: val.key))); - connectWithTransform( - _nodeListStore.nodes, - nodes, - (Node val) => ItemCell(val, - isSelected: val.key == currentNode.key, key: val.key), - filter: (Node val) => val.type == _wallet.type); - reaction((_) => _settingsStore.nodes[_wallet.type], - (Node _) => _updateCurrentNode()); + NodeListViewModelBase(this._nodeSource, this._wallet, this.settingsStore) + : nodes = ObservableList() { + _nodeSource.bindToList(nodes, + filter: (Node val) => val.type == _wallet.type, initialFire: true); } - ObservableList> nodes; + final ObservableList nodes; + final SettingsStore settingsStore; final WalletBase _wallet; final Box _nodeSource; - final NodeListStore _nodeListStore; - final SettingsStore _settingsStore; Future reset() async { await resetToDefault(_nodeSource); @@ -64,24 +48,6 @@ abstract class NodeListViewModelBase with Store { Future delete(Node node) async => _nodeSource.delete(node.key); - Future setAsCurrent(Node node) async { - await _settingsStore.setCurrentNode(node, _wallet.type); - _updateCurrentNode(); - await _wallet.connectToNode(node: node); - } - - @action - void _updateCurrentNode() { - final currentNode = _settingsStore.getCurrentNode(_wallet.type); - - for (var i = 0; i < nodes.length; i++) { - final item = nodes[i]; - final isSelected = item.value.key == currentNode.key; - - if (item.isSelected != isSelected) { - nodes[i] = ItemCell(item.value, - isSelected: isSelected, key: item.keyIndex); - } - } - } + Future setAsCurrent(Node node) async => + settingsStore.currentNode = node; } diff --git a/pubspec.lock b/pubspec.lock index 612b1ac91..f9bbbbd26 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -217,7 +217,7 @@ packages: name: connectivity url: "https://pub.dartlang.org" source: hosted - version: "0.4.9+2" + version: "0.4.9+3" connectivity_for_web: dependency: transitive description: @@ -252,7 +252,7 @@ packages: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.1.4" + version: "2.1.5" csslib: dependency: transitive description: @@ -395,7 +395,7 @@ packages: name: flutter_plugin_android_lifecycle url: "https://pub.dartlang.org" source: hosted - version: "1.0.9" + version: "1.0.11" flutter_secure_storage: dependency: "direct main" description: @@ -470,7 +470,7 @@ packages: name: hive_generator url: "https://pub.dartlang.org" source: hosted - version: "0.7.1" + version: "0.7.2+1" html: dependency: transitive description: @@ -505,7 +505,7 @@ packages: name: image url: "https://pub.dartlang.org" source: hosted - version: "2.1.12" + version: "2.1.18" intl: dependency: "direct main" description: @@ -533,14 +533,14 @@ packages: name: json_annotation url: "https://pub.dartlang.org" source: hosted - version: "3.0.1" + version: "3.1.0" local_auth: dependency: "direct main" description: name: local_auth url: "https://pub.dartlang.org" source: hosted - version: "0.6.3+1" + version: "0.6.3+2" logging: dependency: transitive description: @@ -645,7 +645,7 @@ packages: name: path_provider url: "https://pub.dartlang.org" source: hosted - version: "1.6.17" + version: "1.6.18" path_provider_linux: dependency: transitive description: @@ -687,7 +687,7 @@ packages: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "3.0.4" platform: dependency: transitive description: @@ -695,13 +695,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.2.1" - platform_detect: - dependency: transitive - description: - name: platform_detect - url: "https://pub.dartlang.org" - source: hosted - version: "1.4.0" plugin_platform_interface: dependency: transitive description: @@ -785,14 +778,14 @@ packages: name: share url: "https://pub.dartlang.org" source: hosted - version: "0.6.5+1" + version: "0.6.5+2" shared_preferences: dependency: "direct main" description: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "0.5.11" + version: "0.5.12" shared_preferences_linux: dependency: transitive description: @@ -937,7 +930,7 @@ packages: name: url_launcher url: "https://pub.dartlang.org" source: hosted - version: "5.7.0" + version: "5.7.2" url_launcher_linux: dependency: transitive description: @@ -965,7 +958,7 @@ packages: name: url_launcher_web url: "https://pub.dartlang.org" source: hosted - version: "0.1.3+2" + version: "0.1.4+1" url_launcher_windows: dependency: transitive description: @@ -1021,7 +1014,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "3.6.1" + version: "4.5.1" yaml: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index f15f131c1..d6ac4bf73 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -14,7 +14,7 @@ description: Cake Wallet. version: 1.0.5+5 environment: - sdk: ">=2.2.2 <3.0.0" + sdk: ">=2.7.0 <3.0.0" dependencies: flutter: From e3678d2cf91e06d3ec0e32142e5c48ef80899f5f Mon Sep 17 00:00:00 2001 From: M Date: Mon, 28 Sep 2020 18:47:43 +0300 Subject: [PATCH 9/9] Fixes --- lib/core/contact_service.dart | 38 --- lib/di.dart | 31 +- lib/entities/language.dart | 38 --- lib/entities/language_service.dart | 26 ++ lib/entities/node.dart | 36 ++- lib/entities/record.dart | 3 +- lib/main.dart | 195 +++--------- lib/router.dart | 9 +- lib/src/reactions/set_reactions.dart | 98 ------ lib/src/screens/base_page.dart | 44 ++- .../screens/contact/contact_list_page.dart | 8 +- .../dashboard/create_dashboard_page.dart | 33 -- lib/src/screens/dashboard/dashboard_page.dart | 2 +- .../dashboard/widgets/balance_page.dart | 73 ++--- .../exchange/widgets/exchange_card.dart | 10 +- lib/src/screens/faq/faq_item.dart | 61 ++++ lib/src/screens/faq/faq_page.dart | 140 +------- lib/src/screens/send/send_page.dart | 299 +++++++++--------- lib/src/screens/settings/change_language.dart | 96 +++--- lib/src/widgets/alert_close_button.dart | 2 +- lib/store/app_store.dart | 4 - lib/store/contact_list_store.dart | 12 - lib/store/settings_store.dart | 24 +- lib/store/theme_changer_store.dart | 13 - lib/theme_changer.dart | 16 - lib/utils/date_formatter.dart | 2 +- lib/utils/mobx.dart | 6 +- .../contact_list/contact_list_view_model.dart | 24 +- .../contact_list/contact_view_model.dart | 9 +- lib/view_model/send/send_view_model.dart | 8 +- .../settings/settings_view_model.dart | 24 +- test/widget_test.dart | 2 +- 32 files changed, 482 insertions(+), 904 deletions(-) delete mode 100644 lib/core/contact_service.dart delete mode 100644 lib/entities/language.dart create mode 100644 lib/entities/language_service.dart delete mode 100644 lib/src/reactions/set_reactions.dart delete mode 100644 lib/src/screens/dashboard/create_dashboard_page.dart create mode 100644 lib/src/screens/faq/faq_item.dart delete mode 100644 lib/store/contact_list_store.dart delete mode 100644 lib/store/theme_changer_store.dart delete mode 100644 lib/theme_changer.dart diff --git a/lib/core/contact_service.dart b/lib/core/contact_service.dart deleted file mode 100644 index 3f2a46203..000000000 --- a/lib/core/contact_service.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'package:hive/hive.dart'; -import 'package:cake_wallet/store/contact_list_store.dart'; -import 'package:cake_wallet/entities/contact.dart'; - -class ContactService { - ContactService(this.contactSource, this.contactListStore) { - _forceUpdateContactListStore(); - } - - final Box contactSource; - final ContactListStore contactListStore; - - Future add(Contact contact) async { - await contactSource.add(contact); - // contactListStore.contacts.add(contact); - } - - Future update(Contact contact) async { - await contact.save(); - final index = contactListStore.contacts.indexOf(contact) ?? -1; - - if (index >= 0) { - _forceUpdateContactListStore(); - } else { - // contactListStore.contacts.add(contact); - } - } - - Future delete(Contact contact) async { - await contact.delete(); - contactListStore.contacts.remove(contact); - } - - void _forceUpdateContactListStore() { - contactListStore.contacts.clear(); - // contactListStore.contacts.addAll(contactSource.values); - } -} diff --git a/lib/di.dart b/lib/di.dart index d6ccde3cc..d133b6ed0 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1,5 +1,4 @@ import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart'; -import 'package:cake_wallet/core/contact_service.dart'; import 'package:cake_wallet/core/wallet_service.dart'; import 'package:cake_wallet/entities/biometric_auth.dart'; import 'package:cake_wallet/entities/contact_record.dart'; @@ -8,22 +7,22 @@ import 'package:cake_wallet/entities/contact.dart'; import 'package:cake_wallet/entities/node.dart'; import 'package:cake_wallet/exchange/trade.dart'; -// import 'package:cake_wallet/src/domain/services/wallet_service.dart'; import 'package:cake_wallet/src/screens/contact/contact_list_page.dart'; import 'package:cake_wallet/src/screens/contact/contact_page.dart'; import 'package:cake_wallet/src/screens/exchange_trade/exchange_confirm_page.dart'; import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_page.dart'; +import 'package:cake_wallet/src/screens/faq/faq_page.dart'; import 'package:cake_wallet/src/screens/nodes/node_create_or_edit_page.dart'; import 'package:cake_wallet/src/screens/nodes/nodes_list_page.dart'; import 'package:cake_wallet/src/screens/rescan/rescan_page.dart'; import 'package:cake_wallet/src/screens/seed/wallet_seed_page.dart'; import 'package:cake_wallet/src/screens/send/send_template_page.dart'; +import 'package:cake_wallet/src/screens/settings/change_language.dart'; import 'package:cake_wallet/src/screens/settings/settings.dart'; import 'package:cake_wallet/src/screens/setup_pin_code/setup_pin_code.dart'; import 'package:cake_wallet/src/screens/wallet_keys/wallet_keys_page.dart'; import 'package:cake_wallet/src/screens/exchange/exchange_page.dart'; import 'package:cake_wallet/src/screens/exchange/exchange_template_page.dart'; -import 'package:cake_wallet/store/contact_list_store.dart'; import 'package:cake_wallet/store/node_list_store.dart'; import 'package:cake_wallet/store/settings_store.dart'; import 'package:cake_wallet/core/auth_service.dart'; @@ -38,10 +37,7 @@ import 'package:cake_wallet/src/screens/receive/receive_page.dart'; import 'package:cake_wallet/src/screens/send/send_page.dart'; import 'package:cake_wallet/src/screens/subaddress/address_edit_or_create_page.dart'; import 'package:cake_wallet/src/screens/wallet_list/wallet_list_page.dart'; -import 'package:cake_wallet/store/theme_changer_store.dart'; import 'package:cake_wallet/store/wallet_list_store.dart'; -import 'package:cake_wallet/utils/mobx.dart'; -import 'package:cake_wallet/theme_changer.dart'; import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart'; import 'package:cake_wallet/view_model/contact_list/contact_view_model.dart'; import 'package:cake_wallet/view_model/exchange/exchange_trade_view_model.dart'; @@ -62,11 +58,9 @@ import 'package:cake_wallet/view_model/wallet_keys_view_model.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart'; import 'package:cake_wallet/view_model/wallet_seed_view_model.dart'; import 'package:cake_wallet/view_model/exchange/exchange_view_model.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'package:get_it/get_it.dart'; import 'package:hive/hive.dart'; -import 'package:mobx/mobx.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:cake_wallet/view_model/wallet_restoration_from_seed_vm.dart'; @@ -104,17 +98,13 @@ Future setup( getIt.registerSingleton(FlutterSecureStorage()); getIt.registerSingleton(AuthenticationStore()); getIt.registerSingleton(WalletListStore()); - getIt.registerSingleton(ContactListStore()); getIt.registerSingleton(NodeListStoreBase.instance); getIt.registerSingleton(settingsStore); getIt.registerSingleton(AppStore( authenticationStore: getIt.get(), walletList: getIt.get(), settingsStore: getIt.get(), - contactListStore: getIt.get(), nodeListStore: getIt.get())); - getIt.registerSingleton( - ContactService(contactSource, getIt.get().contactListStore)); getIt.registerSingleton(TradesStore( tradesSource: tradesSource, settingsStore: getIt.get())); getIt.registerSingleton(TradeFilterStore()); @@ -285,14 +275,10 @@ Future setup( getIt.registerFactory(() => WalletKeysPage(getIt.get())); getIt.registerFactoryParam( - (ContactRecord contact, _) => ContactViewModel( - contactSource, getIt.get().wallet, - contact: contact)); + (ContactRecord contact, _) => + ContactViewModel(contactSource, contact: contact)); - getIt.registerFactory(() => ContactListViewModel( - getIt.get().contactListStore, - getIt.get(), - contactSource)); + getIt.registerFactory(() => ContactListViewModel(contactSource)); getIt.registerFactoryParam( (bool isEditable, _) => ContactListPage(getIt.get(), @@ -366,9 +352,8 @@ Future setup( getIt.registerFactory(() => RescanViewModel(getIt.get().wallet)); getIt.registerFactory(() => RescanPage(getIt.get())); -} -void setupThemeChangerStore(ThemeChanger themeChanger) { - getIt.registerSingleton( - ThemeChangerStore(themeChanger: themeChanger)); + getIt.registerFactory(() => FaqPage(getIt.get())); + + getIt.registerFactory(() => LanguageListPage(getIt.get())); } diff --git a/lib/entities/language.dart b/lib/entities/language.dart deleted file mode 100644 index 16e1d1a6a..000000000 --- a/lib/entities/language.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:devicelocale/devicelocale.dart'; -import 'package:intl/intl.dart'; - -const Map languages = { - 'en': 'English', - 'de': 'Deutsch (German)', - 'es': 'Español (Spanish)', - 'hi': 'हिंदी (Hindi)', - 'ja': '日本 (Japanese)', - 'ko': '한국어 (Korean)', - 'nl': 'Nederlands (Dutch)', - 'pl': 'Polski (Polish)', - 'pt': 'Português (Portuguese)', - 'ru': 'Русский (Russian)', - 'uk': 'Українська (Ukrainian)', - 'zh': '中文 (Chinese)' -}; - -class Language with ChangeNotifier { - Language(this._currentLanguage); - - String _currentLanguage; - - String getCurrentLanguage() => _currentLanguage; - - void setCurrentLanguage(String language) { - _currentLanguage = language; - notifyListeners(); - } - - static Future localeDetection() async { - var locale = await Devicelocale.currentLocale; - locale = Intl.shortLocale(locale); - - return languages.keys.contains(locale) ? locale : 'en'; - } -} \ No newline at end of file diff --git a/lib/entities/language_service.dart b/lib/entities/language_service.dart new file mode 100644 index 000000000..4ea158353 --- /dev/null +++ b/lib/entities/language_service.dart @@ -0,0 +1,26 @@ +import 'package:devicelocale/devicelocale.dart'; +import 'package:intl/intl.dart'; + +class LanguageService { + static const Map list = { + 'en': 'English', + 'de': 'Deutsch (German)', + 'es': 'Español (Spanish)', + 'hi': 'हिंदी (Hindi)', + 'ja': '日本 (Japanese)', + 'ko': '한국어 (Korean)', + 'nl': 'Nederlands (Dutch)', + 'pl': 'Polski (Polish)', + 'pt': 'Português (Portuguese)', + 'ru': 'Русский (Russian)', + 'uk': 'Українська (Ukrainian)', + 'zh': '中文 (Chinese)' + }; + + static Future localeDetection() async { + var locale = await Devicelocale.currentLocale; + locale = Intl.shortLocale(locale); + + return list.keys.contains(locale) ? locale : 'en'; + } +} diff --git a/lib/entities/node.dart b/lib/entities/node.dart index f79b8b2e0..d96834dcb 100644 --- a/lib/entities/node.dart +++ b/lib/entities/node.dart @@ -61,24 +61,28 @@ class Node extends HiveObject with Keyable { } Future requestMoneroNode() async { - Map resBody; + try { + Map resBody; - if (login != null && password != null) { - final digestRequest = DigestRequest(); - final response = await digestRequest.request( - uri: uri, login: login, password: password); - resBody = response.data as Map; - } else { - final url = Uri.http(uri, '/json_rpc'); - final headers = {'Content-type': 'application/json'}; - final body = - json.encode({'jsonrpc': '2.0', 'id': '0', 'method': 'get_info'}); - final response = - await http.post(url.toString(), headers: headers, body: body); - resBody = json.decode(response.body) as Map; + if (login != null && password != null) { + final digestRequest = DigestRequest(); + final response = await digestRequest.request( + uri: uri, login: login, password: password); + resBody = response.data as Map; + } else { + final url = Uri.http(uri, '/json_rpc'); + final headers = {'Content-type': 'application/json'}; + final body = + json.encode({'jsonrpc': '2.0', 'id': '0', 'method': 'get_info'}); + final response = + await http.post(url.toString(), headers: headers, body: body); + resBody = json.decode(response.body) as Map; + } + + return !(resBody['result']['offline'] as bool); + } catch (_) { + return false; } - - return !(resBody['result']['offline'] as bool); } Future requestBitcoinElectrumServer() async { diff --git a/lib/entities/record.dart b/lib/entities/record.dart index 3c21441cc..1ca661684 100644 --- a/lib/entities/record.dart +++ b/lib/entities/record.dart @@ -5,6 +5,7 @@ import 'package:hive/hive.dart'; abstract class Record with Keyable { Record(this._source, this.original) { + key = original.key; _listener?.cancel(); _listener = _source.watch(key: original.key).listen((event) { if (!event.deleted) { @@ -16,7 +17,7 @@ abstract class Record with Keyable { toBind(original); } - dynamic get key => original.key; + dynamic key; @override dynamic get keyIndex => key; diff --git a/lib/main.dart b/lib/main.dart index 66cca43a5..4a49b646a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,66 +1,30 @@ -import 'package:cake_wallet/entities/fs_migration.dart'; -import 'package:cake_wallet/entities/transaction_description.dart'; -import 'package:cake_wallet/entities/transaction_description.dart'; -import 'package:cake_wallet/reactions/bootstrap.dart'; -import 'package:cake_wallet/routes.dart'; -import 'package:cake_wallet/store/app_store.dart'; -import 'package:cake_wallet/store/authentication_store.dart'; -import 'package:cake_wallet/core/auth_service.dart'; -import 'package:cake_wallet/bitcoin/bitcoin_wallet_service.dart'; -import 'package:cake_wallet/monero/monero_wallet_service.dart'; -import 'package:cake_wallet/core/wallet_creation_service.dart'; -import 'package:cake_wallet/di.dart'; -import 'package:cake_wallet/view_model/wallet_new_vm.dart'; -import 'package:flutter_localizations/flutter_localizations.dart'; -import 'package:get_it/get_it.dart'; -import 'package:path_provider/path_provider.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:provider/provider.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:hive/hive.dart'; +import 'package:cake_wallet/di.dart'; +import 'package:path_provider/path_provider.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:flutter_localizations/flutter_localizations.dart'; +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:cw_monero/wallet.dart' as monero_wallet; import 'package:cake_wallet/router.dart'; -import 'theme_changer.dart'; -import 'themes.dart'; +import 'package:cake_wallet/routes.dart'; +import 'package:cake_wallet/generated/i18n.dart'; +import 'package:cake_wallet/reactions/bootstrap.dart'; +import 'package:cake_wallet/store/app_store.dart'; +import 'package:cake_wallet/store/authentication_store.dart'; +import 'package:cake_wallet/entities/transaction_description.dart'; import 'package:cake_wallet/entities/get_encryption_key.dart'; import 'package:cake_wallet/entities/contact.dart'; import 'package:cake_wallet/entities/node.dart'; import 'package:cake_wallet/entities/wallet_info.dart'; -import 'package:cake_wallet/exchange/trade.dart'; - -// import 'package:cake_wallet/monero/transaction_description.dart'; -import 'package:cake_wallet/src/reactions/set_reactions.dart'; - -// import 'package:cake_wallet/src/stores/login/login_store.dart'; -// import 'package:cake_wallet/src/stores/balance/balance_store.dart'; -// import 'package:cake_wallet/src/stores/sync/sync_store.dart'; -// import 'package:cake_wallet/src/stores/wallet/wallet_store.dart'; -// import 'package:cake_wallet/src/stores/send_template/send_template_store.dart'; -// import 'package:cake_wallet/src/stores/exchange_template/exchange_template_store.dart'; -import 'package:cake_wallet/src/screens/root/root.dart'; - -//import 'package:cake_wallet/src/stores/authentication/authentication_store.dart'; -// import 'package:cake_wallet/src/stores/settings/settings_store.dart'; -// import 'package:cake_wallet/src/stores/price/price_store.dart'; -// import 'package:cake_wallet/src/domain/services/user_service.dart'; -// import 'package:cake_wallet/src/domain/services/wallet_list_service.dart'; -import 'package:cake_wallet/entities/balance_display_mode.dart'; import 'package:cake_wallet/entities/default_settings_migration.dart'; -import 'package:cake_wallet/entities/fiat_currency.dart'; -import 'package:cake_wallet/entities/transaction_priority.dart'; import 'package:cake_wallet/entities/wallet_type.dart'; import 'package:cake_wallet/entities/template.dart'; +import 'package:cake_wallet/exchange/trade.dart'; import 'package:cake_wallet/exchange/exchange_template.dart'; - -// import 'package:cake_wallet/src/domain/services/wallet_service.dart'; -// import 'package:cake_wallet/src/domain/services/fiat_convertation_service.dart'; -import 'package:cake_wallet/generated/i18n.dart'; -import 'package:cake_wallet/entities/language.dart'; -// import 'package:cake_wallet/src/stores/seed_language/seed_language_store.dart'; - -bool isThemeChangerRegistered = false; +import 'package:cake_wallet/src/screens/root/root.dart'; final navigatorKey = GlobalKey(); @@ -94,41 +58,6 @@ void main() async { final templates = await Hive.openBox