From e2a8dc702bc7539c4ca76a88ee5404403ea0c859 Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 10 Feb 2023 10:48:54 -0500 Subject: [PATCH] show popup for error notifications sent through notification service --- core/src/main/java/bisq/core/api/CoreApi.java | 5 ---- .../core/api/CoreNotificationService.java | 13 ++++++++-- .../bisq/core/api/NotificationListener.java | 25 +++++++++++++++++++ core/src/main/java/bisq/core/trade/Trade.java | 1 + .../java/bisq/core/trade/TradeManager.java | 2 +- .../core/trade/protocol/ProcessModel.java | 1 - .../daemon/grpc/GrpcNotificationsService.java | 3 +-- .../notifications/NotificationCenter.java | 17 +++++++++++-- proto/src/main/proto/grpc.proto | 9 ++++--- 9 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 core/src/main/java/bisq/core/api/NotificationListener.java diff --git a/core/src/main/java/bisq/core/api/CoreApi.java b/core/src/main/java/bisq/core/api/CoreApi.java index 5e118a6a1f..ac9d369a02 100644 --- a/core/src/main/java/bisq/core/api/CoreApi.java +++ b/core/src/main/java/bisq/core/api/CoreApi.java @@ -67,7 +67,6 @@ import java.util.concurrent.TimeoutException; import java.util.function.Consumer; import lombok.Getter; -import lombok.NonNull; import lombok.extern.slf4j.Slf4j; @@ -346,10 +345,6 @@ public class CoreApi { // Notifications /////////////////////////////////////////////////////////////////////////////////////////// - public interface NotificationListener { - void onMessage(@NonNull NotificationMessage message); - } - public void addNotificationListener(NotificationListener listener) { notificationService.addListener(listener); } diff --git a/core/src/main/java/bisq/core/api/CoreNotificationService.java b/core/src/main/java/bisq/core/api/CoreNotificationService.java index 8825a86164..0a0ebbad36 100644 --- a/core/src/main/java/bisq/core/api/CoreNotificationService.java +++ b/core/src/main/java/bisq/core/api/CoreNotificationService.java @@ -1,6 +1,5 @@ package bisq.core.api; -import bisq.core.api.CoreApi.NotificationListener; import bisq.core.api.model.TradeInfo; import bisq.core.trade.Trade; import bisq.core.support.messages.ChatMessage; @@ -55,7 +54,8 @@ public class CoreNotificationService { .setTrade(TradeInfo.toTradeInfo(trade).toProtoMessage()) .setTimestamp(System.currentTimeMillis()) .setTitle(title) - .setMessage(message).build()); + .setMessage(message) + .build()); } public void sendChatNotification(ChatMessage chatMessage) { @@ -65,4 +65,13 @@ public class CoreNotificationService { .setChatMessage(chatMessage.toProtoChatMessageBuilder()) .build()); } + + public void sendErrorNotification(String title, String errorMessage) { + sendNotification(NotificationMessage.newBuilder() + .setType(NotificationType.ERROR) + .setTimestamp(System.currentTimeMillis()) + .setTitle(title) + .setMessage(errorMessage) + .build()); + } } diff --git a/core/src/main/java/bisq/core/api/NotificationListener.java b/core/src/main/java/bisq/core/api/NotificationListener.java new file mode 100644 index 0000000000..bb2a74ebf9 --- /dev/null +++ b/core/src/main/java/bisq/core/api/NotificationListener.java @@ -0,0 +1,25 @@ +package bisq.core.api; + +import bisq.proto.grpc.NotificationMessage; +import lombok.NonNull; + +/* + * This file is part of Haveno. + * + * Haveno is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Haveno is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Haveno. If not, see . + */ + +public interface NotificationListener { + void onMessage(@NonNull NotificationMessage message); +} \ No newline at end of file diff --git a/core/src/main/java/bisq/core/trade/Trade.java b/core/src/main/java/bisq/core/trade/Trade.java index f608faf2cc..9954759ac8 100644 --- a/core/src/main/java/bisq/core/trade/Trade.java +++ b/core/src/main/java/bisq/core/trade/Trade.java @@ -831,6 +831,7 @@ public abstract class Trade implements Tradable, Model { log.warn(e.getMessage()); e.printStackTrace(); setErrorMessage(e.getMessage()); + processModel.getTradeManager().getNotificationService().sendErrorNotification("Error", e.getMessage()); } } else { log.warn("Multisig wallet to delete for trade {} does not exist", getId()); diff --git a/core/src/main/java/bisq/core/trade/TradeManager.java b/core/src/main/java/bisq/core/trade/TradeManager.java index fe18d3d487..3066f344fc 100644 --- a/core/src/main/java/bisq/core/trade/TradeManager.java +++ b/core/src/main/java/bisq/core/trade/TradeManager.java @@ -125,6 +125,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi private final KeyRing keyRing; private final CoreAccountService accountService; private final XmrWalletService xmrWalletService; + @Getter private final CoreNotificationService notificationService; private final OfferBookService offerBookService; private final OpenOfferManager openOfferManager; @@ -328,7 +329,6 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi trade.shutDown(); } catch (Exception e) { log.warn("Error closing trade subprocess. Was Haveno stopped manually with ctrl+c?"); - e.printStackTrace(); } }); HavenoUtils.executeTasks(tasks); diff --git a/core/src/main/java/bisq/core/trade/protocol/ProcessModel.java b/core/src/main/java/bisq/core/trade/protocol/ProcessModel.java index 7c838f99f4..82ce683efe 100644 --- a/core/src/main/java/bisq/core/trade/protocol/ProcessModel.java +++ b/core/src/main/java/bisq/core/trade/protocol/ProcessModel.java @@ -33,7 +33,6 @@ import bisq.core.support.dispute.arbitration.arbitrator.ArbitratorManager; import bisq.core.support.dispute.mediation.mediator.MediatorManager; import bisq.core.support.dispute.messages.DisputeClosedMessage; import bisq.core.support.dispute.refund.refundagent.RefundAgentManager; -import bisq.core.trade.MakerTrade; import bisq.core.trade.Trade; import bisq.core.trade.TradeManager; import bisq.core.trade.messages.PaymentReceivedMessage; diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcNotificationsService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcNotificationsService.java index 5953fd76eb..5c0b44ca81 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcNotificationsService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcNotificationsService.java @@ -1,8 +1,7 @@ package bisq.daemon.grpc; import bisq.core.api.CoreApi; -import bisq.core.api.CoreApi.NotificationListener; - +import bisq.core.api.NotificationListener; import bisq.proto.grpc.NotificationMessage; import bisq.proto.grpc.NotificationsGrpc.NotificationsImplBase; import bisq.proto.grpc.RegisterNotificationListenerRequest; diff --git a/desktop/src/main/java/bisq/desktop/main/overlays/notifications/NotificationCenter.java b/desktop/src/main/java/bisq/desktop/main/overlays/notifications/NotificationCenter.java index a313becd76..fe79f20fc5 100644 --- a/desktop/src/main/java/bisq/desktop/main/overlays/notifications/NotificationCenter.java +++ b/desktop/src/main/java/bisq/desktop/main/overlays/notifications/NotificationCenter.java @@ -19,6 +19,7 @@ package bisq.desktop.main.overlays.notifications; import bisq.desktop.Navigation; import bisq.desktop.main.MainView; +import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.portfolio.PortfolioView; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesView; import bisq.desktop.main.support.SupportView; @@ -27,7 +28,9 @@ import bisq.desktop.main.support.dispute.agent.arbitration.ArbitratorView; import bisq.desktop.main.support.dispute.client.arbitration.ArbitrationClientView; import bisq.desktop.main.support.dispute.client.mediation.MediationClientView; import bisq.desktop.main.support.dispute.client.refund.RefundClientView; - +import bisq.proto.grpc.NotificationMessage; +import bisq.proto.grpc.NotificationMessage.NotificationType; +import bisq.core.api.NotificationListener; import bisq.core.locale.Res; import bisq.core.support.dispute.Dispute; import bisq.core.support.dispute.arbitration.ArbitrationManager; @@ -58,6 +61,7 @@ import java.util.List; import java.util.Map; import java.util.function.Consumer; +import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import javax.annotation.Nullable; @@ -165,6 +169,16 @@ public class NotificationCenter { tradePhaseSubscriptionsMap.put(tradeId, tradePhaseSubscription); } ); + + // show popup for error notifications + tradeManager.getNotificationService().addListener(new NotificationListener() { + @Override + public void onMessage(@NonNull NotificationMessage message) { + if (message.getType() == NotificationType.ERROR) { + new Popup().warning(message.getMessage()).show(); + } + } + }); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -319,5 +333,4 @@ public class NotificationCenter { notification.show(); } } - } diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index feb9d0fbc4..1418e30ca9 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -255,10 +255,11 @@ message RegisterNotificationListenerRequest { message NotificationMessage { enum NotificationType { - APP_INITIALIZED = 0; - KEEP_ALIVE = 1; - TRADE_UPDATE = 2; - CHAT_MESSAGE = 3; + ERROR = 0; + APP_INITIALIZED = 1; + KEEP_ALIVE = 2; + TRADE_UPDATE = 3; + CHAT_MESSAGE = 4; } string id = 1;