Skip to content

Commit

Permalink
Properly await all notifications (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
KingGorrin authored Mar 14, 2024
1 parent 66d4b1e commit c96d847
Show file tree
Hide file tree
Showing 48 changed files with 254 additions and 254 deletions.
10 changes: 5 additions & 5 deletions lib/blocs/notifications_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ class NotificationsBloc extends BaseBloc<WalletNotification?> {
title: notification.title ?? 'Empty title',
body: notification.details ?? 'No details available',
);
localNotification.show();
await localNotification.show();
}
addEvent(notification);
} catch (e, stackTrace) {
addError(e, stackTrace);
}
}

sendPlasmaNotification(String purposeOfGeneratingPlasma) {
addNotification(
Future<void> sendPlasmaNotification(String purposeOfGeneratingPlasma) async {
await addNotification(
WalletNotification(
title: 'Plasma will be generated in order to '
'$purposeOfGeneratingPlasma',
Expand All @@ -43,8 +43,8 @@ class NotificationsBloc extends BaseBloc<WalletNotification?> {
);
}

addErrorNotification(Object error, String title) {
addNotification(
Future<void> addErrorNotification(Object error, String title) async {
await addNotification(
WalletNotification(
title: title,
timestamp: DateTime.now().millisecondsSinceEpoch,
Expand Down
6 changes: 3 additions & 3 deletions lib/blocs/wallet_connect/chains/nom_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class NoMService extends IChain {
'chainId': getChainIdentifier(),
};
} else {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
Errors.getSdkError(Errors.USER_REJECTED),
'You have rejected the WalletConnect request');
throw Errors.getSdkError(Errors.USER_REJECTED);
Expand Down Expand Up @@ -212,7 +212,7 @@ class NoMService extends IChain {
if (actionWasAccepted) {
return await walletSign(message.codeUnits);
} else {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
Errors.getSdkError(Errors.USER_REJECTED),
'You have rejected the WalletConnect request');
throw Errors.getSdkError(Errors.USER_REJECTED);
Expand Down Expand Up @@ -301,7 +301,7 @@ class NoMService extends IChain {

return result!;
} else {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
Errors.getSdkError(Errors.USER_REJECTED),
'You have rejected the WalletConnect request');
throw Errors.getSdkError(Errors.USER_REJECTED);
Expand Down
6 changes: 3 additions & 3 deletions lib/screens/change_wallet_password_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,22 @@ class _ChangeWalletPasswordScreenState
_newPasswordController.text,
);
} catch (e) {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
e,
'An error occurred while trying to change password',
);
} finally {
_loadingButtonKey.currentState!.animateReverse();
}
}
}, onError: (e) {
}, onError: (e) async {
_loadingButtonKey.currentState!.animateReverse();
if (e is IncorrectPasswordException) {
setState(() {
_currentPassErrorText = 'Incorrect password';
});
} else {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
e,
'An error occurred while trying to decrypt wallet',
);
Expand Down
6 changes: 3 additions & 3 deletions lib/screens/export/export_wallet_password_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class _ExportWalletPasswordScreenState
name: path.basename(walletPath.path),
);
if (widget.backupWalletFlow) {
_sendSuccessNotification(walletPath.path);
await _sendSuccessNotification(walletPath.path);
} else {
_updateExportedSeedList();
}
Expand All @@ -197,8 +197,8 @@ class _ExportWalletPasswordScreenState
).value = exportedSeeds;
}

void _sendSuccessNotification(String path) {
sl.get<NotificationsBloc>().addNotification(
Future<void> _sendSuccessNotification(String path) async {
await sl.get<NotificationsBloc>().addNotification(
WalletNotification(
title: 'Seed Vault successfully exported',
timestamp: DateTime.now().millisecondsSinceEpoch,
Expand Down
30 changes: 15 additions & 15 deletions lib/screens/node_management_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ class _NodeManagementScreenState extends State<NodeManagementScreen> {
}
setState(() {
_autoReceive = value;
_changeAutoReceiveStatus(value ?? false);
});
await _changeAutoReceiveStatus(value ?? false);
},
),
Text(
Expand All @@ -163,17 +163,17 @@ class _NodeManagementScreenState extends State<NodeManagementScreen> {
Future<void> _changeAutoReceiveStatus(bool enabled) async {
try {
await _saveAutoReceiveValueToCache(enabled);
_sendAutoReceiveNotification(enabled);
await _sendAutoReceiveNotification(enabled);
} on Exception catch (e) {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
e,
'Something went wrong while setting automatic receive preference',
);
}
}

void _sendAutoReceiveNotification(bool enabled) {
sl.get<NotificationsBloc>().addNotification(
Future<void> _sendAutoReceiveNotification(bool enabled) async {
await sl.get<NotificationsBloc>().addNotification(
WalletNotification(
title: 'Auto-receiver ${enabled ? 'enabled' : 'disabled'}',
details:
Expand Down Expand Up @@ -242,7 +242,7 @@ class _NodeManagementScreenState extends State<NodeManagementScreen> {
_selectedNode,
);
kCurrentNode = _selectedNode!;
_sendChangingNodeSuccessNotification();
await _sendChangingNodeSuccessNotification();
if (widget.nodeConfirmationCallback != null) {
widget.nodeConfirmationCallback!();
} else {
Expand All @@ -252,7 +252,7 @@ class _NodeManagementScreenState extends State<NodeManagementScreen> {
throw 'Connection could not be established to $_selectedNode';
}
} catch (e) {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
e,
'Connection failed',
);
Expand Down Expand Up @@ -306,10 +306,10 @@ class _NodeManagementScreenState extends State<NodeManagementScreen> {
bool _ifUserInputValid() =>
InputValidators.node(_newNodeController.text) == null;

void _onAddNodePressed() async {
Future<void> _onAddNodePressed() async {
if ([...kDbNodes, ...kDefaultCommunityNodes, ...kDefaultNodes]
.contains(_newNodeController.text)) {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
'Node ${_newNodeController.text} already exists',
'Node already exists');
} else {
Expand All @@ -325,13 +325,13 @@ class _NodeManagementScreenState extends State<NodeManagementScreen> {
}
Hive.box<String>(kNodesBox).add(_newNodeController.text);
await NodeUtils.loadDbNodes();
_sendAddNodeSuccessNotification();
await _sendAddNodeSuccessNotification();
setState(() {
_newNodeController = TextEditingController();
_newNodeKey = GlobalKey();
});
} catch (e) {
NotificationUtils.sendNotificationError(e, 'Error while adding new node');
await NotificationUtils.sendNotificationError(e, 'Error while adding new node');
} finally {
_addNodeButtonKey.currentState?.animateReverse();
}
Expand Down Expand Up @@ -378,8 +378,8 @@ class _NodeManagementScreenState extends State<NodeManagementScreen> {
);
}

void _sendChangingNodeSuccessNotification() {
sl.get<NotificationsBloc>().addNotification(
Future<void> _sendChangingNodeSuccessNotification() async {
await sl.get<NotificationsBloc>().addNotification(
WalletNotification(
title: 'Successfully connected to $_selectedNode',
timestamp: DateTime.now().millisecondsSinceEpoch,
Expand All @@ -395,8 +395,8 @@ class _NodeManagementScreenState extends State<NodeManagementScreen> {
super.dispose();
}

void _sendAddNodeSuccessNotification() {
sl.get<NotificationsBloc>().addNotification(
Future<void> _sendAddNodeSuccessNotification() async {
await sl.get<NotificationsBloc>().addNotification(
WalletNotification(
title: 'Successfully added node ${_newNodeController.text}',
timestamp: DateTime.now().millisecondsSinceEpoch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class _HardwareWalletDeviceChoiceScreenState
Future<Address> _getWalletAddress(Wallet wallet) async {
final account = await wallet.getAccount();
if (account is LedgerWalletAccount) {
sl.get<NotificationsBloc>().addNotification(
await sl.get<NotificationsBloc>().addNotification(
WalletNotification(
title:
'Resolving address, please confirm the address on your hardware device',
Expand Down
18 changes: 9 additions & 9 deletions lib/services/wallet_connect_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class WalletConnectService {
'https://raw.githubusercontent.com/zenon-network/syrius/master/macos/Runner/Assets.xcassets/AppIcon.appiconset/Icon-MacOS-512x512%402x.png'
],
),
).onError((e, stackTrace) {
).onError((e, stackTrace) async {
Logger('WalletConnectService')
.log(Level.SEVERE, 'initClient onError ', e, stackTrace);
if (e != null) {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
e, 'WalletConnect initialization failed');
}
throw 'WalletConnect init failed';
Expand Down Expand Up @@ -211,7 +211,7 @@ class WalletConnectService {
'chainId': getChainIdentifier(),
};
} else {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
Errors.getSdkError(Errors.USER_REJECTED),
'You have rejected the WalletConnect request');
throw Errors.getSdkError(Errors.USER_REJECTED);
Expand Down Expand Up @@ -283,7 +283,7 @@ class WalletConnectService {
if (actionWasAccepted) {
return await walletSign(message.codeUnits);
} else {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
Errors.getSdkError(Errors.USER_REJECTED),
'You have rejected the WalletConnect request');
throw Errors.getSdkError(Errors.USER_REJECTED);
Expand Down Expand Up @@ -375,7 +375,7 @@ class WalletConnectService {

return result!;
} else {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
Errors.getSdkError(Errors.USER_REJECTED),
'You have rejected the WalletConnect request');
throw Errors.getSdkError(Errors.USER_REJECTED);
Expand Down Expand Up @@ -526,9 +526,9 @@ class WalletConnectService {
pairingTopic: pairingTopic,
);

void _sendSuccessfullyApprovedSessionNotification(
PairingMetadata dAppMetadata) {
sl.get<NotificationsBloc>().addNotification(
Future<void> _sendSuccessfullyApprovedSessionNotification(
PairingMetadata dAppMetadata) async {
await sl.get<NotificationsBloc>().addNotification(
WalletNotification(
title: 'Successfully connected to ${dAppMetadata.name}',
timestamp: DateTime.now().millisecondsSinceEpoch,
Expand Down Expand Up @@ -604,7 +604,7 @@ class WalletConnectService {
},
);

_sendSuccessfullyApprovedSessionNotification(dAppMetadata);
await _sendSuccessfullyApprovedSessionNotification(dAppMetadata);
dAppsActiveSessions.add(approveResponse.session);
}
} else {
Expand Down
10 changes: 5 additions & 5 deletions lib/services/web3wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ class Web3WalletService extends IWeb3WalletService {
try {
ApproveResponse approveResponse =
await _approveSession(id: event.id);
_sendSuccessfullyApprovedSessionNotification(dAppMetadata);
await _sendSuccessfullyApprovedSessionNotification(dAppMetadata);
sessions.value.add(approveResponse.session);
} catch (e, stackTrace) {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
e, 'WalletConnect session approval failed');
Logger('WalletConnectService').log(
Level.INFO, 'onSessionProposal approveResponse', e, stackTrace);
Expand All @@ -363,9 +363,9 @@ class Web3WalletService extends IWeb3WalletService {
.then((value) => sl.get<WalletConnectSessionsBloc>().refreshResults());
}

void _sendSuccessfullyApprovedSessionNotification(
PairingMetadata dAppMetadata) {
sl.get<NotificationsBloc>().addNotification(
Future<void> _sendSuccessfullyApprovedSessionNotification(
PairingMetadata dAppMetadata) async {
await sl.get<NotificationsBloc>().addNotification(
WalletNotification(
title: 'Successfully connected to ${dAppMetadata.name}',
timestamp: DateTime.now().millisecondsSinceEpoch,
Expand Down
18 changes: 9 additions & 9 deletions lib/utils/account_block_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ class AccountBlockUtils {
bool needReview = kWalletFile!.isHardwareWallet;

if (needPlasma) {
sl
await sl
.get<NotificationsBloc>()
.sendPlasmaNotification(purposeOfGeneratingPlasma);
} else if (needReview) {
_sendReviewNotification(transactionParams);
await _sendReviewNotification(transactionParams);
}
final AccountBlockTemplate response = await zenon!.send(
transactionParams,
currentKeyPair: walletAccount,
generatingPowCallback: (status) {
generatingPowCallback: (status) async {
// Wait for plasma to be generated before sending review notification
if (needReview && status == PowStatus.done) {
_sendReviewNotification(transactionParams);
await _sendReviewNotification(transactionParams);
}
_addEventToPowGeneratingStatusBloc(status);
},
Expand All @@ -81,7 +81,7 @@ class AccountBlockUtils {
if (BlockUtils.isReceiveBlock(transactionParams.blockType)) {
sl.get<TransferWidgetsBalanceBloc>().getBalanceForAllAddresses();
}
sl.get<NotificationsBloc>().addNotification(
await sl.get<NotificationsBloc>().addNotification(
WalletNotification(
title: 'Account-block published',
timestamp: DateTime.now().millisecondsSinceEpoch,
Expand All @@ -102,8 +102,7 @@ class AccountBlockUtils {
await Future.delayed(const Duration(seconds: 1));

return response;
}
finally {
} finally {
kWalletFile!.close();
}
} else {
Expand Down Expand Up @@ -190,8 +189,9 @@ class AccountBlockUtils {
return null;
}

static void _sendReviewNotification(AccountBlockTemplate transactionParams) {
sl.get<NotificationsBloc>().addNotification(
static Future<void> _sendReviewNotification(
AccountBlockTemplate transactionParams) async {
await sl.get<NotificationsBloc>().addNotification(
WalletNotification(
title:
'${BlockUtils.isSendBlock(transactionParams.blockType) ? 'Sending transaction' : 'Receiving transaction'}, please review the transaction on your hardware device',
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/address_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ZenonAddressUtils {
WalletAccount walletAccount = await wallet.getAccount(addrListCounter);
Address? address;
if (walletAccount is LedgerWalletAccount) {
sl.get<NotificationsBloc>().addNotification(
await sl.get<NotificationsBloc>().addNotification(
WalletNotification(
title:
'Adding address, please confirm the address on your hardware device',
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/clipboard_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class ClipboardUtils {

static void pasteToClipboard(
BuildContext context, Function(String) callback) {
Clipboard.getData('text/plain').then((value) {
Clipboard.getData('text/plain').then((value) async {
if (value != null) {
callback(value.text!);
} else {
NotificationUtils.sendNotificationError(
await NotificationUtils.sendNotificationError(
Exception('The clipboard data could not be obtained'),
'Something went wrong while getting the clipboard data',
);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/navigation_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class NavigationUtils {
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
sl.get<NotificationsBloc>().addNotification(
await sl.get<NotificationsBloc>().addNotification(
WalletNotification(
title: 'Error while trying to open $url',
timestamp: DateTime.now().millisecondsSinceEpoch,
Expand Down
Loading

0 comments on commit c96d847

Please sign in to comment.