diff --git a/lib/data/models/multi_wallet_transaction_cubit.dart b/lib/data/models/multi_wallet_transaction_cubit.dart index 368dd02ecd97651a6ba24bd50d36a33eabb35c5c..289498b95c7823c9ce830541cb17c920d5203e15 100644 --- a/lib/data/models/multi_wallet_transaction_cubit.dart +++ b/lib/data/models/multi_wallet_transaction_cubit.dart @@ -168,37 +168,47 @@ class MultiWalletTransactionCubit _checkPendingTx(cursor, newParsedState, pubKey, node); _emitState(pubKey, newState); - for (final Transaction tx in newState.transactions.reversed) { + TransactionState currentModifiedState = newState; + + for (final Transaction tx in currentModifiedState.transactions.reversed) { + bool stateModified = false; + if (tx.type == TransactionType.received && - newState.latestReceivedNotification.isBefore(tx.time)) { + currentModifiedState.latestReceivedNotification.isBefore(tx.time)) { // Future final Contact from = tx.from; - NotificationController.createNewNotification( + NotificationController.notifyTransaction( tx.time.millisecondsSinceEpoch.toString(), amount: tx.amount, currentUd: appCubit.currentUd, from: from.title, isG1: isG1); - final TransactionState notifState = - newState.copyWith(latestReceivedNotification: tx.time); - _emitState(pubKey, notifState); + currentModifiedState = currentModifiedState.copyWith( + latestReceivedNotification: tx.time); + stateModified = true; } + if (tx.type == TransactionType.sent && - newState.latestSentNotification.isBefore(tx.time)) { + currentModifiedState.latestSentNotification.isBefore(tx.time)) { // Future final Contact to = tx.to; - NotificationController.createNewNotification( + NotificationController.notifyTransaction( tx.time.millisecondsSinceEpoch.toString(), amount: -tx.amount, currentUd: appCubit.currentUd, to: to.title, isG1: isG1); - final TransactionState notifState = - newState.copyWith(latestSentNotification: tx.time); - _emitState(pubKey, notifState); + currentModifiedState = + currentModifiedState.copyWith(latestSentNotification: tx.time); + stateModified = true; + } + + if (stateModified) { + _emitState(pubKey, currentModifiedState); } } - return newState.transactions; + + return currentModifiedState.transactions; } if (!success) { throw Exception('Failed to get transactions after $retries attempts'); diff --git a/lib/ui/notification_controller_mobile.dart b/lib/ui/notification_controller_mobile.dart index db230aa1c2fe8e55f08110a43bd4517f0ded33ab..f895e9dfba3757692cbac58d2a845e80bcf5cc3f 100644 --- a/lib/ui/notification_controller_mobile.dart +++ b/lib/ui/notification_controller_mobile.dart @@ -140,7 +140,7 @@ class NotificationController { /// NOTIFICATION CREATION METHODS /// ********************************************* /// - static Future<void> createNewNotification(String id, + static Future<void> notifyTransaction(String id, {required double amount, String? to, String? from, @@ -168,18 +168,13 @@ class NotificationController { useSymbol: true), 'to': to!, }); + await notify(title: title, desc: desc, id: id); + } + + static Future<void> notify( + {required String title, required String desc, required String id}) async { if (kIsWeb) { // dart:html cannot be used in Android - /* if (html.Notification.permission != 'granted') { - await html.Notification.requestPermission(); - } - if (html.Notification.permission == 'granted') { - final html.Notification notification = html.Notification( - title, body: desc, - // icon: - ); - // html.Notification.show(); - } */ } else { bool isAllowed = await AwesomeNotifications().isNotificationAllowed(); if (!isAllowed) { @@ -205,18 +200,9 @@ class NotificationController { actionButtons: <NotificationActionButton>[ NotificationActionButton( key: 'notification_open', label: tr('notification_open')), - /* NotificationActionButton( - key: 'REPLY', - label: 'Reply Message', - requireInputText: true, - actionType: ActionType.SilentAction), */ - /* NotificationActionButton( - key: 'DISMISS', - label: 'Dismiss', - actionType: ActionType.DismissAction, - isDangerousOption: true) */ ]); } + return; } static Future<void> scheduleNewNotification() async {