show popup for error notifications sent through notification service

This commit is contained in:
woodser 2023-02-10 10:48:54 -05:00
parent 88f0ad543a
commit e2a8dc702b
9 changed files with 59 additions and 17 deletions

View file

@ -67,7 +67,6 @@ import java.util.concurrent.TimeoutException;
import java.util.function.Consumer; import java.util.function.Consumer;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -346,10 +345,6 @@ public class CoreApi {
// Notifications // Notifications
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public interface NotificationListener {
void onMessage(@NonNull NotificationMessage message);
}
public void addNotificationListener(NotificationListener listener) { public void addNotificationListener(NotificationListener listener) {
notificationService.addListener(listener); notificationService.addListener(listener);
} }

View file

@ -1,6 +1,5 @@
package bisq.core.api; package bisq.core.api;
import bisq.core.api.CoreApi.NotificationListener;
import bisq.core.api.model.TradeInfo; import bisq.core.api.model.TradeInfo;
import bisq.core.trade.Trade; import bisq.core.trade.Trade;
import bisq.core.support.messages.ChatMessage; import bisq.core.support.messages.ChatMessage;
@ -55,7 +54,8 @@ public class CoreNotificationService {
.setTrade(TradeInfo.toTradeInfo(trade).toProtoMessage()) .setTrade(TradeInfo.toTradeInfo(trade).toProtoMessage())
.setTimestamp(System.currentTimeMillis()) .setTimestamp(System.currentTimeMillis())
.setTitle(title) .setTitle(title)
.setMessage(message).build()); .setMessage(message)
.build());
} }
public void sendChatNotification(ChatMessage chatMessage) { public void sendChatNotification(ChatMessage chatMessage) {
@ -65,4 +65,13 @@ public class CoreNotificationService {
.setChatMessage(chatMessage.toProtoChatMessageBuilder()) .setChatMessage(chatMessage.toProtoChatMessageBuilder())
.build()); .build());
} }
public void sendErrorNotification(String title, String errorMessage) {
sendNotification(NotificationMessage.newBuilder()
.setType(NotificationType.ERROR)
.setTimestamp(System.currentTimeMillis())
.setTitle(title)
.setMessage(errorMessage)
.build());
}
} }

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
public interface NotificationListener {
void onMessage(@NonNull NotificationMessage message);
}

View file

@ -831,6 +831,7 @@ public abstract class Trade implements Tradable, Model {
log.warn(e.getMessage()); log.warn(e.getMessage());
e.printStackTrace(); e.printStackTrace();
setErrorMessage(e.getMessage()); setErrorMessage(e.getMessage());
processModel.getTradeManager().getNotificationService().sendErrorNotification("Error", e.getMessage());
} }
} else { } else {
log.warn("Multisig wallet to delete for trade {} does not exist", getId()); log.warn("Multisig wallet to delete for trade {} does not exist", getId());

View file

@ -125,6 +125,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
private final KeyRing keyRing; private final KeyRing keyRing;
private final CoreAccountService accountService; private final CoreAccountService accountService;
private final XmrWalletService xmrWalletService; private final XmrWalletService xmrWalletService;
@Getter
private final CoreNotificationService notificationService; private final CoreNotificationService notificationService;
private final OfferBookService offerBookService; private final OfferBookService offerBookService;
private final OpenOfferManager openOfferManager; private final OpenOfferManager openOfferManager;
@ -328,7 +329,6 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
trade.shutDown(); trade.shutDown();
} catch (Exception e) { } catch (Exception e) {
log.warn("Error closing trade subprocess. Was Haveno stopped manually with ctrl+c?"); log.warn("Error closing trade subprocess. Was Haveno stopped manually with ctrl+c?");
e.printStackTrace();
} }
}); });
HavenoUtils.executeTasks(tasks); HavenoUtils.executeTasks(tasks);

View file

@ -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.mediation.mediator.MediatorManager;
import bisq.core.support.dispute.messages.DisputeClosedMessage; import bisq.core.support.dispute.messages.DisputeClosedMessage;
import bisq.core.support.dispute.refund.refundagent.RefundAgentManager; import bisq.core.support.dispute.refund.refundagent.RefundAgentManager;
import bisq.core.trade.MakerTrade;
import bisq.core.trade.Trade; import bisq.core.trade.Trade;
import bisq.core.trade.TradeManager; import bisq.core.trade.TradeManager;
import bisq.core.trade.messages.PaymentReceivedMessage; import bisq.core.trade.messages.PaymentReceivedMessage;

View file

@ -1,8 +1,7 @@
package bisq.daemon.grpc; package bisq.daemon.grpc;
import bisq.core.api.CoreApi; 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.NotificationMessage;
import bisq.proto.grpc.NotificationsGrpc.NotificationsImplBase; import bisq.proto.grpc.NotificationsGrpc.NotificationsImplBase;
import bisq.proto.grpc.RegisterNotificationListenerRequest; import bisq.proto.grpc.RegisterNotificationListenerRequest;

View file

@ -19,6 +19,7 @@ package bisq.desktop.main.overlays.notifications;
import bisq.desktop.Navigation; import bisq.desktop.Navigation;
import bisq.desktop.main.MainView; import bisq.desktop.main.MainView;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.portfolio.PortfolioView; import bisq.desktop.main.portfolio.PortfolioView;
import bisq.desktop.main.portfolio.pendingtrades.PendingTradesView; import bisq.desktop.main.portfolio.pendingtrades.PendingTradesView;
import bisq.desktop.main.support.SupportView; 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.arbitration.ArbitrationClientView;
import bisq.desktop.main.support.dispute.client.mediation.MediationClientView; import bisq.desktop.main.support.dispute.client.mediation.MediationClientView;
import bisq.desktop.main.support.dispute.client.refund.RefundClientView; 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.locale.Res;
import bisq.core.support.dispute.Dispute; import bisq.core.support.dispute.Dispute;
import bisq.core.support.dispute.arbitration.ArbitrationManager; import bisq.core.support.dispute.arbitration.ArbitrationManager;
@ -58,6 +61,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -165,6 +169,16 @@ public class NotificationCenter {
tradePhaseSubscriptionsMap.put(tradeId, tradePhaseSubscription); 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(); notification.show();
} }
} }
} }

View file

@ -255,10 +255,11 @@ message RegisterNotificationListenerRequest {
message NotificationMessage { message NotificationMessage {
enum NotificationType { enum NotificationType {
APP_INITIALIZED = 0; ERROR = 0;
KEEP_ALIVE = 1; APP_INITIALIZED = 1;
TRADE_UPDATE = 2; KEEP_ALIVE = 2;
CHAT_MESSAGE = 3; TRADE_UPDATE = 3;
CHAT_MESSAGE = 4;
} }
string id = 1; string id = 1;