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 de7de248f5..aa4cf28cec 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; @@ -34,6 +35,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 @@ -61,8 +64,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; @@ -82,6 +83,7 @@ public class OfferInfo implements Payload { private final String challenge; private final String extraInfo; private final List acceptedCountryCodes; + private final String acceptedCountriesString; private final String city; public OfferInfo(OfferInfoBuilder builder) { @@ -120,6 +122,7 @@ public class OfferInfo implements Payload { this.challenge = builder.getChallenge(); this.extraInfo = builder.getExtraInfo(); this.acceptedCountryCodes = builder.getAcceptedCountryCodes(); + this.acceptedCountriesString = builder.getAcceptedCountriesString(); this.city = builder.getCity(); } @@ -160,6 +163,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()) @@ -191,8 +196,9 @@ public class OfferInfo implements Payload { .withIsPrivateOffer(offer.isPrivateOffer()) .withChallenge(offer.getChallenge()) .withExtraInfo(offer.getCombinedExtraInfo()) - .withAcceptedCountryCodes(offer.getAcceptedCountryCodes()) - .withCity(offer.getF2FCity()); + .withAcceptedCountryCodes(hasAcceptedCountries ? offer.getAcceptedCountryCodes() : null) + .withAcceptedCountriesString(hasAcceptedCountries ? CountryUtil.getCountriesString(offer.getAcceptedCountryCodes()) : null) + .withCity(city == null || city.isEmpty() ? null : city); } /////////////////////////////////////////////////////////////////////////////////////////// @@ -236,8 +242,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(builder::addAllAcceptedCountryCodes); - builder.setCity(city == null ? "" : city); + Optional.ofNullable(acceptedCountryCodes).ifPresent(e -> builder.addAllAcceptedCountryCodes(acceptedCountryCodes)); + Optional.ofNullable(acceptedCountriesString).ifPresent(builder::setAcceptedCountriesString); + Optional.ofNullable(city).ifPresent(builder::setCity); return builder.build(); } @@ -279,6 +286,7 @@ public class OfferInfo implements Payload { .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 a1492a330f..b0af131b59 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 java.util.List; import lombok.Getter; @@ -68,6 +70,7 @@ public final class OfferInfoBuilder { private String challenge; private String extraInfo; private List acceptedCountryCodes; + private String acceptedCountriesString; private String city; public OfferInfoBuilder withId(String id) { @@ -260,6 +263,11 @@ public final class OfferInfoBuilder { return this; } + public OfferInfoBuilder withAcceptedCountriesString(String acceptedCountriesString) { + this.acceptedCountriesString = acceptedCountriesString; + return this; + } + public OfferInfoBuilder withCity(String city) { this.city = city; return 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 48559466df..611375f6a9 100644 --- a/proto/src/main/proto/grpc.proto +++ b/proto/src/main/proto/grpc.proto @@ -613,7 +613,8 @@ message OfferInfo { string challenge = 33; string extra_info = 34; repeated string accepted_country_codes = 35; - string city = 36; + string accepted_countries_string = 36; + string city = 37; } message AvailabilityResultWithDescription {