Change Currency to CurrencyCode

This commit is contained in:
Manfred Karrer 2015-03-25 11:01:19 +01:00
parent 7750ae6e00
commit d73a43271c
22 changed files with 150 additions and 158 deletions

View File

@ -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<Arbitrator> 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<String> languages;
private Coin fee;
private List<METHOD> arbitrationMethods;
private List<ID_VERIFICATION> 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<String> languages) {
this.languages = languages;
doSave();
save();
}
public void setFee(Coin fee) {
this.fee = fee;
doSave();
save();
}
public void setArbitrationMethods(List<METHOD> arbitrationMethods) {
this.arbitrationMethods = arbitrationMethods;
doSave();
save();
}
public void setIdVerifications(List<ID_VERIFICATION> idVerifications) {
this.idVerifications = idVerifications;
doSave();
save();
}
public void setWebUrl(String webUrl) {
this.webUrl = webUrl;
doSave();
save();
}

View File

@ -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 + '\'' +
'}';
}

View File

@ -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)",

View File

@ -244,15 +244,12 @@ public class ArbitratorRegistrationView extends ActivatableView<AnchorPane, Void
@FXML
public void onSaveProfile() {
arbitrator.setSaveOnEveryUpdate(false);
arbitrator.setWebUrl(webPageTextField.getText());
arbitrator.setFee(formatter.parseToCoin(arbitrationFeeTextField.getText()));
arbitrator.setIdType(idType);
arbitrator.setIdVerifications(idVerificationList);
// arbitrator.setLanguages(languageList);
arbitrator.setArbitrationMethods(methodList);
arbitrator.setSaveOnEveryUpdate(true);
arbitrator.save();
if (isEditMode) {

View File

@ -30,8 +30,6 @@ import io.bitsquare.user.User;
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,16 +50,16 @@ class FiatAccountDataModel implements Activatable, DataModel {
final StringProperty secondaryID = new SimpleStringProperty();
final StringProperty primaryIDPrompt = new SimpleStringProperty();
final StringProperty secondaryIDPrompt = new SimpleStringProperty();
final StringProperty currencyCode = new SimpleStringProperty();
final BooleanProperty countryNotInAcceptedCountriesList = new SimpleBooleanProperty();
final ObjectProperty<FiatAccountType> type = new SimpleObjectProperty<>();
final ObjectProperty<Country> country = new SimpleObjectProperty<>();
final ObjectProperty<Currency> currency = new SimpleObjectProperty<>();
final ObservableList<FiatAccountType> allTypes = FXCollections.observableArrayList(FiatAccountType
.getAllBankAccountTypes());
final ObservableList<FiatAccount> allFiatAccounts = FXCollections.observableArrayList();
final ObservableList<Currency> allCurrencies = FXCollections.observableArrayList(CurrencyUtil
.getAllCurrencies());
final ObservableList<String> allCurrencyCodes = FXCollections.observableArrayList(CurrencyUtil
.getAllCurrencyCodes());
final ObservableList<Region> 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);
}
}

View File

@ -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<GridPane, FiatAccou
@FXML Button saveButton, completedButton, removeBankAccountButton;
@FXML ComboBox<FiatAccount> selectionComboBox;
@FXML ComboBox<FiatAccountType> typesComboBox;
@FXML ComboBox<Currency> currencyComboBox;
@FXML ComboBox<String> currencyComboBox;
private Wizard wizard;
@ -77,7 +76,7 @@ public class FiatAccountView extends ActivatableViewAndModel<GridPane, FiatAccou
typesComboBox.setItems(model.getAllTypes());
typesComboBox.setConverter(model.getTypesConverter());
selectionComboBox.setConverter(model.getSelectionConverter());
currencyComboBox.setItems(model.getAllCurrencies());
currencyComboBox.setItems(model.getAllCurrencyCodes());
currencyComboBox.setConverter(model.getCurrencyConverter());
regionComboBox.setItems(model.getAllRegions());
regionComboBox.setConverter(model.getRegionConverter());
@ -120,7 +119,7 @@ public class FiatAccountView extends ActivatableViewAndModel<GridPane, FiatAccou
@FXML
void onSelectCurrency() {
model.setCurrency(currencyComboBox.getSelectionModel().getSelectedItem());
model.setCurrencyCode(currencyComboBox.getSelectionModel().getSelectedItem());
}
@FXML
@ -179,7 +178,7 @@ public class FiatAccountView extends ActivatableViewAndModel<GridPane, FiatAccou
typesComboBox.getSelectionModel().clearSelection();
});
model.currency.addListener((ov, oldValue, newValue) -> {
model.currencyCode.addListener((ov, oldValue, newValue) -> {
if (newValue != null)
currencyComboBox.getSelectionModel().select(currencyComboBox.getItems().indexOf(newValue));
else

View File

@ -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<FiatAccountDataModel
final StringProperty primaryIDPrompt = new SimpleStringProperty();
final StringProperty secondaryIDPrompt = new SimpleStringProperty();
final StringProperty selectionPrompt = new SimpleStringProperty();
final StringProperty currencyCode = new SimpleStringProperty();
final BooleanProperty selectionDisable = new SimpleBooleanProperty();
final BooleanProperty saveButtonDisable = new SimpleBooleanProperty(true);
final ObjectProperty<FiatAccountType> type = new SimpleObjectProperty<>();
final ObjectProperty<Country> country = new SimpleObjectProperty<>();
final ObjectProperty<Currency> currency = new SimpleObjectProperty<>();
@Inject
@ -71,7 +70,7 @@ class FiatAccountViewModel extends ActivatableWithDataModel<FiatAccountDataModel
secondaryID.bindBidirectional(dataModel.secondaryID);
type.bindBidirectional(dataModel.type);
country.bindBidirectional(dataModel.country);
currency.bindBidirectional(dataModel.currency);
currencyCode.bindBidirectional(dataModel.currencyCode);
primaryIDPrompt.bind(dataModel.primaryIDPrompt);
secondaryIDPrompt.bind(dataModel.secondaryIDPrompt);
@ -141,17 +140,17 @@ class FiatAccountViewModel extends ActivatableWithDataModel<FiatAccountDataModel
};
}
StringConverter<Currency> getCurrencyConverter() {
return new StringConverter<Currency>() {
StringConverter<String> getCurrencyConverter() {
return new StringConverter<String>() {
@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<FiatAccountDataModel
return dataModel.allFiatAccounts;
}
ObservableList<Currency> getAllCurrencies() {
return dataModel.allCurrencies;
ObservableList<String> getAllCurrencyCodes() {
return dataModel.allCurrencyCodes;
}
ObservableList<Region> getAllRegions() {
@ -225,8 +224,8 @@ class FiatAccountViewModel extends ActivatableWithDataModel<FiatAccountDataModel
validateInput();
}
void setCurrency(Currency currency) {
dataModel.setCurrency(currency);
void setCurrencyCode(String currencyCode) {
dataModel.setCurrencyCode(currencyCode);
validateInput();
}
@ -251,7 +250,7 @@ class FiatAccountViewModel extends ActivatableWithDataModel<FiatAccountDataModel
if (result.isValid) {
result = bankAccountNumberValidator.validate(dataModel.secondaryID.get());
if (result.isValid) {
if (dataModel.currency.get() == null)
if (dataModel.currencyCode.get() == null)
result = new InputValidator.ValidationResult(false,
"You have not selected a currency");
if (result.isValid) {

View File

@ -27,8 +27,6 @@ import io.bitsquare.user.User;
import com.google.inject.Inject;
import java.util.Currency;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
@ -41,12 +39,12 @@ class IrcAccountDataModel implements Activatable, DataModel {
private final User user;
final StringProperty nickName = new SimpleStringProperty();
final StringProperty currencyCode = new SimpleStringProperty();
final ObjectProperty<FiatAccountType> type = new SimpleObjectProperty<>();
final ObjectProperty<Currency> currency = new SimpleObjectProperty<>();
final ObservableList<FiatAccountType> allTypes =
FXCollections.observableArrayList(FiatAccountType.getAllBankAccountTypes());
final ObservableList<Currency> allCurrencies = FXCollections.observableArrayList(CurrencyUtil.getAllCurrencies());
final ObservableList<String> allCurrencyCodes = FXCollections.observableArrayList(CurrencyUtil.getAllCurrencyCodes());
final ObservableList<FiatAccount> 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);
}
}

View File

@ -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<GridPane, IrcAccount
@FXML InputTextField ircNickNameTextField;
@FXML Button saveButton;
@FXML ComboBox<FiatAccountType> typesComboBox;
@FXML ComboBox<Currency> currencyComboBox;
@FXML ComboBox<String> currencyComboBox;
private Wizard wizard;
@ -87,25 +86,25 @@ public class IrcAccountView extends ActivatableViewAndModel<GridPane, IrcAccount
});
typesComboBox.getSelectionModel().select(0);
currencyComboBox.setItems(model.getAllCurrencies());
currencyComboBox.setItems(model.getAllCurrencyCodes());
currencyComboBox.setConverter(model.getCurrencyConverter());
// we use a custom cell for deactivating non EUR items, later we use the standard cell and the StringConverter
currencyComboBox.setCellFactory(new Callback<ListView<Currency>, ListCell<Currency>>() {
currencyComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
@Override
public ListCell<Currency> call(ListView<Currency> p) {
return new ListCell<Currency>() {
public ListCell<String> call(ListView<String> p) {
return new ListCell<String>() {
@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<GridPane, IrcAccount
@FXML
void onSelectCurrency() {
model.setCurrency(currencyComboBox.getSelectionModel().getSelectedItem());
model.setCurrencyCode(currencyComboBox.getSelectionModel().getSelectedItem());
}
@FXML
@ -180,7 +179,7 @@ public class IrcAccountView extends ActivatableViewAndModel<GridPane, IrcAccount
typesComboBox.getSelectionModel().clearSelection();
});
model.currency.addListener((ov, oldValue, newValue) -> {
model.currencyCode.addListener((ov, oldValue, newValue) -> {
if (newValue != null)
currencyComboBox.getSelectionModel().select(currencyComboBox.getItems().indexOf(newValue));
else

View File

@ -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<IrcAccountDataModel>
private final InputValidator nickNameValidator;
final StringProperty ircNickName = new SimpleStringProperty();
final StringProperty currencyCode = new SimpleStringProperty();
final BooleanProperty saveButtonDisable = new SimpleBooleanProperty(true);
final ObjectProperty<FiatAccountType> type = new SimpleObjectProperty<>();
final ObjectProperty<Currency> currency = new SimpleObjectProperty<>();
@Inject
public IrcAccountViewModel(IrcAccountDataModel dataModel, BankAccountNumberValidator nickNameValidator) {
@ -55,7 +53,7 @@ class IrcAccountViewModel extends ActivatableWithDataModel<IrcAccountDataModel>
// 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<IrcAccountDataModel>
return fiatAccountType != null ? BSResources.get(fiatAccountType.toString()) : "";
}
StringConverter<Currency> getCurrencyConverter() {
return new StringConverter<Currency>() {
StringConverter<String> getCurrencyConverter() {
return new StringConverter<String>() {
@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<IrcAccountDataModel>
return dataModel.allTypes;
}
ObservableList<Currency> getAllCurrencies() {
return dataModel.allCurrencies;
ObservableList<String> getAllCurrencyCodes() {
return dataModel.allCurrencyCodes;
}
InputValidator getNickNameValidator() {
@ -120,15 +118,15 @@ class IrcAccountViewModel extends ActivatableWithDataModel<IrcAccountDataModel>
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) {

View File

@ -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) {

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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<TakeOfferDataModel> 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<TakeOfferDataModel> 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));

View File

@ -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());
});
}

View File

@ -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());
});
}
}

View File

@ -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());
});
}
}

View File

@ -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<Currency> getAllCurrencies() {
public static List<String> 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<Currency> getAllCurrencies() {
final ArrayList<Currency> 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());
}
}

View File

@ -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<Arbitrator> 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 +

View File

@ -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();
}
}

View File

@ -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());
});
}

View File

@ -170,7 +170,7 @@ public class TradeManager {
amount,
minAmount,
currentFiatAccount.getFiatAccountType(),
currentFiatAccount.getCurrency(),
currentFiatAccount.getCurrencyCode(),
currentFiatAccount.getCountry(),
currentFiatAccount.getId(),
accountSettings.getAcceptedArbitrators(),