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

Avoid unawaited futures (lint) #995

Merged
merged 19 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ linter:
require_trailing_commas: false
depend_on_referenced_packages: false

unawaited_futures: false
unawaited_futures: true
use_build_context_synchronously: false
use_setters_to_change_properties: false
avoid_equals_and_hash_code_on_mutable_classes: false
Expand Down
2 changes: 1 addition & 1 deletion app/lib/common/components/password_input_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _PasswordInputDialogState extends State<PasswordInputDialog> {
});
}
if (res == null) {
showCupertinoDialog<void>(
await showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
final dic = I18n.of(context)!.translationsForLocale();
Expand Down
22 changes: 11 additions & 11 deletions app/lib/mocks/ipfs/mock_ipfs_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import 'dart:io';
import 'package:encointer_wallet/service/ipfs/http_api.dart';
import 'package:encointer_wallet/service/log/log_service.dart';

const mockIcon = '<svg viewBox="0 0 132.09 131.85" '
'xmlns="http://www.w3.org/2000/svg"><circle cx="65.4" '
'cy="66.45" fill="#67c4e7" r="65.4" transform= '
'"matrix(.37233994 -.92809642 .92809642 .37233994 -20.62 102.4)"/> '
'<path d="m65.46.5a65.43 65.43 0 0 0 -60 41.05l83.54 85.37a65.25 65.25 0 '
'0 0 -23.54-126.42z" fill="#fff" stroke="#67c4e7" stroke-miterlimit="10"/> '
'<path d="m64.76 22.3 5.68 13.54-30.93-13.54z"/><path d="m85.59 22.3 11.04 11.28v-11.28z"/> '
'<path d="m82.28 48.09 12.14 11.29v8.38l-23.98 14.79-13.57-6.09 13.57 9.67 '
'26.19-11.6 7.26 8.06v-10.32l-4.42-4.35v-8.87l4.42-5.8v-5.16z"/> '
'<path d="m97.62 95.38-12.03 11.17-8.84-11.17z"/></svg>';

class MockIpfs extends Ipfs {
MockIpfs(String gateway) : super(gateway: gateway);

Expand All @@ -13,17 +24,6 @@ class MockIpfs extends Ipfs {

@override
Future<String?> getCommunityIcon(String? cid) {
const mockIcon = '<svg viewBox="0 0 132.09 131.85" '
'xmlns="http://www.w3.org/2000/svg"><circle cx="65.4" '
'cy="66.45" fill="#67c4e7" r="65.4" transform= '
'"matrix(.37233994 -.92809642 .92809642 .37233994 -20.62 102.4)"/> '
'<path d="m65.46.5a65.43 65.43 0 0 0 -60 41.05l83.54 85.37a65.25 65.25 0 '
'0 0 -23.54-126.42z" fill="#fff" stroke="#67c4e7" stroke-miterlimit="10"/> '
'<path d="m64.76 22.3 5.68 13.54-30.93-13.54z"/><path d="m85.59 22.3 11.04 11.28v-11.28z"/> '
'<path d="m82.28 48.09 12.14 11.29v8.38l-23.98 14.79-13.57-6.09 13.57 9.67 '
'26.19-11.6 7.26 8.06v-10.32l-4.42-4.35v-8.87l4.42-5.8v-5.16z"/> '
'<path d="m97.62 95.38-12.03 11.17-8.84-11.17z"/></svg>';
Log.d('Getting mock icon: $mockIcon', 'MockIpfs');
return Future.value(mockIcon);
}

Expand Down
2 changes: 1 addition & 1 deletion app/lib/mocks/substrate_api/mock_assets_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MockAssetsApi extends AssetsApi {
@override
Future<void> fetchBalance() async {
Log.d('api: fetching mock balance', 'MockAssetsApi');
store.assets.setAccountBalances(
await store.assets.setAccountBalances(
store.account.currentAccountPubKey,
Map.of({store.settings.networkState!.tokenSymbol: balancesInfo}),
needCache: false,
Expand Down
6 changes: 4 additions & 2 deletions app/lib/page-encointer/ceremony_box/ceremony_box.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
Expand Down Expand Up @@ -192,13 +194,13 @@ Widget getMeetupInfoWidget(BuildContext context, AppStore store) {
}

Future<void> awaitDataUpdateWithDialog(BuildContext context, AppStore store) async {
showCupertinoDialog<void>(
unawaited(showCupertinoDialog<void>(
context: context,
builder: (_) => CupertinoAlertDialog(
title: Text(I18n.of(context)!.translationsForLocale().home.updatingAppState),
content: const CupertinoActivityIndicator(),
),
);
));

await store.dataUpdate.executeUpdate().whenComplete(() => Navigator.of(context).pop());
}
2 changes: 1 addition & 1 deletion app/lib/page-encointer/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class _EncointerHomePageState extends State<EncointerHomePage> {
onTap: (index) async {
if (_tabList[index].key == TabKey.scan) {
// Push `ScanPage.Route`instead of changing the Page.
Navigator.of(context).pushNamed(
await Navigator.of(context).pushNamed(
ScanPage.route,
arguments: ScanPageParams(scannerContext: QrScannerContext.mainPage),
);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/page-encointer/meetup/ceremony_step1_count.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CeremonyStep1Count extends StatelessWidget {

Future<void> _pushStep2ScanPage(BuildContext context, int count) async {
store.encointer.communityAccount!.setParticipantCountVote(count);
Navigator.of(context).push(
await Navigator.of(context).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) => CeremonyStep2Scan(
store,
Expand Down
5 changes: 2 additions & 3 deletions app/lib/page/account/create/add_account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class _AddAccountPageState extends State<AddAccountPage> {
setState(() {
_submitting = false;
});
_showErrorCreatingAccountDialog(context);
return;
return _showErrorCreatingAccountDialog(context);
Copy link
Member

Choose a reason for hiding this comment

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

👍

}

final addresses = await webApi.account.encodeAddress([acc['pubKey'] as String]);
Expand All @@ -77,7 +76,7 @@ class _AddAccountPageState extends State<AddAccountPage> {
}

static Future<void> _showErrorCreatingAccountDialog(BuildContext context) async {
showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down
7 changes: 3 additions & 4 deletions app/lib/page/account/create/create_account_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ class CreateAccountForm extends StatelessWidget {
final acc = await webApi.account.importAccount();

if (acc['error'] != null) {
_showErrorCreatingAccountDialog(context);
return;
return _showErrorCreatingAccountDialog(context);
}

final addresses = await webApi.account.encodeAddress([acc['pubKey'] as String]);
await store.addAccount(acc, store.account.newAccount.password, addresses[0]);

final pubKey = acc['pubKey'] as String?;
store.setCurrentAccount(pubKey);
await store.setCurrentAccount(pubKey);

await store.loadAccountCache();

Expand Down Expand Up @@ -121,7 +120,7 @@ class CreateAccountForm extends StatelessWidget {
}

Future<void> _showErrorCreatingAccountDialog(BuildContext context) async {
showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down
2 changes: 1 addition & 1 deletion app/lib/page/account/create/create_pin_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _CreatePinPageState extends State<CreatePinPage> {
});

// Even if we do not choose a community, we go back to the home screen.
Navigator.pushAndRemoveUntil<void>(
await Navigator.pushAndRemoveUntil<void>(
context,
CupertinoPageRoute<void>(builder: (context) => const EncointerHomePage()),
(route) => false,
Expand Down
15 changes: 8 additions & 7 deletions app/lib/page/account/import/import_account_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -38,15 +40,15 @@ class _ImportAccountPageState extends State<ImportAccountPage> {
setState(() {
_submitting = true;
});
showCupertinoDialog<void>(
unawaited(showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text(I18n.of(context)!.translationsForLocale().home.loading),
content: const SizedBox(height: 64, child: CupertinoActivityIndicator()),
);
},
);
));

/// import account
final acc = await webApi.account.importAccount(
Expand All @@ -64,7 +66,7 @@ class _ImportAccountPageState extends State<ImportAccountPage> {
msg = '${I18n.of(context)!.translationsForLocale().account.importInvalid}: $_keyType';
}

showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand All @@ -85,7 +87,6 @@ class _ImportAccountPageState extends State<ImportAccountPage> {
);
},
);
return;
}
await _checkAccountDuplicate(acc);
return;
Expand All @@ -98,7 +99,7 @@ class _ImportAccountPageState extends State<ImportAccountPage> {
context.read<AppStore>().account.pubKeyAddressMap[context.read<AppStore>().settings.endpoint.ss58]!;
final address = pubKeyMap[acc['pubKey']];
if (address != null) {
showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down Expand Up @@ -169,11 +170,11 @@ class _ImportAccountPageState extends State<ImportAccountPage> {
});

if (context.read<AppStore>().account.isFirstAccount) {
Navigator.pushNamed(context, CreatePinPage.route, arguments: CreatePinPageParams(_importAccount));
await Navigator.pushNamed(context, CreatePinPage.route, arguments: CreatePinPageParams(_importAccount));
} else {
context.read<AppStore>().account.setNewAccountPin(context.read<AppStore>().settings.cachedPin);
await _importAccount();
Navigator.pushAndRemoveUntil<void>(
await Navigator.pushAndRemoveUntil<void>(
context,
CupertinoPageRoute<void>(builder: (context) => const EncointerHomePage()),
(route) => false,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/page/assets/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class _AssetsState extends State<Assets> {

Future<void> switchAccount(AccountData account) async {
if (account.pubKey != widget.store.account.currentAccountPubKey) {
widget.store.setCurrentAccount(account.pubKey);
await widget.store.setCurrentAccount(account.pubKey);
Copy link
Member

Choose a reason for hiding this comment

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

This might actually be important to prevent occasional bugs due to race conditions. :)

await widget.store.loadAccountCache();

webApi.fetchAccountData();
Expand Down
2 changes: 1 addition & 1 deletion app/lib/page/assets/receive/receive_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class _ReceivePageState extends State<ReceivePage> {
}
}

webApi.encointer.getAllBalances(store.account.currentAddress).then((balances) {
await webApi.encointer.getAllBalances(store.account.currentAddress).then((balances) {
final cid = store.encointer.chosenCid;

if (cid == null) {
Expand Down
8 changes: 5 additions & 3 deletions app/lib/page/network_select_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
Expand Down Expand Up @@ -41,15 +43,15 @@ class _NetworkSelectPageState extends State<NetworkSelectPage> {
setState(() {
_networkChanging = true;
});
showCupertinoDialog<void>(
unawaited(showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text(I18n.of(context)!.translationsForLocale().home.loading),
content: const SizedBox(height: 64, child: CupertinoActivityIndicator()),
);
},
);
));

await context.read<AppStore>().settings.reloadNetwork(_selectedNetwork);

Expand All @@ -67,7 +69,7 @@ class _NetworkSelectPageState extends State<NetworkSelectPage> {
final isCurrentNetwork = _selectedNetwork.info == context.read<AppStore>().settings.endpoint.info;
if (address != context.read<AppStore>().account.currentAddress || !isCurrentNetwork) {
/// set current account
context.read<AppStore>().setCurrentAccount(i.pubKey);
await context.read<AppStore>().setCurrentAccount(i.pubKey);

if (isCurrentNetwork) {
await context.read<AppStore>().loadAccountCache();
Expand Down
4 changes: 2 additions & 2 deletions app/lib/page/profile/account/account_manage_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ class _AccountManagePageState extends State<AccountManagePage> {
final seed =
await _appStore.account.decryptSeed(accountToBeEdited.pubKey, AccountStore.seedTypeMnemonic, password);

Navigator.of(context).pushNamed(ExportResultPage.route, arguments: {
await Navigator.of(context).pushNamed(ExportResultPage.route, arguments: {
'key': seed,
'type': AccountStore.seedTypeMnemonic,
});
} else {
// Assume that the account was imported via `RawSeed` if mnemonic does not exist.
showCupertinoDialog<void>(
await showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down
4 changes: 2 additions & 2 deletions app/lib/page/profile/account/change_password_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _ChangePassword extends State<ChangePasswordPage> {
passOld,
);
if (passChecked == null) {
showCupertinoDialog<void>(
await showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down Expand Up @@ -86,7 +86,7 @@ class _ChangePassword extends State<ChangePasswordPage> {
store.account.updateSeed(accountData.pubKey, _passOldCtrl.text, _passCtrl.text);
});
}
showCupertinoDialog<void>(
await showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down
4 changes: 2 additions & 2 deletions app/lib/page/profile/account/export_account_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ExportAccountPage extends StatelessWidget {
_passCtrl.text,
);
if (res == null) {
showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand All @@ -49,7 +49,7 @@ class ExportAccountPage extends StatelessWidget {
Navigator.of(context).pop();
final seed =
await store.account.decryptSeed(store.account.currentAccount.pubKey, seedType, _passCtrl.text.trim());
Navigator.of(context).pushNamed(ExportResultPage.route, arguments: {
await Navigator.of(context).pushNamed(ExportResultPage.route, arguments: {
'key': seed!,
'type': seedType,
});
Expand Down
6 changes: 3 additions & 3 deletions app/lib/page/profile/contacts/contact_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,17 @@ class EndorseButton extends StatelessWidget {
final bootstrappers = community?.bootstrappers;
final dic = I18n.of(context)!.translationsForLocale();
if (bootstrappers != null && bootstrappers.contains(contact.address)) {
_popupDialog(context, dic.profile.cantEndorseBootstrapper);
await _popupDialog(context, dic.profile.cantEndorseBootstrapper);
} else if (store.encointer.currentPhase != CeremonyPhase.Registering) {
_popupDialog(context, dic.profile.canEndorseInRegisteringPhaseOnly);
await _popupDialog(context, dic.profile.canEndorseInRegisteringPhaseOnly);
} else {
await submitEndorseNewcomer(context, store, api, store.encointer.chosenCid, contact.address);
}
}
}

Future<void> _popupDialog(BuildContext context, String content) async {
showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand Down
11 changes: 5 additions & 6 deletions app/lib/page/profile/contacts/contact_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _Contact extends State<ContactPage> {
// create new contact
final exist = context.read<AppStore>().settings.contactList.indexWhere((i) => i.address == addr);
if (exist > -1) {
showCupertinoDialog<void>(
return showCupertinoDialog<void>(
context: context,
builder: (BuildContext context) {
return CupertinoAlertDialog(
Expand All @@ -71,23 +71,22 @@ class _Contact extends State<ContactPage> {
);
},
);
return;
} else {
context.read<AppStore>().settings.addContact(con);
await context.read<AppStore>().settings.addContact(con);
}
} else {
// edit contact
context.read<AppStore>().settings.updateContact(con);
await context.read<AppStore>().settings.updateContact(con);
}

// get contact info
if (_isObservation!) {
webApi.account.encodeAddress([pubKey]);
await webApi.account.encodeAddress([pubKey]);
} else {
// if this address was used as observation and current account,
// we need to change current account
if (pubKey == context.read<AppStore>().account.currentAccountPubKey) {
webApi.account.changeCurrentAccount(fetchData: true);
await webApi.account.changeCurrentAccount(fetchData: true);
}
}
Navigator.of(context).pop();
Expand Down
2 changes: 1 addition & 1 deletion app/lib/page/profile/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Future<void> showRemoveAccountsDialog(BuildContext context, AppStore store) {
await store.account.removeAccount(acc);
}

Navigator.pushAndRemoveUntil(
await Navigator.pushAndRemoveUntil(
context,
CupertinoPageRoute<void>(builder: (context) => const CreateAccountEntryPage()),
(route) => false,
Expand Down
Loading