Skip to content

Commit

Permalink
Merge pull request #35 from haveno-dex/master
Browse files Browse the repository at this point in the history
v1.0.14
  • Loading branch information
retoaccess1 authored Nov 15, 2024
2 parents 9d6bdc8 + 264cb5f commit c8a91de
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 124 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ configure(project(':desktop')) {
apply plugin: 'com.github.johnrengelman.shadow'
apply from: 'package/package.gradle'

version = '1.0.13-SNAPSHOT'
version = '1.0.14-SNAPSHOT'

jar.manifest.attributes(
"Implementation-Title": project.name,
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/haveno/common/app/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public class Version {
// The application versions
// We use semantic versioning with major, minor and patch
public static final String VERSION = "1.0.13";
public static final String VERSION = "1.0.14";

/**
* Holds a list of the tagged resource files for optimizing the getData requests.
Expand Down
5 changes: 3 additions & 2 deletions common/src/main/java/haveno/common/file/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
Expand Down Expand Up @@ -76,11 +77,11 @@ public static void rollingBackup(File dir, String fileName, int numMaxBackupFile

public static List<File> getBackupFiles(File dir, String fileName) {
File backupDir = new File(Paths.get(dir.getAbsolutePath(), BACKUP_DIR).toString());
if (!backupDir.exists()) return null;
if (!backupDir.exists()) return new ArrayList<File>();
String dirName = "backups_" + fileName;
if (dirName.contains(".")) dirName = dirName.replace(".", "_");
File backupFileDir = new File(Paths.get(backupDir.getAbsolutePath(), dirName).toString());
if (!backupFileDir.exists()) return null;
if (!backupFileDir.exists()) return new ArrayList<File>();
File[] files = backupFileDir.listFiles();
return Arrays.asList(files);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public boolean isNew() {
}

public boolean isOpen() {
return this.disputeState == State.OPEN || this.disputeState == State.REOPENED;
return isNew() || this.disputeState == State.OPEN || this.disputeState == State.REOPENED;
}

public boolean isClosed() {
Expand Down
208 changes: 104 additions & 104 deletions core/src/main/java/haveno/core/support/dispute/DisputeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ public void sendDisputeOpenedMessage(Dispute dispute,
return;
}

// skip if payout is confirmed
if (trade.isPayoutConfirmed()) {
String errorMsg = "Cannot open dispute because payout is already confirmed for " + trade.getClass().getSimpleName() + " " + trade.getId();
faultHandler.handleFault(errorMsg, new IllegalStateException(errorMsg));
return;
}

synchronized (disputeList.getObservableList()) {
if (disputeList.contains(dispute)) {
String msg = "We got a dispute msg that we have already stored. TradeId = " + dispute.getTradeId() + ", DisputeId = " + dispute.getId();
Expand All @@ -368,116 +375,109 @@ public void sendDisputeOpenedMessage(Dispute dispute,
}

Optional<Dispute> storedDisputeOptional = findDispute(dispute);
boolean reOpen = storedDisputeOptional.isPresent() && storedDisputeOptional.get().isClosed();
if (!storedDisputeOptional.isPresent() || reOpen) {

// add or re-open dispute
if (reOpen) {
dispute = storedDisputeOptional.get();
} else {
disputeList.add(dispute);
}
boolean reOpen = storedDisputeOptional.isPresent();

String disputeInfo = getDisputeInfo(dispute);
String sysMsg = dispute.isSupportTicket() ?
Res.get("support.youOpenedTicket", disputeInfo, Version.VERSION) :
Res.get("support.youOpenedDispute", disputeInfo, Version.VERSION);
// add or re-open dispute
if (reOpen) {
dispute = storedDisputeOptional.get();
} else {
disputeList.add(dispute);
}

ChatMessage chatMessage = new ChatMessage(
getSupportType(),
dispute.getTradeId(),
keyRing.getPubKeyRing().hashCode(),
false,
Res.get("support.systemMsg", sysMsg),
p2PService.getAddress());
chatMessage.setSystemMessage(true);
dispute.addAndPersistChatMessage(chatMessage);
String disputeInfo = getDisputeInfo(dispute);
String sysMsg = dispute.isSupportTicket() ?
Res.get("support.youOpenedTicket", disputeInfo, Version.VERSION) :
Res.get("support.youOpenedDispute", disputeInfo, Version.VERSION);

// export latest multisig hex
try {
trade.exportMultisigHex();
} catch (Exception e) {
log.error("Failed to export multisig hex", e);
}
ChatMessage chatMessage = new ChatMessage(
getSupportType(),
dispute.getTradeId(),
keyRing.getPubKeyRing().hashCode(),
false,
Res.get("support.systemMsg", sysMsg),
p2PService.getAddress());
chatMessage.setSystemMessage(true);
dispute.addAndPersistChatMessage(chatMessage);

// create dispute opened message
NodeAddress agentNodeAddress = getAgentNodeAddress(dispute);
DisputeOpenedMessage disputeOpenedMessage = new DisputeOpenedMessage(dispute,
p2PService.getAddress(),
UUID.randomUUID().toString(),
getSupportType(),
trade.getSelf().getUpdatedMultisigHex(),
trade.getArbitrator().getPaymentSentMessage());
log.info("Send {} to peer {}. tradeId={}, openNewDisputeMessage.uid={}, " +
"chatMessage.uid={}",
disputeOpenedMessage.getClass().getSimpleName(), agentNodeAddress,
disputeOpenedMessage.getTradeId(), disputeOpenedMessage.getUid(),
chatMessage.getUid());
recordPendingMessage(disputeOpenedMessage.getClass().getSimpleName());

// send dispute opened message
trade.setDisputeState(Trade.DisputeState.DISPUTE_REQUESTED);
mailboxMessageService.sendEncryptedMailboxMessage(agentNodeAddress,
dispute.getAgentPubKeyRing(),
disputeOpenedMessage,
new SendMailboxMessageListener() {
@Override
public void onArrived() {
log.info("{} arrived at peer {}. tradeId={}, openNewDisputeMessage.uid={}, " +
"chatMessage.uid={}",
disputeOpenedMessage.getClass().getSimpleName(), agentNodeAddress,
disputeOpenedMessage.getTradeId(), disputeOpenedMessage.getUid(),
chatMessage.getUid());
clearPendingMessage();

// We use the chatMessage wrapped inside the openNewDisputeMessage for
// the state, as that is displayed to the user and we only persist that msg
chatMessage.setArrived(true);
trade.advanceDisputeState(Trade.DisputeState.DISPUTE_REQUESTED);
requestPersistence();
resultHandler.handleResult();
}
// export latest multisig hex
try {
trade.exportMultisigHex();
} catch (Exception e) {
log.error("Failed to export multisig hex", e);
}

@Override
public void onStoredInMailbox() {
log.info("{} stored in mailbox for peer {}. tradeId={}, openNewDisputeMessage.uid={}, " +
"chatMessage.uid={}",
disputeOpenedMessage.getClass().getSimpleName(), agentNodeAddress,
disputeOpenedMessage.getTradeId(), disputeOpenedMessage.getUid(),
chatMessage.getUid());
clearPendingMessage();

// We use the chatMessage wrapped inside the openNewDisputeMessage for
// the state, as that is displayed to the user and we only persist that msg
chatMessage.setStoredInMailbox(true);
requestPersistence();
resultHandler.handleResult();
}
// create dispute opened message
NodeAddress agentNodeAddress = getAgentNodeAddress(dispute);
DisputeOpenedMessage disputeOpenedMessage = new DisputeOpenedMessage(dispute,
p2PService.getAddress(),
UUID.randomUUID().toString(),
getSupportType(),
trade.getSelf().getUpdatedMultisigHex(),
trade.getArbitrator().getPaymentSentMessage());
log.info("Send {} to peer {}. tradeId={}, openNewDisputeMessage.uid={}, " +
"chatMessage.uid={}",
disputeOpenedMessage.getClass().getSimpleName(), agentNodeAddress,
disputeOpenedMessage.getTradeId(), disputeOpenedMessage.getUid(),
chatMessage.getUid());
recordPendingMessage(disputeOpenedMessage.getClass().getSimpleName());

// send dispute opened message
trade.setDisputeState(Trade.DisputeState.DISPUTE_REQUESTED);
mailboxMessageService.sendEncryptedMailboxMessage(agentNodeAddress,
dispute.getAgentPubKeyRing(),
disputeOpenedMessage,
new SendMailboxMessageListener() {
@Override
public void onArrived() {
log.info("{} arrived at peer {}. tradeId={}, openNewDisputeMessage.uid={}, " +
"chatMessage.uid={}",
disputeOpenedMessage.getClass().getSimpleName(), agentNodeAddress,
disputeOpenedMessage.getTradeId(), disputeOpenedMessage.getUid(),
chatMessage.getUid());
clearPendingMessage();

@Override
public void onFault(String errorMessage) {
log.error("{} failed: Peer {}. tradeId={}, openNewDisputeMessage.uid={}, " +
"chatMessage.uid={}, errorMessage={}",
disputeOpenedMessage.getClass().getSimpleName(), agentNodeAddress,
disputeOpenedMessage.getTradeId(), disputeOpenedMessage.getUid(),
chatMessage.getUid(), errorMessage);

clearPendingMessage();
// We use the chatMessage wrapped inside the openNewDisputeMessage for
// the state, as that is displayed to the user and we only persist that msg
chatMessage.setSendMessageError(errorMessage);
trade.setDisputeState(Trade.DisputeState.NO_DISPUTE);
requestPersistence();
faultHandler.handleFault("Sending dispute message failed: " +
errorMessage, new DisputeMessageDeliveryFailedException());
}
});
} else {
String msg = "We got a dispute already open for that trade and trading peer.\n" +
"TradeId = " + dispute.getTradeId();
log.warn(msg);
faultHandler.handleFault(msg, new DisputeAlreadyOpenException());
}
// We use the chatMessage wrapped inside the openNewDisputeMessage for
// the state, as that is displayed to the user and we only persist that msg
chatMessage.setArrived(true);
trade.advanceDisputeState(Trade.DisputeState.DISPUTE_REQUESTED);
requestPersistence();
resultHandler.handleResult();
}

@Override
public void onStoredInMailbox() {
log.info("{} stored in mailbox for peer {}. tradeId={}, openNewDisputeMessage.uid={}, " +
"chatMessage.uid={}",
disputeOpenedMessage.getClass().getSimpleName(), agentNodeAddress,
disputeOpenedMessage.getTradeId(), disputeOpenedMessage.getUid(),
chatMessage.getUid());
clearPendingMessage();

// We use the chatMessage wrapped inside the openNewDisputeMessage for
// the state, as that is displayed to the user and we only persist that msg
chatMessage.setStoredInMailbox(true);
requestPersistence();
resultHandler.handleResult();
}

@Override
public void onFault(String errorMessage) {
log.error("{} failed: Peer {}. tradeId={}, openNewDisputeMessage.uid={}, " +
"chatMessage.uid={}, errorMessage={}",
disputeOpenedMessage.getClass().getSimpleName(), agentNodeAddress,
disputeOpenedMessage.getTradeId(), disputeOpenedMessage.getUid(),
chatMessage.getUid(), errorMessage);

clearPendingMessage();
// We use the chatMessage wrapped inside the openNewDisputeMessage for
// the state, as that is displayed to the user and we only persist that msg
chatMessage.setSendMessageError(errorMessage);
trade.setDisputeState(Trade.DisputeState.NO_DISPUTE);
requestPersistence();
faultHandler.handleFault("Sending dispute message failed: " +
errorMessage, new DisputeMessageDeliveryFailedException());
}
});
}

requestPersistence();
Expand Down
4 changes: 2 additions & 2 deletions desktop/package/macosx/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<!-- See: https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -->

<key>CFBundleVersion</key>
<string>1.0.13</string>
<string>1.0.14</string>

<key>CFBundleShortVersionString</key>
<string>1.0.13</string>
<string>1.0.14</string>

<key>CFBundleExecutable</key>
<string>Haveno</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void initWithData(OfferDirection direction, TradeCurrency tradeCurrency,
if (CurrencyUtil.isTraditionalCurrency(tradeCurrency.getCode())) {
placeOfferButtonLabel = Res.get("createOffer.placeOfferButton", Res.get("shared.buy"));
} else {
placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonCrypto", Res.get("shared.buy"), tradeCurrency.getCode());
placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonCrypto", Res.get("shared.sell"), tradeCurrency.getCode());
}
nextButton.setId("buy-button");
fundFromSavingsWalletButton.setId("buy-button");
Expand All @@ -317,7 +317,7 @@ public void initWithData(OfferDirection direction, TradeCurrency tradeCurrency,
if (CurrencyUtil.isTraditionalCurrency(tradeCurrency.getCode())) {
placeOfferButtonLabel = Res.get("createOffer.placeOfferButton", Res.get("shared.sell"));
} else {
placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonCrypto", Res.get("shared.sell"), tradeCurrency.getCode());
placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonCrypto", Res.get("shared.buy"), tradeCurrency.getCode());
}
nextButton.setId("sell-button");
fundFromSavingsWalletButton.setId("sell-button");
Expand Down Expand Up @@ -707,10 +707,10 @@ private void createListeners() {
triggerPriceInputTextField.clear();
if (!CurrencyUtil.isTraditionalCurrency(newValue)) {
if (model.isShownAsBuyOffer()) {
placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonCrypto", Res.get("shared.buy"),
placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonCrypto", Res.get("shared.sell"),
model.getTradeCurrency().getCode()));
} else {
placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonCrypto", Res.get("shared.sell"),
placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonCrypto", Res.get("shared.buy"),
model.getTradeCurrency().getCode()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,7 @@ String getPriceAsPercentage(OfferBookListItem item) {
}

public Optional<Double> getMarketBasedPrice(Offer offer) {
OfferDirection displayDirection = offer.isTraditionalOffer() ? direction :
direction.equals(OfferDirection.BUY) ? OfferDirection.SELL : OfferDirection.BUY;
return priceUtil.getMarketBasedPrice(offer, displayDirection);
return priceUtil.getMarketBasedPrice(offer, direction);
}

String formatMarketPriceMarginPct(Offer offer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,12 @@ public void initWithData(Offer offer) {
takeOfferButton.setId("buy-button-big");
nextButton.setId("buy-button");
fundFromSavingsWalletButton.setId("buy-button");
takeOfferButton.updateText(getTakeOfferLabel(offer, Res.get("shared.buy")));
takeOfferButton.updateText(getTakeOfferLabel(offer, false));
} else {
takeOfferButton.setId("sell-button-big");
nextButton.setId("sell-button");
fundFromSavingsWalletButton.setId("sell-button");
takeOfferButton.updateText(getTakeOfferLabel(offer, Res.get("shared.sell")));
takeOfferButton.updateText(getTakeOfferLabel(offer, true));
}
priceAsPercentageDescription.setText(model.getPercentagePriceDescription());

Expand Down Expand Up @@ -1232,11 +1232,11 @@ private GridPane createInfoPopover() {
}

@NotNull
private String getTakeOfferLabel(Offer offer, String direction) {
private String getTakeOfferLabel(Offer offer, boolean isBuyOffer) {
return offer.isTraditionalOffer() ?
Res.get("takeOffer.takeOfferButton", direction) :
Res.get("takeOffer.takeOfferButton", isBuyOffer ? Res.get("shared.sell") : Res.get("shared.buy")) :
Res.get("takeOffer.takeOfferButtonCrypto",
direction,
isBuyOffer ? Res.get("shared.buy") : Res.get("shared.sell"),
offer.getCurrencyCode());
}

Expand Down
Loading

0 comments on commit c8a91de

Please sign in to comment.