Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: (balance) 🐛 fixed multiple balance load bug #217

Merged
merged 12 commits into from
Feb 23, 2022
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ install:

fix-lint:
$(info Running flutter format)
fvm flutter format --line-length 120 --set-exit-if-changed lib test
fvm flutter format --line-length 120 --set-exit-if-changed lib test
Zfinix marked this conversation as resolved.
Show resolved Hide resolved
cd starport_template && find lib test -name "*.dart" -not -name "*.g.dart" -not -name "*.freezed.dart" -not -name "*.gen.dart" -exec dart format -l 120 --set-exit-if-changed {} +;
42 changes: 24 additions & 18 deletions starport_template/lib/pages/assets_portfolio_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<AssetsPortfolioPage> createState() => _AssetsPortfolioPageState();
Expand All @@ -35,12 +37,6 @@ class _AssetsPortfolioPageState extends State<AssetsPortfolioPage> {

WalletPublicInfo get selectedWallet => StarportApp.walletsStore.selectedWallet;

@override
void initState() {
super.initState();
_fetchWalletBalances();
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -54,7 +50,10 @@ class _AssetsPortfolioPageState extends State<AssetsPortfolioPage> {
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),
Expand All @@ -65,8 +64,11 @@ class _AssetsPortfolioPageState extends State<AssetsPortfolioPage> {
StarportButtonBar(
onReceivePressed: _onTapReceive,
onSendPressed: () {
Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => SelectAssetPage(balancesList: balancesList)));
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SelectAssetPage(balancesList: balancesList),
),
);
},
),
],
Expand Down Expand Up @@ -97,12 +99,9 @@ class _AssetsPortfolioPageState extends State<AssetsPortfolioPage> {
);
}

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<void> _onTapDropDown() async {
final wallet = await showMaterialModalBottomSheet(
Expand All @@ -125,7 +124,9 @@ class _AssetsPortfolioPageState extends State<AssetsPortfolioPage> {
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,
),
),
);
}
Expand All @@ -134,7 +135,12 @@ class _AssetsPortfolioPageState extends State<AssetsPortfolioPage> {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty<WalletPublicInfo>('selectedWallet', selectedWallet))
..add(
DiagnosticsProperty<WalletPublicInfo>(
'selectedWallet',
selectedWallet,
),
)
..add(DiagnosticsProperty<bool>('isBalancesLoading', isBalancesLoading))
..add(DiagnosticsProperty<bool>('isSendMoneyLoading', isSendMoneyLoading))
..add(IterableProperty<Balance>('balancesList', balancesList))
Expand Down
4 changes: 3 additions & 1 deletion starport_template/lib/pages/create_wallet_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ class _CreateWalletPageState extends State<CreateWalletPage> {
);
if (mounted) {
await Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (_) => const AssetsPortfolioPage()),
MaterialPageRoute(
builder: (_) => const AssetsPortfolioPage(),
),
(route) => false,
);
}
Expand Down
4 changes: 3 additions & 1 deletion starport_template/lib/pages/import_wallet_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ class _ImportWalletPageState extends State<ImportWalletPage> {
_showImportErrorDialog();
} else if (mounted) {
await Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (_) => const AssetsPortfolioPage()),
MaterialPageRoute(
builder: (_) => const AssetsPortfolioPage(),
),
(route) => false,
);
}
Expand Down
35 changes: 28 additions & 7 deletions starport_template/lib/pages/sign_transaction_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -31,13 +32,17 @@ class SignTransactionPage extends StatefulWidget {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty<Balance>('balance', balance))
..add(DiagnosticsProperty<MsgSendTransaction>('transaction', transaction));
..add(
DiagnosticsProperty<MsgSendTransaction>('transaction', transaction),
);
}
}

class _SignTransactionPageState extends State<SignTransactionPage> {
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);
Expand Down Expand Up @@ -123,10 +128,18 @@ class _SignTransactionPageState extends State<SignTransactionPage> {
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: () async {
unawaited(
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (_) => const AssetsPortfolioPage(),
),
(route) => false,
),
);

await StarportApp.walletsStore.getBalances(selectedWallet.publicAddress);
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a rule of a thumb, let's extract user interaction code to a separate method, outside of the build method for readability:

Suggested change
onTapDone: () async {
unawaited(
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (_) => const AssetsPortfolioPage(),
),
(route) => false,
),
);
await StarportApp.walletsStore.getBalances(selectedWallet.publicAddress);
},
onTapDone: onTapDone,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is still not updated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry about that didnt push the commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can check it out now

),
),
);
Expand All @@ -152,8 +165,16 @@ class _SignTransactionPageState extends State<SignTransactionPage> {
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties
..add(DiagnosticsProperty<MsgSendTransaction>('transaction', widget.transaction))
..add(
DiagnosticsProperty<MsgSendTransaction>(
'transaction',
widget.transaction,
),
)
..add(DoubleProperty('recipientGetsAmount', recipientGetsAmount))
..add(DiagnosticsProperty<Balance>('balance', widget.balance));
..add(DiagnosticsProperty<Balance>('balance', widget.balance))
..add(
DiagnosticsProperty<WalletPublicInfo>('selectedWallet', selectedWallet),
);
}
}