mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-13 11:09:10 +01:00
ass UITestRunner, fix error handling
This commit is contained in:
parent
4fd06ac161
commit
58cdfa76d4
5 changed files with 113 additions and 16 deletions
89
src/main/java/io/bitsquare/UITestRunner.java
Normal file
89
src/main/java/io/bitsquare/UITestRunner.java
Normal file
|
@ -0,0 +1,89 @@
|
|||
package io.bitsquare;
|
||||
|
||||
import io.bitsquare.di.BitSquareModule;
|
||||
import io.bitsquare.di.GuiceFXMLLoader;
|
||||
import io.bitsquare.gui.NavigationItem;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.scene.*;
|
||||
import javafx.scene.input.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* For testing single isolated UI screens
|
||||
*/
|
||||
public class UITestRunner extends Application {
|
||||
private static final Logger log = LoggerFactory.getLogger(UITestRunner.class);
|
||||
private Scene scene;
|
||||
private Parent view;
|
||||
private Pane pane;
|
||||
private boolean devTest = true;
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException {
|
||||
Injector injector = Guice.createInjector(new BitSquareModule());
|
||||
GuiceFXMLLoader.setInjector(injector);
|
||||
|
||||
pane = new StackPane();
|
||||
scene = new Scene(pane, 1000, 750);
|
||||
scene.getAccelerators().put(KeyCombination.valueOf("Shortcut+S"), this::loadMainWindow);
|
||||
loadMainWindow();
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
public void loadMainWindow() {
|
||||
log.debug("re load");
|
||||
pane.getChildren().removeAll();
|
||||
GuiceFXMLLoader loader = new GuiceFXMLLoader(getUrl(NavigationItem.CREATE_OFFER.getFxmlUrl()), false);
|
||||
// GuiceFXMLLoader loader = new GuiceFXMLLoader(getUrl("/io/bitsquare/gui/trade/createoffer/CreateOfferView
|
||||
// .fxml"), false);
|
||||
|
||||
try {
|
||||
view = loader.load();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
pane.getChildren().setAll(view);
|
||||
refreshStylesheets();
|
||||
}
|
||||
|
||||
private void refreshStylesheets() {
|
||||
scene.getStylesheets().clear();
|
||||
scene.getStylesheets().setAll(getUrl("/io/bitsquare/gui/bitsquare.css").toExternalForm());
|
||||
}
|
||||
|
||||
private URL getUrl(String subPath) {
|
||||
if (devTest) {
|
||||
try {
|
||||
// load from file system location to make a reload possible. makes dev process easier with hot reload
|
||||
return new URL("file:///Users/mk/Documents/_intellij/bitsquare/src/main/java" + subPath);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return getClass().getResource(subPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -174,10 +174,9 @@ public class CreateOfferCB extends CachedCodeBehind<CreateOfferPM> {
|
|||
|
||||
|
||||
presentationModel.requestPlaceOfferFailed.addListener((o, oldValue, newValue) -> {
|
||||
if (newValue) {
|
||||
if (newValue && presentationModel.requestPlaceOfferErrorMessage.get() != null) {
|
||||
Popups.openErrorPopup("Error", "An error occurred when placing the offer.\n" +
|
||||
presentationModel.requestPlaceOfferErrorMessage.get());
|
||||
presentationModel.requestPlaceOfferFailed.set(false);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -166,9 +166,14 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void placeOffer() {
|
||||
model.placeOffer();
|
||||
model.requestPlaceOfferErrorMessage.set(null);
|
||||
model.requestPlaceOfferFailed.set(false);
|
||||
model.requestPlaceOfferSuccess.set(false);
|
||||
|
||||
isPlaceOfferButtonDisabled.set(true);
|
||||
isPlaceOfferButtonVisible.set(true);
|
||||
|
||||
model.placeOffer();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -171,12 +171,13 @@ public class MessageFacade implements MessageBroker {
|
|||
public void addOffer(Offer offer, AddOfferListener addOfferListener) {
|
||||
Number160 locationKey = Number160.createHash(offer.getCurrency().getCurrencyCode());
|
||||
try {
|
||||
final Data data = new Data(offer);
|
||||
final Data offerData = new Data(offer);
|
||||
|
||||
// the offer is default 30 days valid
|
||||
int defaultOfferTTL = 30 * 24 * 60 * 60 * 1000;
|
||||
data.ttlSeconds(defaultOfferTTL);
|
||||
offerData.ttlSeconds(defaultOfferTTL);
|
||||
|
||||
FuturePut futurePut = p2pNode.addProtectedData(locationKey, data);
|
||||
FuturePut futurePut = p2pNode.addProtectedData(locationKey, offerData);
|
||||
futurePut.addListener(new BaseFutureListener<BaseFuture>() {
|
||||
@Override
|
||||
public void operationComplete(BaseFuture future) throws Exception {
|
||||
|
@ -184,12 +185,13 @@ public class MessageFacade implements MessageBroker {
|
|||
Platform.runLater(() -> {
|
||||
addOfferListener.onComplete();
|
||||
orderBookListeners.stream().forEach(listener ->
|
||||
listener.onOfferAdded(data, future.isSuccess()));
|
||||
listener.onOfferAdded(offerData, future.isSuccess()));
|
||||
|
||||
// TODO will be removed when we don't use polling anymore
|
||||
setDirty(locationKey);
|
||||
log.trace("Add offer to DHT was successful. Stored data: [key: " + locationKey + ", " +
|
||||
"value: " + data + "]");
|
||||
log.trace("Add offer to DHT was successful. Stored data: [locationKey: " + locationKey +
|
||||
", " +
|
||||
"value: " + offerData + "]");
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
@ -217,25 +219,28 @@ public class MessageFacade implements MessageBroker {
|
|||
}
|
||||
}
|
||||
|
||||
//TODO remove is failing, probably due Coin or Fiat class (was working before)
|
||||
// objects are identical but returned object form network might have soem problem with serialisation?
|
||||
public void removeOffer(Offer offer) {
|
||||
Number160 locationKey = Number160.createHash(offer.getCurrency().getCurrencyCode());
|
||||
try {
|
||||
final Data data = new Data(offer);
|
||||
FutureRemove futureRemove = p2pNode.removeFromDataMap(locationKey, data);
|
||||
final Data offerData = new Data(offer);
|
||||
FutureRemove futureRemove = p2pNode.removeFromDataMap(locationKey, offerData);
|
||||
futureRemove.addListener(new BaseFutureListener<BaseFuture>() {
|
||||
@Override
|
||||
public void operationComplete(BaseFuture future) throws Exception {
|
||||
Platform.runLater(() -> {
|
||||
orderBookListeners.stream().forEach(orderBookListener ->
|
||||
orderBookListener.onOfferRemoved(data, future.isSuccess()));
|
||||
orderBookListener.onOfferRemoved(offerData, future.isSuccess()));
|
||||
setDirty(locationKey);
|
||||
});
|
||||
if (future.isSuccess()) {
|
||||
log.trace("Remove offer from DHT was successful. Stored data: [key: " + locationKey + ", " +
|
||||
"value: " + data + "]");
|
||||
"value: " + offerData + "]");
|
||||
}
|
||||
else {
|
||||
log.error("Remove offer from DHT failed. Reason: " + future.failedReason());
|
||||
log.error("Remove offer from DHT failed. locationKey: " + locationKey + ", Reason: " + future
|
||||
.failedReason());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -222,9 +222,8 @@ public class TradeManager {
|
|||
}
|
||||
|
||||
public void removeOffer(Offer offer) {
|
||||
if (!offers.containsKey(offer.getId())) {
|
||||
if (!offers.containsKey(offer.getId()))
|
||||
log.error("offers does not contain the offer with the ID " + offer.getId());
|
||||
}
|
||||
|
||||
offers.remove(offer.getId());
|
||||
persistOffers();
|
||||
|
|
Loading…
Add table
Reference in a new issue