From 00a892845d457fc937ca64fbaf31f94d11f153a0 Mon Sep 17 00:00:00 2001 From: Chiziaruhoma Ogbonda Date: Wed, 23 Feb 2022 10:24:05 +0100 Subject: [PATCH] fix: (balance) :bug: fixed multiple balance load bug (#217) --- Makefile | 3 +- .../lib/pages/assets_portfolio_page.dart | 42 +++++++++++-------- .../lib/pages/create_wallet_page.dart | 4 +- .../lib/pages/import_wallet_page.dart | 4 +- .../lib/pages/sign_transaction_page.dart | 37 ++++++++++++---- 5 files changed, 62 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 7bd4811d..2e64a285 100644 --- a/Makefile +++ b/Makefile @@ -25,4 +25,5 @@ install: fix-lint: $(info Running flutter format) - fvm flutter format --line-length 120 --set-exit-if-changed lib test \ No newline at end of file + fvm flutter format --line-length 120 --set-exit-if-changed starport_template/lib starport_template/test + \ No newline at end of file diff --git a/starport_template/lib/pages/assets_portfolio_page.dart b/starport_template/lib/pages/assets_portfolio_page.dart index 2ab1cc46..ad477d67 100644 --- a/starport_template/lib/pages/assets_portfolio_page.dart +++ b/starport_template/lib/pages/assets_portfolio_page.dart @@ -18,7 +18,9 @@ import 'package:starport_template/widgets/starport_button_bar.dart'; import 'package:transaction_signing_gateway/model/wallet_public_info.dart'; class AssetsPortfolioPage extends StatefulWidget { - const AssetsPortfolioPage({Key? key}) : super(key: key); + const AssetsPortfolioPage({ + Key? key, + }) : super(key: key); @override State createState() => _AssetsPortfolioPageState(); @@ -35,12 +37,6 @@ class _AssetsPortfolioPageState extends State { WalletPublicInfo get selectedWallet => StarportApp.walletsStore.selectedWallet; - @override - void initState() { - super.initState(); - _fetchWalletBalances(); - } - @override Widget build(BuildContext context) { return Scaffold( @@ -54,7 +50,10 @@ class _AssetsPortfolioPageState extends State { Column( children: [ _gradientAvatar(context), - AssetPortfolioHeading(title: selectedWallet.name, onTap: _onTapDropDown), + AssetPortfolioHeading( + title: selectedWallet.name, + onTap: _onTapDropDown, + ), SizedBox(height: CosmosTheme.of(context).spacingXL), const Divider(), SizedBox(height: CosmosTheme.of(context).spacingL), @@ -65,8 +64,11 @@ class _AssetsPortfolioPageState extends State { StarportButtonBar( onReceivePressed: _onTapReceive, onSendPressed: () { - Navigator.of(context) - .push(MaterialPageRoute(builder: (context) => SelectAssetPage(balancesList: balancesList))); + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => SelectAssetPage(balancesList: balancesList), + ), + ); }, ), ], @@ -97,12 +99,9 @@ class _AssetsPortfolioPageState extends State { ); } - void _onTapAvatar(BuildContext context) => - Navigator.of(context).push(MaterialPageRoute(builder: (context) => const TransactionHistoryPage())); - - Future _fetchWalletBalances() async { - await StarportApp.walletsStore.getBalances(selectedWallet.publicAddress); - } + void _onTapAvatar(BuildContext context) => Navigator.of(context).push( + MaterialPageRoute(builder: (context) => const TransactionHistoryPage()), + ); Future _onTapDropDown() async { final wallet = await showMaterialModalBottomSheet( @@ -125,7 +124,9 @@ class _AssetsPortfolioPageState extends State { backgroundColor: Colors.transparent, builder: (context) => SizedBox( height: MediaQuery.of(context).size.height / 1.06, - child: ReceiveMoneySheet(walletInfo: StarportApp.walletsStore.selectedWallet), + child: ReceiveMoneySheet( + walletInfo: StarportApp.walletsStore.selectedWallet, + ), ), ); } @@ -134,7 +135,12 @@ class _AssetsPortfolioPageState extends State { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(DiagnosticsProperty('selectedWallet', selectedWallet)) + ..add( + DiagnosticsProperty( + 'selectedWallet', + selectedWallet, + ), + ) ..add(DiagnosticsProperty('isBalancesLoading', isBalancesLoading)) ..add(DiagnosticsProperty('isSendMoneyLoading', isSendMoneyLoading)) ..add(IterableProperty('balancesList', balancesList)) diff --git a/starport_template/lib/pages/create_wallet_page.dart b/starport_template/lib/pages/create_wallet_page.dart index 17bd0a2c..3ad2601d 100644 --- a/starport_template/lib/pages/create_wallet_page.dart +++ b/starport_template/lib/pages/create_wallet_page.dart @@ -174,7 +174,9 @@ class _CreateWalletPageState extends State { ); if (mounted) { await Navigator.of(context).pushAndRemoveUntil( - MaterialPageRoute(builder: (_) => const AssetsPortfolioPage()), + MaterialPageRoute( + builder: (_) => const AssetsPortfolioPage(), + ), (route) => false, ); } diff --git a/starport_template/lib/pages/import_wallet_page.dart b/starport_template/lib/pages/import_wallet_page.dart index 0cc00dd4..3532528d 100644 --- a/starport_template/lib/pages/import_wallet_page.dart +++ b/starport_template/lib/pages/import_wallet_page.dart @@ -124,7 +124,9 @@ class _ImportWalletPageState extends State { _showImportErrorDialog(); } else if (mounted) { await Navigator.of(context).pushAndRemoveUntil( - MaterialPageRoute(builder: (_) => const AssetsPortfolioPage()), + MaterialPageRoute( + builder: (_) => const AssetsPortfolioPage(), + ), (route) => false, ); } diff --git a/starport_template/lib/pages/sign_transaction_page.dart b/starport_template/lib/pages/sign_transaction_page.dart index b300252f..4c676214 100644 --- a/starport_template/lib/pages/sign_transaction_page.dart +++ b/starport_template/lib/pages/sign_transaction_page.dart @@ -12,6 +12,7 @@ import 'package:starport_template/pages/assets_transfer_sheet.dart'; import 'package:starport_template/pages/passcode_prompt_page.dart'; import 'package:starport_template/starport_app.dart'; import 'package:starport_template/widgets/sign_transaction_tab_view_item.dart'; +import 'package:transaction_signing_gateway/transaction_signing_gateway.dart'; class SignTransactionPage extends StatefulWidget { const SignTransactionPage({ @@ -31,13 +32,17 @@ class SignTransactionPage extends StatefulWidget { super.debugFillProperties(properties); properties ..add(DiagnosticsProperty('balance', balance)) - ..add(DiagnosticsProperty('transaction', transaction)); + ..add( + DiagnosticsProperty('transaction', transaction), + ); } } class _SignTransactionPageState extends State { double get recipientGetsAmount => widget.transaction.amount.value.toDouble() - widget.transaction.fee; + WalletPublicInfo get selectedWallet => StarportApp.walletsStore.selectedWallet; + @override Widget build(BuildContext context) { final theme = CosmosTheme.of(context); @@ -123,13 +128,23 @@ class _SignTransactionPageState extends State { builder: (context) => SizedBox( height: MediaQuery.of(context).size.height / 2.24, child: AssetsTransferSheet( - onTapDone: () => Navigator.of(context).pushAndRemoveUntil( - MaterialPageRoute(builder: (_) => const AssetsPortfolioPage()), - (route) => false, - ), + onTapDone: () => _onTapAssetTranserSheetDone(context), + ), + ), + ); + } + + Future _onTapAssetTranserSheetDone(BuildContext context) async { + unawaited( + Navigator.of(context).pushAndRemoveUntil( + MaterialPageRoute( + builder: (_) => const AssetsPortfolioPage(), ), + (route) => false, ), ); + + await StarportApp.walletsStore.getBalances(selectedWallet.publicAddress); } Padding _transactionFee(CosmosThemeData theme) { @@ -152,8 +167,16 @@ class _SignTransactionPageState extends State { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(DiagnosticsProperty('transaction', widget.transaction)) + ..add( + DiagnosticsProperty( + 'transaction', + widget.transaction, + ), + ) ..add(DoubleProperty('recipientGetsAmount', recipientGetsAmount)) - ..add(DiagnosticsProperty('balance', widget.balance)); + ..add(DiagnosticsProperty('balance', widget.balance)) + ..add( + DiagnosticsProperty('selectedWallet', selectedWallet), + ); } }