From eb492d3ebd15724e43ad93375efdf116a8bc6508 Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 6 Jan 2026 09:44:13 -0400 Subject: [PATCH] add accepted countries and city to OfferInfo (#2101) --- .../java/haveno/core/api/model/OfferInfo.java | 24 ++++++++++++++++--- .../api/model/builder/OfferInfoBuilder.java | 20 ++++++++++++++++ .../java/haveno/core/locale/CountryUtil.java | 12 ++++++++++ .../overlays/windows/OfferDetailsWindow.java | 8 ++----- proto/src/main/proto/grpc.proto | 3 +++ 5 files changed, 58 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/haveno/core/api/model/OfferInfo.java b/core/src/main/java/haveno/core/api/model/OfferInfo.java index 74a715cd48..7754428bbe 100644 --- a/core/src/main/java/haveno/core/api/model/OfferInfo.java +++ b/core/src/main/java/haveno/core/api/model/OfferInfo.java @@ -19,6 +19,7 @@ package haveno.core.api.model; import haveno.common.Payload; import haveno.core.api.model.builder.OfferInfoBuilder; +import haveno.core.locale.CountryUtil; import haveno.core.monetary.Price; import haveno.core.offer.Offer; import haveno.core.offer.OpenOffer; @@ -33,6 +34,8 @@ import static haveno.core.util.PriceUtil.reformatMarketPrice; import static haveno.core.util.VolumeUtil.formatVolume; import static java.util.Objects.requireNonNull; +import java.util.List; + @EqualsAndHashCode @ToString @Getter @@ -60,8 +63,6 @@ public class OfferInfo implements Payload { private final String paymentAccountId; private final String paymentMethodId; private final String paymentMethodShortName; - // For traditional offer the baseCurrencyCode is XMR and the counterCurrencyCode is the traditional currency - // For crypto offers it is the opposite. baseCurrencyCode is the crypto and the counterCurrencyCode is XMR. private final String baseCurrencyCode; private final String counterCurrencyCode; private final long date; @@ -80,6 +81,9 @@ public class OfferInfo implements Payload { private final boolean isPrivateOffer; private final String challenge; private final String extraInfo; + private final List acceptedCountryCodes; + private final String acceptedCountriesString; + private final String city; public OfferInfo(OfferInfoBuilder builder) { this.id = builder.getId(); @@ -116,6 +120,9 @@ public class OfferInfo implements Payload { this.isPrivateOffer = builder.isPrivateOffer(); this.challenge = builder.getChallenge(); this.extraInfo = builder.getExtraInfo(); + this.acceptedCountryCodes = builder.getAcceptedCountryCodes(); + this.acceptedCountriesString = builder.getAcceptedCountriesString(); + this.city = builder.getCity(); } public static OfferInfo toOfferInfo(Offer offer) { @@ -155,6 +162,8 @@ public class OfferInfo implements Payload { currencyCode); var roundedVolume = formatVolume(requireNonNull(offer.getVolume())); var roundedMinVolume = formatVolume(requireNonNull(offer.getMinVolume())); + boolean hasAcceptedCountries = offer.getAcceptedCountryCodes() != null && !offer.getAcceptedCountryCodes().isEmpty(); + String city = offer.getF2FCity(); return new OfferInfoBuilder() .withId(offer.getId()) .withDirection(offer.getDirection().name()) @@ -185,7 +194,10 @@ public class OfferInfo implements Payload { .withArbitratorSigner(offer.getOfferPayload().getArbitratorSigner() == null ? null : offer.getOfferPayload().getArbitratorSigner().getFullAddress()) .withIsPrivateOffer(offer.isPrivateOffer()) .withChallenge(offer.getChallenge()) - .withExtraInfo(offer.getCombinedExtraInfo()); + .withExtraInfo(offer.getCombinedExtraInfo()) + .withAcceptedCountryCodes(hasAcceptedCountries ? offer.getAcceptedCountryCodes() : null) + .withAcceptedCountriesString(hasAcceptedCountries ? CountryUtil.getCountriesString(offer.getAcceptedCountryCodes()) : null) + .withCity(city == null || city.isEmpty() ? null : city); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -229,6 +241,9 @@ public class OfferInfo implements Payload { Optional.ofNullable(splitOutputTxHash).ifPresent(builder::setSplitOutputTxHash); Optional.ofNullable(challenge).ifPresent(builder::setChallenge); Optional.ofNullable(extraInfo).ifPresent(builder::setExtraInfo); + Optional.ofNullable(acceptedCountryCodes).ifPresent(e -> builder.addAllAcceptedCountryCodes(acceptedCountryCodes)); + Optional.ofNullable(acceptedCountriesString).ifPresent(builder::setAcceptedCountriesString); + Optional.ofNullable(city).ifPresent(builder::setCity); return builder.build(); } @@ -269,6 +284,9 @@ public class OfferInfo implements Payload { .withIsPrivateOffer(proto.getIsPrivateOffer()) .withChallenge(proto.getChallenge()) .withExtraInfo(proto.getExtraInfo()) + .withAcceptedCountryCodes(proto.getAcceptedCountryCodesList()) + .withAcceptedCountriesString(proto.getAcceptedCountriesString()) + .withCity(proto.getCity()) .build(); } } diff --git a/core/src/main/java/haveno/core/api/model/builder/OfferInfoBuilder.java b/core/src/main/java/haveno/core/api/model/builder/OfferInfoBuilder.java index 23e403fcd2..7af0641995 100644 --- a/core/src/main/java/haveno/core/api/model/builder/OfferInfoBuilder.java +++ b/core/src/main/java/haveno/core/api/model/builder/OfferInfoBuilder.java @@ -17,6 +17,8 @@ package haveno.core.api.model.builder; +import java.util.List; + import haveno.core.api.model.OfferInfo; import lombok.Getter; @@ -66,6 +68,9 @@ public final class OfferInfoBuilder { private boolean isPrivateOffer; private String challenge; private String extraInfo; + private List acceptedCountryCodes; + private String acceptedCountriesString; + private String city; public OfferInfoBuilder withId(String id) { this.id = id; @@ -252,6 +257,21 @@ public final class OfferInfoBuilder { return this; } + public OfferInfoBuilder withAcceptedCountryCodes(List acceptedCountryCodes) { + this.acceptedCountryCodes = acceptedCountryCodes; + return this; + } + + public OfferInfoBuilder withAcceptedCountriesString(String acceptedCountriesString) { + this.acceptedCountriesString = acceptedCountriesString; + return this; + } + + public OfferInfoBuilder withCity(String city) { + this.city = city; + return this; + } + public OfferInfo build() { return new OfferInfo(this); } diff --git a/core/src/main/java/haveno/core/locale/CountryUtil.java b/core/src/main/java/haveno/core/locale/CountryUtil.java index 51c8f9e8a3..45576b0e02 100644 --- a/core/src/main/java/haveno/core/locale/CountryUtil.java +++ b/core/src/main/java/haveno/core/locale/CountryUtil.java @@ -199,6 +199,18 @@ public class CountryUtil { return getNamesByCodes(countryCodes).stream().collect(Collectors.joining(",\n")); } + public static String getCountriesString(List countryCodes) { + if (CountryUtil.containsAllSepaEuroCountries(countryCodes)) { + return Res.get("shared.allEuroCountries"); + } else { + if (countryCodes.size() == 1) { + return CountryUtil.getNameAndCode(countryCodes.get(0)); + } else { + return CountryUtil.getCodesString(countryCodes); + } + } + } + public static List getAllRegions() { final List allRegions = new ArrayList<>(); diff --git a/desktop/src/main/java/haveno/desktop/main/overlays/windows/OfferDetailsWindow.java b/desktop/src/main/java/haveno/desktop/main/overlays/windows/OfferDetailsWindow.java index 8940c7c178..de1f88023f 100644 --- a/desktop/src/main/java/haveno/desktop/main/overlays/windows/OfferDetailsWindow.java +++ b/desktop/src/main/java/haveno/desktop/main/overlays/windows/OfferDetailsWindow.java @@ -303,16 +303,12 @@ public class OfferDetailsWindow extends Overlay { } if (showAcceptedCountryCodes) { addSeparator(gridPane, ++rowIndex); - String countries; + String countries = CountryUtil.getCountriesString(acceptedCountryCodes); Tooltip tooltip = null; - if (CountryUtil.containsAllSepaEuroCountries(acceptedCountryCodes)) { - countries = Res.get("shared.allEuroCountries"); - } else { + if (!CountryUtil.containsAllSepaEuroCountries(acceptedCountryCodes)) { if (acceptedCountryCodes.size() == 1) { - countries = CountryUtil.getNameAndCode(acceptedCountryCodes.get(0)); tooltip = new Tooltip(countries); } else { - countries = CountryUtil.getCodesString(acceptedCountryCodes); tooltip = new Tooltip(CountryUtil.getNamesByCodesString(acceptedCountryCodes)); } } diff --git a/proto/src/main/proto/grpc.proto b/proto/src/main/proto/grpc.proto index cc8c1f00f6..611375f6a9 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -612,6 +612,9 @@ message OfferInfo { bool is_private_offer = 32; string challenge = 33; string extra_info = 34; + repeated string accepted_country_codes = 35; + string accepted_countries_string = 36; + string city = 37; } message AvailabilityResultWithDescription {