Merge branch 'haveno-dex:master' into haveno-reto

This commit is contained in:
boldsuck 2025-01-11 00:04:19 +01:00 committed by GitHub
commit 4666430429
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 200 additions and 217 deletions

View file

@ -1343,6 +1343,7 @@ public class XmrWalletService extends XmrWalletBase {
try { try {
doMaybeInitMainWallet(sync, MAX_SYNC_ATTEMPTS); doMaybeInitMainWallet(sync, MAX_SYNC_ATTEMPTS);
} catch (Exception e) { } catch (Exception e) {
if (isShutDownStarted) return;
log.warn("Error initializing main wallet: {}\n", e.getMessage(), e); log.warn("Error initializing main wallet: {}\n", e.getMessage(), e);
HavenoUtils.setTopError(e.getMessage()); HavenoUtils.setTopError(e.getMessage());
throw e; throw e;
@ -1510,10 +1511,11 @@ public class XmrWalletService extends XmrWalletBase {
// try opening wallet // try opening wallet
config.setNetworkType(getMoneroNetworkType()); config.setNetworkType(getMoneroNetworkType());
config.setServer(connection); config.setServer(connection);
log.info("Opening full wallet " + config.getPath() + " with monerod=" + connection.getUri() + ", proxyUri=" + connection.getProxyUri()); log.info("Opening full wallet '{}' with monerod={}, proxyUri={}", config.getPath(), connection.getUri(), connection.getProxyUri());
try { try {
walletFull = MoneroWalletFull.openWallet(config); walletFull = MoneroWalletFull.openWallet(config);
} catch (Exception e) { } catch (Exception e) {
if (isShutDownStarted) throw e;
log.warn("Failed to open full wallet '{}', attempting to use backup cache files, error={}", config.getPath(), e.getMessage()); log.warn("Failed to open full wallet '{}', attempting to use backup cache files, error={}", config.getPath(), e.getMessage());
boolean retrySuccessful = false; boolean retrySuccessful = false;
try { try {
@ -1551,7 +1553,7 @@ public class XmrWalletService extends XmrWalletBase {
// retry opening wallet after cache deleted // retry opening wallet after cache deleted
try { try {
log.warn("Failed to open full wallet using backup cache files, retrying with cache deleted"); log.warn("Failed to open full wallet '{}' using backup cache files, retrying with cache deleted", config.getPath());
walletFull = MoneroWalletFull.openWallet(config); walletFull = MoneroWalletFull.openWallet(config);
log.warn("Successfully opened full wallet after cache deleted"); log.warn("Successfully opened full wallet after cache deleted");
retrySuccessful = true; retrySuccessful = true;
@ -1565,7 +1567,7 @@ public class XmrWalletService extends XmrWalletBase {
} else { } else {
// restore original wallet cache // restore original wallet cache
log.warn("Failed to open full wallet after deleting cache, restoring original cache"); log.warn("Failed to open full wallet '{}' after deleting cache, restoring original cache", config.getPath());
File cacheFile = new File(cachePath); File cacheFile = new File(cachePath);
if (cacheFile.exists()) cacheFile.delete(); if (cacheFile.exists()) cacheFile.delete();
if (originalCacheBackup.exists()) originalCacheBackup.renameTo(new File(cachePath)); if (originalCacheBackup.exists()) originalCacheBackup.renameTo(new File(cachePath));
@ -1637,11 +1639,12 @@ public class XmrWalletService extends XmrWalletBase {
if (!applyProxyUri) connection.setProxyUri(null); if (!applyProxyUri) connection.setProxyUri(null);
// try opening wallet // try opening wallet
log.info("Opening RPC wallet " + config.getPath() + " with monerod=" + connection.getUri() + ", proxyUri=" + connection.getProxyUri()); log.info("Opening RPC wallet '{}' with monerod={}, proxyUri={}", config.getPath(), connection.getUri(), connection.getProxyUri());
config.setServer(connection); config.setServer(connection);
try { try {
walletRpc.openWallet(config); walletRpc.openWallet(config);
} catch (Exception e) { } catch (Exception e) {
if (isShutDownStarted) throw e;
log.warn("Failed to open RPC wallet '{}', attempting to use backup cache files, error={}", config.getPath(), e.getMessage()); log.warn("Failed to open RPC wallet '{}', attempting to use backup cache files, error={}", config.getPath(), e.getMessage());
boolean retrySuccessful = false; boolean retrySuccessful = false;
try { try {
@ -1679,7 +1682,7 @@ public class XmrWalletService extends XmrWalletBase {
// retry opening wallet after cache deleted // retry opening wallet after cache deleted
try { try {
log.warn("Failed to open RPC wallet using backup cache files, retrying with cache deleted"); log.warn("Failed to open RPC wallet '{}' using backup cache files, retrying with cache deleted", config.getPath());
walletRpc.openWallet(config); walletRpc.openWallet(config);
log.warn("Successfully opened RPC wallet after cache deleted"); log.warn("Successfully opened RPC wallet after cache deleted");
retrySuccessful = true; retrySuccessful = true;
@ -1693,7 +1696,7 @@ public class XmrWalletService extends XmrWalletBase {
} else { } else {
// restore original wallet cache // restore original wallet cache
log.warn("Failed to open RPC wallet after deleting cache, restoring original cache"); log.warn("Failed to open RPC wallet '{}' after deleting cache, restoring original cache", config.getPath());
File cacheFile = new File(cachePath); File cacheFile = new File(cachePath);
if (cacheFile.exists()) cacheFile.delete(); if (cacheFile.exists()) cacheFile.delete();
if (originalCacheBackup.exists()) originalCacheBackup.renameTo(new File(cachePath)); if (originalCacheBackup.exists()) originalCacheBackup.renameTo(new File(cachePath));

View file

@ -424,7 +424,7 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
currencySelectionSubscriber = currencySelectionBinding.subscribe((observable, oldValue, newValue) -> { currencySelectionSubscriber = currencySelectionBinding.subscribe((observable, oldValue, newValue) -> {
}); });
tableView.setItems(model.getOfferList()); UserThread.execute(() -> tableView.setItems(model.getOfferList()));
model.getOfferList().addListener(offerListListener); model.getOfferList().addListener(offerListListener);
nrOfOffersLabel.setText(Res.get("offerbook.nrOffers", model.getOfferList().size())); nrOfOffersLabel.setText(Res.get("offerbook.nrOffers", model.getOfferList().size()));
@ -788,13 +788,11 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
return new TableCell<>() { return new TableCell<>() {
@Override @Override
public void updateItem(final OfferBookListItem item, boolean empty) { public void updateItem(final OfferBookListItem item, boolean empty) {
UserThread.execute(() -> { super.updateItem(item, empty);
super.updateItem(item, empty); if (item != null && !empty)
if (item != null && !empty) setGraphic(new ColoredDecimalPlacesWithZerosText(model.getAmount(item), GUIUtil.AMOUNT_DECIMALS_WITH_ZEROS));
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getAmount(item), GUIUtil.AMOUNT_DECIMALS_WITH_ZEROS)); else
else setGraphic(null);
setGraphic(null);
});
} }
}; };
} }
@ -819,13 +817,11 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
@Override @Override
public void updateItem(final OfferBookListItem item, boolean empty) { public void updateItem(final OfferBookListItem item, boolean empty) {
UserThread.execute(() -> { super.updateItem(item, empty);
super.updateItem(item, empty); if (item != null && !empty)
if (item != null && !empty) setText(CurrencyUtil.getCurrencyPair(item.getOffer().getCurrencyCode()));
setText(CurrencyUtil.getCurrencyPair(item.getOffer().getCurrencyCode())); else
else setText("");
setText("");
});
} }
}; };
} }
@ -855,15 +851,13 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
return new TableCell<>() { return new TableCell<>() {
@Override @Override
public void updateItem(final OfferBookListItem item, boolean empty) { public void updateItem(final OfferBookListItem item, boolean empty) {
UserThread.execute(() -> { super.updateItem(item, empty);
super.updateItem(item, empty);
if (item != null && !empty) { if (item != null && !empty) {
setGraphic(getPriceAndPercentage(item)); setGraphic(getPriceAndPercentage(item));
} else { } else {
setGraphic(null); setGraphic(null);
} }
});
} }
private HBox getPriceAndPercentage(OfferBookListItem item) { private HBox getPriceAndPercentage(OfferBookListItem item) {
@ -939,23 +933,21 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
return new TableCell<>() { return new TableCell<>() {
@Override @Override
public void updateItem(final OfferBookListItem item, boolean empty) { public void updateItem(final OfferBookListItem item, boolean empty) {
UserThread.execute(() -> { super.updateItem(item, empty);
super.updateItem(item, empty);
if (item != null && !empty) { if (item != null && !empty) {
if (item.getOffer().getPrice() == null) { if (item.getOffer().getPrice() == null) {
setText(Res.get("shared.na")); setText(Res.get("shared.na"));
setGraphic(null); setGraphic(null);
} else {
setText("");
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(item),
model.getNumberOfDecimalsForVolume(item)));
}
} else { } else {
setText(""); setText("");
setGraphic(null); setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(item),
model.getNumberOfDecimalsForVolume(item)));
} }
}); } else {
setText("");
setGraphic(null);
}
} }
}; };
} }
@ -981,32 +973,30 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
@Override @Override
public void updateItem(final OfferBookListItem item, boolean empty) { public void updateItem(final OfferBookListItem item, boolean empty) {
UserThread.execute(() -> { super.updateItem(item, empty);
super.updateItem(item, empty);
if (item != null && !empty) { if (item != null && !empty) {
Offer offer = item.getOffer(); Offer offer = item.getOffer();
if (model.isOfferBanned(offer)) { if (model.isOfferBanned(offer)) {
setGraphic(new AutoTooltipLabel(model.getPaymentMethod(item))); setGraphic(new AutoTooltipLabel(model.getPaymentMethod(item)));
} else {
if (offer.isXmrAutoConf()) {
field = new HyperlinkWithIcon(model.getPaymentMethod(item), AwesomeIcon.ROCKET);
} else {
field = new HyperlinkWithIcon(model.getPaymentMethod(item));
}
field.setOnAction(event -> {
offerDetailsWindow.show(offer);
});
field.setTooltip(new Tooltip(model.getPaymentMethodToolTip(item)));
setGraphic(field);
}
} else { } else {
setGraphic(null); if (offer.isXmrAutoConf()) {
if (field != null) field = new HyperlinkWithIcon(model.getPaymentMethod(item), AwesomeIcon.ROCKET);
field.setOnAction(null); } else {
field = new HyperlinkWithIcon(model.getPaymentMethod(item));
}
field.setOnAction(event -> {
offerDetailsWindow.show(offer);
});
field.setTooltip(new Tooltip(model.getPaymentMethodToolTip(item)));
setGraphic(field);
} }
}); } else {
setGraphic(null);
if (field != null)
field.setOnAction(null);
}
} }
}; };
} }
@ -1035,28 +1025,26 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
return new TableCell<>() { return new TableCell<>() {
@Override @Override
public void updateItem(final OfferBookListItem item, boolean empty) { public void updateItem(final OfferBookListItem item, boolean empty) {
UserThread.execute(() -> { super.updateItem(item, empty);
super.updateItem(item, empty);
if (item != null && !empty) { if (item != null && !empty) {
var isSellOffer = item.getOffer().getDirection() == OfferDirection.SELL; var isSellOffer = item.getOffer().getDirection() == OfferDirection.SELL;
var deposit = isSellOffer ? item.getOffer().getMaxBuyerSecurityDeposit() : var deposit = isSellOffer ? item.getOffer().getMaxBuyerSecurityDeposit() :
item.getOffer().getMaxSellerSecurityDeposit(); item.getOffer().getMaxSellerSecurityDeposit();
if (deposit == null) { if (deposit == null) {
setText(Res.get("shared.na")); setText(Res.get("shared.na"));
setGraphic(null); setGraphic(null);
} else {
setText("");
String rangePrefix = item.getOffer().isRange() ? "<= " : "";
setGraphic(new ColoredDecimalPlacesWithZerosText(rangePrefix + model.formatDepositString(
deposit, item.getOffer().getAmount().longValueExact()),
GUIUtil.AMOUNT_DECIMALS_WITH_ZEROS));
}
} else { } else {
setText(""); setText("");
setGraphic(null); String rangePrefix = item.getOffer().isRange() ? "<= " : "";
setGraphic(new ColoredDecimalPlacesWithZerosText(rangePrefix + model.formatDepositString(
deposit, item.getOffer().getAmount().longValueExact()),
GUIUtil.AMOUNT_DECIMALS_WITH_ZEROS));
} }
}); } else {
setText("");
setGraphic(null);
}
} }
}; };
} }
@ -1083,114 +1071,112 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
@Override @Override
public void updateItem(final OfferBookListItem item, boolean empty) { public void updateItem(final OfferBookListItem item, boolean empty) {
UserThread.execute(() -> { super.updateItem(item, empty);
super.updateItem(item, empty);
final ImageView iconView = new ImageView(); final ImageView iconView = new ImageView();
final AutoTooltipButton button = new AutoTooltipButton(); final AutoTooltipButton button = new AutoTooltipButton();
{
button.setGraphic(iconView);
button.setGraphicTextGap(10);
button.setPrefWidth(10000);
}
final ImageView iconView2 = new ImageView();
final AutoTooltipButton button2 = new AutoTooltipButton();
{
button2.setGraphic(iconView2);
button2.setGraphicTextGap(10);
button2.setPrefWidth(10000);
}
final HBox hbox = new HBox();
{
hbox.setSpacing(8);
hbox.setAlignment(Pos.CENTER);
hbox.getChildren().add(button);
hbox.getChildren().add(button2);
HBox.setHgrow(button, Priority.ALWAYS);
HBox.setHgrow(button2, Priority.ALWAYS);
}
TableRow<OfferBookListItem> tableRow = getTableRow(); {
if (item != null && !empty) { button.setGraphic(iconView);
Offer offer = item.getOffer(); button.setGraphicTextGap(10);
boolean myOffer = model.isMyOffer(offer); button.setPrefWidth(10000);
}
// https://github.com/bisq-network/bisq/issues/4986 final ImageView iconView2 = new ImageView();
if (tableRow != null) { final AutoTooltipButton button2 = new AutoTooltipButton();
canTakeOfferResult = model.offerFilterService.canTakeOffer(offer, false);
tableRow.setOpacity(canTakeOfferResult.isValid() || myOffer ? 1 : 0.4);
if (myOffer) { {
button.setDefaultButton(false); button2.setGraphic(iconView2);
tableRow.setOnMousePressed(null); button2.setGraphicTextGap(10);
} else if (canTakeOfferResult.isValid()) { button2.setPrefWidth(10000);
// set first row button as default }
button.setDefaultButton(getIndex() == 0);
tableRow.setOnMousePressed(null);
} else {
button.setDefaultButton(false);
tableRow.setOnMousePressed(e -> {
// ugly hack to get the icon clickable when deactivated
if (!(e.getTarget() instanceof ImageView || e.getTarget() instanceof Canvas))
onShowInfo(offer, canTakeOfferResult);
});
}
}
String title; final HBox hbox = new HBox();
{
hbox.setSpacing(8);
hbox.setAlignment(Pos.CENTER);
hbox.getChildren().add(button);
hbox.getChildren().add(button2);
HBox.setHgrow(button, Priority.ALWAYS);
HBox.setHgrow(button2, Priority.ALWAYS);
}
TableRow<OfferBookListItem> tableRow = getTableRow();
if (item != null && !empty) {
Offer offer = item.getOffer();
boolean myOffer = model.isMyOffer(offer);
// https://github.com/bisq-network/bisq/issues/4986
if (tableRow != null) {
canTakeOfferResult = model.offerFilterService.canTakeOffer(offer, false);
tableRow.setOpacity(canTakeOfferResult.isValid() || myOffer ? 1 : 0.4);
if (myOffer) { if (myOffer) {
iconView.setId("image-remove"); button.setDefaultButton(false);
title = Res.get("shared.remove");
button.setOnAction(e -> onRemoveOpenOffer(offer));
iconView2.setId("image-edit");
button2.updateText(Res.get("shared.edit"));
button2.setOnAction(e -> onEditOpenOffer(offer));
button2.setManaged(true);
button2.setVisible(true);
} else {
boolean isSellOffer = OfferViewUtil.isShownAsSellOffer(offer);
boolean isPrivateOffer = offer.isPrivateOffer();
iconView.setId(isPrivateOffer ? "image-lock2x" : isSellOffer ? "image-buy-white" : "image-sell-white");
iconView.setFitHeight(16);
iconView.setFitWidth(16);
button.setId(isSellOffer ? "buy-button" : "sell-button");
button.setStyle("-fx-text-fill: white");
title = Res.get("offerbook.takeOffer");
button.setTooltip(new Tooltip(Res.get("offerbook.takeOfferButton.tooltip", model.getDirectionLabelTooltip(offer))));
button.setOnAction(e -> onTakeOffer(offer));
button2.setManaged(false);
button2.setVisible(false);
}
if (!myOffer) {
if (canTakeOfferResult == null) {
canTakeOfferResult = model.offerFilterService.canTakeOffer(offer, false);
}
if (!canTakeOfferResult.isValid()) {
button.setOnAction(e -> onShowInfo(offer, canTakeOfferResult));
}
}
button.updateText(title);
setPadding(new Insets(0, 15, 0, 0));
setGraphic(hbox);
} else {
setGraphic(null);
button.setOnAction(null);
button2.setOnAction(null);
if (tableRow != null) {
tableRow.setOpacity(1);
tableRow.setOnMousePressed(null); tableRow.setOnMousePressed(null);
} else if (canTakeOfferResult.isValid()) {
// set first row button as default
button.setDefaultButton(getIndex() == 0);
tableRow.setOnMousePressed(null);
} else {
button.setDefaultButton(false);
tableRow.setOnMousePressed(e -> {
// ugly hack to get the icon clickable when deactivated
if (!(e.getTarget() instanceof ImageView || e.getTarget() instanceof Canvas))
onShowInfo(offer, canTakeOfferResult);
});
} }
} }
});
String title;
if (myOffer) {
iconView.setId("image-remove");
title = Res.get("shared.remove");
button.setOnAction(e -> onRemoveOpenOffer(offer));
iconView2.setId("image-edit");
button2.updateText(Res.get("shared.edit"));
button2.setOnAction(e -> onEditOpenOffer(offer));
button2.setManaged(true);
button2.setVisible(true);
} else {
boolean isSellOffer = OfferViewUtil.isShownAsSellOffer(offer);
boolean isPrivateOffer = offer.isPrivateOffer();
iconView.setId(isPrivateOffer ? "image-lock2x" : isSellOffer ? "image-buy-white" : "image-sell-white");
iconView.setFitHeight(16);
iconView.setFitWidth(16);
button.setId(isSellOffer ? "buy-button" : "sell-button");
button.setStyle("-fx-text-fill: white");
title = Res.get("offerbook.takeOffer");
button.setTooltip(new Tooltip(Res.get("offerbook.takeOfferButton.tooltip", model.getDirectionLabelTooltip(offer))));
button.setOnAction(e -> onTakeOffer(offer));
button2.setManaged(false);
button2.setVisible(false);
}
if (!myOffer) {
if (canTakeOfferResult == null) {
canTakeOfferResult = model.offerFilterService.canTakeOffer(offer, false);
}
if (!canTakeOfferResult.isValid()) {
button.setOnAction(e -> onShowInfo(offer, canTakeOfferResult));
}
}
button.updateText(title);
setPadding(new Insets(0, 15, 0, 0));
setGraphic(hbox);
} else {
setGraphic(null);
button.setOnAction(null);
button2.setOnAction(null);
if (tableRow != null) {
tableRow.setOpacity(1);
tableRow.setOnMousePressed(null);
}
}
} }
}; };
} }
@ -1218,19 +1204,17 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
return new TableCell<>() { return new TableCell<>() {
@Override @Override
public void updateItem(final OfferBookListItem item, boolean empty) { public void updateItem(final OfferBookListItem item, boolean empty) {
UserThread.execute(() -> { super.updateItem(item, empty);
super.updateItem(item, empty);
if (item != null && !empty) { if (item != null && !empty) {
var witnessAgeData = item.getWitnessAgeData(accountAgeWitnessService, signedWitnessService); var witnessAgeData = item.getWitnessAgeData(accountAgeWitnessService, signedWitnessService);
var label = witnessAgeData.isSigningRequired() var label = witnessAgeData.isSigningRequired()
? new AccountStatusTooltipLabel(witnessAgeData) ? new AccountStatusTooltipLabel(witnessAgeData)
: new InfoAutoTooltipLabel(witnessAgeData.getDisplayString(), witnessAgeData.getIcon(), ContentDisplay.RIGHT, witnessAgeData.getInfo()); : new InfoAutoTooltipLabel(witnessAgeData.getDisplayString(), witnessAgeData.getIcon(), ContentDisplay.RIGHT, witnessAgeData.getInfo());
setGraphic(label); setGraphic(label);
} else { } else {
setGraphic(null); setGraphic(null);
} }
});
} }
}; };
} }
@ -1256,26 +1240,24 @@ abstract public class OfferBookView<R extends GridPane, M extends OfferBookViewM
return new TableCell<>() { return new TableCell<>() {
@Override @Override
public void updateItem(final OfferBookListItem newItem, boolean empty) { public void updateItem(final OfferBookListItem newItem, boolean empty) {
UserThread.execute(() -> { super.updateItem(newItem, empty);
super.updateItem(newItem, empty); if (newItem != null && !empty) {
if (newItem != null && !empty) { final Offer offer = newItem.getOffer();
final Offer offer = newItem.getOffer(); final NodeAddress makersNodeAddress = offer.getOwnerNodeAddress();
final NodeAddress makersNodeAddress = offer.getOwnerNodeAddress(); String role = Res.get("peerInfoIcon.tooltip.maker");
String role = Res.get("peerInfoIcon.tooltip.maker"); int numTrades = model.getNumTrades(offer);
int numTrades = model.getNumTrades(offer); PeerInfoIconTrading peerInfoIcon = new PeerInfoIconTrading(makersNodeAddress,
PeerInfoIconTrading peerInfoIcon = new PeerInfoIconTrading(makersNodeAddress, role,
role, numTrades,
numTrades, privateNotificationManager,
privateNotificationManager, offer,
offer, model.preferences,
model.preferences, model.accountAgeWitnessService,
model.accountAgeWitnessService, useDevPrivilegeKeys);
useDevPrivilegeKeys); setGraphic(peerInfoIcon);
setGraphic(peerInfoIcon); } else {
} else { setGraphic(null);
setGraphic(null); }
}
});
} }
}; };
} }

View file

@ -277,9 +277,6 @@ public class BroadcastHandler implements PeerManager.Listener {
@Override @Override
public void onFailure(@NotNull Throwable throwable) { public void onFailure(@NotNull Throwable throwable) {
log.warn("Broadcast to " + connection.getPeersNodeAddressOptional() + " failed. ", throwable);
numOfFailedBroadcasts.incrementAndGet();
if (stopped.get()) { if (stopped.get()) {
return; return;
} }
@ -356,7 +353,8 @@ public class BroadcastHandler implements PeerManager.Listener {
try { try {
future.cancel(true); future.cancel(true);
} catch (Exception e) { } catch (Exception e) {
if (!networkNode.isShutDownStarted()) throw e; if (networkNode.isShutDownStarted()) return; // ignore if shut down
throw e;
} }
}); });
sendMessageFutures.clear(); sendMessageFutures.clear();