Skip to content

Commit

Permalink
Merge pull request #6053 from jmacxx/display_signed_account_age
Browse files Browse the repository at this point in the history
Show signed status when applicable in Trade & Dispute info screens
  • Loading branch information
ripcurlx authored Feb 17, 2022
2 parents 2f66f96 + 1227781 commit 12a797d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public AccountAgeWitness getNewWitness(PaymentAccountPayload paymentAccountPaylo
return new AccountAgeWitness(hash, new Date().getTime());
}

Optional<AccountAgeWitness> findWitness(PaymentAccountPayload paymentAccountPayload,
public Optional<AccountAgeWitness> findWitness(PaymentAccountPayload paymentAccountPayload,
PubKeyRing pubKeyRing) {
if (paymentAccountPayload == null) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

import lombok.extern.slf4j.Slf4j;

import static bisq.desktop.util.DisplayUtils.getAccountWitnessDescription;
import static bisq.desktop.util.FormBuilder.*;

@Slf4j
Expand Down Expand Up @@ -186,9 +187,8 @@ private void addContent() {
addConfirmationLabelTextField(gridPane,
++rowIndex,
Res.get("contractWindow.accountAge"),
getAccountAge(contract.getBuyerPaymentAccountPayload(),
contract.getBuyerPubKeyRing(),
offer.getCurrencyCode()) + " / " + getAccountAge(contract.getSellerPaymentAccountPayload(), contract.getSellerPubKeyRing(), offer.getCurrencyCode()));
getAccountWitnessDescription(accountAgeWitnessService, offer.getPaymentMethod(), contract.getBuyerPaymentAccountPayload(), contract.getBuyerPubKeyRing()) + " / " +
getAccountWitnessDescription(accountAgeWitnessService, offer.getPaymentMethod(), contract.getSellerPaymentAccountPayload(), contract.getSellerPubKeyRing()));

DisputeManager<? extends DisputeList<Dispute>> disputeManager = getDisputeManager(dispute);
String nrOfDisputesAsBuyer = disputeManager != null ? disputeManager.getNrOfDisputes(true, contract) : "";
Expand Down Expand Up @@ -349,14 +349,4 @@ private DisputeManager<? extends DisputeList<Dispute>> getDisputeManager(Dispute
}
return null;
}

private String getAccountAge(PaymentAccountPayload paymentAccountPayload,
PubKeyRing pubKeyRing,
String currencyCode) {
long age = accountAgeWitnessService.getAccountAge(paymentAccountPayload, pubKeyRing);
return CurrencyUtil.isFiatCurrency(currencyCode) ?
age > -1 ? Res.get("peerInfoIcon.tooltip.age", DisplayUtils.formatAccountAge(age)) :
Res.get("peerInfoIcon.tooltip.unknownAge") :
"";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static bisq.desktop.util.DisplayUtils.getAccountWitnessDescription;
import static bisq.desktop.util.FormBuilder.*;
import static com.google.common.base.Preconditions.checkNotNull;

Expand Down Expand Up @@ -252,27 +253,18 @@ private void addContent() {
}

if (contract != null) {
buyersAccountAge = getAccountWitnessDescription(accountAgeWitnessService, offer.getPaymentMethod(), buyerPaymentAccountPayload, contract.getBuyerPubKeyRing());
sellersAccountAge = getAccountWitnessDescription(accountAgeWitnessService, offer.getPaymentMethod(), sellerPaymentAccountPayload, contract.getSellerPubKeyRing());
if (buyerPaymentAccountPayload != null) {
String paymentDetails = buyerPaymentAccountPayload.getPaymentDetails();
long age = accountAgeWitnessService.getAccountAge(buyerPaymentAccountPayload, contract.getBuyerPubKeyRing());
buyersAccountAge = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ?
age > -1 ? Res.get("peerInfoIcon.tooltip.age", DisplayUtils.formatAccountAge(age)) :
Res.get("peerInfoIcon.tooltip.unknownAge") :
"";

String postFix = buyersAccountAge.isEmpty() ? "" : " / " + buyersAccountAge;
String postFix = " / " + buyersAccountAge;
addConfirmationLabelTextField(gridPane, ++rowIndex,
Res.get("shared.paymentDetails", Res.get("shared.buyer")),
paymentDetails + postFix).second.setTooltip(new Tooltip(paymentDetails + postFix));
}
if (sellerPaymentAccountPayload != null) {
String paymentDetails = sellerPaymentAccountPayload.getPaymentDetails();
long age = accountAgeWitnessService.getAccountAge(sellerPaymentAccountPayload, contract.getSellerPubKeyRing());
sellersAccountAge = CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) ?
age > -1 ? Res.get("peerInfoIcon.tooltip.age", DisplayUtils.formatAccountAge(age)) :
Res.get("peerInfoIcon.tooltip.unknownAge") :
"";
String postFix = sellersAccountAge.isEmpty() ? "" : " / " + sellersAccountAge;
String postFix = " / " + sellersAccountAge;
addConfirmationLabelTextField(gridPane, ++rowIndex,
Res.get("shared.paymentDetails", Res.get("shared.seller")),
paymentDetails + postFix).second.setTooltip(new Tooltip(paymentDetails + postFix));
Expand Down
30 changes: 30 additions & 0 deletions desktop/src/main/java/bisq/desktop/util/DisplayUtils.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
package bisq.desktop.util;

import bisq.core.account.witness.AccountAgeWitness;
import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.GlobalSettings;
import bisq.core.locale.Res;
import bisq.core.monetary.Price;
import bisq.core.monetary.Volume;
import bisq.core.offer.Offer;
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.util.FormattingUtils;
import bisq.core.offer.OfferDirection;
import bisq.core.payment.PaymentAccount;
import bisq.core.util.ParsingUtils;
import bisq.core.util.VolumeUtil;
import bisq.core.util.coin.CoinFormatter;

import bisq.common.crypto.PubKeyRing;

import org.bitcoinj.core.Coin;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -74,6 +80,30 @@ public static String formatDateAxis(Date date, String format) {
}
}

public static String getAccountWitnessDescription(AccountAgeWitnessService accountAgeWitnessService,
PaymentMethod paymentMethod,
PaymentAccountPayload paymentAccountPayload,
PubKeyRing pubKeyRing) {
String description = Res.get("peerInfoIcon.tooltip.unknownAge");
Optional<AccountAgeWitness> aaw = accountAgeWitnessService.findWitness(paymentAccountPayload, pubKeyRing);
if (aaw.isPresent()) {
long accountAge = accountAgeWitnessService.getAccountAge(aaw.get(), new Date());
long signAge = -1L;
if (PaymentMethod.hasChargebackRisk(paymentMethod)) {
signAge = accountAgeWitnessService.getWitnessSignAge(aaw.get(), new Date());
}
if (signAge > -1) {
description = Res.get("peerInfo.age.chargeBackRisk") + ": " + formatAccountAge(accountAge);
} else if (accountAge > -1) {
description = Res.get("peerInfoIcon.tooltip.age", formatAccountAge(accountAge));
if (PaymentMethod.hasChargebackRisk(paymentMethod)) {
description += ", " + Res.get("offerbook.timeSinceSigning.notSigned");
}
}
}
return description;
}

public static String formatAccountAge(long durationMillis) {
durationMillis = Math.max(0, durationMillis);
String day = Res.get("time.day").toLowerCase();
Expand Down

0 comments on commit 12a797d

Please sign in to comment.