From 7d10ae201198a2420973f8de4c7ca105c5954537 Mon Sep 17 00:00:00 2001 From: julian Date: Tue, 24 Jan 2023 10:16:44 -0600 Subject: [PATCH] go directly to wallet view on single wallet per coin on desktop and mobile --- .../sub_widgets/wallet_list_item.dart | 45 ++++++++++++++----- .../my_stack_view/wallet_summary_table.dart | 12 +++++ lib/widgets/expandable.dart | 4 +- lib/widgets/table_view/table_view_row.dart | 3 ++ 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart b/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart index e3fd5d614..7b9d0b53f 100644 --- a/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart +++ b/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart @@ -1,16 +1,19 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; +import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; import 'package:stackwallet/pages/wallets_sheet/wallets_sheet.dart'; import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/format.dart'; -import 'package:stackwallet/utilities/prefs.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; +import 'package:tuple/tuple.dart'; class WalletListItem extends ConsumerWidget { const WalletListItem({ @@ -41,17 +44,37 @@ class WalletListItem extends ConsumerWidget { borderRadius: BorderRadius.circular(Constants.size.circularBorderRadius), ), - onPressed: () { - showModalBottomSheet( - backgroundColor: Colors.transparent, - context: context, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.vertical( - top: Radius.circular(20), + onPressed: () async { + if (walletCount == 1) { + final providersByCoin = ref.watch(walletsChangeNotifierProvider + .select((value) => value.getManagerProvidersByCoin())); + final manager = ref.read(providersByCoin[coin]!.first); + if (coin == Coin.monero || coin == Coin.wownero) { + await manager.initializeExisting(); + } + unawaited( + Navigator.of(context).pushNamed( + WalletView.routeName, + arguments: Tuple2( + manager.walletId, + providersByCoin[coin]!.first, + ), ), - ), - builder: (_) => WalletsSheet(coin: coin), - ); + ); + } else { + unawaited( + showModalBottomSheet( + backgroundColor: Colors.transparent, + context: context, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical( + top: Radius.circular(20), + ), + ), + builder: (_) => WalletsSheet(coin: coin), + ), + ); + } }, child: Row( children: [ diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart b/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart index d638b3d04..b638d72a1 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/coin_wallets_table.dart'; +import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart'; import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; @@ -43,7 +44,18 @@ class _WalletTableState extends ConsumerState { (value) => value .getManagerProvidersForCoin(providersByCoin[i].key))); + VoidCallback? expandOverride; + if (providers.length == 1) { + expandOverride = () { + Navigator.of(context).pushNamed( + DesktopWalletView.routeName, + arguments: ref.read(providers.first).walletId, + ); + }; + } + return TableViewRow( + expandOverride: expandOverride, padding: const EdgeInsets.symmetric( horizontal: 20, vertical: 16, diff --git a/lib/widgets/expandable.dart b/lib/widgets/expandable.dart index 737f4ce7d..b60226a50 100644 --- a/lib/widgets/expandable.dart +++ b/lib/widgets/expandable.dart @@ -20,6 +20,7 @@ class Expandable extends StatefulWidget { this.animationDurationMultiplier = 1.0, this.onExpandChanged, this.controller, + this.expandOverride, }) : super(key: key); final Widget header; @@ -29,6 +30,7 @@ class Expandable extends StatefulWidget { final double animationDurationMultiplier; final void Function(ExpandableState)? onExpandChanged; final ExpandableController? controller; + final VoidCallback? expandOverride; @override State createState() => _ExpandableState(); @@ -92,7 +94,7 @@ class _ExpandableState extends State with TickerProviderStateMixin { MouseRegion( cursor: SystemMouseCursors.click, child: GestureDetector( - onTap: toggle, + onTap: widget.expandOverride ?? toggle, child: Container( color: Colors.transparent, child: widget.header, diff --git a/lib/widgets/table_view/table_view_row.dart b/lib/widgets/table_view/table_view_row.dart index 2bfc9d0c2..57f5da638 100644 --- a/lib/widgets/table_view/table_view_row.dart +++ b/lib/widgets/table_view/table_view_row.dart @@ -10,6 +10,7 @@ class TableViewRow extends StatefulWidget { required this.expandingChild, this.decoration, this.onExpandChanged, + this.expandOverride, this.padding = const EdgeInsets.all(0), this.spacing = 0.0, this.crossAxisAlignment = CrossAxisAlignment.center, @@ -19,6 +20,7 @@ class TableViewRow extends StatefulWidget { final Widget? expandingChild; final BoxDecoration? decoration; final void Function(ExpandableState)? onExpandChanged; + final VoidCallback? expandOverride; final EdgeInsetsGeometry padding; final double spacing; final CrossAxisAlignment crossAxisAlignment; @@ -74,6 +76,7 @@ class _TableViewRowState extends State { ), ) : Expandable( + expandOverride: widget.expandOverride, onExpandChanged: widget.onExpandChanged, header: MouseRegion( onEnter: (_) {