From d73a43271c1bcf345b7714bd40453ee5280243a4 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 25 Mar 2015 11:01:19 +0100 Subject: [PATCH] Change Currency to CurrencyCode --- .../io/bitsquare/arbitration/Arbitrator.java | 79 ++++++++----------- .../java/io/bitsquare/fiat/FiatAccount.java | 13 ++- .../io/bitsquare/gui/main/MainViewModel.java | 3 +- .../ArbitratorRegistrationView.java | 3 - .../content/fiat/FiatAccountDataModel.java | 18 ++--- .../account/content/fiat/FiatAccountView.java | 9 +-- .../content/fiat/FiatAccountViewModel.java | 27 +++---- .../content/irc/IrcAccountDataModel.java | 14 ++-- .../account/content/irc/IrcAccountView.java | 27 +++---- .../content/irc/IrcAccountViewModel.java | 28 +++---- .../pending/PendingTradesDataModel.java | 2 +- .../createoffer/CreateOfferDataModel.java | 4 +- .../trade/offerbook/OfferBookDataModel.java | 4 +- .../trade/takeoffer/TakeOfferViewModel.java | 5 +- .../io/bitsquare/gui/util/BSFormatter.java | 8 +- .../gui/util/validation/FiatValidator.java | 6 +- .../validation/OptionalFiatValidator.java | 6 +- .../io/bitsquare/locale/CurrencyUtil.java | 19 ++++- .../main/java/io/bitsquare/offer/Offer.java | 19 +++-- .../java/io/bitsquare/offer/OfferBook.java | 4 +- .../offer/tomp2p/TomP2POfferBookService.java | 8 +- .../java/io/bitsquare/trade/TradeManager.java | 2 +- 22 files changed, 150 insertions(+), 158 deletions(-) diff --git a/core/src/main/java/io/bitsquare/arbitration/Arbitrator.java b/core/src/main/java/io/bitsquare/arbitration/Arbitrator.java index 1c9ad38beb..b9e76a0216 100644 --- a/core/src/main/java/io/bitsquare/arbitration/Arbitrator.java +++ b/core/src/main/java/io/bitsquare/arbitration/Arbitrator.java @@ -31,6 +31,7 @@ import java.security.PublicKey; import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.UUID; import javax.inject.Inject; @@ -71,7 +72,6 @@ public class Arbitrator implements Serializable { transient private Storage storage; - transient private boolean saveOnEveryUpdate; // Persisted fields private String id; @@ -82,9 +82,8 @@ public class Arbitrator implements Serializable { // editable private ID_TYPE idType; - // TODO languages breaks something in serialisation with TomP2P when uing Locale. cannot remove an offer private List languages; - + private Coin fee; private List arbitrationMethods; private List idVerifications; @@ -99,47 +98,43 @@ public class Arbitrator implements Serializable { Arbitrator persisted = storage.initAndGetPersisted(this); if (persisted != null) { //TODO for mock arbitrator - id = persisted.getName(); - this.pubKey = persisted.getPubKey(); - this.p2pSigPubKey = persisted.getP2pSigPubKey(); - this.name = persisted.getName(); - this.idType = persisted.getIdType(); - this.languages = persisted.getLanguages(); - this.reputation = persisted.getReputation(); - this.fee = persisted.getFee(); - this.arbitrationMethods = persisted.getArbitrationMethods(); - this.idVerifications = persisted.getIdVerifications(); - this.webUrl = persisted.getWebUrl(); - this.description = persisted.getDescription(); + id = persisted.getId(); + pubKey = persisted.getPubKey(); + p2pSigPubKey = persisted.getP2pSigPubKey(); + name = persisted.getName(); + idType = persisted.getIdType(); + languages = persisted.getLanguages(); + reputation = persisted.getReputation(); + fee = persisted.getFee(); + arbitrationMethods = persisted.getArbitrationMethods(); + idVerifications = persisted.getIdVerifications(); + webUrl = persisted.getWebUrl(); + description = persisted.getDescription(); } else { // Mock - id = "Manfred Karrer"; - this.pubKey = new ECKey().getPubKey(); - this.p2pSigPubKey = user.getP2PSigPubKey(); - this.name = "Manfred Karrer"; - this.idType = Arbitrator.ID_TYPE.REAL_LIFE_ID; - this.languages = Arrays.asList(LanguageUtil.getDefaultLanguageLocale().getISO3Language()); - this.reputation = new Reputation(); - this.fee = Coin.parseCoin("0.1"); - this.arbitrationMethods = Arrays.asList(Arbitrator.METHOD.TLS_NOTARY); - this.idVerifications = Arrays.asList(ID_VERIFICATION.PASSPORT); - this.webUrl = "https://bitsquare.io"; - this.description = "Bla bla..."; - doSave(); + id = UUID.randomUUID().toString(); + pubKey = new ECKey().getPubKey(); + p2pSigPubKey = user.getP2PSigPubKey(); + name = "Mr. Default"; + idType = Arbitrator.ID_TYPE.REAL_LIFE_ID; + languages = Arrays.asList(LanguageUtil.getDefaultLanguageLocale().getISO3Language()); + reputation = new Reputation(); + fee = Coin.parseCoin("0.1"); + arbitrationMethods = Arrays.asList(Arbitrator.METHOD.TLS_NOTARY); + idVerifications = Arrays.asList(ID_VERIFICATION.PASSPORT); + webUrl = "https://bitsquare.io"; + description = "Bla bla..."; + save(); } } public void save() { - if (saveOnEveryUpdate) - doSave(); - } - - private void doSave() { storage.save(); } + @Override public int hashCode() { if (id != null) { @@ -168,43 +163,39 @@ public class Arbitrator implements Serializable { // Setters /////////////////////////////////////////////////////////////////////////////////////////// - public void setSaveOnEveryUpdate(boolean saveOnEveryUpdate) { - this.saveOnEveryUpdate = saveOnEveryUpdate; - } - public void setDescription(String description) { this.description = description; - doSave(); + save(); } public void setIdType(ID_TYPE idType) { this.idType = idType; - doSave(); + save(); } public void setLanguages(List languages) { this.languages = languages; - doSave(); + save(); } public void setFee(Coin fee) { this.fee = fee; - doSave(); + save(); } public void setArbitrationMethods(List arbitrationMethods) { this.arbitrationMethods = arbitrationMethods; - doSave(); + save(); } public void setIdVerifications(List idVerifications) { this.idVerifications = idVerifications; - doSave(); + save(); } public void setWebUrl(String webUrl) { this.webUrl = webUrl; - doSave(); + save(); } diff --git a/core/src/main/java/io/bitsquare/fiat/FiatAccount.java b/core/src/main/java/io/bitsquare/fiat/FiatAccount.java index 3c3cb30664..94d18ed497 100644 --- a/core/src/main/java/io/bitsquare/fiat/FiatAccount.java +++ b/core/src/main/java/io/bitsquare/fiat/FiatAccount.java @@ -21,7 +21,6 @@ import io.bitsquare.locale.Country; import java.io.Serializable; -import java.util.Currency; import java.util.Objects; import javax.annotation.concurrent.Immutable; @@ -40,17 +39,17 @@ public class FiatAccount implements Serializable { // The main currency if account support multiple currencies. // The user can create multiple bank accounts with same bank account but other currency if his bank account // support that. - private final Currency currency; + private final String currencyCode; /////////////////////////////////////////////////////////////////////////////////////////// // Constructor /////////////////////////////////////////////////////////////////////////////////////////// - public FiatAccount(FiatAccountType fiatAccountType, Currency currency, Country country, String nameOfBank, + public FiatAccount(FiatAccountType fiatAccountType, String currencyCode, Country country, String nameOfBank, String accountHolderName, String accountPrimaryID, String accountSecondaryID) { this.fiatAccountType = fiatAccountType; - this.currency = currency; + this.currencyCode = currencyCode; this.country = country; this.nameOfBank = nameOfBank; this.accountHolderName = accountHolderName; @@ -79,8 +78,8 @@ public class FiatAccount implements Serializable { return fiatAccountType; } - public Currency getCurrency() { - return currency; + public String getCurrencyCode() { + return currencyCode; } public Country getCountry() { @@ -123,7 +122,7 @@ public class FiatAccount implements Serializable { ", accountSecondaryID='" + accountSecondaryID + '\'' + ", accountHolderName='" + accountHolderName + '\'' + ", country=" + country + - ", currency=" + currency + + ", currency=" + currencyCode + ", accountTitle='" + nameOfBank + '\'' + '}'; } diff --git a/core/src/main/java/io/bitsquare/gui/main/MainViewModel.java b/core/src/main/java/io/bitsquare/gui/main/MainViewModel.java index ae96b8152a..6dc5e837cc 100644 --- a/core/src/main/java/io/bitsquare/gui/main/MainViewModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/MainViewModel.java @@ -34,7 +34,6 @@ import io.bitsquare.user.User; import com.google.inject.Inject; -import java.util.Currency; import java.util.concurrent.TimeoutException; import javafx.application.Platform; @@ -192,7 +191,7 @@ class MainViewModel implements ViewModel { // For alpha version if (!user.isRegistered()) { FiatAccount fiatAccount = new FiatAccount(FiatAccountType.IRC, - Currency.getInstance("EUR"), + "EUR", CountryUtil.getDefaultCountry(), "Demo (Name of bank)", "Demo (Account holder name)", diff --git a/core/src/main/java/io/bitsquare/gui/main/account/arbitrator/registration/ArbitratorRegistrationView.java b/core/src/main/java/io/bitsquare/gui/main/account/arbitrator/registration/ArbitratorRegistrationView.java index 9deba56694..4a81c3087f 100644 --- a/core/src/main/java/io/bitsquare/gui/main/account/arbitrator/registration/ArbitratorRegistrationView.java +++ b/core/src/main/java/io/bitsquare/gui/main/account/arbitrator/registration/ArbitratorRegistrationView.java @@ -244,15 +244,12 @@ public class ArbitratorRegistrationView extends ActivatableView type = new SimpleObjectProperty<>(); final ObjectProperty country = new SimpleObjectProperty<>(); - final ObjectProperty currency = new SimpleObjectProperty<>(); final ObservableList allTypes = FXCollections.observableArrayList(FiatAccountType .getAllBankAccountTypes()); final ObservableList allFiatAccounts = FXCollections.observableArrayList(); - final ObservableList allCurrencies = FXCollections.observableArrayList(CurrencyUtil - .getAllCurrencies()); + final ObservableList allCurrencyCodes = FXCollections.observableArrayList(CurrencyUtil + .getAllCurrencyCodes()); final ObservableList allRegions = FXCollections.observableArrayList(CountryUtil.getAllRegions()); @@ -85,7 +83,7 @@ class FiatAccountDataModel implements Activatable, DataModel { void saveBankAccount() { FiatAccount fiatAccount = new FiatAccount(type.get(), - currency.get(), + currencyCode.get(), country.get(), title.get(), holderName.get(), @@ -123,7 +121,7 @@ class FiatAccountDataModel implements Activatable, DataModel { type.set(fiatAccount.getFiatAccountType()); country.set(fiatAccount.getCountry()); - currency.set(fiatAccount.getCurrency()); + currencyCode.set(fiatAccount.getCurrencyCode()); } else { reset(); @@ -153,8 +151,8 @@ class FiatAccountDataModel implements Activatable, DataModel { this.country.set(country); } - void setCurrency(Currency currency) { - this.currency.set(currency); + void setCurrencyCode(String currencyCode) { + this.currencyCode.set(currencyCode); } @@ -168,6 +166,6 @@ class FiatAccountDataModel implements Activatable, DataModel { type.set(null); country.set(null); - currency.set(null); + currencyCode.set(null); } } diff --git a/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.java b/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.java index a404745b96..33a35dcaf4 100644 --- a/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.java +++ b/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.java @@ -33,7 +33,6 @@ import io.bitsquare.locale.Country; import io.bitsquare.locale.Region; import java.util.ArrayList; -import java.util.Currency; import java.util.List; import javax.inject.Inject; @@ -60,7 +59,7 @@ public class FiatAccountView extends ActivatableViewAndModel selectionComboBox; @FXML ComboBox typesComboBox; - @FXML ComboBox currencyComboBox; + @FXML ComboBox currencyComboBox; private Wizard wizard; @@ -77,7 +76,7 @@ public class FiatAccountView extends ActivatableViewAndModel { + model.currencyCode.addListener((ov, oldValue, newValue) -> { if (newValue != null) currencyComboBox.getSelectionModel().select(currencyComboBox.getItems().indexOf(newValue)); else diff --git a/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewModel.java b/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewModel.java index a9028fc448..2d11a215e7 100644 --- a/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/account/content/fiat/FiatAccountViewModel.java @@ -25,12 +25,11 @@ import io.bitsquare.gui.util.validation.BankAccountNumberValidator; import io.bitsquare.gui.util.validation.InputValidator; import io.bitsquare.locale.BSResources; import io.bitsquare.locale.Country; +import io.bitsquare.locale.CurrencyUtil; import io.bitsquare.locale.Region; import com.google.inject.Inject; -import java.util.Currency; - import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleBooleanProperty; @@ -52,11 +51,11 @@ class FiatAccountViewModel extends ActivatableWithDataModel type = new SimpleObjectProperty<>(); final ObjectProperty country = new SimpleObjectProperty<>(); - final ObjectProperty currency = new SimpleObjectProperty<>(); @Inject @@ -71,7 +70,7 @@ class FiatAccountViewModel extends ActivatableWithDataModel getCurrencyConverter() { - return new StringConverter() { + StringConverter getCurrencyConverter() { + return new StringConverter() { @Override - public String toString(Currency currency) { - return currency.getCurrencyCode() + " (" + currency.getDisplayName() + ")"; + public String toString(String currencyCode) { + return currencyCode+ " (" + CurrencyUtil.getDisplayName(currencyCode) + ")"; } @Override - public Currency fromString(String s) { + public String fromString(String s) { return null; } }; @@ -194,8 +193,8 @@ class FiatAccountViewModel extends ActivatableWithDataModel getAllCurrencies() { - return dataModel.allCurrencies; + ObservableList getAllCurrencyCodes() { + return dataModel.allCurrencyCodes; } ObservableList getAllRegions() { @@ -225,8 +224,8 @@ class FiatAccountViewModel extends ActivatableWithDataModel type = new SimpleObjectProperty<>(); - final ObjectProperty currency = new SimpleObjectProperty<>(); final ObservableList allTypes = FXCollections.observableArrayList(FiatAccountType.getAllBankAccountTypes()); - final ObservableList allCurrencies = FXCollections.observableArrayList(CurrencyUtil.getAllCurrencies()); + final ObservableList allCurrencyCodes = FXCollections.observableArrayList(CurrencyUtil.getAllCurrencyCodes()); final ObservableList allFiatAccounts = FXCollections.observableArrayList(); @@ -67,7 +65,7 @@ class IrcAccountDataModel implements Activatable, DataModel { void saveBankAccount() { FiatAccount fiatAccount = new FiatAccount(type.get(), - currency.get(), + currencyCode.get(), CountryUtil.getDefaultCountry(), nickName.get(), nickName.get(), @@ -82,14 +80,14 @@ class IrcAccountDataModel implements Activatable, DataModel { this.type.set(type); } - void setCurrency(Currency currency) { - this.currency.set(currency); + void setCurrencyCode(String currencyCode) { + this.currencyCode.set(currencyCode); } private void reset() { nickName.set(null); type.set(null); - currency.set(null); + currencyCode.set(null); } } diff --git a/core/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountView.java b/core/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountView.java index d35f6af570..d68e12069d 100644 --- a/core/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountView.java +++ b/core/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountView.java @@ -25,10 +25,9 @@ import io.bitsquare.gui.components.InputTextField; import io.bitsquare.gui.components.Popups; import io.bitsquare.gui.main.help.Help; import io.bitsquare.gui.main.help.HelpId; +import io.bitsquare.locale.CurrencyUtil; import io.bitsquare.util.Utilities; -import java.util.Currency; - import javax.inject.Inject; import javafx.application.Platform; @@ -47,7 +46,7 @@ public class IrcAccountView extends ActivatableViewAndModel typesComboBox; - @FXML ComboBox currencyComboBox; + @FXML ComboBox currencyComboBox; private Wizard wizard; @@ -87,25 +86,25 @@ public class IrcAccountView extends ActivatableViewAndModel, ListCell>() { + currencyComboBox.setCellFactory(new Callback, ListCell>() { @Override - public ListCell call(ListView p) { - return new ListCell() { + public ListCell call(ListView p) { + return new ListCell() { @Override - protected void updateItem(Currency currency, boolean empty) { - super.updateItem(currency, empty); + protected void updateItem(String currencyCode, boolean empty) { + super.updateItem(currencyCode, empty); - if (currency == null || empty) { + if (currencyCode == null || empty) { setGraphic(null); } else { - setText(currency.getCurrencyCode() + " (" + currency.getDisplayName() + ")"); + setText(currencyCode+ " (" + CurrencyUtil.getDisplayName(currencyCode) + ")"); - if (!currency.getCurrencyCode().equals("EUR")) { + if (!currencyCode.equals("EUR")) { setOpacity(0.3); setDisable(true); } @@ -146,7 +145,7 @@ public class IrcAccountView extends ActivatableViewAndModel { + model.currencyCode.addListener((ov, oldValue, newValue) -> { if (newValue != null) currencyComboBox.getSelectionModel().select(currencyComboBox.getItems().indexOf(newValue)); else diff --git a/core/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountViewModel.java b/core/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountViewModel.java index d0cb43aaf9..b2f283d62e 100644 --- a/core/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountViewModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/account/content/irc/IrcAccountViewModel.java @@ -23,11 +23,10 @@ import io.bitsquare.fiat.FiatAccountType; import io.bitsquare.gui.util.validation.BankAccountNumberValidator; import io.bitsquare.gui.util.validation.InputValidator; import io.bitsquare.locale.BSResources; +import io.bitsquare.locale.CurrencyUtil; import com.google.inject.Inject; -import java.util.Currency; - import javafx.beans.property.BooleanProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleBooleanProperty; @@ -42,10 +41,9 @@ class IrcAccountViewModel extends ActivatableWithDataModel private final InputValidator nickNameValidator; final StringProperty ircNickName = new SimpleStringProperty(); + final StringProperty currencyCode = new SimpleStringProperty(); final BooleanProperty saveButtonDisable = new SimpleBooleanProperty(true); final ObjectProperty type = new SimpleObjectProperty<>(); - final ObjectProperty currency = new SimpleObjectProperty<>(); - @Inject public IrcAccountViewModel(IrcAccountDataModel dataModel, BankAccountNumberValidator nickNameValidator) { @@ -55,7 +53,7 @@ class IrcAccountViewModel extends ActivatableWithDataModel // input ircNickName.bindBidirectional(dataModel.nickName); type.bindBidirectional(dataModel.type); - currency.bindBidirectional(dataModel.currency); + currencyCode.bindBidirectional(dataModel.currencyCode); dataModel.nickName.addListener((ov, oldValue, newValue) -> validateInput()); } @@ -87,15 +85,15 @@ class IrcAccountViewModel extends ActivatableWithDataModel return fiatAccountType != null ? BSResources.get(fiatAccountType.toString()) : ""; } - StringConverter getCurrencyConverter() { - return new StringConverter() { + StringConverter getCurrencyConverter() { + return new StringConverter() { @Override - public String toString(Currency currency) { - return currency.getCurrencyCode() + " (" + currency.getDisplayName() + ")"; + public String toString(String currencyCode) { + return currencyCode + " (" + CurrencyUtil.getDisplayName(currencyCode) + ")"; } @Override - public Currency fromString(String s) { + public String fromString(String s) { return null; } }; @@ -106,8 +104,8 @@ class IrcAccountViewModel extends ActivatableWithDataModel return dataModel.allTypes; } - ObservableList getAllCurrencies() { - return dataModel.allCurrencies; + ObservableList getAllCurrencyCodes() { + return dataModel.allCurrencyCodes; } InputValidator getNickNameValidator() { @@ -120,15 +118,15 @@ class IrcAccountViewModel extends ActivatableWithDataModel validateInput(); } - void setCurrency(Currency currency) { - dataModel.setCurrency(currency); + void setCurrencyCode(String currencyCode) { + dataModel.setCurrencyCode(currencyCode); validateInput(); } private InputValidator.ValidationResult validateInput() { InputValidator.ValidationResult result = nickNameValidator.validate(dataModel.nickName.get()); - if (dataModel.currency.get() == null) + if (dataModel.currencyCode.get() == null) result = new InputValidator.ValidationResult(false, "You have not selected a currency"); if (result.isValid) { diff --git a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesDataModel.java b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesDataModel.java index 08474b6d9b..0ea3c519cd 100644 --- a/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesDataModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/portfolio/pending/PendingTradesDataModel.java @@ -229,7 +229,7 @@ class PendingTradesDataModel implements Activatable, DataModel { } String getCurrencyCode() { - return selectedItem.getTrade().getOffer().getCurrency().getCurrencyCode(); + return selectedItem.getTrade().getOffer().getCurrencyCode(); } public Offer.Direction getDirection(Offer offer) { diff --git a/core/src/main/java/io/bitsquare/gui/main/trade/createoffer/CreateOfferDataModel.java b/core/src/main/java/io/bitsquare/gui/main/trade/createoffer/CreateOfferDataModel.java index db2a84de5a..f933afe55f 100644 --- a/core/src/main/java/io/bitsquare/gui/main/trade/createoffer/CreateOfferDataModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/trade/createoffer/CreateOfferDataModel.java @@ -261,10 +261,10 @@ class CreateOfferDataModel implements Activatable, DataModel { private void applyBankAccount(FiatAccount fiatAccount) { if (fiatAccount != null) { bankAccountType.set(fiatAccount.getFiatAccountType().toString()); - bankAccountCurrency.set(fiatAccount.getCurrency().getCurrencyCode()); + bankAccountCurrency.set(fiatAccount.getCurrencyCode()); bankAccountCounty.set(fiatAccount.getCountry().getName()); - fiatCode.set(fiatAccount.getCurrency().getCurrencyCode()); + fiatCode.set(fiatAccount.getCurrencyCode()); } } diff --git a/core/src/main/java/io/bitsquare/gui/main/trade/offerbook/OfferBookDataModel.java b/core/src/main/java/io/bitsquare/gui/main/trade/offerbook/OfferBookDataModel.java index e94d706cbe..655573d39b 100644 --- a/core/src/main/java/io/bitsquare/gui/main/trade/offerbook/OfferBookDataModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/trade/offerbook/OfferBookDataModel.java @@ -245,12 +245,12 @@ class OfferBookDataModel implements Activatable, DataModel { private void setBankAccount(FiatAccount fiatAccount) { if (fiatAccount != null) { - fiatCode.set(fiatAccount.getCurrency().getCurrencyCode()); + fiatCode.set(fiatAccount.getCurrencyCode()); bankAccountCountry.set(fiatAccount.getCountry()); sortedItems.stream().forEach(e -> e.setBankAccountCountry(fiatAccount.getCountry())); } else { - fiatCode.set(CurrencyUtil.getDefaultCurrency().getCurrencyCode()); + fiatCode.set(CurrencyUtil.getDefaultCurrencyAsCode()); } } diff --git a/core/src/main/java/io/bitsquare/gui/main/trade/takeoffer/TakeOfferViewModel.java b/core/src/main/java/io/bitsquare/gui/main/trade/takeoffer/TakeOfferViewModel.java index 09df38527e..4402a13b8a 100644 --- a/core/src/main/java/io/bitsquare/gui/main/trade/takeoffer/TakeOfferViewModel.java +++ b/core/src/main/java/io/bitsquare/gui/main/trade/takeoffer/TakeOfferViewModel.java @@ -24,6 +24,7 @@ import io.bitsquare.gui.util.BSFormatter; import io.bitsquare.gui.util.validation.BtcValidator; import io.bitsquare.gui.util.validation.InputValidator; import io.bitsquare.locale.BSResources; +import io.bitsquare.locale.CurrencyUtil; import io.bitsquare.offer.Offer; import org.bitcoinj.core.Address; @@ -120,7 +121,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel im directionLabel = direction == Offer.Direction.BUY ? BSResources.get("shared.buy") : BSResources.get("shared.sell"); - fiatCode = offer.getCurrency().getCurrencyCode(); + fiatCode = offer.getCurrencyCode(); if (!dataModel.isMinAmountLessOrEqualAmount()) { amountValidationResult.set(new InputValidator.ValidationResult(false, BSResources.get("takeOffer.validation.amountSmallerThanMinAmount"))); @@ -142,7 +143,7 @@ class TakeOfferViewModel extends ActivatableWithDataModel im acceptedLanguages = formatter.languageLocalesToString(offer.getAcceptedLanguageLocales()); acceptedArbitrators = formatter.arbitratorsToString(offer.getArbitrators()); bankAccountType = BSResources.get(offer.getFiatAccountType().toString()); - bankAccountCurrency = BSResources.get(offer.getCurrency().getDisplayName()); + bankAccountCurrency = BSResources.get(CurrencyUtil.getDisplayName(offer.getCurrencyCode())); bankAccountCounty = BSResources.get(offer.getBankAccountCountry().getName()); offer.stateProperty().addListener((ov, oldValue, newValue) -> applyOfferState(newValue)); diff --git a/core/src/main/java/io/bitsquare/gui/util/BSFormatter.java b/core/src/main/java/io/bitsquare/gui/util/BSFormatter.java index c02b08ddf8..3d9d192eb3 100644 --- a/core/src/main/java/io/bitsquare/gui/util/BSFormatter.java +++ b/core/src/main/java/io/bitsquare/gui/util/BSFormatter.java @@ -67,7 +67,7 @@ public class BSFormatter { // no way to remove grouping separator). It seems to be not optimal for user input formatting. private MonetaryFormat coinFormat = MonetaryFormat.BTC.repeatOptionalDecimals(2, 2); - private String currencyCode = CurrencyUtil.getDefaultCurrency().getCurrencyCode(); + private String currencyCode = CurrencyUtil.getDefaultCurrencyAsCode(); // format is like: 1,00 never more then 2 decimals private final MonetaryFormat fiatFormat = MonetaryFormat.FIAT.repeatOptionalDecimals(0, 0).code(0, currencyCode); @@ -76,13 +76,13 @@ public class BSFormatter { @Inject public BSFormatter(User user) { if (user.currentFiatAccountProperty().get() == null) - setFiatCurrencyCode(CurrencyUtil.getDefaultCurrency().getCurrencyCode()); + setFiatCurrencyCode(CurrencyUtil.getDefaultCurrencyAsCode()); else if (user.currentFiatAccountProperty().get() != null) - setFiatCurrencyCode(user.currentFiatAccountProperty().get().getCurrency().getCurrencyCode()); + setFiatCurrencyCode(user.currentFiatAccountProperty().get().getCurrencyCode()); user.currentFiatAccountProperty().addListener((ov, oldValue, newValue) -> { if (newValue != null) - setFiatCurrencyCode(newValue.getCurrency().getCurrencyCode()); + setFiatCurrencyCode(newValue.getCurrencyCode()); }); } diff --git a/core/src/main/java/io/bitsquare/gui/util/validation/FiatValidator.java b/core/src/main/java/io/bitsquare/gui/util/validation/FiatValidator.java index e9d9a5d5b7..282728e279 100644 --- a/core/src/main/java/io/bitsquare/gui/util/validation/FiatValidator.java +++ b/core/src/main/java/io/bitsquare/gui/util/validation/FiatValidator.java @@ -40,13 +40,13 @@ public final class FiatValidator extends NumberValidator { public FiatValidator(User user) { if (user != null) { if (user.currentFiatAccountProperty().get() == null) - setFiatCurrencyCode(CurrencyUtil.getDefaultCurrency().getCurrencyCode()); + setFiatCurrencyCode(CurrencyUtil.getDefaultCurrencyAsCode()); else if (user.currentFiatAccountProperty().get() != null) - setFiatCurrencyCode(user.currentFiatAccountProperty().get().getCurrency().getCurrencyCode()); + setFiatCurrencyCode(user.currentFiatAccountProperty().get().getCurrencyCode()); user.currentFiatAccountProperty().addListener((ov, oldValue, newValue) -> { if (newValue != null) - setFiatCurrencyCode(newValue.getCurrency().getCurrencyCode()); + setFiatCurrencyCode(newValue.getCurrencyCode()); }); } } diff --git a/core/src/main/java/io/bitsquare/gui/util/validation/OptionalFiatValidator.java b/core/src/main/java/io/bitsquare/gui/util/validation/OptionalFiatValidator.java index cad9e42c39..42f77c970f 100644 --- a/core/src/main/java/io/bitsquare/gui/util/validation/OptionalFiatValidator.java +++ b/core/src/main/java/io/bitsquare/gui/util/validation/OptionalFiatValidator.java @@ -40,13 +40,13 @@ public final class OptionalFiatValidator extends NumberValidator { public OptionalFiatValidator(User user) { if (user != null) { if (user.currentFiatAccountProperty().get() == null) - setFiatCurrencyCode(CurrencyUtil.getDefaultCurrency().getCurrencyCode()); + setFiatCurrencyCode(CurrencyUtil.getDefaultCurrencyAsCode()); else if (user.currentFiatAccountProperty().get() != null) - setFiatCurrencyCode(user.currentFiatAccountProperty().get().getCurrency().getCurrencyCode()); + setFiatCurrencyCode(user.currentFiatAccountProperty().get().getCurrencyCode()); user.currentFiatAccountProperty().addListener((ov, oldValue, newValue) -> { if (newValue != null) - setFiatCurrencyCode(newValue.getCurrency().getCurrencyCode()); + setFiatCurrencyCode(newValue.getCurrencyCode()); }); } } diff --git a/core/src/main/java/io/bitsquare/locale/CurrencyUtil.java b/core/src/main/java/io/bitsquare/locale/CurrencyUtil.java index 073385f702..20ac874c19 100644 --- a/core/src/main/java/io/bitsquare/locale/CurrencyUtil.java +++ b/core/src/main/java/io/bitsquare/locale/CurrencyUtil.java @@ -21,10 +21,23 @@ import java.util.ArrayList; import java.util.Currency; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; public class CurrencyUtil { - public static List getAllCurrencies() { + public static List getAllCurrencyCodes() { + return getAllCurrencies().stream().map(e -> e.getCurrencyCode()).collect(Collectors.toList()); + } + + public static String getDefaultCurrencyAsCode() { + return getDefaultCurrency().getCurrencyCode(); + } + + public static String getDisplayName(String currencyCode) { + return Currency.getInstance(currencyCode).getDisplayName(); + } + + private static List getAllCurrencies() { final ArrayList mainCurrencies = new ArrayList<>(); mainCurrencies.add(Currency.getInstance("EUR")); mainCurrencies.add(Currency.getInstance("USD")); @@ -52,9 +65,11 @@ public class CurrencyUtil { return resultList; } - public static Currency getDefaultCurrency() { + private static Currency getDefaultCurrency() { // TODO Only display EUR for the moment return Currency.getInstance("EUR"); // return Currency.getInstance(Locale.getDefault()); } + + } diff --git a/core/src/main/java/io/bitsquare/offer/Offer.java b/core/src/main/java/io/bitsquare/offer/Offer.java index c431cacb54..214261db70 100644 --- a/core/src/main/java/io/bitsquare/offer/Offer.java +++ b/core/src/main/java/io/bitsquare/offer/Offer.java @@ -30,7 +30,6 @@ import java.io.Serializable; import java.security.PublicKey; -import java.util.Currency; import java.util.Date; import java.util.List; import java.util.Locale; @@ -60,7 +59,7 @@ public class Offer implements Serializable { // key attributes for lookup private final Direction direction; - private final Currency currency; + private final String currencyCode; private final String id; private final Date creationDate; @@ -100,7 +99,7 @@ public class Offer implements Serializable { Coin amount, Coin minAmount, FiatAccountType fiatAccountType, - Currency currency, + String currencyCode, Country bankAccountCountry, String bankAccountUID, List arbitrators, @@ -114,7 +113,7 @@ public class Offer implements Serializable { this.amount = amount; this.minAmount = minAmount; this.fiatAccountType = fiatAccountType; - this.currency = currency; + this.currencyCode = currencyCode; this.bankAccountCountry = bankAccountCountry; this.bankAccountUID = bankAccountUID; this.arbitrators = arbitrators; @@ -150,7 +149,7 @@ public class Offer implements Serializable { } public Fiat getPrice() { - return Fiat.valueOf(currency.getCurrencyCode(), fiatPrice); + return Fiat.valueOf(currencyCode, fiatPrice); } public Coin getAmount() { @@ -173,8 +172,8 @@ public class Offer implements Serializable { return fiatAccountType; } - public Currency getCurrency() { - return currency; + public String getCurrencyCode() { + return currencyCode; } public Country getBankAccountCountry() { @@ -191,7 +190,7 @@ public class Offer implements Serializable { public Fiat getVolumeByAmount(Coin amount) { if (fiatPrice != 0 && amount != null && !amount.isZero()) - return new ExchangeRate(Fiat.valueOf(currency.getCurrencyCode(), fiatPrice)).coinToFiat(amount); + return new ExchangeRate(Fiat.valueOf(currencyCode, fiatPrice)).coinToFiat(amount); else return null; } @@ -246,7 +245,7 @@ public class Offer implements Serializable { checkNotNull(getBankAccountId(), "BankAccountId is null"); checkNotNull(getSecurityDeposit(), "SecurityDeposit is null"); checkNotNull(getCreationDate(), "CreationDate is null"); - checkNotNull(getCurrency(), "Currency is null"); + checkNotNull(getCurrencyCode(), "Currency is null"); checkNotNull(getDirection(), "Direction is null"); checkNotNull(getId(), "Id is null"); checkNotNull(getP2PSigPubKey(), "p2pSigPubKey is null"); @@ -271,7 +270,7 @@ public class Offer implements Serializable { "id='" + id + '\'' + ", state=" + state + ", direction=" + direction + - ", currency=" + currency + + ", currency=" + currencyCode + ", creationDate=" + creationDate + ", fiatPrice=" + fiatPrice + ", amount=" + amount + diff --git a/core/src/main/java/io/bitsquare/offer/OfferBook.java b/core/src/main/java/io/bitsquare/offer/OfferBook.java index 5370cc3272..f47b95fcd0 100644 --- a/core/src/main/java/io/bitsquare/offer/OfferBook.java +++ b/core/src/main/java/io/bitsquare/offer/OfferBook.java @@ -138,13 +138,13 @@ public class OfferBook { log.debug("setBankAccount " + fiatAccount); if (fiatAccount != null) { country = fiatAccount.getCountry(); - fiatCode = fiatAccount.getCurrency().getCurrencyCode(); + fiatCode = fiatAccount.getCurrencyCode(); // TODO check why that was used (probably just for update triggering, if so refactor that) //offerBookListItems.stream().forEach(e -> e.setBankAccountCountry(country)); } else { - fiatCode = CurrencyUtil.getDefaultCurrency().getCurrencyCode(); + fiatCode = CurrencyUtil.getDefaultCurrencyAsCode(); } } diff --git a/core/src/main/java/io/bitsquare/offer/tomp2p/TomP2POfferBookService.java b/core/src/main/java/io/bitsquare/offer/tomp2p/TomP2POfferBookService.java index d7ea97ac24..ea468fac44 100644 --- a/core/src/main/java/io/bitsquare/offer/tomp2p/TomP2POfferBookService.java +++ b/core/src/main/java/io/bitsquare/offer/tomp2p/TomP2POfferBookService.java @@ -65,7 +65,7 @@ public class TomP2POfferBookService extends TomP2PDHTService implements OfferBoo @Override public void addOffer(Offer offer, ResultHandler resultHandler, FaultHandler faultHandler) { log.debug("addOffer " + offer); - Number160 locationKey = Number160.createHash(offer.getCurrency().getCurrencyCode()); + Number160 locationKey = Number160.createHash(offer.getCurrencyCode()); try { final Data offerData = new Data(offer); offerData.ttlSeconds(TTL); @@ -91,7 +91,7 @@ public class TomP2POfferBookService extends TomP2PDHTService implements OfferBoo } }); - writeInvalidationTimestampToDHT(offer.getCurrency().getCurrencyCode()); + writeInvalidationTimestampToDHT(offer.getCurrencyCode()); log.trace("Add offer to DHT was successful. Added data: [locationKey: " + locationKey + ", value: " + offerData + "]"); }); @@ -110,7 +110,7 @@ public class TomP2POfferBookService extends TomP2PDHTService implements OfferBoo public void removeOffer(Offer offer, ResultHandler resultHandler, FaultHandler faultHandler) { log.debug("removeOffer " + offer); - Number160 locationKey = Number160.createHash(offer.getCurrency().getCurrencyCode()); + Number160 locationKey = Number160.createHash(offer.getCurrencyCode()); try { final Data offerData = new Data(offer); log.trace("Remove offer from DHT requested. Removed data: [locationKey: " + locationKey + @@ -140,7 +140,7 @@ public class TomP2POfferBookService extends TomP2PDHTService implements OfferBoo faultHandler.handleFault("Remove offer from DHT failed. Error: " + e.getMessage(), e); } }); - writeInvalidationTimestampToDHT(offer.getCurrency().getCurrencyCode()); + writeInvalidationTimestampToDHT(offer.getCurrencyCode()); }); } diff --git a/core/src/main/java/io/bitsquare/trade/TradeManager.java b/core/src/main/java/io/bitsquare/trade/TradeManager.java index 675b7570b8..39d90152c2 100644 --- a/core/src/main/java/io/bitsquare/trade/TradeManager.java +++ b/core/src/main/java/io/bitsquare/trade/TradeManager.java @@ -170,7 +170,7 @@ public class TradeManager { amount, minAmount, currentFiatAccount.getFiatAccountType(), - currentFiatAccount.getCurrency(), + currentFiatAccount.getCurrencyCode(), currentFiatAccount.getCountry(), currentFiatAccount.getId(), accountSettings.getAcceptedArbitrators(),