diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/desktop_token_view.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/desktop_token_view.dart new file mode 100644 index 000000000..70f319cf1 --- /dev/null +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/desktop_token_view.dart @@ -0,0 +1,228 @@ +import 'package:event_bus/event_bus.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:stackwallet/pages/token_view/sub_widgets/token_summary.dart'; +import 'package:stackwallet/pages/token_view/sub_widgets/token_transaction_list_widget.dart'; +import 'package:stackwallet/pages/token_view/token_view.dart'; +import 'package:stackwallet/pages/wallet_view/transaction_views/all_transactions_view.dart'; +import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_features.dart'; +import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_summary.dart'; +import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/my_wallet.dart'; +import 'package:stackwallet/providers/providers.dart'; +import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart'; +import 'package:stackwallet/utilities/assets.dart'; +import 'package:stackwallet/utilities/text_styles.dart'; +import 'package:stackwallet/utilities/theme/stack_colors.dart'; +import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart'; +import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart'; +import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart'; +import 'package:stackwallet/widgets/desktop/secondary_button.dart'; +import 'package:stackwallet/widgets/icon_widgets/eth_token_icon.dart'; +import 'package:stackwallet/widgets/rounded_white_container.dart'; + +/// [eventBus] should only be set during testing +class DesktopTokenView extends ConsumerStatefulWidget { + const DesktopTokenView({ + Key? key, + required this.walletId, + this.eventBus, + }) : super(key: key); + + static const String routeName = "/desktopTokenView"; + + final String walletId; + final EventBus? eventBus; + + @override + ConsumerState createState() => _DesktopTokenViewState(); +} + +class _DesktopTokenViewState extends ConsumerState { + late final WalletSyncStatus initialSyncStatus; + + @override + void initState() { + initialSyncStatus = ref.read(tokenServiceProvider)!.isRefreshing + ? WalletSyncStatus.syncing + : WalletSyncStatus.synced; + super.initState(); + } + + @override + void dispose() { + super.dispose(); + } + + @override + Widget build(BuildContext context) { + debugPrint("BUILD: $runtimeType"); + + return DesktopScaffold( + appBar: DesktopAppBar( + background: Theme.of(context).extension()!.popupBG, + leading: Expanded( + flex: 3, + child: Row( + children: [ + const SizedBox( + width: 32, + ), + SecondaryButton( + padding: const EdgeInsets.only( + left: 12, + right: 18, + ), + buttonHeight: ButtonHeight.s, + label: ref.watch( + walletsChangeNotifierProvider.select( + (value) => value.getManager(widget.walletId).walletName, + ), + ), + icon: SvgPicture.asset( + Assets.svg.arrowLeft, + width: 18, + height: 18, + color: Theme.of(context) + .extension()! + .topNavIconPrimary, + ), + onPressed: Navigator.of(context).pop, + ), + const SizedBox( + width: 15, + ), + ], + ), + ), + center: Expanded( + flex: 4, + child: Row( + children: [ + EthTokenIcon( + contractAddress: ref.watch( + tokenServiceProvider.select( + (value) => value!.tokenContract.address, + ), + ), + size: 32, + ), + const SizedBox( + width: 12, + ), + Text( + ref.watch( + tokenServiceProvider.select( + (value) => value!.tokenContract.name, + ), + ), + style: STextStyles.desktopH3(context), + ), + const SizedBox( + width: 12, + ), + CoinTickerTag( + walletId: widget.walletId, + ), + ], + ), + ), + useSpacers: false, + isCompactHeight: true, + ), + body: Padding( + padding: const EdgeInsets.all(24), + child: Column( + children: [ + RoundedWhiteContainer( + padding: const EdgeInsets.all(20), + child: Row( + children: [ + EthTokenIcon( + contractAddress: ref.watch( + tokenServiceProvider.select( + (value) => value!.tokenContract.address, + ), + ), + size: 40, + ), + const SizedBox( + width: 10, + ), + DesktopWalletSummary( + walletId: widget.walletId, + isToken: true, + initialSyncStatus: ref.watch( + walletsChangeNotifierProvider.select((value) => + value.getManager(widget.walletId).isRefreshing)) + ? WalletSyncStatus.syncing + : WalletSyncStatus.synced, + ), + const Spacer(), + DesktopWalletFeatures( + walletId: widget.walletId, + ), + ], + ), + ), + const SizedBox( + height: 24, + ), + Expanded( + child: Row( + children: [ + SizedBox( + width: 450, + child: MyWallet( + walletId: widget.walletId, + ), + ), + const SizedBox( + width: 16, + ), + Expanded( + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Recent transactions", + style: STextStyles.desktopTextExtraSmall(context) + .copyWith( + color: Theme.of(context) + .extension()! + .textFieldActiveSearchIconLeft, + ), + ), + CustomTextButton( + text: "See all", + onTap: () { + Navigator.of(context).pushNamed( + AllTransactionsView.routeName, + arguments: widget.walletId, + ); + }, + ), + ], + ), + const SizedBox( + height: 16, + ), + Expanded( + child: TokenTransactionsList( + walletId: widget.walletId, + ), + ), + ], + ), + ), + ], + ), + ), + ], + ), + ), + ); + } +} diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_summary.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_summary.dart index 4d30ebc60..75937a7d8 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_summary.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_wallet_summary.dart @@ -2,6 +2,7 @@ import 'package:decimal/decimal.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/models/balance.dart'; +import 'package:stackwallet/pages/token_view/token_view.dart'; import 'package:stackwallet/pages/wallet_view/sub_widgets/wallet_refresh_button.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_balance_toggle_button.dart'; import 'package:stackwallet/providers/providers.dart'; @@ -19,10 +20,12 @@ class DesktopWalletSummary extends ConsumerStatefulWidget { Key? key, required this.walletId, required this.initialSyncStatus, + this.isToken = false, }) : super(key: key); final String walletId; final WalletSyncStatus initialSyncStatus; + final bool isToken; @override ConsumerState createState() => @@ -58,15 +61,30 @@ class _WDesktopWalletSummaryState extends ConsumerState { final baseCurrency = ref .watch(prefsChangeNotifierProvider.select((value) => value.currency)); - final priceTuple = ref.watch(priceAnd24hChangeNotifierProvider - .select((value) => value.getPrice(coin))); + final priceTuple = widget.isToken + ? ref.watch(priceAnd24hChangeNotifierProvider.select((value) => + value.getTokenPrice(ref.watch(tokenServiceProvider + .select((value) => value!.tokenContract.address))))) + : ref.watch(priceAnd24hChangeNotifierProvider + .select((value) => value.getPrice(coin))); final _showAvailable = ref.watch(walletBalanceToggleStateProvider.state).state == WalletBalanceToggleState.available; - Balance balance = ref.watch(walletsChangeNotifierProvider - .select((value) => value.getManager(walletId).balance)); + final unit = widget.isToken + ? ref.watch( + tokenServiceProvider.select((value) => value!.tokenContract.symbol)) + : coin.ticker; + final decimalPlaces = widget.isToken + ? ref.watch(tokenServiceProvider + .select((value) => value!.tokenContract.decimals)) + : coin.decimals; + + Balance balance = widget.isToken + ? ref.watch(tokenServiceProvider.select((value) => value!.balance)) + : ref.watch(walletsChangeNotifierProvider + .select((value) => value.getManager(walletId).balance)); Decimal balanceToShow; if (coin == Coin.firo || coin == Coin.firoTestNet) { @@ -112,8 +130,8 @@ class _WDesktopWalletSummaryState extends ConsumerState { "${Format.localizedStringAsFixed( value: balanceToShow, locale: locale, - decimalPlaces: 8, - )} ${coin.ticker}", + decimalPlaces: decimalPlaces, + )} $unit", style: STextStyles.desktopH3(context), ), ), diff --git a/lib/route_generator.dart b/lib/route_generator.dart index 4decebcdf..9ef8bc2aa 100644 --- a/lib/route_generator.dart +++ b/lib/route_generator.dart @@ -117,6 +117,7 @@ import 'package:stackwallet/pages_desktop_specific/desktop_exchange/desktop_all_ import 'package:stackwallet/pages_desktop_specific/desktop_exchange/desktop_exchange_view.dart'; import 'package:stackwallet/pages_desktop_specific/desktop_home_view.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/my_stack_view.dart'; +import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_token_view.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/delete_wallet_keys_popup.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/sub_widgets/desktop_attention_delete_wallet.dart'; @@ -230,6 +231,20 @@ class RouteGenerator { } return _routeError("${settings.name} invalid args: ${args.toString()}"); + case DesktopTokenView.routeName: + if (args is String) { + return getRoute( + shouldUseMaterialRoute: useMaterialPageRoute, + builder: (_) => DesktopTokenView( + walletId: args, + ), + settings: RouteSettings( + name: settings.name, + ), + ); + } + return _routeError("${settings.name} invalid args: ${args.toString()}"); + case SelectWalletForTokenView.routeName: if (args is EthTokenEntity) { return getRoute( diff --git a/lib/widgets/wallet_card.dart b/lib/widgets/wallet_card.dart index 1747fa545..9e4fbc034 100644 --- a/lib/widgets/wallet_card.dart +++ b/lib/widgets/wallet_card.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/pages/token_view/token_view.dart'; import 'package:stackwallet/pages/wallet_view/wallet_view.dart'; +import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_token_view.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart'; import 'package:stackwallet/providers/db/main_db_provider.dart'; import 'package:stackwallet/providers/global/secure_store_provider.dart'; @@ -89,10 +90,10 @@ class WalletSheetCard extends ConsumerWidget { nav.pop(); if (desktopNavigatorState != null) { - // await desktopNavigatorState !.pushNamed( - // DesktopTokenView.routeName, - // arguments: walletId, - // ); + await desktopNavigatorState!.pushNamed( + DesktopTokenView.routeName, + arguments: walletId, + ); } else { await nav.pushNamed( TokenView.routeName,