Apply minor improvements and clean-ups

This commit is contained in:
Christoph Atteneder 2022-01-11 12:36:44 +01:00
parent 3ea1543882
commit a1d0e570d1
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
14 changed files with 130 additions and 56 deletions

View File

@ -130,7 +130,7 @@ public class FileUtil {
try {
deleteFileIfExists(file, ignoreLockedFiles);
} catch (Throwable t) {
log.error("Could not delete file. Error=" + t.toString());
log.error("Could not delete file. Error=" + t);
throw new IOException(t);
}
}

View File

@ -145,7 +145,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
@Override
public NodeAddress getPeerNodeAddress(ChatMessage message) {
Optional<Dispute> disputeOptional = findDispute(message);
if (!disputeOptional.isPresent()) {
if (disputeOptional.isEmpty()) {
log.warn("Could not find dispute for tradeId = {} traderId = {}",
message.getTradeId(), message.getTraderId());
return null;
@ -156,7 +156,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
@Override
public PubKeyRing getPeerPubKeyRing(ChatMessage message) {
Optional<Dispute> disputeOptional = findDispute(message);
if (!disputeOptional.isPresent()) {
if (disputeOptional.isEmpty()) {
log.warn("Could not find dispute for tradeId = {} traderId = {}",
message.getTradeId(), message.getTraderId());
return null;
@ -325,7 +325,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
if (isAgent(dispute)) {
if (!disputeList.contains(dispute)) {
Optional<Dispute> storedDisputeOptional = findDispute(dispute);
if (!storedDisputeOptional.isPresent()) {
if (storedDisputeOptional.isEmpty()) {
disputeList.add(dispute);
sendPeerOpenedDisputeMessage(dispute, contract, peersPubKeyRing);
} else {
@ -378,7 +378,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
Dispute dispute = peerOpenedDisputeMessage.getDispute();
Optional<Trade> optionalTrade = tradeManager.getTradeById(dispute.getTradeId());
if (!optionalTrade.isPresent()) {
if (optionalTrade.isEmpty()) {
return;
}
@ -399,11 +399,10 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
if (!isAgent(dispute)) {
if (!disputeList.contains(dispute)) {
Optional<Dispute> storedDisputeOptional = findDispute(dispute);
if (!storedDisputeOptional.isPresent()) {
if (storedDisputeOptional.isEmpty()) {
disputeList.add(dispute);
trade.setDisputeState(getDisputeStateStartedByPeer());
tradeManager.requestPersistence();
errorMessage = null;
} else {
// valid case if both have opened a dispute and agent was not online.
log.debug("We got a dispute already open for that trade and trading peer. TradeId = {}",
@ -452,7 +451,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
}
Optional<Dispute> storedDisputeOptional = findDispute(dispute);
if (!storedDisputeOptional.isPresent() || reOpen) {
if (storedDisputeOptional.isEmpty() || reOpen) {
String disputeInfo = getDisputeInfo(dispute);
String disputeMessage = getDisputeIntroForDisputeCreator(disputeInfo);
String sysMsg = dispute.isSupportTicket() ?
@ -836,7 +835,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
public Optional<Trade> findTrade(Dispute dispute) {
Optional<Trade> retVal = tradeManager.getTradeById(dispute.getTradeId());
if (!retVal.isPresent()) {
if (retVal.isEmpty()) {
retVal = closedTradableManager.getClosedTrades().stream().filter(e -> e.getId().equals(dispute.getTradeId())).findFirst();
}
return retVal;
@ -972,7 +971,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
long roundedToLong = MathUtils.roundDoubleToLong(scaled);
return Price.valueOf(currencyCode, roundedToLong);
} catch (Exception e) {
log.error("Exception at getPrice / parseToFiat: " + e.toString());
log.error("Exception at getPrice / parseToFiat: " + e);
return null;
}
} else {

View File

@ -1,3 +1,20 @@
/*
* This file is part of Bisq.
*
* Bisq 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.
*
* Bisq 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 Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.core.support.dispute.mediation;
import bisq.network.p2p.AckMessage;
@ -27,7 +44,7 @@ public class FileTransferReceiver extends FileTransferSession {
protected final String zipFilePath;
public FileTransferReceiver(NetworkNode networkNode, NodeAddress peerNodeAddress,
String tradeId, int traderId, String traderRole, @Nullable FileTransferSession.FtpCallback callback) throws IOException {
String tradeId, int traderId, String traderRole, @Nullable FileTransferSession.FtpCallback callback) throws IOException {
super(networkNode, peerNodeAddress, tradeId, traderId, traderRole, callback);
zipFilePath = ensureReceivingDirectoryExists().getAbsolutePath() + FileSystems.getDefault().getSeparator() + zipId + ".zip";
}
@ -55,9 +72,7 @@ public class FileTransferReceiver extends FileTransferSession {
initSessionTimer();
log.info("Received a start file transfer request, tradeId={}, traderId={}, size={}", fullTradeId, traderId, expectedFileBytes);
log.info("New file will be written to {}", zipFilePath);
UserThread.execute(() -> {
ackReceivedPart(uid, networkNode, peerNodeAddress);
});
UserThread.execute(() -> ackReceivedPart(uid, networkNode, peerNodeAddress));
}
private void processReceivedBlock(FileTransferPart ftp, NetworkNode networkNode, NodeAddress peerNodeAddress) {

View File

@ -1,3 +1,20 @@
/*
* This file is part of Bisq.
*
* Bisq 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.
*
* Bisq 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 Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.core.support.dispute.mediation;
import bisq.network.p2p.FileTransferPart;
@ -39,7 +56,7 @@ public class FileTransferSender extends FileTransferSession {
protected final String zipFilePath;
public FileTransferSender(NetworkNode networkNode, NodeAddress peerNodeAddress,
String tradeId, int traderId, String traderRole, @Nullable FileTransferSession.FtpCallback callback) {
String tradeId, int traderId, String traderRole, @Nullable FileTransferSession.FtpCallback callback) {
super(networkNode, peerNodeAddress, tradeId, traderId, traderRole, callback);
zipFilePath = Config.appDataDir() + FileSystems.getDefault().getSeparator() + zipId + ".zip";
updateProgress();
@ -54,10 +71,10 @@ public class FileTransferSender extends FileTransferSession {
Stream<Path> paths = Files.walk(Paths.get(Config.appDataDir().toString()), 1);
paths.filter(Files::isRegularFile).forEach(externalTxtFile -> {
try {
// always include bisq.log; and other .log files if they contain the TradeId
if (externalTxtFile.getFileName().toString().equals("bisq.log") ||
(externalTxtFile.getFileName().toString().matches(".*.log") &&
doesFileContainKeyword(externalTxtFile.toFile(), fullTradeId))) {
// always include bisq.log; and other .log files if they contain the TradeId
if (externalTxtFile.getFileName().toString().equals("bisq.log") ||
(externalTxtFile.getFileName().toString().matches(".*.log") &&
doesFileContainKeyword(externalTxtFile.toFile(), fullTradeId))) {
Path pathInZipfile = zipfs.getPath(zipId + "/" + externalTxtFile.getFileName().toString());
log.info("adding {} to zip file {}", pathInZipfile, zipfs);
Files.copy(externalTxtFile, pathInZipfile, StandardCopyOption.REPLACE_EXISTING);
@ -117,7 +134,7 @@ public class FileTransferSender extends FileTransferSession {
}
protected void uploadData() {
if (!dataAwaitingAck.isPresent()) {
if (dataAwaitingAck.isEmpty()) {
return;
}
FileTransferPart ftp = dataAwaitingAck.get();
@ -127,7 +144,7 @@ public class FileTransferSender extends FileTransferSession {
}
public boolean processAckForFilePart(String ackUid) {
if (!dataAwaitingAck.isPresent()) {
if (dataAwaitingAck.isEmpty()) {
log.warn("We received an ACK we were not expecting. {}", ackUid);
return false;
}

View File

@ -1,3 +1,20 @@
/*
* This file is part of Bisq.
*
* Bisq 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.
*
* Bisq 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 Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.core.support.dispute.mediation;
import bisq.network.p2p.AckMessage;
@ -23,8 +40,8 @@ import java.util.Date;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
@ -39,7 +56,9 @@ public abstract class FileTransferSession implements MessageListener {
public interface FtpCallback {
void onFtpProgress(double progressPct);
void onFtpComplete(FileTransferSession session);
void onFtpTimeout(String statusMsg, FileTransferSession session);
}

View File

@ -141,19 +141,17 @@ public final class MediationManager extends DisputeManager<MediationDisputeList>
@Override
public void cleanupDisputes() {
disputeListService.cleanupDisputes(tradeId -> {
tradeManager.getTradeById(tradeId).filter(trade -> trade.getPayoutTx() != null)
.ifPresent(trade -> {
tradeManager.closeDisputedTrade(tradeId, Trade.DisputeState.MEDIATION_CLOSED);
});
});
disputeListService.cleanupDisputes(tradeId -> tradeManager.getTradeById(tradeId).filter(trade -> trade.getPayoutTx() != null)
.ifPresent(trade -> tradeManager.closeDisputedTrade(tradeId, Trade.DisputeState.MEDIATION_CLOSED)));
}
@Override
protected String getDisputeInfo(Dispute dispute) {
String role = Res.get("shared.mediator").toLowerCase();
NodeAddress agentNodeAddress = getAgentNodeAddress(dispute);
checkNotNull(agentNodeAddress, "Agent node address must not be null");
String roleContextMsg = Res.get("support.initialMediatorMsg",
DisputeAgentLookupMap.getKeybaseLinkForAgent(getAgentNodeAddress(dispute).getFullAddress()));
DisputeAgentLookupMap.getKeybaseLinkForAgent(agentNodeAddress.getFullAddress()));
String link = "https://bisq.wiki/Dispute_resolution#Level_2:_Mediation";
return Res.get("support.initialInfo", role, roleContextMsg, role, link);
}
@ -181,7 +179,7 @@ public final class MediationManager extends DisputeManager<MediationDisputeList>
checkNotNull(chatMessage, "chatMessage must not be null");
Optional<Dispute> disputeOptional = findDispute(disputeResult);
String uid = disputeResultMessage.getUid();
if (!disputeOptional.isPresent()) {
if (disputeOptional.isEmpty()) {
log.warn("We got a dispute result msg but we don't have a matching dispute. " +
"That might happen when we get the disputeResultMessage before the dispute was created. " +
"We try again after 2 sec. to apply the disputeResultMessage. TradeId = " + tradeId);
@ -293,7 +291,7 @@ public final class MediationManager extends DisputeManager<MediationDisputeList>
}
// we create a new session which is related to an open dispute from our list
Optional<Dispute> dispute = findDispute(ftp.getTradeId(), ftp.getTraderId());
if (!dispute.isPresent()) {
if (dispute.isEmpty()) {
log.error("Received log upload request for unknown TradeId/TraderId {}/{}", ftp.getTradeId(), ftp.getTraderId());
return;
}

View File

@ -1233,26 +1233,26 @@ support.state=State
support.chat=Chat
support.closed=Closed
support.open=Open
support.sendLogFiles=Send Log Files
support.process=Process
support.buyerOfferer=BTC buyer/Maker
support.sellerOfferer=BTC seller/Maker
support.buyerTaker=BTC buyer/Taker
support.sellerTaker=BTC seller/Taker
support.sendLogs.title=Send Logs
support.sendLogs.backgroundInfo=When traders experience a bug, mediators and support staff will often request copies of the users logs to diagnose the issue.\n\n\
Upon pressing [Send], your log file will be compressed and transmitted direct to the mediator.
support.sendLogs.step1=Create Zip Archive of Logs
support.sendLogs.title=Send Log Files
support.sendLogs.backgroundInfo=When you experience a bug, mediators and support staff will often request copies of the your log files to diagnose the issue.\n\n\ \
Upon pressing 'Send', your log files will be compressed and transmitted directly to the mediator.
support.sendLogs.step1=Create Zip Archive of Log Files
support.sendLogs.step2=Connection Request to Mediator
support.sendLogs.step3=Upload Archived Log Data
support.sendLogs.waiting=Waiting for your input
support.sendLogs.send=Send
support.sendLogs.stop=Stop
support.sendLogs.cancel=Cancel
support.sendLogs.init=Initializing
support.sendLogs.retry=Retrying send
support.sendLogs.stopped=Transfer stopped
support.sendLogs.progress=Transfer progress: %.0f%%
support.sendLogs.finished=Transfer complete!
support.sendLogs.command=Press [Send] to retry, or [Stop] to abort
support.sendLogs.command=Press 'Send' to retry, or 'Stop' to abort
support.backgroundInfo=Bisq is not a company, so it handles disputes differently.\n\n\
Traders can communicate within the application via secure chat on the open trades screen to try solving disputes on their own. \

View File

@ -1,3 +1,20 @@
/*
* This file is part of Bisq.
*
* Bisq 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.
*
* Bisq 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 Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.core.support.dispute.mediation;
import bisq.network.p2p.FileTransferPart;
@ -14,7 +31,8 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class FileTransferSessionTest implements FileTransferSession.FtpCallback {

View File

@ -2032,7 +2032,7 @@ textfield */
}
.dispute-chat-border {
-fx-background-color: -bs-color-blue-5;
-fx-background-color: -bs-support-chat-background;
}
/********************************************************************************************************************

View File

@ -23,6 +23,7 @@ import bisq.desktop.main.portfolio.pendingtrades.steps.TradeWizardItem;
import bisq.desktop.main.portfolio.pendingtrades.steps.buyer.BuyerStep1View;
import bisq.desktop.main.portfolio.pendingtrades.steps.buyer.BuyerStep2View;
import bisq.desktop.main.portfolio.pendingtrades.steps.buyer.BuyerStep3View;
import bisq.desktop.util.Layout;
import bisq.core.locale.Res;
import bisq.core.support.dispute.mediation.FileTransferSender;
@ -31,20 +32,22 @@ import bisq.core.support.dispute.mediation.MediationManager;
import bisq.common.UserThread;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import com.jfoenix.controls.JFXProgressBar;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import java.io.IOException;
@ -58,7 +61,6 @@ public class SendLogFilesWindow extends Overlay<SendLogFilesWindow> implements F
private final String tradeId;
private final int traderId;
private final MediationManager mediationManager;
private ProgressBar progressBar;
private Label statusLabel;
private Button sendButton, stopButton;
private final DoubleProperty ftpProgress = new SimpleDoubleProperty(-1);
@ -136,21 +138,25 @@ public class SendLogFilesWindow extends Overlay<SendLogFilesWindow> implements F
addWizardsToGridPane(step3);
addRegionToGridPane();
progressBar = new ProgressBar();
JFXProgressBar progressBar = new JFXProgressBar();
progressBar.setMinHeight(19);
progressBar.setMaxHeight(19);
progressBar.setPrefWidth(9305);
progressBar.setVisible(false);
progressBar.progressProperty().bind(ftpProgress);
gridPane.add(progressBar, 0, ++rowIndex);
statusLabel = addMultilineLabel(gridPane, ++rowIndex, Res.get("support.sendLogs.waiting"));
statusLabel = addMultilineLabel(gridPane, ++rowIndex, "", -Layout.FLOATING_LABEL_DISTANCE);
statusLabel.getStyleClass().add("sub-info");
addRegionToGridPane();
sendButton = new AutoTooltipButton(Res.get("support.sendLogs.send"));
stopButton = new AutoTooltipButton(Res.get("support.sendLogs.stop"));
stopButton = new AutoTooltipButton(Res.get("support.sendLogs.cancel"));
stopButton.setDisable(true);
closeButton = new AutoTooltipButton(Res.get("shared.close"));
sendButton.setOnAction(e -> {
try {
progressBar.setVisible(true);
if (fileTransferSender == null) {
setActiveStep(1);
statusLabel.setText(Res.get("support.sendLogs.init"));

View File

@ -58,11 +58,9 @@ public class DisputeChatPopup {
protected final DisputeManager<? extends DisputeList<Dispute>> disputeManager;
protected final CoinFormatter formatter;
protected final Preferences preferences;
private ChatCallback chatCallback;
private final ChatCallback chatCallback;
private double chatPopupStageXPosition = -1;
private double chatPopupStageYPosition = -1;
private ChangeListener<Number> xPositionListener;
private ChangeListener<Number> yPositionListener;
@Getter private Dispute selectedDispute;
DisputeChatPopup(DisputeManager<? extends DisputeList<Dispute>> disputeManager,
@ -111,7 +109,7 @@ public class DisputeChatPopup {
closeDisputeButton.setOnAction(e -> chatCallback.onCloseDisputeFromChatWindow(selectedDispute));
chatView.display(concreteDisputeSession, closeDisputeButton, pane.widthProperty());
} else {
Button sendLogsButton = new AutoTooltipButton("Send Logs");
Button sendLogsButton = new AutoTooltipButton(Res.get("support.sendLogFiles"));
sendLogsButton.setOnAction(e -> chatCallback.onSendLogsFromChatWindow(selectedDispute));
chatView.display(concreteDisputeSession, sendLogsButton, pane.widthProperty());
}
@ -146,9 +144,9 @@ public class DisputeChatPopup {
chatPopupStage.setOpacity(0);
chatPopupStage.show();
xPositionListener = (observable, oldValue, newValue) -> chatPopupStageXPosition = (double) newValue;
ChangeListener<Number> xPositionListener = (observable, oldValue, newValue) -> chatPopupStageXPosition = (double) newValue;
chatPopupStage.xProperty().addListener(xPositionListener);
yPositionListener = (observable, oldValue, newValue) -> chatPopupStageYPosition = (double) newValue;
ChangeListener<Number> yPositionListener = (observable, oldValue, newValue) -> chatPopupStageYPosition = (double) newValue;
chatPopupStage.yProperty().addListener(yPositionListener);
if (chatPopupStageXPosition == -1) {

View File

@ -148,6 +148,8 @@
/* Monero orange color code */
-xmr-orange: #f26822;
-bs-support-chat-background: #cccccc;
}
/* table view */

View File

@ -115,6 +115,8 @@
/* Monero orange color code */
-xmr-orange: #f26822;
-bs-support-chat-background: #4b4b4b;
}
.warning-box {

View File

@ -27,8 +27,8 @@ import lombok.Value;
@EqualsAndHashCode(callSuper = true)
@Value
public final class FileTransferPart extends NetworkEnvelope implements ExtendedDataSizePermission, SendersNodeAddressMessage {
private final NodeAddress senderNodeAddress;
public class FileTransferPart extends NetworkEnvelope implements ExtendedDataSizePermission, SendersNodeAddressMessage {
NodeAddress senderNodeAddress;
public String uid;
public String tradeId;
public int traderId;