mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-02 20:36:44 +00:00
show error dialogs on invalid files
This commit is contained in:
parent
7bfddc1c98
commit
97de5ef6dc
2 changed files with 35 additions and 17 deletions
2
drongo
2
drongo
|
@ -1 +1 @@
|
||||||
Subproject commit a1696ec2e8d5ca17fc98246e374e9d3ae9ab368f
|
Subproject commit 314ee075c20c9a23d09e9dd84ee2b6eb3588a129
|
|
@ -3,10 +3,12 @@ package com.craigraw.sparrow;
|
||||||
import com.craigraw.drongo.Utils;
|
import com.craigraw.drongo.Utils;
|
||||||
import com.craigraw.drongo.protocol.Transaction;
|
import com.craigraw.drongo.protocol.Transaction;
|
||||||
import com.craigraw.drongo.psbt.PSBT;
|
import com.craigraw.drongo.psbt.PSBT;
|
||||||
|
import com.craigraw.drongo.psbt.PSBTParseException;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Tab;
|
import javafx.scene.control.Tab;
|
||||||
import javafx.scene.control.TabPane;
|
import javafx.scene.control.TabPane;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
|
@ -49,22 +51,34 @@ public class AppController implements Initializable {
|
||||||
stream.read(bytes);
|
stream.read(bytes);
|
||||||
stream.close();
|
stream.close();
|
||||||
|
|
||||||
Tab tab = null;
|
Tab tab;
|
||||||
if(PSBT.isPSBT(Hex.toHexString(bytes))) {
|
if(PSBT.isPSBT(bytes)) {
|
||||||
PSBT psbt = new PSBT(bytes);
|
try {
|
||||||
tab = addTransactionTab(file.getName(), null, psbt);
|
PSBT psbt = new PSBT(bytes);
|
||||||
|
tab = addTransactionTab(file.getName(), null, psbt);
|
||||||
|
} catch(PSBTParseException e) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.setTitle("PSBT File Invalid");
|
||||||
|
alert.setHeaderText("PSBT File Invalid");
|
||||||
|
alert.setContentText(e.getMessage());
|
||||||
|
alert.showAndWait();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
Transaction transaction = new Transaction(bytes);
|
||||||
|
tab = addTransactionTab(file.getName(), transaction, null);
|
||||||
|
} catch(RuntimeException e) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.setTitle("File Invalid");
|
||||||
|
alert.setHeaderText("File Invalid");
|
||||||
|
alert.setContentText("Unknown file format or invalid transaction");
|
||||||
|
alert.showAndWait();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
tabs.getSelectionModel().select(tab);
|
||||||
Transaction transaction = new Transaction(bytes);
|
|
||||||
tab = addTransactionTab(file.getName(), transaction, null);
|
|
||||||
} catch(Exception e) {
|
|
||||||
//TODO: Handle not a transaction
|
|
||||||
}
|
|
||||||
|
|
||||||
if(tab != null) {
|
|
||||||
tabs.getSelectionModel().select(tab);
|
|
||||||
}
|
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -87,8 +101,12 @@ public class AppController implements Initializable {
|
||||||
Transaction transaction = new Transaction(txbytes);
|
Transaction transaction = new Transaction(txbytes);
|
||||||
addTransactionTab(name, transaction, null);
|
addTransactionTab(name, transaction, null);
|
||||||
} else if(psbtHex != null) {
|
} else if(psbtHex != null) {
|
||||||
PSBT psbt = PSBT.fromString(psbtHex);
|
try {
|
||||||
addTransactionTab(name, null, psbt);
|
PSBT psbt = PSBT.fromString(psbtHex);
|
||||||
|
addTransactionTab(name, null, psbt);
|
||||||
|
} catch(Exception e) {
|
||||||
|
//ignore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue