From 79c0f7769a682aa6ce365c33771b1d338fdf2f03 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 28 Mar 2022 09:31:18 +0200 Subject: [PATCH] indicate when a server failure occurs loading a transaction from file --- .../event/TransactionFetchFailedEvent.java | 13 +++++++++++++ .../sparrow/transaction/HeadersController.java | 18 ++++++++++++++++++ .../transaction/TransactionController.java | 6 +++++- 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/sparrowwallet/sparrow/event/TransactionFetchFailedEvent.java diff --git a/src/main/java/com/sparrowwallet/sparrow/event/TransactionFetchFailedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/TransactionFetchFailedEvent.java new file mode 100644 index 00000000..8c614fdb --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/event/TransactionFetchFailedEvent.java @@ -0,0 +1,13 @@ +package com.sparrowwallet.sparrow.event; + +import com.sparrowwallet.drongo.protocol.Transaction; + +public class TransactionFetchFailedEvent extends TransactionReferencesFailedEvent { + public TransactionFetchFailedEvent(Transaction transaction, Throwable exception) { + super(transaction, exception); + } + + public TransactionFetchFailedEvent(Transaction transaction, Throwable exception, int pageStart, int pageEnd) { + super(transaction, exception, pageStart, pageEnd); + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java index e95a0329..b816f578 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java @@ -14,6 +14,7 @@ import com.sparrowwallet.sparrow.AppServices; import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.control.*; import com.sparrowwallet.sparrow.event.*; +import com.sparrowwallet.sparrow.glyphfont.FontAwesome5; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5Brands; import com.sparrowwallet.sparrow.io.Device; import com.sparrowwallet.sparrow.net.ElectrumServer; @@ -1177,6 +1178,23 @@ public class HeadersController extends TransactionFormController implements Init } } + @Subscribe + public void transactionFetchFailed(TransactionFetchFailedEvent event) { + if(event.getTransaction().getTxId().equals(headersForm.getTransaction().getTxId()) + && !blockchainForm.isVisible() && !signingWalletForm.isVisible() && !signaturesForm.isVisible()) { + blockchainForm.setVisible(true); + blockStatus.setText("Unknown transaction status, server failed to respond"); + Glyph errorGlyph = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.EXCLAMATION_CIRCLE); + errorGlyph.setFontSize(12); + blockStatus.setGraphic(errorGlyph); + blockStatus.setContentDisplay(ContentDisplay.LEFT); + errorGlyph.getStyleClass().add("failure"); + blockHeightField.setVisible(false); + blockTimestampField.setVisible(false); + blockHashField.setVisible(false); + } + } + @Subscribe public void bitcoinUnitChanged(BitcoinUnitChangedEvent event) { fee.refresh(event.getBitcoinUnit()); diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/TransactionController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/TransactionController.java index baa258da..823a3723 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/TransactionController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/TransactionController.java @@ -379,7 +379,11 @@ public class TransactionController implements Initializable { }); transactionReferenceService.setOnFailed(failedEvent -> { log.error("Error fetching transaction or input references", failedEvent.getSource().getException()); - EventManager.get().post(new TransactionReferencesFailedEvent(getTransaction(), failedEvent.getSource().getException(), indexStart, maxIndex)); + if(references.contains(getTransaction().getTxId())) { + EventManager.get().post(new TransactionFetchFailedEvent(getTransaction(), failedEvent.getSource().getException(), indexStart, maxIndex)); + } else { + EventManager.get().post(new TransactionReferencesFailedEvent(getTransaction(), failedEvent.getSource().getException(), indexStart, maxIndex)); + } }); EventManager.get().post(new TransactionReferencesStartedEvent(getTransaction(), indexStart, maxIndex)); transactionReferenceService.start();