diff --git a/lib/widgets/balance.dart b/lib/widgets/balance.dart index 4521cc84..e4909ed5 100644 --- a/lib/widgets/balance.dart +++ b/lib/widgets/balance.dart @@ -17,8 +17,7 @@ import 'package:my_wit_wallet/util/extensions/num_extensions.dart'; typedef void VoidCallback(); class Balance extends StatefulWidget { - Balance({required this.currentWallet, required this.onShowBalanceDetails}); - final Wallet currentWallet; + Balance({required this.onShowBalanceDetails}); final VoidCallback onShowBalanceDetails; @override @@ -37,6 +36,8 @@ class BalanceState extends State { builder: (BuildContext context, DashboardState state) { Account currentAccount = Locator.instance.get().walletStorage.currentAccount; + Wallet currentWallet = + Locator.instance.get().walletStorage.currentWallet; return Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ @@ -56,7 +57,7 @@ class BalanceState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( - '${widget.currentWallet.balanceNanoWit().availableNanoWit.toInt().standardizeWitUnits().formatWithCommaSeparator()} ${WIT_UNIT[WitUnit.Wit]}', + '${currentWallet.balanceNanoWit().availableNanoWit.standardizeWitUnits().formatWithCommaSeparator()} ${WIT_UNIT[WitUnit.Wit]}', textAlign: TextAlign.center, style: theme.textTheme.headlineMedium! .copyWith( diff --git a/lib/widgets/layouts/dashboard_layout.dart b/lib/widgets/layouts/dashboard_layout.dart index eb6117db..17698163 100644 --- a/lib/widgets/layouts/dashboard_layout.dart +++ b/lib/widgets/layouts/dashboard_layout.dart @@ -6,6 +6,7 @@ import 'package:my_wit_wallet/screens/login/bloc/login_bloc.dart'; import 'package:my_wit_wallet/shared/api_database.dart'; import 'package:my_wit_wallet/util/is_desktop_size.dart'; import 'package:my_wit_wallet/util/panel.dart'; +import 'package:my_wit_wallet/util/storage/database/account.dart'; import 'package:my_wit_wallet/util/storage/database/wallet.dart'; import 'package:my_wit_wallet/widgets/balance.dart'; import 'package:my_wit_wallet/widgets/balance_details.dart'; @@ -15,6 +16,7 @@ import 'package:my_wit_wallet/widgets/stake_unstake.dart'; import 'package:my_wit_wallet/widgets/top_navigation.dart'; import 'package:my_wit_wallet/widgets/layouts/layout.dart'; import 'package:my_wit_wallet/screens/login/view/init_screen.dart'; +import 'package:my_wit_wallet/screens/dashboard/bloc/dashboard_bloc.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:my_wit_wallet/shared/locator.dart'; import 'package:my_wit_wallet/widgets/wallet_list.dart'; @@ -54,8 +56,6 @@ class DashboardLayoutState extends State FocusNode _copyToClipboardFocusNode = FocusNode(); PanelUtils panel = PanelUtils(); Widget get _panelContent => panel.getContent(); - Wallet get currentWallet => - Locator.instance.get().walletStorage.currentWallet; @override void initState() { @@ -75,7 +75,7 @@ class DashboardLayoutState extends State }); } - Widget _buildDashboardHeader() { + Widget _buildDashboardHeader(final Wallet wallet) { return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ @@ -83,12 +83,11 @@ class DashboardLayoutState extends State onShowBalanceDetails: () => { setState(() { panel.toggle(BalanceDetails( - balance: currentWallet.balanceNanoWit(), - stakedBalance: currentWallet.stakedNanoWit(), + balance: wallet.balanceNanoWit(), + stakedBalance: wallet.stakedNanoWit(), )); }) - }, - currentWallet: currentWallet), + }), if (isDesktopSize) ...[SizedBox(height: 24), _buildBottomNavigation()] ], ); @@ -154,22 +153,27 @@ class DashboardLayoutState extends State children: [], ); } - return Layout( - scrollController: widget.scrollController, - topNavigation: TopNavigation( - onShowWalletList: () => - {setState(() => panel.toggle(WalletList()))}, - currentScreen: currentRoute(context), - currentWallet: currentWallet) - .getNavigationActions(context), - dashboardActions: _buildDashboardHeader(), - bottomNavigation: isDesktopSize ? null : _buildBottomNavigation(), - widgetList: [ - _body, - ], - actions: [], - slidingPanel: _panelContent, - ); + return BlocBuilder( + builder: (BuildContext context, DashboardState state) { + Wallet currentWallet = + Locator.instance.get().walletStorage.currentWallet; + return Layout( + scrollController: widget.scrollController, + topNavigation: TopNavigation( + onShowWalletList: () => + {setState(() => panel.toggle(WalletList()))}, + currentScreen: currentRoute(context), + currentWallet: currentWallet) + .getNavigationActions(context), + dashboardActions: _buildDashboardHeader(currentWallet), + bottomNavigation: isDesktopSize ? null : _buildBottomNavigation(), + widgetList: [ + _body, + ], + actions: [], + slidingPanel: _panelContent, + ); + }); }), ); }