Show signed status when applicable in Trade & Dispute screens

This commit is contained in:
jmacxx 2022-02-16 16:09:08 -06:00
parent d671b6805a
commit 1227781d43
No known key found for this signature in database
GPG key ID: 155297BABFE94A1B
4 changed files with 39 additions and 27 deletions

View file

@ -286,7 +286,7 @@ public class AccountAgeWitnessService {
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();

View file

@ -72,6 +72,7 @@ import java.util.List;
import lombok.extern.slf4j.Slf4j;
import static bisq.desktop.util.DisplayUtils.getAccountWitnessDescription;
import static bisq.desktop.util.FormBuilder.*;
@Slf4j
@ -186,9 +187,8 @@ public class ContractWindow extends Overlay<ContractWindow> {
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) : "";
@ -349,14 +349,4 @@ public class ContractWindow extends Overlay<ContractWindow> {
}
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") :
"";
}
}

View file

@ -76,6 +76,7 @@ import javafx.beans.value.ChangeListener;
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;
@ -252,27 +253,18 @@ public class TradeDetailsWindow extends Overlay<TradeDetailsWindow> {
}
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));

View file

@ -1,11 +1,15 @@
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;
@ -13,6 +17,8 @@ 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;
@ -74,6 +80,30 @@ public class DisplayUtils {
}
}
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();