refactor buy/sell tab functionality #1351

This commit is contained in:
woodser 2024-11-03 10:16:21 -05:00
parent f470112cae
commit 0c76c48c65
24 changed files with 363 additions and 351 deletions

View file

@ -73,14 +73,6 @@ public class CurrencyUtil {
private static String baseCurrencyCode = "XMR";
private static List<TraditionalCurrency> getTraditionalNonFiatCurrencies() {
return Arrays.asList(
new TraditionalCurrency("XAG", "Silver"),
new TraditionalCurrency("XAU", "Gold"),
new TraditionalCurrency("XGB", "Goldback")
);
}
// Calls to isTraditionalCurrency and isCryptoCurrency are very frequent so we use a cache of the results.
// The main improvement was already achieved with using memoize for the source maps, but
// the caching still reduces performance costs by about 20% for isCryptoCurrency (1752 ms vs 2121 ms) and about 50%
@ -124,6 +116,14 @@ public class CurrencyUtil {
return new ArrayList<>(traditionalCurrencyMapSupplier.get().values());
}
public static List<TraditionalCurrency> getTraditionalNonFiatCurrencies() {
return Arrays.asList(
new TraditionalCurrency("XAG", "Silver"),
new TraditionalCurrency("XAU", "Gold"),
new TraditionalCurrency("XGB", "Goldback")
);
}
public static Collection<TraditionalCurrency> getAllSortedTraditionalCurrencies(Comparator comparator) {
return (List<TraditionalCurrency>) getAllSortedTraditionalCurrencies().stream()
.sorted(comparator)

View file

@ -139,6 +139,10 @@ public abstract class PaymentAccount implements PersistablePayload {
return getSingleTradeCurrency() == null || CurrencyUtil.isFiatCurrency(getSingleTradeCurrency().getCode()); // TODO: check if trade currencies contain fiat
}
public boolean isCryptoCurrency() {
return getSingleTradeCurrency() != null && CurrencyUtil.isCryptoCurrency(getSingleTradeCurrency().getCode());
}
///////////////////////////////////////////////////////////////////////////////////////////
// PROTO BUFFER

View file

@ -566,6 +566,16 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
requestPersistence();
}
public void setBuyScreenOtherCurrencyCode(String buyScreenCurrencyCode) {
prefPayload.setBuyScreenOtherCurrencyCode(buyScreenCurrencyCode);
requestPersistence();
}
public void setSellScreenOtherCurrencyCode(String sellScreenCurrencyCode) {
prefPayload.setSellScreenOtherCurrencyCode(sellScreenCurrencyCode);
requestPersistence();
}
public void setIgnoreTradersList(List<String> ignoreTradersList) {
prefPayload.setIgnoreTradersList(ignoreTradersList);
requestPersistence();

View file

@ -77,6 +77,10 @@ public final class PreferencesPayload implements PersistableEnvelope {
private String buyScreenCryptoCurrencyCode;
@Nullable
private String sellScreenCryptoCurrencyCode;
@Nullable
private String buyScreenOtherCurrencyCode;
@Nullable
private String sellScreenOtherCurrencyCode;
private int tradeStatisticsTickUnitIndex = 3;
private boolean resyncSpvRequested;
private boolean sortMarketCurrenciesNumerically = true;
@ -212,6 +216,8 @@ public final class PreferencesPayload implements PersistableEnvelope {
Optional.ofNullable(sellScreenCurrencyCode).ifPresent(builder::setSellScreenCurrencyCode);
Optional.ofNullable(buyScreenCryptoCurrencyCode).ifPresent(builder::setBuyScreenCryptoCurrencyCode);
Optional.ofNullable(sellScreenCryptoCurrencyCode).ifPresent(builder::setSellScreenCryptoCurrencyCode);
Optional.ofNullable(buyScreenOtherCurrencyCode).ifPresent(builder::setBuyScreenOtherCurrencyCode);
Optional.ofNullable(sellScreenOtherCurrencyCode).ifPresent(builder::setSellScreenOtherCurrencyCode);
Optional.ofNullable(selectedPaymentAccountForCreateOffer).ifPresent(
account -> builder.setSelectedPaymentAccountForCreateOffer(selectedPaymentAccountForCreateOffer.toProtoMessage()));
Optional.ofNullable(bridgeAddresses).ifPresent(builder::addAllBridgeAddresses);
@ -260,6 +266,8 @@ public final class PreferencesPayload implements PersistableEnvelope {
ProtoUtil.stringOrNullFromProto(proto.getSellScreenCurrencyCode()),
ProtoUtil.stringOrNullFromProto(proto.getBuyScreenCryptoCurrencyCode()),
ProtoUtil.stringOrNullFromProto(proto.getSellScreenCryptoCurrencyCode()),
ProtoUtil.stringOrNullFromProto(proto.getBuyScreenOtherCurrencyCode()),
ProtoUtil.stringOrNullFromProto(proto.getSellScreenOtherCurrencyCode()),
proto.getTradeStatisticsTickUnitIndex(),
proto.getResyncSpvRequested(),
proto.getSortMarketCurrenciesNumerically(),

View file

@ -207,6 +207,7 @@ shared.crypto=Crypto
shared.traditional=Traditional
shared.otherAssets=other assets
shared.other=Other
shared.preciousMetals=Precious Metals
shared.all=All
shared.edit=Edit
shared.advancedOptions=Advanced options
@ -245,8 +246,8 @@ shared.taker=Taker
####################################################################
mainView.menu.market=Market
mainView.menu.buy=Buy
mainView.menu.sell=Sell
mainView.menu.buyXmr=Buy XMR
mainView.menu.sellXmr=Sell XMR
mainView.menu.portfolio=Portfolio
mainView.menu.funds=Funds
mainView.menu.support=Support

View file

@ -245,8 +245,8 @@ shared.taker=Alıcı
####################################################################
mainView.menu.market=Piyasa
mainView.menu.buy=Satın Al
mainView.menu.sell=Sat
mainView.menu.buyXmr=XMR Satın Al
mainView.menu.sellXmr=XMR Sat
mainView.menu.portfolio=Portföy
mainView.menu.funds=Fonlar
mainView.menu.support=Destek