adjust bank account combobox and balance label

This commit is contained in:
Manfred Karrer 2014-08-24 17:53:43 +02:00
parent 5fa7872606
commit 4e2f977ff0
7 changed files with 103 additions and 81 deletions

View file

@ -3,7 +3,7 @@
## About Bitsquare ## About Bitsquare
Bitsquare is a **P2P Fiat-BTC Exchange**. Bitsquare is a **P2P Fiat-BTC Exchange**.
It allows to trade fiat money (USD, EURO, ...) for Bitcoins without relying on a centralized exchange like MtGox. It allows to trade fiat money (USD, EURO, ...) for Bitcoins without relying on a centralized exchange like Coinbase or BitStamp.
Instead, all participants form a peer to peer market. Instead, all participants form a peer to peer market.
## Dependencies ## Dependencies

View file

@ -473,13 +473,9 @@ public class WalletFacade
{ {
Coin balance; Coin balance;
if (balanceListener.getAddress() != null) if (balanceListener.getAddress() != null)
{
balance = getBalanceForAddress(balanceListener.getAddress()); balance = getBalanceForAddress(balanceListener.getAddress());
}
else else
{
balance = getWalletBalance(); balance = getWalletBalance();
}
balanceListener.onBalanceChanged(balance); balanceListener.onBalanceChanged(balance);
} }

View file

@ -7,6 +7,7 @@ import io.bitsquare.btc.listeners.BalanceListener;
import io.bitsquare.di.GuiceFXMLLoader; import io.bitsquare.di.GuiceFXMLLoader;
import io.bitsquare.gui.components.NetworkSyncPane; import io.bitsquare.gui.components.NetworkSyncPane;
import io.bitsquare.gui.orders.OrdersController; import io.bitsquare.gui.orders.OrdersController;
import io.bitsquare.gui.util.BitSquareFormatter;
import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.gui.util.ImageUtil;
import io.bitsquare.gui.util.Profiler; import io.bitsquare.gui.util.Profiler;
import io.bitsquare.gui.util.Transitions; import io.bitsquare.gui.util.Transitions;
@ -59,6 +60,7 @@ public class MainController extends ViewController
private Pane ordersButtonButtonHolder; private Pane ordersButtonButtonHolder;
private boolean messageFacadeInited; private boolean messageFacadeInited;
private boolean walletFacadeInited; private boolean walletFacadeInited;
private VBox accountComboBoxHolder;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -272,8 +274,16 @@ public class MainController extends ViewController
viewBuilder.leftNavPane.getChildren().add(msgButtonHolder); viewBuilder.leftNavPane.getChildren().add(msgButtonHolder);
addBalanceInfo(viewBuilder.rightNavPane); addBalanceInfo(viewBuilder.rightNavPane);
addAccountComboBox(viewBuilder.rightNavPane); addAccountComboBox(viewBuilder.rightNavPane);
user.getBankAccountsSizeProperty().addListener((observableValue, oldValue, newValue) -> {
if ((int) newValue == 2)
viewBuilder.rightNavPane.getChildren().add(1, accountComboBoxHolder);// accountComboBoxHolder.setVisible(true);
else if ((int) newValue < 2)
viewBuilder.rightNavPane.getChildren().remove(accountComboBoxHolder);//accountComboBoxHolder.setVisible(false);
});
settingsButton = addNavButton(viewBuilder.rightNavPane, "Settings", NavigationItem.SETTINGS); settingsButton = addNavButton(viewBuilder.rightNavPane, "Settings", NavigationItem.SETTINGS);
Platform.runLater(this::onNavigationAdded); Platform.runLater(this::onNavigationAdded);
@ -358,50 +368,44 @@ public class MainController extends ViewController
balanceTextField.setEditable(false); balanceTextField.setEditable(false);
balanceTextField.setPrefWidth(110); balanceTextField.setPrefWidth(110);
balanceTextField.setId("nav-balance-label"); balanceTextField.setId("nav-balance-label");
balanceTextField.setText(walletFacade.getWalletBalance().toFriendlyString()); balanceTextField.setText(BitSquareFormatter.formatCoinWithCode(walletFacade.getWalletBalance()));
walletFacade.addBalanceListener(new BalanceListener() walletFacade.addBalanceListener(new BalanceListener()
{ {
@Override @Override
public void onBalanceChanged(Coin balance) public void onBalanceChanged(Coin balance)
{ {
balanceTextField.setText(balance.toFriendlyString()); balanceTextField.setText(BitSquareFormatter.formatCoinWithCode(walletFacade.getWalletBalance()));
} }
}); });
final HBox hBox = new HBox();
hBox.setSpacing(2);
hBox.getChildren().setAll(balanceTextField);
final Label titleLabel = new Label("Balance"); final Label titleLabel = new Label("Balance");
titleLabel.prefWidthProperty().bind(balanceTextField.widthProperty());
titleLabel.setMouseTransparent(true); titleLabel.setMouseTransparent(true);
titleLabel.setPrefWidth(90);
titleLabel.setId("nav-button-label"); titleLabel.setId("nav-button-label");
final VBox vBox = new VBox(); final VBox vBox = new VBox();
vBox.setPadding(new Insets(12, 0, 0, 0)); vBox.setPadding(new Insets(12, 0, 0, 0));
vBox.setSpacing(2); vBox.setSpacing(2);
vBox.getChildren().setAll(hBox, titleLabel); vBox.getChildren().setAll(balanceTextField, titleLabel);
parent.getChildren().add(vBox); parent.getChildren().add(vBox);
} }
private void addAccountComboBox(Pane parent) private void addAccountComboBox(Pane parent)
{
if (user.getBankAccounts().size() > 1)
{ {
final ComboBox<BankAccount> accountComboBox = new ComboBox<>(FXCollections.observableArrayList(user.getBankAccounts())); final ComboBox<BankAccount> accountComboBox = new ComboBox<>(FXCollections.observableArrayList(user.getBankAccounts()));
accountComboBox.setId("nav-account-combo-box");
accountComboBox.setLayoutY(12); accountComboBox.setLayoutY(12);
accountComboBox.setValue(user.getCurrentBankAccount()); if (user.getCurrentBankAccount() != null)
accountComboBox.getSelectionModel().select(user.getCurrentBankAccount());
accountComboBox.valueProperty().addListener((ov, oldValue, newValue) -> user.setCurrentBankAccount(newValue)); accountComboBox.valueProperty().addListener((ov, oldValue, newValue) -> user.setCurrentBankAccount(newValue));
accountComboBox.setConverter(new StringConverter<BankAccount>() accountComboBox.setConverter(new StringConverter<BankAccount>()
{ {
@Override @Override
public String toString(BankAccount bankAccount) public String toString(BankAccount bankAccount)
{ {
return bankAccount.getAccountTitle(); return bankAccount.getAccountTitle();
} }
@Override @Override
public BankAccount fromString(String s) public BankAccount fromString(String s)
{ {
@ -409,20 +413,26 @@ public class MainController extends ViewController
} }
}); });
user.getSelectedBankAccountIndexProperty().addListener(observable -> accountComboBox.getSelectionModel().select(user.getCurrentBankAccount()));
user.getBankAccountsSizeProperty().addListener(observable -> {
accountComboBox.setItems(FXCollections.observableArrayList(user.getBankAccounts()));
// need to delay it a bit otherwise it will not be set
Platform.runLater(() -> accountComboBox.getSelectionModel().select(user.getCurrentBankAccount()));
});
final Label titleLabel = new Label("Bank account"); final Label titleLabel = new Label("Bank account");
titleLabel.prefWidthProperty().bind(accountComboBox.widthProperty());
titleLabel.setMouseTransparent(true); titleLabel.setMouseTransparent(true);
titleLabel.setPrefWidth(90);
titleLabel.setId("nav-button-label"); titleLabel.setId("nav-button-label");
final VBox vBox = new VBox(); accountComboBoxHolder = new VBox();
vBox.setPadding(new Insets(12, 0, 0, 0)); accountComboBoxHolder.setPadding(new Insets(12, 0, 0, 0));
vBox.setSpacing(2); accountComboBoxHolder.setSpacing(2);
vBox.getChildren().setAll(accountComboBox, titleLabel); accountComboBoxHolder.getChildren().setAll(accountComboBox, titleLabel);
parent.getChildren().add(vBox);
}
}
if (user.getBankAccounts().size() > 1)
parent.getChildren().add(accountComboBoxHolder);
}
} }

View file

@ -47,17 +47,15 @@
#nav-button-label { #nav-button-label {
-fx-font-size: 10; -fx-font-size: 10;
-fx-text-alignment: center;
-fx-alignment: center; -fx-alignment: center;
} }
#nav-balance-label { #nav-balance-label {
-fx-font-weight: bold; -fx-font-weight: bold;
-fx-text-alignment: right; -fx-alignment: center;
} }
#nav-account-combo-box .list-cell{
#nav-balance-currency-label { -fx-alignment: center;
-fx-text-alignment: left;
} }
.text-field:readonly { .text-field:readonly {

View file

@ -229,7 +229,7 @@ public class SettingsController extends CachedViewController
{ {
user.setCurrentBankAccount(bankAccount); user.setCurrentBankAccount(bankAccount);
persistence.write(user); persistence.write(user);
initBankAccountScreen(); fillWithCurrentBankAccount();
} }
} }
@ -539,13 +539,8 @@ public class SettingsController extends CachedViewController
// Bank Account Settings // Bank Account Settings
private void initBankAccountScreen() private void fillWithCurrentBankAccount()
{ {
initBankAccountComboBox();
initBankAccountTypesComboBox();
initBankAccountCurrencyComboBox();
initBankAccountCountryComboBox();
BankAccount currentBankAccount = user.getCurrentBankAccount(); BankAccount currentBankAccount = user.getCurrentBankAccount();
if (currentBankAccount != null) if (currentBankAccount != null)
{ {
@ -560,6 +555,16 @@ public class SettingsController extends CachedViewController
{ {
resetBankAccountInput(); resetBankAccountInput();
} }
}
private void initBankAccountScreen()
{
initBankAccountComboBox();
initBankAccountTypesComboBox();
initBankAccountCurrencyComboBox();
initBankAccountCountryComboBox();
fillWithCurrentBankAccount();
//TODO //TODO
if (BitSquare.fillFormsWithDummyData) if (BitSquare.fillFormsWithDummyData)
@ -751,8 +756,6 @@ public class SettingsController extends CachedViewController
saveUser(); saveUser();
initBankAccountScreen();
if (!settings.getAcceptedCountries().contains(bankAccount.getCountry())) if (!settings.getAcceptedCountries().contains(bankAccount.getCountry()))
{ {
List<Action> actions = new ArrayList<>(); List<Action> actions = new ArrayList<>();
@ -775,7 +778,7 @@ public class SettingsController extends CachedViewController
saveUser(); saveUser();
saveSettings(); saveSettings();
initBankAccountScreen(); fillWithCurrentBankAccount();
} }
private boolean verifyBankAccountData() private boolean verifyBankAccountData()

View file

@ -179,9 +179,9 @@ public class OrderBookController extends CachedViewController
updateVolume(); updateVolume();
}); });
orderBookFilter.getDirectionChangedProperty().addListener((observable, oldValue, newValue) -> applyOffers()); orderBookFilter.getDirectionChangedProperty().addListener((observable) -> applyOffers());
user.getBankAccountChangedProperty().addListener((observable, oldValue, newValue) -> orderBook.loadOffers()); user.getSelectedBankAccountIndexProperty().addListener((observable) -> orderBook.loadOffers());
createOfferButton.setOnAction(e -> createOffer()); createOfferButton.setOnAction(e -> createOffer());
@ -213,18 +213,9 @@ public class OrderBookController extends CachedViewController
if (isRegistered()) if (isRegistered())
{ {
createOfferButton.setDisable(true); createOfferButton.setDisable(true);
/* if (walletFacade.isUnusedTradeAddressBalanceAboveCreationFee())
{ */
ViewController nextController = parentController.loadViewAndGetChildController(NavigationItem.CREATE_OFFER); ViewController nextController = parentController.loadViewAndGetChildController(NavigationItem.CREATE_OFFER);
if (nextController != null) if (nextController != null)
((CreateOfferController) nextController).setOrderBookFilter(orderBookFilter); ((CreateOfferController) nextController).setOrderBookFilter(orderBookFilter);
/* }
else
{
Action response = Popups.openErrorPopup("No funds for a trade", "You have to add some funds before you create a new offer.");
if (response == Dialog.Actions.OK)
MainController.GET_INSTANCE().navigateToView(NavigationItem.FUNDS);
} */
} }
else else
{ {

View file

@ -7,7 +7,9 @@ import java.security.KeyPair;
import java.security.PublicKey; import java.security.PublicKey;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javax.annotation.Nullable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -19,7 +21,8 @@ public class User implements Serializable
private static final Logger log = LoggerFactory.getLogger(User.class); private static final Logger log = LoggerFactory.getLogger(User.class);
private static final long serialVersionUID = 7409078808248518638L; private static final long serialVersionUID = 7409078808248518638L;
transient private final SimpleBooleanProperty bankAccountChangedProperty = new SimpleBooleanProperty(); transient private final IntegerProperty selectedBankAccountIndexProperty = new SimpleIntegerProperty();
transient private final IntegerProperty bankAccountsSizeProperty = new SimpleIntegerProperty();
private KeyPair messageKeyPair; private KeyPair messageKeyPair;
private String accountID; private String accountID;
@ -42,7 +45,6 @@ public class User implements Serializable
{ {
bankAccounts = persistedUser.getBankAccounts(); bankAccounts = persistedUser.getBankAccounts();
messageKeyPair = persistedUser.getMessageKeyPair(); messageKeyPair = persistedUser.getMessageKeyPair();
accountID = persistedUser.getAccountId(); accountID = persistedUser.getAccountId();
setCurrentBankAccount(persistedUser.getCurrentBankAccount()); setCurrentBankAccount(persistedUser.getCurrentBankAccount());
} }
@ -52,22 +54,33 @@ public class User implements Serializable
bankAccounts = new ArrayList<>(); bankAccounts = new ArrayList<>();
messageKeyPair = DSAKeyUtil.generateKeyPair(); // DSAKeyUtil.getKeyPair() runs in same thread now messageKeyPair = DSAKeyUtil.generateKeyPair(); // DSAKeyUtil.getKeyPair() runs in same thread now
} }
DSAKeyUtil.generateKeyPair();
bankAccountsSizeProperty.set(bankAccounts.size());
} }
public void addBankAccount(BankAccount bankAccount) public void addBankAccount(BankAccount bankAccount)
{ {
if (!bankAccounts.contains(bankAccount)) bankAccounts.add(bankAccount); if (!bankAccounts.contains(bankAccount))
{
bankAccounts.add(bankAccount);
bankAccountsSizeProperty.set(bankAccounts.size());
}
setCurrentBankAccount(bankAccount); setCurrentBankAccount(bankAccount);
} }
public void removeCurrentBankAccount() public void removeCurrentBankAccount()
{ {
if (currentBankAccount != null) bankAccounts.remove(currentBankAccount); if (currentBankAccount != null)
{
bankAccounts.remove(currentBankAccount);
bankAccountsSizeProperty.set(bankAccounts.size());
}
if (bankAccounts.isEmpty()) currentBankAccount = null; if (bankAccounts.isEmpty())
else setCurrentBankAccount(bankAccounts.get(0)); setCurrentBankAccount(null);
else
setCurrentBankAccount(bankAccounts.get(0));
} }
@ -82,10 +95,16 @@ public class User implements Serializable
this.accountID = accountID; this.accountID = accountID;
} }
public void setCurrentBankAccount(BankAccount bankAccount) public void setCurrentBankAccount(@Nullable BankAccount bankAccount)
{ {
this.currentBankAccount = bankAccount; currentBankAccount = bankAccount;
bankAccountChangedProperty.set(!bankAccountChangedProperty.get()); int index = -1;
for (index = 0; index < bankAccounts.size(); index++)
{
if (currentBankAccount != null && currentBankAccount.equals(bankAccounts.get(index)))
break;
}
selectedBankAccountIndexProperty.set(index);
} }
@ -137,9 +156,9 @@ public class User implements Serializable
return null; return null;
} }
public SimpleBooleanProperty getBankAccountChangedProperty() public IntegerProperty getSelectedBankAccountIndexProperty()
{ {
return bankAccountChangedProperty; return selectedBankAccountIndexProperty;
} }
public KeyPair getMessageKeyPair() public KeyPair getMessageKeyPair()
@ -156,4 +175,9 @@ public class User implements Serializable
{ {
return DSAKeyUtil.getHexStringFromPublicKey(getMessagePublicKey()); return DSAKeyUtil.getHexStringFromPublicKey(getMessagePublicKey());
} }
public IntegerProperty getBankAccountsSizeProperty()
{
return bankAccountsSizeProperty;
}
} }