Skip to content

Commit

Permalink
(Fix): Update Balance and Wallet Info when switching wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
parodyBit committed Oct 16, 2024
1 parent 9c4ed07 commit 66b7d44
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
7 changes: 4 additions & 3 deletions lib/widgets/balance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +36,8 @@ class BalanceState extends State<Balance> {
builder: (BuildContext context, DashboardState state) {
Account currentAccount =
Locator.instance.get<ApiDatabase>().walletStorage.currentAccount;
Wallet currentWallet =
Locator.instance.get<ApiDatabase>().walletStorage.currentWallet;
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expand All @@ -56,7 +57,7 @@ class BalanceState extends State<Balance> {
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(
Expand Down
50 changes: 27 additions & 23 deletions lib/widgets/layouts/dashboard_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -54,8 +56,6 @@ class DashboardLayoutState extends State<DashboardLayout>
FocusNode _copyToClipboardFocusNode = FocusNode();
PanelUtils panel = PanelUtils();
Widget get _panelContent => panel.getContent();
Wallet get currentWallet =>
Locator.instance.get<ApiDatabase>().walletStorage.currentWallet;

@override
void initState() {
Expand All @@ -75,20 +75,19 @@ class DashboardLayoutState extends State<DashboardLayout>
});
}

Widget _buildDashboardHeader() {
Widget _buildDashboardHeader(final Wallet wallet) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Balance(
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()]
],
);
Expand Down Expand Up @@ -154,22 +153,27 @@ class DashboardLayoutState extends State<DashboardLayout>
children: <Widget>[],
);
}
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<DashboardBloc, DashboardState>(
builder: (BuildContext context, DashboardState state) {
Wallet currentWallet =
Locator.instance.get<ApiDatabase>().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,
);
});
}),
);
}
Expand Down

0 comments on commit 66b7d44

Please sign in to comment.