mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 10:22:18 +01:00
Refactor User and Preferences (User still not working correctly)
This commit is contained in:
parent
028d26e23e
commit
3cc27fe89a
@ -189,14 +189,12 @@ public class FileManager<T extends PersistableEnvelope> {
|
||||
ObjectOutputStream objectOutputStream = null;
|
||||
PrintWriter printWriter = null;
|
||||
|
||||
log.error("persistable.class " + persistable.getClass().getSimpleName());
|
||||
log.error("persistable " + persistable);
|
||||
log.info("saveToFile persistable.class " + persistable.getClass().getSimpleName());
|
||||
PB.PersistableEnvelope protoPersistable = null;
|
||||
try {
|
||||
protoPersistable = (PB.PersistableEnvelope) persistable.toProtoMessage();
|
||||
log.error("protoPersistable " + protoPersistable);
|
||||
} catch (Throwable e) {
|
||||
log.error("Not protobufferable: {}, {}, {}", persistable.getClass().getSimpleName(), storageFile, e.getStackTrace());
|
||||
log.error("Error at saveToFile: {}, {}, {}", persistable.getClass().getSimpleName(), storageFile, e.getStackTrace());
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -293,6 +293,7 @@ public class Utilities {
|
||||
Object result = null;
|
||||
try {
|
||||
in = new LookAheadObjectInputStream(bis, true);
|
||||
//in = new ObjectInputStream(bis);
|
||||
result = in.readObject();
|
||||
if (!(result instanceof Serializable))
|
||||
throw new RuntimeException("Object not of type Serializable");
|
||||
|
@ -19,11 +19,13 @@ package io.bisq.core.app;
|
||||
|
||||
import io.bisq.common.app.Version;
|
||||
import io.bisq.common.crypto.KeyRing;
|
||||
import io.bisq.core.user.Preferences;
|
||||
import io.bisq.common.proto.persistable.PersistedDataHost;
|
||||
import io.bisq.core.trade.statistics.TradeStatisticsManager;
|
||||
import io.bisq.network.crypto.EncryptionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Slf4j
|
||||
public class AppSetup {
|
||||
@ -34,12 +36,19 @@ public class AppSetup {
|
||||
public AppSetup(BisqEnvironment bisqEnvironment,
|
||||
EncryptionService encryptionService,
|
||||
KeyRing keyRing,
|
||||
Preferences preferences) {
|
||||
TradeStatisticsManager tradeStatisticsManager) {
|
||||
// we need to reference it so the seed node stores tradeStatistics
|
||||
this.encryptionService = encryptionService;
|
||||
this.keyRing = keyRing;
|
||||
|
||||
preferences.init();
|
||||
|
||||
// All classes which are persisting objects need to be added here
|
||||
// Maintain order!
|
||||
ArrayList<PersistedDataHost> persistedDataHosts = new ArrayList<>();
|
||||
persistedDataHosts.add(tradeStatisticsManager);
|
||||
|
||||
// we apply at startup the reading of persisted data but don't want to get it triggered in the constructor
|
||||
persistedDataHosts.stream().forEach(PersistedDataHost::readPersisted);
|
||||
|
||||
Version.setBtcNetworkId(bisqEnvironment.getBitcoinNetwork().ordinal());
|
||||
Version.printVersion();
|
||||
|
@ -18,7 +18,7 @@
|
||||
package io.bisq.core.app;
|
||||
|
||||
import io.bisq.common.crypto.KeyRing;
|
||||
import io.bisq.core.user.Preferences;
|
||||
import io.bisq.core.trade.statistics.TradeStatisticsManager;
|
||||
import io.bisq.network.crypto.EncryptionService;
|
||||
import io.bisq.network.p2p.P2PService;
|
||||
import io.bisq.network.p2p.P2PServiceListener;
|
||||
@ -41,11 +41,11 @@ public class AppSetupWithP2P extends AppSetup {
|
||||
EncryptionService encryptionService,
|
||||
KeyRing keyRing,
|
||||
P2PService p2PService,
|
||||
Preferences preferences) {
|
||||
TradeStatisticsManager tradeStatisticsManager) {
|
||||
super(bisqEnvironment,
|
||||
encryptionService,
|
||||
keyRing,
|
||||
preferences);
|
||||
tradeStatisticsManager);
|
||||
this.p2PService = p2PService;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ package io.bisq.core.app;
|
||||
|
||||
import io.bisq.common.crypto.KeyRing;
|
||||
import io.bisq.core.dao.blockchain.BsqBlockchainManager;
|
||||
import io.bisq.core.user.Preferences;
|
||||
import io.bisq.core.trade.statistics.TradeStatisticsManager;
|
||||
import io.bisq.network.crypto.EncryptionService;
|
||||
import io.bisq.network.p2p.P2PService;
|
||||
import io.bisq.network.p2p.P2PServiceListener;
|
||||
@ -45,11 +45,11 @@ public class AppSetupWithP2PAndDAO extends AppSetup {
|
||||
KeyRing keyRing,
|
||||
P2PService p2PService,
|
||||
BsqBlockchainManager bsqBlockchainManager,
|
||||
Preferences preferences) {
|
||||
TradeStatisticsManager tradeStatisticsManager) {
|
||||
super(bisqEnvironment,
|
||||
encryptionService,
|
||||
keyRing,
|
||||
preferences);
|
||||
tradeStatisticsManager);
|
||||
this.p2PService = p2PService;
|
||||
this.bsqBlockchainManager = bsqBlockchainManager;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package io.bisq.core.proto.persistable;
|
||||
|
||||
import com.google.inject.Provider;
|
||||
import io.bisq.common.locale.*;
|
||||
import io.bisq.common.proto.ProtobufferException;
|
||||
import io.bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import io.bisq.common.proto.persistable.PersistableViewPath;
|
||||
@ -11,11 +10,9 @@ import io.bisq.core.btc.AddressEntryList;
|
||||
import io.bisq.core.btc.wallet.BtcWalletService;
|
||||
import io.bisq.core.dao.compensation.CompensationRequestPayload;
|
||||
import io.bisq.core.offer.OpenOffer;
|
||||
import io.bisq.core.payment.PaymentAccount;
|
||||
import io.bisq.core.proto.CoreProtoResolver;
|
||||
import io.bisq.core.trade.*;
|
||||
import io.bisq.core.trade.statistics.TradeStatisticsList;
|
||||
import io.bisq.core.user.BlockChainExplorer;
|
||||
import io.bisq.core.user.Preferences;
|
||||
import io.bisq.core.user.UserPayload;
|
||||
import io.bisq.generated.protobuffer.PB;
|
||||
@ -26,7 +23,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Slf4j
|
||||
public class CorePersistenceProtoResolver extends CoreProtoResolver implements PersistenceProtoResolver {
|
||||
@ -78,7 +74,7 @@ public class CorePersistenceProtoResolver extends CoreProtoResolver implements P
|
||||
// TODO There will be another object for PersistableEnvelope
|
||||
return CompensationRequestPayload.fromProto(proto.getCompensationRequestPayload());
|
||||
case PREFERENCES:
|
||||
return fillPreferences(proto, preferencesProvider.get());
|
||||
return Preferences.fromProto(proto.getPreferences(), preferencesProvider, this);
|
||||
case USER_PAYLOAD:
|
||||
return UserPayload.fromProto(proto.getUserPayload(), this);
|
||||
case SEQUENCE_NUMBER_MAP:
|
||||
@ -90,7 +86,6 @@ public class CorePersistenceProtoResolver extends CoreProtoResolver implements P
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
public Tradable fromProto(PB.Tradable proto, Storage<TradableList<SellerAsMakerTrade>> storage) {
|
||||
log.error("Convert protobuffer disk proto: {}", proto.getMessageCase());
|
||||
|
||||
@ -109,63 +104,4 @@ public class CorePersistenceProtoResolver extends CoreProtoResolver implements P
|
||||
throw new ProtobufferException("Unknown proto message case. messageCase=" + proto.getMessageCase());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Preferences fillPreferences(PB.PersistableEnvelope envelope, Preferences preferences) {
|
||||
final PB.Preferences env = envelope.getPreferences();
|
||||
preferences.setUserLanguage(env.getUserLanguage());
|
||||
PB.Country userCountry = env.getUserCountry();
|
||||
preferences.setUserCountry(new Country(userCountry.getCode(), userCountry.getName(), new Region(userCountry.getRegion().getCode(), userCountry.getRegion().getName())));
|
||||
env.getFiatCurrenciesList().stream()
|
||||
.forEach(tradeCurrency -> preferences.addFiatCurrency((FiatCurrency) TradeCurrency.fromProto(tradeCurrency)));
|
||||
env.getCryptoCurrenciesList().stream()
|
||||
.forEach(tradeCurrency -> preferences.addCryptoCurrency((CryptoCurrency) TradeCurrency.fromProto(tradeCurrency)));
|
||||
PB.BlockChainExplorer bceMain = env.getBlockChainExplorerMainNet();
|
||||
preferences.setBlockChainExplorerMainNet(new BlockChainExplorer(bceMain.getName(), bceMain.getTxUrl(), bceMain.getAddressUrl()));
|
||||
PB.BlockChainExplorer bceTest = env.getBlockChainExplorerTestNet();
|
||||
preferences.setBlockChainExplorerTestNet(new BlockChainExplorer(bceTest.getName(), bceTest.getTxUrl(), bceTest.getAddressUrl()));
|
||||
|
||||
preferences.setAutoSelectArbitrators(env.getAutoSelectArbitrators());
|
||||
preferences.setDontShowAgainMap(new HashMap<>(env.getDontShowAgainMapMap()));
|
||||
preferences.setTacAccepted(env.getTacAccepted());
|
||||
preferences.setUseTorForBitcoinJ(env.getUseTorForBitcoinJ());
|
||||
preferences.setShowOwnOffersInOfferBook(env.getShowOwnOffersInOfferBook());
|
||||
PB.TradeCurrency preferredTradeCurrency = env.getPreferredTradeCurrency();
|
||||
preferences.setPreferredTradeCurrency(TradeCurrency.fromProto(preferredTradeCurrency));
|
||||
preferences.setWithdrawalTxFeeInBytes(env.getWithdrawalTxFeeInBytes());
|
||||
preferences.setMaxPriceDistanceInPercent(env.getMaxPriceDistanceInPercent());
|
||||
|
||||
preferences.setSortMarketCurrenciesNumerically(env.getSortMarketCurrenciesNumerically());
|
||||
preferences.setUsePercentageBasedPrice(env.getUsePercentageBasedPrice());
|
||||
preferences.setPeerTagMap(env.getPeerTagMapMap());
|
||||
preferences.setBitcoinNodes(env.getBitcoinNodes());
|
||||
preferences.setIgnoreTradersList(env.getIgnoreTradersListList());
|
||||
preferences.setDirectoryChooserPath(env.getDirectoryChooserPath());
|
||||
preferences.setBuyerSecurityDepositAsLong(env.getBuyerSecurityDepositAsLong());
|
||||
|
||||
final PB.BlockChainExplorer bsqExPl = env.getBsqBlockChainExplorer();
|
||||
preferences.setBsqBlockChainExplorer(new BlockChainExplorer(bsqExPl.getName(), bsqExPl.getTxUrl(), bsqExPl.getAddressUrl()));
|
||||
|
||||
preferences.setBtcDenomination(env.getBtcDenomination());
|
||||
preferences.setUseAnimations(env.getUseAnimations());
|
||||
preferences.setPayFeeInBtc(env.getPayFeeInBtc());
|
||||
preferences.setResyncSpvRequested(env.getResyncSpvRequested());
|
||||
|
||||
// optional
|
||||
preferences.setBackupDirectory(env.getBackupDirectory().isEmpty() ? null : env.getBackupDirectory());
|
||||
preferences.setOfferBookChartScreenCurrencyCode(env.getOfferBookChartScreenCurrencyCode().isEmpty() ?
|
||||
null :
|
||||
env.getOfferBookChartScreenCurrencyCode());
|
||||
preferences.setTradeChartsScreenCurrencyCode(env.getTradeChartsScreenCurrencyCode().isEmpty() ?
|
||||
null :
|
||||
env.getTradeChartsScreenCurrencyCode());
|
||||
preferences.setBuyScreenCurrencyCode(env.getBuyScreenCurrencyCode().isEmpty() ? null : env.getBuyScreenCurrencyCode());
|
||||
preferences.setSellScreenCurrencyCode(env.getSellScreenCurrencyCode().isEmpty() ? null : env.getSellScreenCurrencyCode());
|
||||
preferences.setSelectedPaymentAccountForCreateOffer(env.getSelectedPaymentAccountForCreateOffer().hasPaymentMethod() ?
|
||||
PaymentAccount.fromProto(env.getSelectedPaymentAccountForCreateOffer(), this) :
|
||||
null);
|
||||
|
||||
preferences.setDoPersist(true);
|
||||
return preferences;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
package io.bisq.core.user;
|
||||
|
||||
import com.google.inject.Provider;
|
||||
import com.google.protobuf.Message;
|
||||
import io.bisq.common.GlobalSettings;
|
||||
import io.bisq.common.app.DevEnv;
|
||||
import io.bisq.common.locale.*;
|
||||
import io.bisq.common.proto.ProtoResolver;
|
||||
import io.bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import io.bisq.common.proto.persistable.PersistedDataHost;
|
||||
import io.bisq.common.storage.Storage;
|
||||
import io.bisq.common.util.Utilities;
|
||||
import io.bisq.core.btc.BitcoinNetwork;
|
||||
@ -18,7 +21,6 @@ import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.utils.MonetaryFormat;
|
||||
@ -30,8 +32,10 @@ import javax.inject.Named;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
@Slf4j
|
||||
public final class Preferences implements PersistableEnvelope {
|
||||
public final class Preferences implements PersistableEnvelope, PersistedDataHost {
|
||||
|
||||
// Deactivate mBit for now as most screens are not supporting it yet
|
||||
@SuppressWarnings("ArraysAsListWithZeroOrOneArgument")
|
||||
@ -153,8 +157,6 @@ public final class Preferences implements PersistableEnvelope {
|
||||
transient private final Storage<Preferences> storage;
|
||||
transient private final String btcNodesFromOptions;
|
||||
transient private final String useTorFlagFromOptions;
|
||||
@Setter
|
||||
transient private boolean doPersist;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -173,7 +175,8 @@ public final class Preferences implements PersistableEnvelope {
|
||||
this.useTorFlagFromOptions = useTorFlagFromOptions;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
@Override
|
||||
public void readPersisted() {
|
||||
// We don't want to pass Preferences to all popups where the dont show again checkbox is used, so we use
|
||||
// that static lookup class to avoid static access to the Preferences directly.
|
||||
DontShowAgainLookup.setPreferences(this);
|
||||
@ -212,13 +215,14 @@ public final class Preferences implements PersistableEnvelope {
|
||||
});
|
||||
|
||||
TradeCurrency defaultTradeCurrency;
|
||||
Preferences persisted = storage.initAndGetPersisted(this);
|
||||
Preferences persisted = storage.initAndGetPersistedWithFileName("Preferences");
|
||||
if (persisted != null) {
|
||||
userLanguage = persisted.userLanguage;
|
||||
userCountry = persisted.userCountry;
|
||||
GlobalSettings.setLocale(new Locale(userLanguage, userCountry.code));
|
||||
GlobalSettings.setUseAnimations(persisted.useAnimations);
|
||||
preferredTradeCurrency = persisted.preferredTradeCurrency;
|
||||
checkNotNull(preferredTradeCurrency, "preferredTradeCurrency must not be null");
|
||||
defaultTradeCurrency = preferredTradeCurrency;
|
||||
setBtcDenomination(persisted.btcDenomination);
|
||||
setUseAnimations(persisted.useAnimations);
|
||||
@ -266,7 +270,6 @@ public final class Preferences implements PersistableEnvelope {
|
||||
directoryChooserPath = Utilities.getSystemHomeDirectory();
|
||||
dontShowAgainMap = new HashMap<>();
|
||||
|
||||
doPersist = true;
|
||||
persist();
|
||||
}
|
||||
GlobalSettings.setDefaultTradeCurrency(defaultTradeCurrency);
|
||||
@ -296,6 +299,109 @@ public final class Preferences implements PersistableEnvelope {
|
||||
setBitcoinNodes(btcNodesFromOptions);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// PROTO BUFFER
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public Message toProtoMessage() {
|
||||
PB.Preferences.Builder builder = PB.Preferences.newBuilder()
|
||||
.setUserLanguage(userLanguage)
|
||||
.setUserCountry((PB.Country) userCountry.toProtoMessage())
|
||||
.addAllFiatCurrencies(fiatCurrencies.stream().map(fiatCurrency -> ((PB.TradeCurrency) fiatCurrency.toProtoMessage())).collect(Collectors.toList()))
|
||||
.addAllCryptoCurrencies(cryptoCurrencies.stream().map(cryptoCurrency -> ((PB.TradeCurrency) cryptoCurrency.toProtoMessage())).collect(Collectors.toList()))
|
||||
.setBlockChainExplorerMainNet((PB.BlockChainExplorer) blockChainExplorerMainNet.toProtoMessage())
|
||||
.setBlockChainExplorerTestNet((PB.BlockChainExplorer) blockChainExplorerTestNet.toProtoMessage())
|
||||
.setBsqBlockChainExplorer((PB.BlockChainExplorer) bsqBlockChainExplorer.toProtoMessage())
|
||||
.setAutoSelectArbitrators(autoSelectArbitrators)
|
||||
.putAllDontShowAgainMap(dontShowAgainMap)
|
||||
.setTacAccepted(tacAccepted)
|
||||
.setUseAnimations(useAnimations)
|
||||
.setUseTorForBitcoinJ(useTorForBitcoinJ)
|
||||
.setShowOwnOffersInOfferBook(showOwnOffersInOfferBook)
|
||||
.setPreferredTradeCurrency((PB.TradeCurrency) preferredTradeCurrency.toProtoMessage())
|
||||
.setWithdrawalTxFeeInBytes(withdrawalTxFeeInBytes)
|
||||
.setMaxPriceDistanceInPercent(maxPriceDistanceInPercent)
|
||||
.setSortMarketCurrenciesNumerically(sortMarketCurrenciesNumerically)
|
||||
.setUsePercentageBasedPrice(usePercentageBasedPrice)
|
||||
.setPayFeeInBtc(payFeeInBtc)
|
||||
.putAllPeerTagMap(peerTagMap)
|
||||
.setBitcoinNodes(bitcoinNodes)
|
||||
.addAllIgnoreTradersList(ignoreTradersList)
|
||||
.setDirectoryChooserPath(directoryChooserPath)
|
||||
.setBuyerSecurityDepositAsLong(buyerSecurityDepositAsLong);
|
||||
|
||||
Optional.ofNullable(backupDirectory).ifPresent(backupDir -> builder.setBackupDirectory(backupDir));
|
||||
Optional.ofNullable(offerBookChartScreenCurrencyCode).ifPresent(code -> builder.setOfferBookChartScreenCurrencyCode(code));
|
||||
Optional.ofNullable(tradeChartsScreenCurrencyCode).ifPresent(code -> builder.setTradeChartsScreenCurrencyCode(code));
|
||||
Optional.ofNullable(buyScreenCurrencyCode).ifPresent(code -> builder.setBuyScreenCurrencyCode(code));
|
||||
Optional.ofNullable(sellScreenCurrencyCode).ifPresent(code -> builder.setSellScreenCurrencyCode(code));
|
||||
Optional.ofNullable(selectedPaymentAccountForCreateOffer).ifPresent(
|
||||
account -> builder.setSelectedPaymentAccountForCreateOffer(selectedPaymentAccountForCreateOffer.toProtoMessage()));
|
||||
return PB.PersistableEnvelope.newBuilder().setPreferences(builder).build();
|
||||
}
|
||||
|
||||
public static PersistableEnvelope fromProto(PB.Preferences proto, Provider<Preferences> preferencesProvider, ProtoResolver protoResolver) {
|
||||
Preferences preferences = preferencesProvider.get();
|
||||
preferences.setUserLanguage(proto.getUserLanguage());
|
||||
PB.Country userCountry = proto.getUserCountry();
|
||||
preferences.setUserCountry(new Country(userCountry.getCode(), userCountry.getName(), new Region(userCountry.getRegion().getCode(), userCountry.getRegion().getName())));
|
||||
proto.getFiatCurrenciesList().stream()
|
||||
.forEach(tradeCurrency -> preferences.addFiatCurrency((FiatCurrency) TradeCurrency.fromProto(tradeCurrency)));
|
||||
proto.getCryptoCurrenciesList().stream()
|
||||
.forEach(tradeCurrency -> preferences.addCryptoCurrency((CryptoCurrency) TradeCurrency.fromProto(tradeCurrency)));
|
||||
PB.BlockChainExplorer bceMain = proto.getBlockChainExplorerMainNet();
|
||||
preferences.setBlockChainExplorerMainNet(new BlockChainExplorer(bceMain.getName(), bceMain.getTxUrl(), bceMain.getAddressUrl()));
|
||||
PB.BlockChainExplorer bceTest = proto.getBlockChainExplorerTestNet();
|
||||
preferences.setBlockChainExplorerTestNet(new BlockChainExplorer(bceTest.getName(), bceTest.getTxUrl(), bceTest.getAddressUrl()));
|
||||
|
||||
preferences.setAutoSelectArbitrators(proto.getAutoSelectArbitrators());
|
||||
preferences.setDontShowAgainMap(new HashMap<>(proto.getDontShowAgainMapMap()));
|
||||
preferences.setTacAccepted(proto.getTacAccepted());
|
||||
preferences.setUseTorForBitcoinJ(proto.getUseTorForBitcoinJ());
|
||||
preferences.setShowOwnOffersInOfferBook(proto.getShowOwnOffersInOfferBook());
|
||||
PB.TradeCurrency preferredTradeCurrency = proto.getPreferredTradeCurrency();
|
||||
preferences.setPreferredTradeCurrency(TradeCurrency.fromProto(preferredTradeCurrency));
|
||||
preferences.setWithdrawalTxFeeInBytes(proto.getWithdrawalTxFeeInBytes());
|
||||
preferences.setMaxPriceDistanceInPercent(proto.getMaxPriceDistanceInPercent());
|
||||
|
||||
preferences.setSortMarketCurrenciesNumerically(proto.getSortMarketCurrenciesNumerically());
|
||||
preferences.setUsePercentageBasedPrice(proto.getUsePercentageBasedPrice());
|
||||
preferences.setPeerTagMap(proto.getPeerTagMapMap());
|
||||
preferences.setBitcoinNodes(proto.getBitcoinNodes());
|
||||
preferences.setIgnoreTradersList(proto.getIgnoreTradersListList());
|
||||
preferences.setDirectoryChooserPath(proto.getDirectoryChooserPath());
|
||||
preferences.setBuyerSecurityDepositAsLong(proto.getBuyerSecurityDepositAsLong());
|
||||
|
||||
final PB.BlockChainExplorer bsqExPl = proto.getBsqBlockChainExplorer();
|
||||
preferences.setBsqBlockChainExplorer(new BlockChainExplorer(bsqExPl.getName(), bsqExPl.getTxUrl(), bsqExPl.getAddressUrl()));
|
||||
|
||||
preferences.setBtcDenomination(proto.getBtcDenomination());
|
||||
preferences.setUseAnimations(proto.getUseAnimations());
|
||||
preferences.setPayFeeInBtc(proto.getPayFeeInBtc());
|
||||
preferences.setResyncSpvRequested(proto.getResyncSpvRequested());
|
||||
|
||||
// optional
|
||||
preferences.setBackupDirectory(proto.getBackupDirectory().isEmpty() ? null : proto.getBackupDirectory());
|
||||
preferences.setOfferBookChartScreenCurrencyCode(proto.getOfferBookChartScreenCurrencyCode().isEmpty() ?
|
||||
null :
|
||||
proto.getOfferBookChartScreenCurrencyCode());
|
||||
preferences.setTradeChartsScreenCurrencyCode(proto.getTradeChartsScreenCurrencyCode().isEmpty() ?
|
||||
null :
|
||||
proto.getTradeChartsScreenCurrencyCode());
|
||||
preferences.setBuyScreenCurrencyCode(proto.getBuyScreenCurrencyCode().isEmpty() ? null : proto.getBuyScreenCurrencyCode());
|
||||
preferences.setSellScreenCurrencyCode(proto.getSellScreenCurrencyCode().isEmpty() ? null : proto.getSellScreenCurrencyCode());
|
||||
preferences.setSelectedPaymentAccountForCreateOffer(proto.getSelectedPaymentAccountForCreateOffer().hasPaymentMethod() ?
|
||||
PaymentAccount.fromProto(proto.getSelectedPaymentAccountForCreateOffer(), protoResolver) :
|
||||
null);
|
||||
return null;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void dontShowAgain(String key, boolean dontShowAgain) {
|
||||
dontShowAgainMap.put(key, dontShowAgain);
|
||||
persist();
|
||||
@ -366,8 +472,7 @@ public final class Preferences implements PersistableEnvelope {
|
||||
}
|
||||
|
||||
private void persist() {
|
||||
if (doPersist)
|
||||
storage.queueUpForSave();
|
||||
storage.queueUpForSave(this);
|
||||
}
|
||||
|
||||
public void setUserLanguage(@NotNull String userLanguageCode) {
|
||||
@ -523,8 +628,7 @@ public final class Preferences implements PersistableEnvelope {
|
||||
public void setResyncSpvRequested(boolean resyncSpvRequested) {
|
||||
this.resyncSpvRequested = resyncSpvRequested;
|
||||
// We call that before shutdown so we dont want a delay here
|
||||
if (doPersist)
|
||||
storage.queueUpForSave(1);
|
||||
storage.queueUpForSave(this, 1);
|
||||
}
|
||||
|
||||
// Only used from PB but keep it explicit as maybe it get used from the client and then we want to persist
|
||||
@ -650,43 +754,4 @@ public final class Preferences implements PersistableEnvelope {
|
||||
else if (change.wasRemoved() && change.getRemovedSize() == 1)
|
||||
tradeCurrenciesAsObservable.remove(change.getRemoved().get(0));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Message toProtoMessage() {
|
||||
PB.Preferences.Builder builder = PB.Preferences.newBuilder()
|
||||
.setUserLanguage(userLanguage)
|
||||
.setUserCountry((PB.Country) userCountry.toProtoMessage())
|
||||
.addAllFiatCurrencies(fiatCurrencies.stream().map(fiatCurrency -> ((PB.TradeCurrency) fiatCurrency.toProtoMessage())).collect(Collectors.toList()))
|
||||
.addAllCryptoCurrencies(cryptoCurrencies.stream().map(cryptoCurrency -> ((PB.TradeCurrency) cryptoCurrency.toProtoMessage())).collect(Collectors.toList()))
|
||||
.setBlockChainExplorerMainNet((PB.BlockChainExplorer) blockChainExplorerMainNet.toProtoMessage())
|
||||
.setBlockChainExplorerTestNet((PB.BlockChainExplorer) blockChainExplorerTestNet.toProtoMessage())
|
||||
.setBsqBlockChainExplorer((PB.BlockChainExplorer) bsqBlockChainExplorer.toProtoMessage())
|
||||
.setAutoSelectArbitrators(autoSelectArbitrators)
|
||||
.putAllDontShowAgainMap(dontShowAgainMap)
|
||||
.setTacAccepted(tacAccepted)
|
||||
.setUseAnimations(useAnimations)
|
||||
.setUseTorForBitcoinJ(useTorForBitcoinJ)
|
||||
.setShowOwnOffersInOfferBook(showOwnOffersInOfferBook)
|
||||
.setPreferredTradeCurrency((PB.TradeCurrency) preferredTradeCurrency.toProtoMessage())
|
||||
.setWithdrawalTxFeeInBytes(withdrawalTxFeeInBytes)
|
||||
.setMaxPriceDistanceInPercent(maxPriceDistanceInPercent)
|
||||
.setSortMarketCurrenciesNumerically(sortMarketCurrenciesNumerically)
|
||||
.setUsePercentageBasedPrice(usePercentageBasedPrice)
|
||||
.setPayFeeInBtc(payFeeInBtc)
|
||||
.putAllPeerTagMap(peerTagMap)
|
||||
.setBitcoinNodes(bitcoinNodes)
|
||||
.addAllIgnoreTradersList(ignoreTradersList)
|
||||
.setDirectoryChooserPath(directoryChooserPath)
|
||||
.setBuyerSecurityDepositAsLong(buyerSecurityDepositAsLong);
|
||||
|
||||
Optional.ofNullable(backupDirectory).ifPresent(backupDir -> builder.setBackupDirectory(backupDir));
|
||||
Optional.ofNullable(offerBookChartScreenCurrencyCode).ifPresent(code -> builder.setOfferBookChartScreenCurrencyCode(code));
|
||||
Optional.ofNullable(tradeChartsScreenCurrencyCode).ifPresent(code -> builder.setTradeChartsScreenCurrencyCode(code));
|
||||
Optional.ofNullable(buyScreenCurrencyCode).ifPresent(code -> builder.setBuyScreenCurrencyCode(code));
|
||||
Optional.ofNullable(sellScreenCurrencyCode).ifPresent(code -> builder.setSellScreenCurrencyCode(code));
|
||||
Optional.ofNullable(selectedPaymentAccountForCreateOffer).ifPresent(
|
||||
account -> builder.setSelectedPaymentAccountForCreateOffer(selectedPaymentAccountForCreateOffer.toProtoMessage()));
|
||||
return PB.PersistableEnvelope.newBuilder().setPreferences(builder).build();
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package io.bisq.core.user;
|
||||
import io.bisq.common.crypto.KeyRing;
|
||||
import io.bisq.common.locale.LanguageUtil;
|
||||
import io.bisq.common.locale.TradeCurrency;
|
||||
import io.bisq.common.proto.persistable.PersistedDataHost;
|
||||
import io.bisq.common.storage.Storage;
|
||||
import io.bisq.core.alert.Alert;
|
||||
import io.bisq.core.arbitration.Arbitrator;
|
||||
@ -41,6 +42,8 @@ import java.security.NoSuchAlgorithmException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
|
||||
/**
|
||||
* The User is persisted locally.
|
||||
@ -48,17 +51,15 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public final class User {
|
||||
public final class User implements PersistedDataHost {
|
||||
final private Storage<UserPayload> storage;
|
||||
final private KeyRing keyRing;
|
||||
|
||||
private ObservableSet<PaymentAccount> paymentAccountsAsObservable;
|
||||
private ObjectProperty<PaymentAccount> currentPaymentAccountProperty;
|
||||
|
||||
private UserPayload userPayload;
|
||||
|
||||
// Transient immutable fields
|
||||
transient final private Storage<UserPayload> storage;
|
||||
transient final private KeyRing keyRing;
|
||||
transient private Set<TradeCurrency> tradeCurrenciesInPaymentAccounts;
|
||||
|
||||
// Observable wrappers
|
||||
transient private ObservableSet<PaymentAccount> paymentAccountsAsObservable;
|
||||
transient private ObjectProperty<PaymentAccount> currentPaymentAccountProperty;
|
||||
private boolean initialReadDone;
|
||||
|
||||
@Inject
|
||||
public User(Storage<UserPayload> storage, KeyRing keyRing) throws NoSuchAlgorithmException {
|
||||
@ -72,199 +73,56 @@ public final class User {
|
||||
keyRing = null;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
UserPayload persisted = storage.initAndGetPersistedWithFileName("UserVO");
|
||||
@Override
|
||||
public void readPersisted() {
|
||||
UserPayload persisted = storage.initAndGetPersistedWithFileName("User");
|
||||
userPayload = persisted != null ? persisted : new UserPayload();
|
||||
|
||||
checkNotNull(userPayload.getPaymentAccounts(), "userPayload.getPaymentAccounts() must not be null");
|
||||
checkNotNull(userPayload.getAcceptedLanguageLocaleCodes(), "userPayload.getAcceptedLanguageLocaleCodes() must not be null");
|
||||
paymentAccountsAsObservable = FXCollections.observableSet(userPayload.getPaymentAccounts());
|
||||
currentPaymentAccountProperty = new SimpleObjectProperty<>(userPayload.getCurrentPaymentAccount());
|
||||
userPayload.setAccountID(String.valueOf(Math.abs(keyRing.getPubKeyRing().hashCode())));
|
||||
userPayload.setAccountId(String.valueOf(Math.abs(keyRing.getPubKeyRing().hashCode())));
|
||||
|
||||
// language setup
|
||||
userPayload.getAcceptedLanguageLocaleCodes().add(LanguageUtil.getDefaultLanguageLocaleAsCode());
|
||||
String english = LanguageUtil.getEnglishLanguageLocaleCode();
|
||||
if (!userPayload.getAcceptedLanguageLocaleCodes().contains(english))
|
||||
userPayload.getAcceptedLanguageLocaleCodes().add(english);
|
||||
|
||||
storage.queueUpForSave();
|
||||
|
||||
// Use that to guarantee update of the serializable field and to make a storage update in case of a change
|
||||
paymentAccountsAsObservable.addListener((SetChangeListener<PaymentAccount>) change -> {
|
||||
userPayload.setPaymentAccounts(new HashSet<>(paymentAccountsAsObservable));
|
||||
tradeCurrenciesInPaymentAccounts = userPayload.getPaymentAccounts().stream().flatMap(e -> e.getTradeCurrencies().stream()).collect(Collectors.toSet());
|
||||
storage.queueUpForSave();
|
||||
persist();
|
||||
});
|
||||
currentPaymentAccountProperty.addListener((ov) -> {
|
||||
userPayload.setCurrentPaymentAccount(currentPaymentAccountProperty.get());
|
||||
storage.queueUpForSave();
|
||||
persist();
|
||||
});
|
||||
|
||||
tradeCurrenciesInPaymentAccounts = userPayload.getPaymentAccounts().stream().flatMap(e -> e.getTradeCurrencies().stream()).collect(Collectors.toSet());
|
||||
//persist();
|
||||
initialReadDone = true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Public Methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void addPaymentAccount(PaymentAccount paymentAccount) {
|
||||
paymentAccountsAsObservable.add(paymentAccount);
|
||||
setCurrentPaymentAccount(paymentAccount);
|
||||
}
|
||||
|
||||
public void removePaymentAccount(PaymentAccount paymentAccount) {
|
||||
paymentAccountsAsObservable.remove(paymentAccount);
|
||||
}
|
||||
|
||||
public void setCurrentPaymentAccount(PaymentAccount paymentAccount) {
|
||||
currentPaymentAccountProperty.set(paymentAccount);
|
||||
}
|
||||
|
||||
public boolean addAcceptedLanguageLocale(String localeCode) {
|
||||
if (!userPayload.getAcceptedLanguageLocaleCodes().contains(localeCode)) {
|
||||
boolean changed = userPayload.getAcceptedLanguageLocaleCodes().add(localeCode);
|
||||
if (changed)
|
||||
storage.queueUpForSave();
|
||||
return changed;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeAcceptedLanguageLocale(String languageLocaleCode) {
|
||||
boolean changed = userPayload.getAcceptedLanguageLocaleCodes().remove(languageLocaleCode);
|
||||
if (changed)
|
||||
storage.queueUpForSave();
|
||||
return changed;
|
||||
}
|
||||
|
||||
public void addAcceptedArbitrator(Arbitrator arbitrator) {
|
||||
if (!userPayload.getAcceptedArbitrators().contains(arbitrator) && !isMyOwnRegisteredArbitrator(arbitrator)) {
|
||||
boolean changed = userPayload.getAcceptedArbitrators().add(arbitrator);
|
||||
if (changed)
|
||||
storage.queueUpForSave();
|
||||
}
|
||||
}
|
||||
|
||||
public void addAcceptedMediator(Mediator mediator) {
|
||||
if (!userPayload.getAcceptedMediators().contains(mediator) && !isMyOwnRegisteredMediator(mediator)) {
|
||||
boolean changed = userPayload.getAcceptedMediators().add(mediator);
|
||||
if (changed)
|
||||
storage.queueUpForSave();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMyOwnRegisteredArbitrator(Arbitrator arbitrator) {
|
||||
return arbitrator.equals(userPayload.getRegisteredArbitrator());
|
||||
}
|
||||
|
||||
public boolean isMyOwnRegisteredMediator(Mediator mediator) {
|
||||
return mediator.equals(userPayload.getRegisteredArbitrator());
|
||||
}
|
||||
|
||||
public void removeAcceptedArbitrator(Arbitrator arbitrator) {
|
||||
boolean changed = userPayload.getAcceptedArbitrators().remove(arbitrator);
|
||||
if (changed)
|
||||
storage.queueUpForSave();
|
||||
}
|
||||
|
||||
public void clearAcceptedArbitrators() {
|
||||
userPayload.getAcceptedArbitrators().clear();
|
||||
storage.queueUpForSave();
|
||||
}
|
||||
|
||||
public void removeAcceptedMediator(Mediator mediator) {
|
||||
boolean changed = userPayload.getAcceptedMediators().remove(mediator);
|
||||
if (changed)
|
||||
storage.queueUpForSave();
|
||||
}
|
||||
|
||||
public void clearAcceptedMediators() {
|
||||
userPayload.getAcceptedMediators().clear();
|
||||
storage.queueUpForSave();
|
||||
}
|
||||
|
||||
public void setRegisteredArbitrator(@Nullable Arbitrator arbitrator) {
|
||||
userPayload.setRegisteredArbitrator(arbitrator);
|
||||
storage.queueUpForSave();
|
||||
}
|
||||
|
||||
public void setRegisteredMediator(@Nullable Mediator mediator) {
|
||||
userPayload.setRegisteredMediator(mediator);
|
||||
storage.queueUpForSave();
|
||||
}
|
||||
|
||||
public void setDevelopersFilter(@Nullable Filter developersFilter) {
|
||||
userPayload.setDevelopersFilter(developersFilter);
|
||||
storage.queueUpForSave();
|
||||
private void persist() {
|
||||
// TODO if we persist we get a blank screen (exception in view class contrs. or circ. dependency?)
|
||||
/* if (initialReadDone)
|
||||
storage.queueUpForSave(userPayload);*/
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getters
|
||||
// API
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Nullable
|
||||
public PaymentAccount getPaymentAccount(String paymentAccountId) {
|
||||
Optional<PaymentAccount> optional = userPayload.getPaymentAccounts().stream().filter(e -> e.getId().equals(paymentAccountId)).findAny();
|
||||
if (optional.isPresent())
|
||||
return optional.get();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getAccountId() {
|
||||
return userPayload.getAccountID();
|
||||
}
|
||||
|
||||
/* public boolean isRegistered() {
|
||||
return getAccountId() != null;
|
||||
/* public Optional<TradeCurrency> getPaymentAccountForCurrency(TradeCurrency tradeCurrency) {
|
||||
return getPaymentAccounts().stream()
|
||||
.flatMap(e -> e.getTradeCurrencies().stream())
|
||||
.filter(e -> e.equals(tradeCurrency))
|
||||
.findFirst();
|
||||
}*/
|
||||
|
||||
private PaymentAccount getCurrentPaymentAccount() {
|
||||
return userPayload.getCurrentPaymentAccount();
|
||||
}
|
||||
|
||||
public ObjectProperty<PaymentAccount> currentPaymentAccountProperty() {
|
||||
return currentPaymentAccountProperty;
|
||||
}
|
||||
|
||||
public Set<PaymentAccount> getPaymentAccounts() {
|
||||
return userPayload.getPaymentAccounts();
|
||||
}
|
||||
|
||||
public ObservableSet<PaymentAccount> getPaymentAccountsAsObservable() {
|
||||
return paymentAccountsAsObservable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Arbitrator getRegisteredArbitrator() {
|
||||
return userPayload.getRegisteredArbitrator();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Mediator getRegisteredMediator() {
|
||||
return userPayload.getRegisteredMediator();
|
||||
}
|
||||
|
||||
public List<Arbitrator> getAcceptedArbitrators() {
|
||||
return userPayload.getAcceptedArbitrators();
|
||||
}
|
||||
|
||||
public List<NodeAddress> getAcceptedArbitratorAddresses() {
|
||||
return userPayload.getAcceptedArbitrators().stream().map(Arbitrator::getNodeAddress).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Mediator> getAcceptedMediators() {
|
||||
return userPayload.getAcceptedMediators();
|
||||
}
|
||||
|
||||
public List<NodeAddress> getAcceptedMediatorAddresses() {
|
||||
return userPayload.getAcceptedMediators().stream().map(Mediator::getNodeAddress).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<String> getAcceptedLanguageLocaleCodes() {
|
||||
return userPayload.getAcceptedLanguageLocaleCodes() != null ? userPayload.getAcceptedLanguageLocaleCodes() : new ArrayList<>();
|
||||
}
|
||||
|
||||
public Arbitrator getAcceptedArbitratorByAddress(NodeAddress nodeAddress) {
|
||||
Optional<Arbitrator> arbitratorOptional = userPayload.getAcceptedArbitrators().stream()
|
||||
.filter(e -> e.getNodeAddress().equals(nodeAddress))
|
||||
@ -285,23 +143,6 @@ public final class User {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Filter getDevelopersFilter() {
|
||||
return userPayload.getDevelopersFilter();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Utils
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* public Optional<TradeCurrency> getPaymentAccountForCurrency(TradeCurrency tradeCurrency) {
|
||||
return getPaymentAccounts().stream()
|
||||
.flatMap(e -> e.getTradeCurrencies().stream())
|
||||
.filter(e -> e.equals(tradeCurrency))
|
||||
.findFirst();
|
||||
}*/
|
||||
|
||||
@Nullable
|
||||
public PaymentAccount findFirstPaymentAccountWithCurrency(TradeCurrency tradeCurrency) {
|
||||
for (PaymentAccount paymentAccount : userPayload.getPaymentAccounts()) {
|
||||
@ -329,9 +170,202 @@ public final class User {
|
||||
return findFirstPaymentAccountWithCurrency(tradeCurrency) != null;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Collection operations
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void addPaymentAccount(PaymentAccount paymentAccount) {
|
||||
boolean changed = paymentAccountsAsObservable.add(paymentAccount);
|
||||
setCurrentPaymentAccount(paymentAccount);
|
||||
if (changed)
|
||||
persist();
|
||||
}
|
||||
|
||||
public void removePaymentAccount(PaymentAccount paymentAccount) {
|
||||
boolean changed = paymentAccountsAsObservable.remove(paymentAccount);
|
||||
if (changed)
|
||||
persist();
|
||||
}
|
||||
|
||||
public boolean addAcceptedLanguageLocale(String localeCode) {
|
||||
boolean changed = userPayload.getAcceptedLanguageLocaleCodes() != null &&
|
||||
!userPayload.getAcceptedLanguageLocaleCodes().contains(localeCode) &&
|
||||
userPayload.getAcceptedLanguageLocaleCodes().add(localeCode);
|
||||
if (changed)
|
||||
persist();
|
||||
return changed;
|
||||
}
|
||||
|
||||
public boolean removeAcceptedLanguageLocale(String languageLocaleCode) {
|
||||
boolean changed = userPayload.getAcceptedLanguageLocaleCodes() != null &&
|
||||
userPayload.getAcceptedLanguageLocaleCodes().remove(languageLocaleCode);
|
||||
if (changed)
|
||||
persist();
|
||||
return changed;
|
||||
}
|
||||
|
||||
public void addAcceptedArbitrator(Arbitrator arbitrator) {
|
||||
if (userPayload.getAcceptedArbitrators() != null &&
|
||||
!userPayload.getAcceptedArbitrators().contains(arbitrator) &&
|
||||
!isMyOwnRegisteredArbitrator(arbitrator)) {
|
||||
boolean changed = userPayload.getAcceptedArbitrators().add(arbitrator);
|
||||
if (changed)
|
||||
persist();
|
||||
}
|
||||
}
|
||||
|
||||
public void addAcceptedMediator(Mediator mediator) {
|
||||
if (userPayload.getAcceptedMediators() != null &&
|
||||
!userPayload.getAcceptedMediators().contains(mediator) &&
|
||||
!isMyOwnRegisteredMediator(mediator)) {
|
||||
boolean changed = userPayload.getAcceptedMediators().add(mediator);
|
||||
if (changed)
|
||||
persist();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void removeAcceptedArbitrator(Arbitrator arbitrator) {
|
||||
if (userPayload.getAcceptedArbitrators() != null) {
|
||||
boolean changed = userPayload.getAcceptedArbitrators().remove(arbitrator);
|
||||
if (changed)
|
||||
persist();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAcceptedArbitrators() {
|
||||
if (userPayload.getAcceptedArbitrators() != null) {
|
||||
userPayload.getAcceptedArbitrators().clear();
|
||||
persist();
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAcceptedMediator(Mediator mediator) {
|
||||
if (userPayload.getAcceptedMediators() != null) {
|
||||
boolean changed = userPayload.getAcceptedMediators().remove(mediator);
|
||||
if (changed)
|
||||
persist();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAcceptedMediators() {
|
||||
if (userPayload.getAcceptedMediators() != null) {
|
||||
userPayload.getAcceptedMediators().clear();
|
||||
persist();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Setters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void setCurrentPaymentAccount(PaymentAccount paymentAccount) {
|
||||
currentPaymentAccountProperty.set(paymentAccount);
|
||||
persist();
|
||||
}
|
||||
|
||||
public void setRegisteredArbitrator(@Nullable Arbitrator arbitrator) {
|
||||
userPayload.setRegisteredArbitrator(arbitrator);
|
||||
persist();
|
||||
}
|
||||
|
||||
public void setRegisteredMediator(@Nullable Mediator mediator) {
|
||||
userPayload.setRegisteredMediator(mediator);
|
||||
persist();
|
||||
}
|
||||
|
||||
public void setDevelopersFilter(@Nullable Filter developersFilter) {
|
||||
userPayload.setDevelopersFilter(developersFilter);
|
||||
persist();
|
||||
}
|
||||
|
||||
public void setDevelopersAlert(@Nullable Alert developersAlert) {
|
||||
userPayload.setDevelopersAlert(developersAlert);
|
||||
storage.queueUpForSave();
|
||||
persist();
|
||||
}
|
||||
|
||||
public void setDisplayedAlert(@Nullable Alert displayedAlert) {
|
||||
userPayload.setDisplayedAlert(displayedAlert);
|
||||
persist();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getters
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Nullable
|
||||
public PaymentAccount getPaymentAccount(String paymentAccountId) {
|
||||
Optional<PaymentAccount> optional = userPayload.getPaymentAccounts().stream().filter(e -> e.getId().equals(paymentAccountId)).findAny();
|
||||
if (optional.isPresent())
|
||||
return optional.get();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getAccountId() {
|
||||
return userPayload.getAccountId();
|
||||
}
|
||||
|
||||
/* public boolean isRegistered() {
|
||||
return getAccountId() != null;
|
||||
}*/
|
||||
|
||||
private PaymentAccount getCurrentPaymentAccount() {
|
||||
return userPayload.getCurrentPaymentAccount();
|
||||
}
|
||||
|
||||
public ObjectProperty<PaymentAccount> currentPaymentAccountProperty() {
|
||||
return currentPaymentAccountProperty;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Set<PaymentAccount> getPaymentAccounts() {
|
||||
return userPayload.getPaymentAccounts();
|
||||
}
|
||||
|
||||
public ObservableSet<PaymentAccount> getPaymentAccountsAsObservable() {
|
||||
return paymentAccountsAsObservable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Arbitrator getRegisteredArbitrator() {
|
||||
return userPayload.getRegisteredArbitrator();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Mediator getRegisteredMediator() {
|
||||
return userPayload.getRegisteredMediator();
|
||||
}
|
||||
|
||||
public List<Arbitrator> getAcceptedArbitrators() {
|
||||
return userPayload.getAcceptedArbitrators();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<NodeAddress> getAcceptedArbitratorAddresses() {
|
||||
return userPayload.getAcceptedArbitrators().stream().map(Arbitrator::getNodeAddress).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Mediator> getAcceptedMediators() {
|
||||
return userPayload.getAcceptedMediators();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<NodeAddress> getAcceptedMediatorAddresses() {
|
||||
return userPayload.getAcceptedMediators().stream().map(Mediator::getNodeAddress).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<String> getAcceptedLanguageLocaleCodes() {
|
||||
return userPayload.getAcceptedLanguageLocaleCodes() != null ? userPayload.getAcceptedLanguageLocaleCodes() : new ArrayList<>();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Filter getDevelopersFilter() {
|
||||
return userPayload.getDevelopersFilter();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@ -339,13 +373,16 @@ public final class User {
|
||||
return userPayload.getDevelopersAlert();
|
||||
}
|
||||
|
||||
public void setDisplayedAlert(@Nullable Alert displayedAlert) {
|
||||
userPayload.setDisplayedAlert(displayedAlert);
|
||||
storage.queueUpForSave();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Alert getDisplayedAlert() {
|
||||
return userPayload.getDisplayedAlert();
|
||||
}
|
||||
|
||||
public boolean isMyOwnRegisteredArbitrator(Arbitrator arbitrator) {
|
||||
return arbitrator.equals(userPayload.getRegisteredArbitrator());
|
||||
}
|
||||
|
||||
public boolean isMyOwnRegisteredMediator(Mediator mediator) {
|
||||
return mediator.equals(userPayload.getRegisteredMediator());
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,8 @@
|
||||
|
||||
package io.bisq.core.user;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import io.bisq.common.proto.ProtoUtil;
|
||||
import io.bisq.common.proto.ProtoResolver;
|
||||
import io.bisq.common.proto.ProtoUtil;
|
||||
import io.bisq.common.proto.persistable.PersistableEnvelope;
|
||||
import io.bisq.core.alert.Alert;
|
||||
import io.bisq.core.arbitration.Arbitrator;
|
||||
@ -39,11 +38,13 @@ import java.util.stream.Collectors;
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class UserPayload implements PersistableEnvelope {
|
||||
// Persisted fields
|
||||
private String accountID;
|
||||
@Nullable
|
||||
private String accountId;
|
||||
@Nullable
|
||||
private Set<PaymentAccount> paymentAccounts = new HashSet<>();
|
||||
@Nullable
|
||||
private PaymentAccount currentPaymentAccount;
|
||||
@Nullable
|
||||
private List<String> acceptedLanguageLocaleCodes = new ArrayList<>();
|
||||
@Nullable
|
||||
private Alert developersAlert;
|
||||
@ -55,8 +56,9 @@ public class UserPayload implements PersistableEnvelope {
|
||||
private Arbitrator registeredArbitrator;
|
||||
@Nullable
|
||||
private Mediator registeredMediator;
|
||||
|
||||
@Nullable
|
||||
private List<Arbitrator> acceptedArbitrators = new ArrayList<>();
|
||||
@Nullable
|
||||
private List<Mediator> acceptedMediators = new ArrayList<>();
|
||||
|
||||
public UserPayload() {
|
||||
@ -64,15 +66,14 @@ public class UserPayload implements PersistableEnvelope {
|
||||
|
||||
@Override
|
||||
public PB.PersistableEnvelope toProtoMessage() {
|
||||
PB.UserPayload.Builder builder = PB.UserPayload.newBuilder()
|
||||
.setAccountId(accountID)
|
||||
.addAllPaymentAccounts(ProtoUtil.collectionToProto(paymentAccounts))
|
||||
.addAllAcceptedLanguageLocaleCodes(acceptedLanguageLocaleCodes)
|
||||
.addAllAcceptedArbitrators(ProtoUtil.collectionToProto(acceptedArbitrators, (Message storage) -> ((PB.StoragePayload) storage).getArbitrator()))
|
||||
.addAllAcceptedMediators(ProtoUtil.collectionToProto(acceptedMediators, (Message storage) -> ((PB.StoragePayload) storage).getMediator()));
|
||||
|
||||
PB.UserPayload.Builder builder = PB.UserPayload.newBuilder();
|
||||
Optional.ofNullable(accountId).ifPresent(e -> builder.setAccountId(accountId));
|
||||
Optional.ofNullable(paymentAccounts)
|
||||
.ifPresent(e -> builder.addAllPaymentAccounts(ProtoUtil.collectionToProto(paymentAccounts)));
|
||||
Optional.ofNullable(currentPaymentAccount)
|
||||
.ifPresent(paymentAccount -> builder.setCurrentPaymentAccount(paymentAccount.toProtoMessage()));
|
||||
.ifPresent(e -> builder.setCurrentPaymentAccount(currentPaymentAccount.toProtoMessage()));
|
||||
Optional.ofNullable(acceptedLanguageLocaleCodes)
|
||||
.ifPresent(e -> builder.addAllAcceptedLanguageLocaleCodes(acceptedLanguageLocaleCodes));
|
||||
Optional.ofNullable(developersAlert)
|
||||
.ifPresent(developersAlert -> builder.setDevelopersAlert(developersAlert.toProtoMessage().getAlert()));
|
||||
Optional.ofNullable(displayedAlert)
|
||||
@ -83,21 +84,50 @@ public class UserPayload implements PersistableEnvelope {
|
||||
.ifPresent(registeredArbitrator -> builder.setRegisteredArbitrator(registeredArbitrator.toProtoMessage().getArbitrator()));
|
||||
Optional.ofNullable(registeredMediator)
|
||||
.ifPresent(developersAlert -> builder.setDevelopersAlert(developersAlert.toProtoMessage().getAlert()));
|
||||
Optional.ofNullable(acceptedArbitrators)
|
||||
.ifPresent(e -> builder.addAllAcceptedArbitrators(ProtoUtil.collectionToProto(acceptedArbitrators,
|
||||
storage -> ((PB.StoragePayload) storage).getArbitrator())));
|
||||
Optional.ofNullable(acceptedMediators)
|
||||
.ifPresent(e -> builder.addAllAcceptedMediators(ProtoUtil.collectionToProto(acceptedMediators,
|
||||
storage -> ((PB.StoragePayload) storage).getMediator())));
|
||||
return PB.PersistableEnvelope.newBuilder().setUserPayload(builder).build();
|
||||
}
|
||||
|
||||
public static UserPayload fromProto(PB.UserPayload proto, ProtoResolver resolver) {
|
||||
return new UserPayload(proto.getAccountId(),
|
||||
proto.getPaymentAccountsList().stream().map(e -> PaymentAccount.fromProto(e, resolver)).collect(Collectors.toSet()),
|
||||
return new UserPayload(
|
||||
proto.getAccountId().isEmpty() ? null : proto.getAccountId(),
|
||||
proto.getPaymentAccountsList().isEmpty() ? null : proto.getPaymentAccountsList().stream()
|
||||
.map(e -> PaymentAccount.fromProto(e, resolver))
|
||||
.collect(Collectors.toSet()),
|
||||
proto.hasCurrentPaymentAccount() ? PaymentAccount.fromProto(proto.getCurrentPaymentAccount(), resolver) : null,
|
||||
proto.getAcceptedLanguageLocaleCodesList(),
|
||||
proto.getAcceptedLanguageLocaleCodesList().isEmpty() ? null : new ArrayList<>(proto.getAcceptedLanguageLocaleCodesList()),
|
||||
proto.hasDevelopersAlert() ? Alert.fromProto(proto.getDevelopersAlert()) : null,
|
||||
proto.hasDisplayedAlert() ? Alert.fromProto(proto.getDisplayedAlert()) : null,
|
||||
proto.hasDevelopersFilter() ? Filter.fromProto(proto.getDevelopersFilter()) : null,
|
||||
proto.hasRegisteredArbitrator() ? Arbitrator.fromProto(proto.getRegisteredArbitrator()) : null,
|
||||
proto.hasRegisteredMediator() ? Mediator.fromProto(proto.getRegisteredMediator()) : null,
|
||||
proto.getAcceptedArbitratorsList().stream().map(Arbitrator::fromProto).collect(Collectors.toList()),
|
||||
proto.getAcceptedMediatorsList().stream().map(Mediator::fromProto).collect(Collectors.toList())
|
||||
proto.getAcceptedArbitratorsList().isEmpty() ? null : proto.getAcceptedArbitratorsList().stream()
|
||||
.map(Arbitrator::fromProto)
|
||||
.collect(Collectors.toList()),
|
||||
proto.getAcceptedMediatorsList().isEmpty() ? null : proto.getAcceptedMediatorsList().stream()
|
||||
.map(Mediator::fromProto)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
/*
|
||||
public void apply(UserPayload persisted) {
|
||||
if (persisted != null) {
|
||||
accountId = persisted.getAccountId();
|
||||
paymentAccounts = persisted.getPaymentAccounts();
|
||||
currentPaymentAccount = persisted.getCurrentPaymentAccount();
|
||||
acceptedLanguageLocaleCodes = persisted.getAcceptedLanguageLocaleCodes();
|
||||
developersAlert = persisted.getDevelopersAlert();
|
||||
displayedAlert = persisted.getDisplayedAlert();
|
||||
developersFilter = persisted.getDevelopersFilter();
|
||||
registeredArbitrator = persisted.getRegisteredArbitrator();
|
||||
registeredMediator = persisted.getRegisteredMediator();
|
||||
acceptedArbitrators = persisted.getAcceptedArbitrators();
|
||||
acceptedMediators = persisted.getAcceptedMediators();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class UserPayloadModelVOTest {
|
||||
@Test
|
||||
public void testRoundtrip() {
|
||||
UserPayload vo = new UserPayload();
|
||||
vo.setAccountID("accountId");
|
||||
vo.setAccountId("accountId");
|
||||
|
||||
UserPayload newVo = UserPayload.fromProto(vo.toProtoMessage().getUserPayload(), new CoreProtoResolver());
|
||||
}
|
||||
@ -38,7 +38,7 @@ public class UserPayloadModelVOTest {
|
||||
@Test
|
||||
public void testRoundtripFull() {
|
||||
UserPayload vo = new UserPayload();
|
||||
vo.setAccountID("accountId");
|
||||
vo.setAccountId("accountId");
|
||||
vo.setDisplayedAlert(new Alert("message", true, "version", new byte[]{12,-64,12}, "string", null));
|
||||
vo.setDevelopersFilter(new Filter(Lists.newArrayList(), Lists.newArrayList(), Lists.newArrayList(), "string", new byte[]{10,0,0}, null));
|
||||
vo.setRegisteredArbitrator(ArbitratorTest.getArbitratorMock());
|
||||
|
@ -174,13 +174,12 @@ public class BisqApp extends Application {
|
||||
grapher.setRankdir("TB");
|
||||
grapher.graph(injector);
|
||||
*/
|
||||
Preferences preferences = injector.getInstance(Preferences.class);
|
||||
preferences.init();
|
||||
User user = injector.getInstance(User.class);
|
||||
user.init();
|
||||
|
||||
// All classes which are persisting objects need to be added here
|
||||
// Maintain order!
|
||||
ArrayList<PersistedDataHost> persistedDataHosts = new ArrayList<>();
|
||||
persistedDataHosts.add(injector.getInstance(Preferences.class));
|
||||
persistedDataHosts.add(injector.getInstance(User.class));
|
||||
persistedDataHosts.add(injector.getInstance(Navigation.class));
|
||||
persistedDataHosts.add(injector.getInstance(AddressEntryList.class));
|
||||
persistedDataHosts.add(injector.getInstance(TradeStatisticsManager.class));
|
||||
@ -190,7 +189,10 @@ public class BisqApp extends Application {
|
||||
persistedDataHosts.add(injector.getInstance(FailedTradesManager.class));
|
||||
|
||||
// we apply at startup the reading of persisted data but don't want to get it triggered in the constructor
|
||||
persistedDataHosts.stream().forEach(PersistedDataHost::readPersisted);
|
||||
persistedDataHosts.stream().forEach(e -> {
|
||||
log.info("call readPersisted at " + e.getClass().getSimpleName());
|
||||
e.readPersisted();
|
||||
});
|
||||
|
||||
Version.setBtcNetworkId(injector.getInstance(BisqEnvironment.class).getBitcoinNetwork().ordinal());
|
||||
Version.printVersion();
|
||||
|
@ -566,7 +566,6 @@ public class MainViewModel implements ViewModel {
|
||||
updateBalance();
|
||||
if (DevEnv.DEV_MODE) {
|
||||
preferences.setShowOwnOffersInOfferBook(true);
|
||||
if (user.getPaymentAccounts().isEmpty())
|
||||
setupDevDummyPaymentAccounts();
|
||||
}
|
||||
|
||||
@ -1021,6 +1020,7 @@ public class MainViewModel implements ViewModel {
|
||||
}
|
||||
|
||||
private void setupDevDummyPaymentAccounts() {
|
||||
if (user.getPaymentAccounts() != null && user.getPaymentAccounts().isEmpty()) {
|
||||
OKPayAccount okPayAccount = new OKPayAccount();
|
||||
okPayAccount.setAccountNr("dummy_" + new Random().nextInt(100));
|
||||
okPayAccount.setAccountName("OKPay dummy");// Don't translate only for dev
|
||||
@ -1034,3 +1034,4 @@ public class MainViewModel implements ViewModel {
|
||||
user.addPaymentAccount(cryptoCurrencyAccount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ class OfferBookChartViewModel extends ActivatableViewModel {
|
||||
|
||||
private void syncPriceFeedCurrency() {
|
||||
if (selectedTabIndex == TAB_INDEX)
|
||||
priceFeedService.setCurrencyCode(selectedTradeCurrencyProperty.get().getCode());
|
||||
priceFeedService.setCurrencyCode(getCurrencyCode());
|
||||
}
|
||||
|
||||
private boolean isAnyPricePresent() {
|
||||
|
Loading…
Reference in New Issue
Block a user