confidence fixed

This commit is contained in:
Manfred Karrer 2014-06-26 16:03:02 +02:00
parent 3d6c2a8c62
commit 0545148f74
32 changed files with 1157 additions and 529 deletions

View File

@ -19,7 +19,7 @@ public class BtcFormatter
public static BigInteger mBTC = new BigInteger("100000");
public static String btcToString(BigInteger value)
public static String satoshiToString(BigInteger value)
{
return Utils.bitcoinValueToFriendlyString(value);
}

View File

@ -0,0 +1,15 @@
package io.bitsquare.btc;
import com.google.bitcoin.core.Transaction;
import java.math.BigInteger;
public class BtcValidator
{
public static boolean isMinSpendableAmount(BigInteger amount)
{
return amount != null && amount.compareTo(FeePolicy.TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT)) > 0;
}
}

View File

@ -31,6 +31,8 @@ import java.util.*;
import java.util.concurrent.ExecutionException;
import static com.google.bitcoin.script.ScriptOpCodes.OP_RETURN;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
public class WalletFacade
{
@ -131,8 +133,6 @@ public class WalletFacade
@Override
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
{
log.debug("onTransactionConfidenceChanged " + tx.getConfidence());
log.debug("onTransactionConfidenceChanged " + tx);
notifyConfidenceListeners(tx);
}
@ -205,9 +205,10 @@ public class WalletFacade
// Listener
///////////////////////////////////////////////////////////////////////////////////////////
public void addDownloadListener(DownloadListener listener)
public DownloadListener addDownloadListener(DownloadListener listener)
{
downloadListeners.add(listener);
return listener;
}
public void removeDownloadListener(DownloadListener listener)
@ -217,20 +218,19 @@ public class WalletFacade
public ConfidenceListener addConfidenceListener(ConfidenceListener listener)
{
log.debug("addConfidenceListener " + listener.getAddress().toString());
confidenceListeners.add(listener);
return listener;
}
public void removeConfidenceListener(ConfidenceListener listener)
{
log.debug("removeConfidenceListener " + listener.getAddress().toString());
confidenceListeners.remove(listener);
}
public void addBalanceListener(BalanceListener listener)
public BalanceListener addBalanceListener(BalanceListener listener)
{
balanceListeners.add(listener);
return listener;
}
public void removeBalanceListener(BalanceListener listener)
@ -238,50 +238,6 @@ public class WalletFacade
balanceListeners.remove(listener);
}
private void notifyConfidenceListeners(Transaction tx)
{
for (int i = 0; i < confidenceListeners.size(); i++)
{
ConfidenceListener confidenceListener = confidenceListeners.get(i);
List<TransactionOutput> transactionOutputs = tx.getOutputs();
for (int n = 0; n < transactionOutputs.size(); n++)
{
TransactionOutput transactionOutput = transactionOutputs.get(n);
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH())
{
Address address = transactionOutput.getScriptPubKey().getToAddress(params);
if (address.equals(confidenceListener.getAddress()))
{
log.debug("notifyConfidenceListeners address " + address.toString() + " / " + tx.getConfidence());
confidenceListener.onTransactionConfidenceChanged(tx.getConfidence());
}
}
}
}
}
private void notifyBalanceListeners(Transaction tx)
{
for (int i = 0; i < balanceListeners.size(); i++)
{
BalanceListener balanceListener = balanceListeners.get(i);
List<TransactionOutput> transactionOutputs = tx.getOutputs();
for (int n = 0; n < transactionOutputs.size(); n++)
{
TransactionOutput transactionOutput = transactionOutputs.get(n);
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH())
{
Address address = transactionOutput.getScriptPubKey().getToAddress(params);
if (address.equals(balanceListener.getAddress()))
{
balanceListener.onBalanceChanged(getBalanceForAddress(address));
}
}
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Get AddressInfo objects
@ -386,39 +342,95 @@ public class WalletFacade
public TransactionConfidence getConfidenceForAddress(Address address)
{
List<TransactionConfidence> transactionConfidenceList = new ArrayList<>();
Set<Transaction> transactions = wallet.getTransactions(true);
if (transactions != null)
{
for (Transaction tx : transactions)
{
List<TransactionOutput> transactionOutputs = tx.getOutputs();
for (int n = 0; n < transactionOutputs.size(); n++)
{
TransactionOutput transactionOutput = transactionOutputs.get(n);
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH())
{
Address addressOutput = transactionOutput.getScriptPubKey().getToAddress(params);
//log.debug("addressOutput / address " + addressOutput.toString() + " / " + address.toString());
if (addressOutput.equals(address))
{
return tx.getConfidence();
}
}
}
transactionConfidenceList.add(getTransactionConfidence(tx, address));
}
}
return null;
return getMostRecentConfidence(transactionConfidenceList);
}
private void notifyConfidenceListeners(Transaction tx)
{
for (int i = 0; i < confidenceListeners.size(); i++)
{
List<TransactionConfidence> transactionConfidenceList = new ArrayList<>();
ConfidenceListener confidenceListener = confidenceListeners.get(i);
transactionConfidenceList.add(getTransactionConfidence(tx, confidenceListener.getAddress()));
TransactionConfidence transactionConfidence = getMostRecentConfidence(transactionConfidenceList);
confidenceListener.onTransactionConfidenceChanged(transactionConfidence);
}
}
private TransactionConfidence getTransactionConfidence(Transaction tx, Address address)
{
List<TransactionConfidence> transactionConfidenceList = new ArrayList<>();
List<TransactionOutput> transactionOutputs = tx.getOutputs();
List<TransactionOutput> connectedOutputs = new ArrayList<>();
// add all connected outputs from any inputs as well
List<TransactionInput> transactionInputs = tx.getInputs();
for (int i = 0; i < transactionInputs.size(); i++)
{
TransactionInput transactionInput = transactionInputs.get(i);
TransactionOutput transactionOutput = transactionInput.getConnectedOutput();
if (transactionOutput != null)
connectedOutputs.add(transactionOutput);
}
List<TransactionOutput> mergedOutputs = new ArrayList<>();
mergedOutputs.addAll(transactionOutputs);
mergedOutputs.addAll(connectedOutputs);
for (int i = 0; i < mergedOutputs.size(); i++)
{
TransactionOutput transactionOutput = mergedOutputs.get(i);
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH())
{
Address outputAddress = transactionOutput.getScriptPubKey().getToAddress(params);
if (address.equals(outputAddress))
{
transactionConfidenceList.add(tx.getConfidence());
}
}
}
return getMostRecentConfidence(transactionConfidenceList);
}
private TransactionConfidence getMostRecentConfidence(List<TransactionConfidence> transactionConfidenceList)
{
TransactionConfidence transactionConfidence = null;
for (int i = 0; i < transactionConfidenceList.size(); i++)
{
TransactionConfidence confidence = transactionConfidenceList.get(i);
if (confidence != null)
{
if (transactionConfidence == null ||
confidence.getConfidenceType().equals(TransactionConfidence.ConfidenceType.PENDING) ||
(confidence.getConfidenceType().equals(TransactionConfidence.ConfidenceType.BUILDING) &&
transactionConfidence.getConfidenceType().equals(TransactionConfidence.ConfidenceType.BUILDING) &&
confidence.getDepthInBlocks() < transactionConfidence.getDepthInBlocks()))
{
transactionConfidence = confidence;
}
}
}
return transactionConfidence;
}
public boolean isRegistrationFeeConfirmed()
{
TransactionConfidence transactionConfidence = getConfidenceForAddress(getRegistrationAddressInfo().getAddress());
return transactionConfidence != null && transactionConfidence.getConfidenceType().equals(TransactionConfidence.ConfidenceType.BUILDING);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Balance
///////////////////////////////////////////////////////////////////////////////////////////
@ -441,6 +453,46 @@ public class WalletFacade
return value;
}
private void notifyBalanceListeners(Transaction tx)
{
for (int i = 0; i < balanceListeners.size(); i++)
{
BalanceListener balanceListener = balanceListeners.get(i);
List<TransactionOutput> transactionOutputs = tx.getOutputs();
for (int n = 0; n < transactionOutputs.size(); n++)
{
TransactionOutput transactionOutput = transactionOutputs.get(n);
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH())
{
Address address = transactionOutput.getScriptPubKey().getToAddress(params);
log.debug("notifyBalanceListeners transactionOutput address/balanceListener.getAddress() " + address.toString() + " / " + balanceListener.getAddress().toString());
if (address.equals(balanceListener.getAddress()))
{
balanceListener.onBalanceChanged(getBalanceForAddress(address));
}
}
}
List<TransactionInput> transactionInputs = tx.getInputs();
for (int n = 0; n < transactionInputs.size(); n++)
{
TransactionInput transactionInput = transactionInputs.get(n);
TransactionOutput transactionOutput = transactionInput.getConnectedOutput();
log.debug("notifyBalanceListeners transactionInput.getConnectedOutput() " + transactionInput.getConnectedOutput());
if (transactionOutput != null && (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH()))
{
Address address = transactionOutput.getScriptPubKey().getToAddress(params);
log.debug("notifyBalanceListeners transactionInput address/balanceListener.getAddress() " + address.toString() + " / " + balanceListener.getAddress().toString());
if (address.equals(balanceListener.getAddress()))
{
balanceListener.onBalanceChanged(getBalanceForAddress(address));
}
}
}
}
}
public BigInteger getWalletBalance()
{
return wallet.getBalance(Wallet.BalanceType.ESTIMATED);
@ -509,7 +561,7 @@ public class WalletFacade
tx.addOutput(Transaction.MIN_NONDUST_OUTPUT, new ScriptBuilder().op(OP_RETURN).data(data).build());
BigInteger fee = FeePolicy.ACCOUNT_REGISTRATION_FEE.subtract(Transaction.MIN_NONDUST_OUTPUT).subtract(FeePolicy.TX_FEE);
log.trace("fee: " + BtcFormatter.btcToString(fee));
log.trace("fee: " + BtcFormatter.satoshiToString(fee));
tx.addOutput(fee, feePolicy.getAddressForRegistrationFee());
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
@ -527,7 +579,7 @@ public class WalletFacade
{
Transaction tx = new Transaction(params);
BigInteger fee = FeePolicy.CREATE_OFFER_FEE.subtract(FeePolicy.TX_FEE);
log.trace("fee: " + BtcFormatter.btcToString(fee));
log.trace("fee: " + BtcFormatter.satoshiToString(fee));
tx.addOutput(fee, feePolicy.getAddressForCreateOfferFee());
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
@ -547,7 +599,7 @@ public class WalletFacade
{
Transaction tx = new Transaction(params);
BigInteger fee = FeePolicy.TAKE_OFFER_FEE.subtract(FeePolicy.TX_FEE);
log.trace("fee: " + BtcFormatter.btcToString(fee));
log.trace("fee: " + BtcFormatter.satoshiToString(fee));
tx.addOutput(fee, feePolicy.getAddressForTakeOfferFee());
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
@ -564,6 +616,33 @@ public class WalletFacade
}
///////////////////////////////////////////////////////////////////////////////////////////
// Withdrawal
///////////////////////////////////////////////////////////////////////////////////////////
public String sendFunds(AddressEntry withdrawFromAddressEntry, String withdrawToAddress, BigInteger amount, FutureCallback<Transaction> callback) throws AddressFormatException, InsufficientMoneyException, IllegalArgumentException
{
checkNotNull(withdrawFromAddressEntry);
checkArgument(withdrawToAddress.length() > 0);
checkArgument(amount.compareTo(FeePolicy.TX_FEE) > 0);
Transaction tx = new Transaction(params);
tx.addOutput(amount.subtract(FeePolicy.TX_FEE), new Address(params, withdrawToAddress));
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
// we allow spending of unconfirmed tx (double spend risk is low and usability would suffer if we need to wait for 1 confirmation)
sendRequest.coinSelector = new AddressBasedCoinSelector(params, withdrawFromAddressEntry, true);
sendRequest.changeAddress = withdrawFromAddressEntry.getAddress();
Wallet.SendResult sendResult = wallet.sendCoins(sendRequest);
Futures.addCallback(sendResult.broadcastComplete, callback);
printInputs("sendFunds", tx);
log.debug("tx=" + tx.toString());
return tx.getHashAsString();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Trade process
///////////////////////////////////////////////////////////////////////////////////////////
@ -574,7 +653,7 @@ public class WalletFacade
{
log.debug("offererCreatesMSTxAndAddPayment");
log.trace("inputs: ");
log.trace("offererInputAmount=" + BtcFormatter.btcToString(offererInputAmount));
log.trace("offererInputAmount=" + BtcFormatter.satoshiToString(offererInputAmount));
log.trace("offererPubKey=" + offererPubKey);
log.trace("takerPubKey=" + takerPubKey);
log.trace("arbitratorPubKey=" + arbitratorPubKey);
@ -631,8 +710,8 @@ public class WalletFacade
{
log.debug("takerAddPaymentAndSignTx");
log.trace("inputs: ");
log.trace("takerInputAmount=" + BtcFormatter.btcToString(takerInputAmount));
log.trace("msOutputAmount=" + BtcFormatter.btcToString(msOutputAmount));
log.trace("takerInputAmount=" + BtcFormatter.satoshiToString(takerInputAmount));
log.trace("msOutputAmount=" + BtcFormatter.satoshiToString(msOutputAmount));
log.trace("offererPubKey=" + offererPubKey);
log.trace("takerPubKey=" + takerPubKey);
log.trace("arbitratorPubKey=" + arbitratorPubKey);
@ -880,8 +959,8 @@ public class WalletFacade
log.debug("offererCreatesAndSignsPayoutTx");
log.trace("inputs: ");
log.trace("depositTxID=" + depositTxID);
log.trace("offererPaybackAmount=" + BtcFormatter.btcToString(offererPaybackAmount));
log.trace("takerPaybackAmount=" + BtcFormatter.btcToString(takerPaybackAmount));
log.trace("offererPaybackAmount=" + BtcFormatter.satoshiToString(offererPaybackAmount));
log.trace("takerPaybackAmount=" + BtcFormatter.satoshiToString(takerPaybackAmount));
log.trace("takerAddress=" + takerAddress);
// Offerer has published depositTx earlier, so he has it in his wallet
@ -920,8 +999,8 @@ public class WalletFacade
log.trace("depositTxAsHex=" + depositTxAsHex);
log.trace("offererSignatureR=" + offererSignatureR);
log.trace("offererSignatureS=" + offererSignatureS);
log.trace("offererPaybackAmount=" + BtcFormatter.btcToString(offererPaybackAmount));
log.trace("takerPaybackAmount=" + BtcFormatter.btcToString(takerPaybackAmount));
log.trace("offererPaybackAmount=" + BtcFormatter.satoshiToString(offererPaybackAmount));
log.trace("takerPaybackAmount=" + BtcFormatter.satoshiToString(takerPaybackAmount));
log.trace("offererAddress=" + offererAddress);
log.trace("callback=" + callback.toString());
@ -986,8 +1065,8 @@ public class WalletFacade
log.trace("createPayoutTx");
log.trace("inputs: ");
log.trace("depositTxAsHex=" + depositTxAsHex);
log.trace("offererPaybackAmount=" + BtcFormatter.btcToString(offererPaybackAmount));
log.trace("takerPaybackAmount=" + BtcFormatter.btcToString(takerPaybackAmount));
log.trace("offererPaybackAmount=" + BtcFormatter.satoshiToString(offererPaybackAmount));
log.trace("takerPaybackAmount=" + BtcFormatter.satoshiToString(takerPaybackAmount));
log.trace("offererAddress=" + offererAddress);
log.trace("takerAddress=" + takerAddress);
@ -1005,7 +1084,7 @@ public class WalletFacade
{
for (TransactionInput input : tx.getInputs())
if (input.getConnectedOutput() != null)
log.trace(tracePrefix + ": " + BtcFormatter.btcToString(input.getConnectedOutput().getValue()));
log.trace(tracePrefix + ": " + BtcFormatter.satoshiToString(input.getConnectedOutput().getValue()));
else
log.trace(tracePrefix + ": " + "Transaction already has inputs but we don't have the connected outputs, so we don't know the value.");
}

View File

@ -0,0 +1,9 @@
package io.bitsquare.gui;
public interface Hibernate
{
void sleep();
void awake();
}

View File

@ -125,9 +125,9 @@ public class MainController implements Initializable, NavigationController
//homeButton.fire();
//settingsButton.fire();
//fundsButton.fire();
fundsButton.fire();
// sellButton.fire();
ordersButton.fire();
// ordersButton.fire();
// homeButton.fire();
// msgButton.fire();
@ -325,31 +325,31 @@ public class MainController implements Initializable, NavigationController
vBox.getChildren().setAll(hBox, titleLabel);
parent.getChildren().add(vBox);
balanceTextField.setText(BtcFormatter.btcToString(walletFacade.getWalletBalance()));
balanceTextField.setText(BtcFormatter.satoshiToString(walletFacade.getWalletBalance()));
walletFacade.getWallet().addEventListener(new WalletEventListener()
{
@Override
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
{
balanceTextField.setText(BtcFormatter.btcToString(newBalance));
balanceTextField.setText(BtcFormatter.satoshiToString(newBalance));
}
@Override
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
{
balanceTextField.setText(BtcFormatter.btcToString(walletFacade.getWallet().getBalance()));
balanceTextField.setText(BtcFormatter.satoshiToString(walletFacade.getWallet().getBalance()));
}
@Override
public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
{
balanceTextField.setText(BtcFormatter.btcToString(newBalance));
balanceTextField.setText(BtcFormatter.satoshiToString(newBalance));
}
@Override
public void onReorganize(Wallet wallet)
{
balanceTextField.setText(BtcFormatter.btcToString(walletFacade.getWallet().getBalance()));
balanceTextField.setText(BtcFormatter.satoshiToString(walletFacade.getWallet().getBalance()));
}
@Override

View File

@ -25,6 +25,9 @@ public interface NavigationController
public static final String OFFER = "/io/bitsquare/gui/orders/offer/OfferView.fxml";
public static final String PENDING_TRADE = "/io/bitsquare/gui/orders/pending/PendingTradeView.fxml";
public static final String DEPOSIT = "/io/bitsquare/gui/funds/deposit/DepositView.fxml";
public static final String WITHDRAWAL = "/io/bitsquare/gui/funds/withdrawal/WithdrawalView.fxml";
ChildController navigateToView(String fxmlView);
ChildController navigateToView(String fxmlView, String title);

View File

@ -53,8 +53,8 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon
private ArbitratorProfileController arbitratorProfileController;
private boolean isEditMode;
private List<Locale> languageList = new ArrayList<>();
private List<Arbitrator.METHODS> methodList = new ArrayList<>();
private List<Arbitrator.ID_VERIFICATIONS> idVerificationList = new ArrayList<>();
private List<Arbitrator.METHOD> methodList = new ArrayList<>();
private List<Arbitrator.ID_VERIFICATION> idVerificationList = new ArrayList<>();
private Arbitrator.ID_TYPE idType;
private ConfidenceDisplay confidenceDisplay;
@ -73,9 +73,9 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon
@FXML
private ComboBox<Arbitrator.ID_TYPE> idTypeComboBox;
@FXML
private ComboBox<Arbitrator.METHODS> methodsComboBox;
private ComboBox<Arbitrator.METHOD> methodsComboBox;
@FXML
private ComboBox<Arbitrator.ID_VERIFICATIONS> idVerificationsComboBox;
private ComboBox<Arbitrator.ID_VERIFICATION> idVerificationsComboBox;
@FXML
private TextField nameTextField, idTypeTextField, languagesTextField, maxTradeVolumeTextField, passiveServiceFeeTextField, minPassiveServiceFeeTextField,
arbitrationFeeTextField, minArbitrationFeeTextField, methodsTextField, idVerificationsTextField, webPageTextField, collateralAddressTextField, balanceTextField;
@ -169,33 +169,33 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon
}
});
methodsComboBox.setItems(FXCollections.observableArrayList(new ArrayList<>(EnumSet.allOf(Arbitrator.METHODS.class))));
methodsComboBox.setConverter(new StringConverter<Arbitrator.METHODS>()
methodsComboBox.setItems(FXCollections.observableArrayList(new ArrayList<>(EnumSet.allOf(Arbitrator.METHOD.class))));
methodsComboBox.setConverter(new StringConverter<Arbitrator.METHOD>()
{
@Override
public String toString(Arbitrator.METHODS item)
public String toString(Arbitrator.METHOD item)
{
return Localisation.get(item.toString());
}
@Override
public Arbitrator.METHODS fromString(String s)
public Arbitrator.METHOD fromString(String s)
{
return null;
}
});
idVerificationsComboBox.setItems(FXCollections.observableArrayList(new ArrayList<>(EnumSet.allOf(Arbitrator.ID_VERIFICATIONS.class))));
idVerificationsComboBox.setConverter(new StringConverter<Arbitrator.ID_VERIFICATIONS>()
idVerificationsComboBox.setItems(FXCollections.observableArrayList(new ArrayList<>(EnumSet.allOf(Arbitrator.ID_VERIFICATION.class))));
idVerificationsComboBox.setConverter(new StringConverter<Arbitrator.ID_VERIFICATION>()
{
@Override
public String toString(Arbitrator.ID_VERIFICATIONS item)
public String toString(Arbitrator.ID_VERIFICATION item)
{
return Localisation.get(item.toString());
}
@Override
public Arbitrator.ID_VERIFICATIONS fromString(String s)
public Arbitrator.ID_VERIFICATION fromString(String s)
{
return null;
}
@ -271,7 +271,7 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon
@FXML
public void onAddMethod(ActionEvent actionEvent)
{
Arbitrator.METHODS item = methodsComboBox.getSelectionModel().getSelectedItem();
Arbitrator.METHOD item = methodsComboBox.getSelectionModel().getSelectedItem();
if (!methodList.contains(item) && item != null)
{
methodList.add(item);
@ -291,12 +291,12 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon
@FXML
public void onAddIDVerification(ActionEvent actionEvent)
{
Arbitrator.ID_VERIFICATIONS item = idVerificationsComboBox.getSelectionModel().getSelectedItem();
if (item != null)
Arbitrator.ID_VERIFICATION idVerification = idVerificationsComboBox.getSelectionModel().getSelectedItem();
if (idVerification != null)
{
if (!idVerificationList.contains(item))
if (!idVerificationList.contains(idVerification))
{
idVerificationList.add(item);
idVerificationList.add(idVerification);
idVerificationsTextField.setText(BitSquareFormatter.arbitrationIDVerificationsToString(idVerificationList));
}
}
@ -456,13 +456,8 @@ public class ArbitratorRegistrationController implements Initializable, ChildCon
{
try
{
TextField[] notEmptyTextFields = {nameTextField, idTypeTextField, languagesTextField, methodsTextField, idVerificationsTextField};
BitSquareValidator.resetTextFields(notEmptyTextFields);
BitSquareValidator.textFieldsNotEmpty(notEmptyTextFields);
TextField[] hasDoubleValueTextFields = {maxTradeVolumeTextField, passiveServiceFeeTextField, minPassiveServiceFeeTextField, arbitrationFeeTextField, minArbitrationFeeTextField};
BitSquareValidator.resetTextFields(hasDoubleValueTextFields);
BitSquareValidator.textFieldsHasDoubleValue(hasDoubleValueTextFields);
BitSquareValidator.textFieldsNotEmptyWithReset(nameTextField, idTypeTextField, languagesTextField, methodsTextField, idVerificationsTextField);
BitSquareValidator.textFieldsHasDoubleValueWithReset(maxTradeVolumeTextField, passiveServiceFeeTextField, minPassiveServiceFeeTextField, arbitrationFeeTextField, minArbitrationFeeTextField);
String pubKeyAsHex = walletFacade.getArbitratorDepositAddressInfo().getPubKeyAsHexString();
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(messageFacade.getPubKey());

View File

@ -2,6 +2,7 @@ package io.bitsquare.gui.components;
import io.bitsquare.di.GuiceFXMLLoader;
import io.bitsquare.gui.ChildController;
import io.bitsquare.gui.Hibernate;
import io.bitsquare.gui.NavigationController;
import io.bitsquare.locale.Localisation;
import io.bitsquare.storage.Storage;
@ -90,10 +91,10 @@ public class LazyLoadingTabPane extends TabPane
private void onTabSelectedIndexChanged()
{
int index = selectionModel.getSelectedIndex();
if (index < tabContentFXMLUrls.length && index > -1)
if (index < tabContentFXMLUrls.length && index >= 0)
{
if (childController != null)
childController.cleanup();
((Hibernate) childController).sleep();
Node view = null;
if (index < views.size())
@ -120,8 +121,12 @@ public class LazyLoadingTabPane extends TabPane
}
selectionModel.getSelectedItem().setContent(view);
childController.setNavigationController(navigationController);
if (childController != null)
{
childController.setNavigationController(navigationController);
((Hibernate) childController).awake();
}
storage.write(storageId, index);
}
}

View File

@ -1,47 +1,25 @@
package io.bitsquare.gui.funds;
import com.google.inject.Inject;
import de.jensd.fx.fontawesome.AwesomeDude;
import de.jensd.fx.fontawesome.AwesomeIcon;
import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.WalletFacade;
import io.bitsquare.gui.ChildController;
import io.bitsquare.gui.NavigationController;
import io.bitsquare.gui.util.ConfidenceDisplay;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import io.bitsquare.gui.components.LazyLoadingTabPane;
import io.bitsquare.storage.Storage;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
public class FundsController implements Initializable, ChildController
public class FundsController implements Initializable, ChildController, NavigationController
{
private static final Logger log = LoggerFactory.getLogger(FundsController.class);
private WalletFacade walletFacade;
private ConfidenceDisplay confidenceDisplay;
protected ObservableList<AddressListItem> addressList = FXCollections.observableArrayList();
private Storage storage;
@FXML
private TableView addressesTable;
@FXML
private TableColumn<String, AddressListItem> labelColumn, addressColumn, balanceColumn, copyColumn, confidenceColumn;
@FXML
private Button addNewAddressButton;
@FXML
private TextField labelTextField;
private LazyLoadingTabPane tabPane;
///////////////////////////////////////////////////////////////////////////////////////////
@ -49,9 +27,9 @@ public class FundsController implements Initializable, ChildController
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public FundsController(WalletFacade walletFacade)
public FundsController(Storage storage)
{
this.walletFacade = walletFacade;
this.storage = storage;
}
@ -62,19 +40,7 @@ public class FundsController implements Initializable, ChildController
@Override
public void initialize(URL url, ResourceBundle rb)
{
List<AddressEntry> addressEntryList = walletFacade.getAddressEntryList();
for (int i = 0; i < addressEntryList.size(); i++)
{
addressList.add(new AddressListItem(addressEntryList.get(i), walletFacade));
}
addressesTable.setItems(addressList);
addressesTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
setLabelColumnCellFactory();
setBalanceColumnCellFactory();
setCopyColumnCellFactory();
setConfidenceColumnCellFactory();
tabPane.initialize(this, storage, NavigationController.DEPOSIT, NavigationController.WITHDRAWAL);
}
@ -90,177 +56,23 @@ public class FundsController implements Initializable, ChildController
@Override
public void cleanup()
{
for (int i = 0; i < addressList.size(); i++)
{
addressList.get(i).cleanup();
}
tabPane.cleanup();
}
///////////////////////////////////////////////////////////////////////////////////////////
// UI handlers
// Interface implementation: NavigationController
///////////////////////////////////////////////////////////////////////////////////////////
@FXML
public void onAddNewTradeAddress(ActionEvent actionEvent)
@Override
public ChildController navigateToView(String fxmlView)
{
addressList.add(new AddressListItem(walletFacade.getNewTradeAddressInfo(), walletFacade));
return navigateToView(fxmlView, "");
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
private void setLabelColumnCellFactory()
@Override
public ChildController navigateToView(String fxmlView, String title)
{
labelColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
labelColumn.setCellFactory(new Callback<TableColumn<String, AddressListItem>, TableCell<String, AddressListItem>>()
{
@Override
public TableCell<String, AddressListItem> call(TableColumn<String, AddressListItem> column)
{
return new TableCell<String, AddressListItem>()
{
Hyperlink hyperlink;
@Override
public void updateItem(final AddressListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null && !empty)
{
hyperlink = new Hyperlink(item.getLabel());
hyperlink.setId("id-link");
if (item.getAddressEntry().getTradeId() != null)
{
Tooltip tooltip = new Tooltip(item.getAddressEntry().getTradeId());
Tooltip.install(hyperlink, tooltip);
hyperlink.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
log.info("Show trade details " + item.getAddressEntry().getTradeId());
}
});
}
setGraphic(hyperlink);
}
else
{
setGraphic(null);
setId(null);
}
}
};
}
});
}
private void setBalanceColumnCellFactory()
{
balanceColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
balanceColumn.setCellFactory(new Callback<TableColumn<String, AddressListItem>, TableCell<String, AddressListItem>>()
{
@Override
public TableCell<String, AddressListItem> call(TableColumn<String, AddressListItem> column)
{
return new TableCell<String, AddressListItem>()
{
@Override
public void updateItem(final AddressListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null && !empty)
{
setGraphic(item.getBalanceLabel());
}
else
{
setGraphic(null);
}
}
};
}
});
}
private void setCopyColumnCellFactory()
{
copyColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
copyColumn.setCellFactory(new Callback<TableColumn<String, AddressListItem>, TableCell<String, AddressListItem>>()
{
@Override
public TableCell<String, AddressListItem> call(TableColumn<String, AddressListItem> column)
{
return new TableCell<String, AddressListItem>()
{
Label copyIcon = new Label();
{
copyIcon.getStyleClass().add("copy-icon");
AwesomeDude.setIcon(copyIcon, AwesomeIcon.COPY);
Tooltip.install(copyIcon, new Tooltip("Copy address to clipboard"));
}
@Override
public void updateItem(final AddressListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null && !empty)
{
setGraphic(copyIcon);
copyIcon.setOnMouseClicked(e -> {
Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
content.putString(item.addressStringProperty().get());
clipboard.setContent(content);
});
}
else
{
setGraphic(null);
}
}
};
}
});
}
private void setConfidenceColumnCellFactory()
{
confidenceColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
confidenceColumn.setCellFactory(new Callback<TableColumn<String, AddressListItem>, TableCell<String, AddressListItem>>()
{
@Override
public TableCell<String, AddressListItem> call(TableColumn<String, AddressListItem> column)
{
return new TableCell<String, AddressListItem>()
{
@Override
public void updateItem(final AddressListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null && !empty)
{
setGraphic(item.getProgressIndicator());
}
else
{
setGraphic(null);
}
}
};
}
});
return tabPane.navigateToView(fxmlView);
}
}

View File

@ -1,84 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import io.bitsquare.gui.components.LazyLoadingTabPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.layout.*?>
<AnchorPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="io.bitsquare.gui.funds.FundsController">
<TabPane fx:id="tabPane" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<LazyLoadingTabPane fx:id="tabPane" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<Tab text="Deposit" closable="false">
<VBox spacing="10">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
<TableView fx:id="addressesTable" VBox.vgrow="ALWAYS">
<columns>
<TableColumn text="Label" fx:id="labelColumn" minWidth="100" sortable="false"/>
<TableColumn text="Address" fx:id="addressColumn" minWidth="240" sortable="false">
<cellValueFactory>
<PropertyValueFactory property="address"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="Balance" fx:id="balanceColumn" minWidth="50" sortable="false"/>
<TableColumn text="Copy" fx:id="copyColumn" minWidth="30" sortable="false"/>
<TableColumn text="Status" fx:id="confidenceColumn" minWidth="30" sortable="false"/>
</columns>
</TableView>
<Tab text="Deposit" closable="false"/>
<Tab text="Withdrawal" closable="false"/>
<Button fx:id="addNewAddressButton" text="Add new address" onAction="#onAddNewTradeAddress"/>
</VBox>
</Tab>
<Tab text="Withdrawal" closable="false">
<GridPane hgap="5.0" vgap="5.0">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
<children>
<Label text="Trading account address:"/>
<TextField fx:id="tradingAccountTextField2" editable="false" GridPane.columnIndex="1"/>
<Label fx:id="copyIcon2" GridPane.columnIndex="2">
<padding>
<Insets bottom="0.0" left="0.0" right="0.0" top="-1.0"/>
</padding>
<tooltip>
<Tooltip text="Copy address to clipboard"/>
</tooltip>
</Label>
<Label text="Balance:" GridPane.rowIndex="1"/>
<TextField fx:id="balanceTextField2" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<ConfidenceProgressIndicator fx:id="progressIndicator2" GridPane.columnIndex="2" GridPane.halignment="LEFT"
GridPane.rowIndex="1" GridPane.rowSpan="2" GridPane.valignment="TOP">
<GridPane.margin>
<Insets top="2.0"/>
</GridPane.margin>
</ConfidenceProgressIndicator>
<Label fx:id="confirmationLabel2" text="Checking confirmations..." GridPane.columnIndex="3" GridPane.rowIndex="1"/>
<Label text="dummy for layout progressIndicator" visible="false" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
</children>
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES"/>
<ColumnConstraints hgrow="ALWAYS"/>
<ColumnConstraints hgrow="SOMETIMES" prefWidth="20.0" minWidth="20.0"/>
<ColumnConstraints hgrow="SOMETIMES"/>
<ColumnConstraints hgrow="SOMETIMES"/>
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="SOMETIMES"/>
<RowConstraints vgrow="SOMETIMES"/>
<RowConstraints vgrow="SOMETIMES"/>
</rowConstraints>
</GridPane>
</Tab>
</TabPane>
</LazyLoadingTabPane>
</AnchorPane>

View File

@ -0,0 +1,287 @@
package io.bitsquare.gui.funds.deposit;
import com.google.inject.Inject;
import de.jensd.fx.fontawesome.AwesomeDude;
import de.jensd.fx.fontawesome.AwesomeIcon;
import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.WalletFacade;
import io.bitsquare.gui.ChildController;
import io.bitsquare.gui.Hibernate;
import io.bitsquare.gui.NavigationController;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
public class DepositController implements Initializable, ChildController, Hibernate
{
private static final Logger log = LoggerFactory.getLogger(DepositController.class);
private WalletFacade walletFacade;
protected ObservableList<DepositListItem> addressList;
@FXML
private TableView tableView;
@FXML
private TableColumn<String, DepositListItem> labelColumn, addressColumn, balanceColumn, copyColumn, confidenceColumn;
@FXML
private Button addNewAddressButton;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public DepositController(WalletFacade walletFacade)
{
this.walletFacade = walletFacade;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: Initializable
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void initialize(URL url, ResourceBundle rb)
{
awake();
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
setLabelColumnCellFactory();
setBalanceColumnCellFactory();
setCopyColumnCellFactory();
setConfidenceColumnCellFactory();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: ChildController
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void setNavigationController(NavigationController navigationController)
{
}
@Override
public void cleanup()
{
for (int i = 0; i < addressList.size(); i++)
{
addressList.get(i).cleanup();
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: Hibernate
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void sleep()
{
cleanup();
}
@Override
public void awake()
{
List<AddressEntry> addressEntryList = walletFacade.getAddressEntryList();
addressList = FXCollections.observableArrayList();
for (int i = 0; i < addressEntryList.size(); i++)
{
addressList.add(new DepositListItem(addressEntryList.get(i), walletFacade));
}
tableView.setItems(addressList);
}
///////////////////////////////////////////////////////////////////////////////////////////
// UI handlers
///////////////////////////////////////////////////////////////////////////////////////////
@FXML
public void onAddNewTradeAddress(ActionEvent actionEvent)
{
addressList.add(new DepositListItem(walletFacade.getNewTradeAddressInfo(), walletFacade));
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Cell factories
///////////////////////////////////////////////////////////////////////////////////////////
private void setLabelColumnCellFactory()
{
labelColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
labelColumn.setCellFactory(new Callback<TableColumn<String, DepositListItem>, TableCell<String, DepositListItem>>()
{
@Override
public TableCell<String, DepositListItem> call(TableColumn<String, DepositListItem> column)
{
return new TableCell<String, DepositListItem>()
{
Hyperlink hyperlink;
@Override
public void updateItem(final DepositListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null && !empty)
{
hyperlink = new Hyperlink(item.getLabel());
hyperlink.setId("id-link");
if (item.getAddressEntry().getTradeId() != null)
{
Tooltip tooltip = new Tooltip(item.getAddressEntry().getTradeId());
Tooltip.install(hyperlink, tooltip);
hyperlink.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
log.info("Show trade details " + item.getAddressEntry().getTradeId());
}
});
}
setGraphic(hyperlink);
}
else
{
setGraphic(null);
setId(null);
}
}
};
}
});
}
private void setBalanceColumnCellFactory()
{
balanceColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
balanceColumn.setCellFactory(new Callback<TableColumn<String, DepositListItem>, TableCell<String, DepositListItem>>()
{
@Override
public TableCell<String, DepositListItem> call(TableColumn<String, DepositListItem> column)
{
return new TableCell<String, DepositListItem>()
{
@Override
public void updateItem(final DepositListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null && !empty)
{
setGraphic(item.getBalanceLabel());
}
else
{
setGraphic(null);
}
}
};
}
});
}
private void setCopyColumnCellFactory()
{
copyColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
copyColumn.setCellFactory(new Callback<TableColumn<String, DepositListItem>, TableCell<String, DepositListItem>>()
{
@Override
public TableCell<String, DepositListItem> call(TableColumn<String, DepositListItem> column)
{
return new TableCell<String, DepositListItem>()
{
Label copyIcon = new Label();
{
copyIcon.getStyleClass().add("copy-icon");
AwesomeDude.setIcon(copyIcon, AwesomeIcon.COPY);
Tooltip.install(copyIcon, new Tooltip("Copy address to clipboard"));
}
@Override
public void updateItem(final DepositListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null && !empty)
{
setGraphic(copyIcon);
copyIcon.setOnMouseClicked(e -> {
Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
content.putString(item.addressStringProperty().get());
clipboard.setContent(content);
});
}
else
{
setGraphic(null);
}
}
};
}
});
}
private void setConfidenceColumnCellFactory()
{
confidenceColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
confidenceColumn.setCellFactory(new Callback<TableColumn<String, DepositListItem>, TableCell<String, DepositListItem>>()
{
@Override
public TableCell<String, DepositListItem> call(TableColumn<String, DepositListItem> column)
{
return new TableCell<String, DepositListItem>()
{
@Override
public void updateItem(final DepositListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null && !empty)
{
setGraphic(item.getProgressIndicator());
}
else
{
setGraphic(null);
}
}
};
}
});
}
}

View File

@ -0,0 +1,14 @@
package io.bitsquare.gui.funds.deposit;
import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.WalletFacade;
import io.bitsquare.gui.funds.withdrawal.WithdrawalListItem;
public class DepositListItem extends WithdrawalListItem
{
public DepositListItem(AddressEntry addressEntry, WalletFacade walletFacade)
{
super(addressEntry, walletFacade);
}
}

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import javafx.scene.layout.VBox?>
<VBox spacing="10" fx:controller="io.bitsquare.gui.funds.deposit.DepositController" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
<TableView fx:id="tableView" VBox.vgrow="ALWAYS">
<columns>
<TableColumn text="Label" fx:id="labelColumn" minWidth="100" sortable="false"/>
<TableColumn text="Address" fx:id="addressColumn" minWidth="240" sortable="false">
<cellValueFactory>
<PropertyValueFactory property="address"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="Balance" fx:id="balanceColumn" minWidth="50" sortable="false"/>
<TableColumn text="Copy" fx:id="copyColumn" minWidth="30" sortable="false"/>
<TableColumn text="Status" fx:id="confidenceColumn" minWidth="30" sortable="false"/>
</columns>
</TableView>
<Button fx:id="addNewAddressButton" text="Add new address" onAction="#onAddNewTradeAddress"/>
</VBox>

View File

@ -0,0 +1,385 @@
package io.bitsquare.gui.funds.withdrawal;
import com.google.bitcoin.core.AddressFormatException;
import com.google.bitcoin.core.InsufficientMoneyException;
import com.google.bitcoin.core.Transaction;
import com.google.common.util.concurrent.FutureCallback;
import com.google.inject.Inject;
import de.jensd.fx.fontawesome.AwesomeDude;
import de.jensd.fx.fontawesome.AwesomeIcon;
import io.bitsquare.btc.*;
import io.bitsquare.gui.ChildController;
import io.bitsquare.gui.Hibernate;
import io.bitsquare.gui.NavigationController;
import io.bitsquare.gui.util.BitSquareValidator;
import io.bitsquare.gui.util.Popups;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.util.Callback;
import org.controlsfx.control.action.Action;
import org.controlsfx.dialog.Dialog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigInteger;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
public class WithdrawalController implements Initializable, ChildController, Hibernate
{
private static final Logger log = LoggerFactory.getLogger(WithdrawalController.class);
private WalletFacade walletFacade;
protected ObservableList<WithdrawalListItem> addressList;
private AddressEntry selectedAddressEntry;
@FXML
private TableView tableView;
@FXML
private TableColumn<String, WithdrawalListItem> labelColumn, addressColumn, balanceColumn, copyColumn, confidenceColumn;
@FXML
private Button addNewAddressButton;
@FXML
private TextField withdrawFromTextField, withdrawToTextField, amountTextField;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public WithdrawalController(WalletFacade walletFacade)
{
this.walletFacade = walletFacade;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: Initializable
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void initialize(URL url, ResourceBundle rb)
{
awake();
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
setLabelColumnCellFactory();
setBalanceColumnCellFactory();
setCopyColumnCellFactory();
setConfidenceColumnCellFactory();
tableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<WithdrawalListItem>()
{
@Override
public void changed(ObservableValue<? extends WithdrawalListItem> observableValue, WithdrawalListItem oldValue, WithdrawalListItem newValue)
{
if (newValue != null)
{
BitSquareValidator.resetTextFields(withdrawFromTextField, withdrawToTextField, amountTextField);
if (newValue.getBalance().compareTo(BigInteger.ZERO) > 0)
{
amountTextField.setText(BtcFormatter.satoshiToString(newValue.getBalance()));
selectedAddressEntry = newValue.getAddressEntry();
withdrawFromTextField.setText(newValue.getAddressEntry().getAddressString());
}
else
{
withdrawFromTextField.setText("");
withdrawFromTextField.setPromptText("No fund to withdrawal on that address.");
amountTextField.setText("");
amountTextField.setPromptText("Invalid amount");
}
}
}
});
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: ChildController
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void setNavigationController(NavigationController navigationController)
{
}
@Override
public void cleanup()
{
for (int i = 0; i < addressList.size(); i++)
{
addressList.get(i).cleanup();
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: Hibernate
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void sleep()
{
cleanup();
}
@Override
public void awake()
{
List<AddressEntry> addressEntryList = walletFacade.getAddressEntryList();
addressList = FXCollections.observableArrayList();
for (int i = 0; i < addressEntryList.size(); i++)
{
addressList.add(new WithdrawalListItem(addressEntryList.get(i), walletFacade));
}
tableView.setItems(addressList);
}
///////////////////////////////////////////////////////////////////////////////////////////
// UI handlers
///////////////////////////////////////////////////////////////////////////////////////////
@FXML
public void onWithdraw(ActionEvent actionEvent)
{
try
{
BitSquareValidator.textFieldsNotEmpty(amountTextField, withdrawFromTextField, withdrawToTextField);
BitSquareValidator.textFieldsHasDoubleValueWithReset(amountTextField);
BigInteger amount = BtcFormatter.stringValueToSatoshis(amountTextField.getText());
if (BtcValidator.isMinSpendableAmount(amount))
{
FutureCallback<Transaction> callback = new FutureCallback<Transaction>()
{
@Override
public void onSuccess(Transaction transaction)
{
BitSquareValidator.resetTextFields(withdrawFromTextField, withdrawToTextField, amountTextField);
log.info("onWithdraw onSuccess txid:" + transaction.getHashAsString());
}
@Override
public void onFailure(Throwable t)
{
log.debug("onWithdraw onFailure");
}
};
Action response = Popups.openConfirmPopup("Withdrawal request", "Confirm your request", "Your withdrawal request:\n\n" +
"Amount: " + amountTextField.getText() + " BTC\n" +
"Sending address: " + withdrawFromTextField.getText() + "\n" +
"Receiving address: " + withdrawToTextField.getText() + "\n" +
"Transaction fee: " + BtcFormatter.satoshiToString(FeePolicy.TX_FEE) + "\n" +
"You receive in total: " + BtcFormatter.satoshiToString(amount.subtract(FeePolicy.TX_FEE)) + " BTC\n\n" +
"Are you sure you withdraw that amount?");
if (response == Dialog.Actions.OK)
{
try
{
walletFacade.sendFunds(selectedAddressEntry, withdrawToTextField.getText(), amount, callback);
} catch (AddressFormatException e)
{
Popups.openErrorPopup("Address invalid", "The address is not correct. Please check the address format.");
} catch (InsufficientMoneyException e)
{
Popups.openInsufficientMoneyPopup();
} catch (IllegalArgumentException e)
{
Popups.openErrorPopup("Wrong inputs", "Please check the inputs.");
}
}
}
else
{
Popups.openErrorPopup("Insufficient amount", "The amount to transfer is lower the the transaction fee and the min. possible tx value.");
}
} catch (BitSquareValidator.ValidationException e)
{
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Cell factories
///////////////////////////////////////////////////////////////////////////////////////////
private void setLabelColumnCellFactory()
{
labelColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
labelColumn.setCellFactory(new Callback<TableColumn<String, WithdrawalListItem>, TableCell<String, WithdrawalListItem>>()
{
@Override
public TableCell<String, WithdrawalListItem> call(TableColumn<String, WithdrawalListItem> column)
{
return new TableCell<String, WithdrawalListItem>()
{
Hyperlink hyperlink;
@Override
public void updateItem(final WithdrawalListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null && !empty)
{
hyperlink = new Hyperlink(item.getLabel());
hyperlink.setId("id-link");
if (item.getAddressEntry().getTradeId() != null)
{
Tooltip tooltip = new Tooltip(item.getAddressEntry().getTradeId());
Tooltip.install(hyperlink, tooltip);
hyperlink.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
log.info("Show trade details " + item.getAddressEntry().getTradeId());
}
});
}
setGraphic(hyperlink);
}
else
{
setGraphic(null);
setId(null);
}
}
};
}
});
}
private void setBalanceColumnCellFactory()
{
balanceColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
balanceColumn.setCellFactory(new Callback<TableColumn<String, WithdrawalListItem>, TableCell<String, WithdrawalListItem>>()
{
@Override
public TableCell<String, WithdrawalListItem> call(TableColumn<String, WithdrawalListItem> column)
{
return new TableCell<String, WithdrawalListItem>()
{
@Override
public void updateItem(final WithdrawalListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null && !empty)
{
setGraphic(item.getBalanceLabel());
}
else
{
setGraphic(null);
}
}
};
}
});
}
private void setCopyColumnCellFactory()
{
copyColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
copyColumn.setCellFactory(new Callback<TableColumn<String, WithdrawalListItem>, TableCell<String, WithdrawalListItem>>()
{
@Override
public TableCell<String, WithdrawalListItem> call(TableColumn<String, WithdrawalListItem> column)
{
return new TableCell<String, WithdrawalListItem>()
{
Label copyIcon = new Label();
{
copyIcon.getStyleClass().add("copy-icon");
AwesomeDude.setIcon(copyIcon, AwesomeIcon.COPY);
Tooltip.install(copyIcon, new Tooltip("Copy address to clipboard"));
}
@Override
public void updateItem(final WithdrawalListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null && !empty)
{
setGraphic(copyIcon);
copyIcon.setOnMouseClicked(e -> {
Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
content.putString(item.addressStringProperty().get());
clipboard.setContent(content);
});
}
else
{
setGraphic(null);
}
}
};
}
});
}
private void setConfidenceColumnCellFactory()
{
confidenceColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
confidenceColumn.setCellFactory(new Callback<TableColumn<String, WithdrawalListItem>, TableCell<String, WithdrawalListItem>>()
{
@Override
public TableCell<String, WithdrawalListItem> call(TableColumn<String, WithdrawalListItem> column)
{
return new TableCell<String, WithdrawalListItem>()
{
@Override
public void updateItem(final WithdrawalListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null && !empty)
{
setGraphic(item.getProgressIndicator());
}
else
{
setGraphic(null);
}
}
};
}
});
}
}

View File

@ -1,4 +1,4 @@
package io.bitsquare.gui.funds;
package io.bitsquare.gui.funds.withdrawal;
import com.google.bitcoin.core.Address;
import com.google.bitcoin.core.TransactionConfidence;
@ -15,7 +15,7 @@ import javafx.scene.control.Tooltip;
import java.math.BigInteger;
public class AddressListItem
public class WithdrawalListItem
{
private final StringProperty addressString = new SimpleStringProperty();
private final BalanceListener balanceListener;
@ -25,13 +25,15 @@ public class AddressListItem
private ConfidenceListener confidenceListener;
private ConfidenceProgressIndicator progressIndicator;
private Tooltip tooltip;
private BigInteger balance;
public AddressListItem(AddressEntry addressEntry, WalletFacade walletFacade)
public WithdrawalListItem(AddressEntry addressEntry, WalletFacade walletFacade)
{
this.addressEntry = addressEntry;
this.walletFacade = walletFacade;
this.addressString.set(getAddress().toString());
// confidence
progressIndicator = new ConfidenceProgressIndicator();
progressIndicator.setId("funds-confidence");
tooltip = new Tooltip("Not used yet");
@ -52,9 +54,9 @@ public class AddressListItem
updateConfidence(walletFacade.getConfidenceForAddress(getAddress()));
balanceListener = new BalanceListener(getAddress());
// balance
balanceLabel = new Label();
walletFacade.addBalanceListener(new BalanceListener(getAddress())
balanceListener = walletFacade.addBalanceListener(new BalanceListener(getAddress())
{
@Override
public void onBalanceChanged(BigInteger balance)
@ -74,9 +76,10 @@ public class AddressListItem
private void updateBalance(BigInteger balance)
{
this.balance = balance;
if (balance != null)
{
balanceLabel.setText(BtcFormatter.btcToString(balance));
balanceLabel.setText(BtcFormatter.satoshiToString(balance));
}
}
@ -131,7 +134,6 @@ public class AddressListItem
return this.addressString;
}
public Address getAddress()
{
return addressEntry.getAddress();
@ -142,28 +144,18 @@ public class AddressListItem
return addressEntry;
}
public ConfidenceListener getConfidenceListener()
{
return confidenceListener;
}
public ConfidenceProgressIndicator getProgressIndicator()
{
return progressIndicator;
}
public Tooltip getTooltip()
{
return tooltip;
}
public BalanceListener getBalanceListener()
{
return balanceListener;
}
public Label getBalanceLabel()
{
return balanceLabel;
}
public BigInteger getBalance()
{
return balance;
}
}

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import javafx.scene.layout.*?>
<VBox spacing="10" fx:controller="io.bitsquare.gui.funds.withdrawal.WithdrawalController" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
<TableView fx:id="tableView" VBox.vgrow="ALWAYS">
<columns>
<TableColumn text="Label" fx:id="labelColumn" minWidth="100" sortable="false"/>
<TableColumn text="Address" fx:id="addressColumn" minWidth="240" sortable="false">
<cellValueFactory>
<PropertyValueFactory property="address"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="Balance" fx:id="balanceColumn" minWidth="50" sortable="false"/>
<TableColumn text="Copy" fx:id="copyColumn" minWidth="30" sortable="false"/>
<TableColumn text="Status" fx:id="confidenceColumn" minWidth="30" sortable="false"/>
</columns>
</TableView>
<GridPane hgap="5.0" vgap="5.0">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
<children>
<Label text="Amount (BTC):" GridPane.rowIndex="0"/>
<TextField fx:id="amountTextField" GridPane.rowIndex="0" GridPane.columnIndex="1"/>
<Label text="Withdraw from address:" GridPane.rowIndex="1"/>
<TextField fx:id="withdrawFromTextField" promptText="Select a source address from the table" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
<Label text="Withdraw to address:" GridPane.rowIndex="2"/>
<TextField fx:id="withdrawToTextField" GridPane.rowIndex="2" GridPane.columnIndex="1"/>
<Button text="Withdraw" defaultButton="true" onAction="#onWithdraw" GridPane.rowIndex="3" GridPane.columnIndex="1"/>
</children>
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES"/>
<ColumnConstraints hgrow="ALWAYS"/>
</columnConstraints>
<rowConstraints>
<RowConstraints vgrow="NEVER"/>
<RowConstraints vgrow="NEVER"/>
<RowConstraints vgrow="NEVER"/>
<RowConstraints vgrow="NEVER"/>
</rowConstraints>
</GridPane>
</VBox>

View File

@ -140,7 +140,7 @@ public class CreateOfferController implements Initializable, ChildController
bankAccountCountyTextField.setText(user.getCurrentBankAccount().getCountry().getName());
acceptedCountriesTextField.setText(BitSquareFormatter.countryLocalesToString(settings.getAcceptedCountries()));
acceptedLanguagesTextField.setText(BitSquareFormatter.languageLocalesToString(settings.getAcceptedLanguageLocales()));
feeLabel.setText(BtcFormatter.btcToString(FeePolicy.CREATE_OFFER_FEE));
feeLabel.setText(BtcFormatter.satoshiToString(FeePolicy.CREATE_OFFER_FEE));
}
@ -229,7 +229,7 @@ public class CreateOfferController implements Initializable, ChildController
placeOfferButton.setDisable(true);
} catch (InsufficientMoneyException e1)
{
Popups.openErrorPopup("Not enough money available", "There is not enough money available. Please pay in first to your wallet. " + e1.getMessage());
Popups.openInsufficientMoneyPopup();
}
}

View File

@ -256,7 +256,7 @@ public class OrderBookController implements Initializable, ChildController
}
else
{
Action response = Popups.openErrorPopup("Missing registration fee", "You have not funded the full registration fee of " + BtcFormatter.btcToString(FeePolicy.ACCOUNT_REGISTRATION_FEE) + " BTC.");
Action response = Popups.openErrorPopup("Missing registration fee", "You have not funded the full registration fee of " + BtcFormatter.satoshiToString(FeePolicy.ACCOUNT_REGISTRATION_FEE) + " BTC.");
if (response == Dialog.Actions.OK)
{
MainController.getInstance().navigateToView(NavigationController.FUNDS);
@ -321,7 +321,7 @@ public class OrderBookController implements Initializable, ChildController
storage.write(user.getClass().getName(), user);
} catch (InsufficientMoneyException e1)
{
Popups.openErrorPopup("Not enough money available", "There is not enough money available. Please pay in first to your wallet.");
Popups.openInsufficientMoneyPopup();
}
}

View File

@ -166,7 +166,7 @@ public class TakerTradeController implements Initializable, ChildController
totalLabel = FormBuilder.addTextField(gridPane, "Total (" + offer.getCurrency() + "):", BitSquareFormatter.formatVolume(getVolume()), ++row);
collateralTextField = FormBuilder.addTextField(gridPane, "Collateral (BTC):", "", ++row);
applyCollateral();
FormBuilder.addTextField(gridPane, "Offer fee (BTC):", BtcFormatter.btcToString(FeePolicy.TAKE_OFFER_FEE.add(FeePolicy.TX_FEE)), ++row);
FormBuilder.addTextField(gridPane, "Offer fee (BTC):", BtcFormatter.satoshiToString(FeePolicy.TAKE_OFFER_FEE.add(FeePolicy.TX_FEE)), ++row);
totalToPayLabel = FormBuilder.addTextField(gridPane, "Total to pay (BTC):", getTotalToPayAsString(), ++row);
isOnlineTextField = FormBuilder.addTextField(gridPane, "Online status:", "Checking offerers online status...", ++row);
@ -369,12 +369,12 @@ public class TakerTradeController implements Initializable, ChildController
String fiatReceived = BitSquareFormatter.formatVolume(trade.getOffer().getPrice() * BtcFormatter.satoshiToBTC(trade.getTradeAmount()));
FormBuilder.addTextField(gridPane, "You have sold (BTC):", BtcFormatter.btcToString(trade.getTradeAmount()), ++row);
FormBuilder.addTextField(gridPane, "You have sold (BTC):", BtcFormatter.satoshiToString(trade.getTradeAmount()), ++row);
if (takerIsSelling())
{
FormBuilder.addTextField(gridPane, "You have received (" + offer.getCurrency() + "):\"", fiatReceived, ++row);
FormBuilder.addTextField(gridPane, "Total fees (take offer fee + tx fee):", BtcFormatter.btcToString(FeePolicy.TAKE_OFFER_FEE.add(FeePolicy.TX_FEE)), ++row);
FormBuilder.addTextField(gridPane, "Refunded collateral:", BtcFormatter.btcToString(trade.getCollateralAmount()), ++row);
FormBuilder.addTextField(gridPane, "Total fees (take offer fee + tx fee):", BtcFormatter.satoshiToString(FeePolicy.TAKE_OFFER_FEE.add(FeePolicy.TX_FEE)), ++row);
FormBuilder.addTextField(gridPane, "Refunded collateral:", BtcFormatter.satoshiToString(trade.getCollateralAmount()), ++row);
}
else
{

View File

@ -18,7 +18,6 @@ public class OrdersController implements Initializable, ChildController, Navigat
private static final Logger log = LoggerFactory.getLogger(OrdersController.class);
private Storage storage;
@FXML
private LazyLoadingTabPane tabPane;
@ -76,14 +75,5 @@ public class OrdersController implements Initializable, ChildController, Navigat
return tabPane.navigateToView(fxmlView);
}
///////////////////////////////////////////////////////////////////////////////////////////
// GUI handlers
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
}

View File

@ -134,11 +134,11 @@ public class OfferController implements Initializable, ChildController
{
super.updateItem(item, empty);
if (item != null)
if (item != null && !empty)
{
hyperlink = new Hyperlink(item.getOfferId());
//hyperlink.getStyleClass().setAll("aaa");
if (item != null)
if (item != null && !empty)
{
Tooltip tooltip = new Tooltip(item.getOfferId());
Tooltip.install(hyperlink, tooltip);

View File

@ -147,11 +147,11 @@ public class SettingsController implements Initializable, ChildController, Navig
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(messageFacade.getPubKey());
List<Locale> languages = new ArrayList<>();
languages.add(LanguageUtil.getDefaultLanguageLocale());
List<Arbitrator.METHODS> arbitrationMethods = new ArrayList<>();
arbitrationMethods.add(Arbitrator.METHODS.TLS_NOTARY);
List<Arbitrator.ID_VERIFICATIONS> idVerifications = new ArrayList<>();
idVerifications.add(Arbitrator.ID_VERIFICATIONS.PASSPORT);
idVerifications.add(Arbitrator.ID_VERIFICATIONS.GOV_ID);
List<Arbitrator.METHOD> arbitrationMethods = new ArrayList<>();
arbitrationMethods.add(Arbitrator.METHOD.TLS_NOTARY);
List<Arbitrator.ID_VERIFICATION> idVerifications = new ArrayList<>();
idVerifications.add(Arbitrator.ID_VERIFICATION.PASSPORT);
idVerifications.add(Arbitrator.ID_VERIFICATION.GOV_ID);
Arbitrator arbitrator = new Arbitrator(pubKeyAsHex,
messagePubKeyAsHex,
@ -393,7 +393,7 @@ public class SettingsController implements Initializable, ChildController, Navig
public void updateItem(final Locale item, boolean empty)
{
super.updateItem(item, empty);
if (item != null)
if (item != null && !empty)
{
label.setText(item.getDisplayName());
@ -485,7 +485,7 @@ public class SettingsController implements Initializable, ChildController, Navig
public void updateItem(final Country item, boolean empty)
{
super.updateItem(item, empty);
if (item != null)
if (item != null && !empty)
{
label.setText(item.getName());
@ -561,7 +561,7 @@ public class SettingsController implements Initializable, ChildController, Navig
public void updateItem(final Arbitrator item, boolean empty)
{
super.updateItem(item, empty);
if (item != null)
if (item != null && !empty)
{
label.setText(item.getName());
@ -851,9 +851,7 @@ public class SettingsController implements Initializable, ChildController, Navig
{
try
{
TextField[] textFields = {bankAccountTitleTextField, bankAccountHolderNameTextField, bankAccountPrimaryIDTextField, bankAccountSecondaryIDTextField};
BitSquareValidator.resetTextFields(textFields);
BitSquareValidator.textFieldsNotEmpty(textFields);
BitSquareValidator.textFieldsNotEmptyWithReset(bankAccountTitleTextField, bankAccountHolderNameTextField, bankAccountPrimaryIDTextField, bankAccountSecondaryIDTextField);
BankAccountTypeInfo bankAccountTypeInfo = bankAccountTypesComboBox.getSelectionModel().getSelectedItem();
BitSquareValidator.textFieldBankAccountPrimaryIDIsValid(bankAccountPrimaryIDTextField, bankAccountTypeInfo);

View File

@ -142,11 +142,11 @@ public class BitSquareFormatter
return result;
}
public static String arbitrationMethodsToString(List<Arbitrator.METHODS> items)
public static String arbitrationMethodsToString(List<Arbitrator.METHOD> items)
{
String result = "";
int i = 0;
for (Arbitrator.METHODS item : items)
for (Arbitrator.METHOD item : items)
{
result += Localisation.get(item.toString());
i++;
@ -156,11 +156,11 @@ public class BitSquareFormatter
return result;
}
public static String arbitrationIDVerificationsToString(List<Arbitrator.ID_VERIFICATIONS> items)
public static String arbitrationIDVerificationsToString(List<Arbitrator.ID_VERIFICATION> items)
{
String result = "";
int i = 0;
for (Arbitrator.ID_VERIFICATIONS item : items)
for (Arbitrator.ID_VERIFICATION item : items)
{
result += Localisation.get(item.toString());
i++;

View File

@ -16,7 +16,13 @@ public class BitSquareValidator
{
}
public static void resetTextFields(TextField[] textFields)
public static void textFieldsNotEmptyWithReset(TextField... textFields) throws ValidationException
{
resetTextFields(textFields);
textFieldsNotEmpty(textFields);
}
public static void resetTextFields(TextField... textFields)
{
for (int i = 0; i < textFields.length; i++)
{
@ -26,7 +32,7 @@ public class BitSquareValidator
}
}
public static void textFieldsNotEmpty(TextField[] textFields) throws ValidationException
public static void textFieldsNotEmpty(TextField... textFields) throws ValidationException
{
for (int i = 0; i < textFields.length; i++)
{
@ -45,8 +51,13 @@ public class BitSquareValidator
}
}
public static void textFieldsHasDoubleValueWithReset(TextField... textFields) throws ValidationException
{
resetTextFields(textFields);
textFieldsHasDoubleValue(textFields);
}
public static void textFieldsHasDoubleValue(TextField[] textFields) throws ValidationException
public static void textFieldsHasDoubleValue(TextField... textFields) throws ValidationException
{
for (int i = 0; i < textFields.length; i++)
{
@ -87,7 +98,7 @@ public class BitSquareValidator
}
}
public static boolean validateStringsAsDouble(String[] inputs)
public static boolean validateStringsAsDouble(String... inputs)
{
boolean result = true;
for (int i = 0; i < inputs.length; i++)
@ -111,7 +122,7 @@ public class BitSquareValidator
}
}
public static boolean validateStringsNotEmpty(String[] inputs)
public static boolean validateStringsNotEmpty(String... inputs)
{
boolean result = true;
for (int i = 0; i < inputs.length; i++)

View File

@ -206,7 +206,7 @@ public class ConfidenceDisplay
}
if (balanceTextField != null)
balanceTextField.setText(BtcFormatter.btcToString(balance));
balanceTextField.setText(BtcFormatter.satoshiToString(balance));
}
private void updateConfidence(Transaction tx)

View File

@ -1,8 +1,11 @@
package io.bitsquare.gui.util;
import io.bitsquare.BitSquare;
import org.controlsfx.control.action.Action;
import org.controlsfx.dialog.Dialog;
import org.controlsfx.dialog.Dialogs;
import java.util.ArrayList;
import java.util.List;
public class Popups
@ -18,9 +21,14 @@ public class Popups
.showError();
}
public static void openWarningPopup(String title, String message)
public static Action openInsufficientMoneyPopup()
{
Dialogs.create()
return openErrorPopup("Not enough money available", "There is not enough money available. Please pay in first to your wallet.");
}
public static Action openWarningPopup(String title, String message)
{
return Dialogs.create()
.title(title)
.message(message)
.nativeTitleBar()
@ -40,4 +48,19 @@ public class Popups
}
public static Action openConfirmPopup(String title, String masthead, String message)
{
List<Action> actions = new ArrayList<>();
actions.add(Dialog.Actions.OK);
actions.add(Dialog.Actions.CANCEL);
return Dialogs.create()
.owner(BitSquare.getStage())
.title(title)
.message(message)
.masthead(masthead)
.nativeTitleBar()
.lightweight()
.actions(actions)
.showConfirm();
}
}

View File

@ -226,7 +226,7 @@ public class OffererPaymentProtocol
checkNotNull(arbitratorPubKey);
log.debug("2.5 offererCreatesMSTxAndAddPayment");
log.debug("offererInputAmount " + BtcFormatter.btcToString(offererInputAmount));
log.debug("offererInputAmount " + BtcFormatter.satoshiToString(offererInputAmount));
log.debug("offerer pubkey " + offererPubKey);
log.debug("taker pubkey " + takerPubKey);
log.debug("arbitrator pubkey " + arbitratorPubKey);

View File

@ -381,8 +381,8 @@ public class TakerPaymentProtocol
checkNotNull(preparedOffererDepositTxAsHex);
log.debug("2.10 offererCreatesMSTxAndAddPayment");
log.debug("takerAmount " + BtcFormatter.btcToString(takerInputAmount));
log.debug("msOutputAmount " + BtcFormatter.btcToString(msOutputAmount));
log.debug("takerAmount " + BtcFormatter.satoshiToString(takerInputAmount));
log.debug("msOutputAmount " + BtcFormatter.satoshiToString(msOutputAmount));
log.debug("offerer pubkey " + offererPubKey);
log.debug("taker pubkey " + takerPubKey);
log.debug("arbitrator pubkey " + arbitratorPubKey);

View File

@ -14,7 +14,7 @@ public class Arbitrator implements Serializable
COMPANY
}
public enum METHODS
public enum METHOD
{
TLS_NOTARY,
SKYPE_SCREEN_SHARING,
@ -24,7 +24,7 @@ public class Arbitrator implements Serializable
OTHER
}
public enum ID_VERIFICATIONS
public enum ID_VERIFICATION
{
PASSPORT,
GOV_ID,
@ -52,8 +52,8 @@ public class Arbitrator implements Serializable
private double minPassiveServiceFee;
private double arbitrationFee;
private double minArbitrationFee;
private List<METHODS> arbitrationMethods;
private List<ID_VERIFICATIONS> idVerifications;
private List<METHOD> arbitrationMethods;
private List<ID_VERIFICATION> idVerifications;
private String webUrl;
private String description;
@ -72,8 +72,8 @@ public class Arbitrator implements Serializable
double minPassiveServiceFee,
double arbitrationFee,
double minArbitrationFee,
List<METHODS> arbitrationMethods,
List<ID_VERIFICATIONS> idVerifications,
List<METHOD> arbitrationMethods,
List<ID_VERIFICATION> idVerifications,
String webUrl,
String description)
{
@ -199,12 +199,12 @@ public class Arbitrator implements Serializable
return minArbitrationFee;
}
public List<METHODS> getArbitrationMethods()
public List<METHOD> getArbitrationMethods()
{
return arbitrationMethods;
}
public List<ID_VERIFICATIONS> getIdVerifications()
public List<ID_VERIFICATION> getIdVerifications()
{
return idVerifications;
}

View File

@ -0,0 +1,18 @@
package io.bitsquare;
import io.bitsquare.btc.BtcValidatorTest;
import io.bitsquare.gui.util.BitSquareConverterTest;
import io.bitsquare.gui.util.BitSquareValidatorTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
BtcValidatorTest.class,
BitSquareConverterTest.class,
BitSquareValidatorTest.class
})
public class BitSquareTestSuite
{
}

View File

@ -0,0 +1,34 @@
package io.bitsquare.btc;
import com.google.bitcoin.core.Transaction;
import org.junit.Test;
import java.math.BigInteger;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class BtcValidatorTest
{
@Test
public void testIsMinSpendableAmount()
{
BigInteger amount = null;
assertFalse("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount));
amount = BigInteger.ZERO;
assertFalse("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount));
amount = FeePolicy.TX_FEE;
assertFalse("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount));
amount = Transaction.MIN_NONDUST_OUTPUT;
assertFalse("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount));
amount = FeePolicy.TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT);
assertFalse("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount));
amount = FeePolicy.TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT).add(BigInteger.ONE);
assertTrue("tx unfunded, pending", BtcValidator.isMinSpendableAmount(amount));
}
}

View File

@ -1,57 +0,0 @@
package io.bitsquare.btc;
import com.google.inject.Guice;
import com.google.inject.Injector;
import io.bitsquare.di.BitSquareModule;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class WalletFacadeTest
{
private WalletFacade walletFacade;
@Before
public void setUp()
{
final Injector injector = Guice.createInjector(new BitSquareModule());
walletFacade = injector.getInstance(WalletFacade.class);
walletFacade.initWallet();
//TODO
/*
java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:276)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:271)
at javafx.application.Platform.runLater(Platform.java:78)
at io.bitsquare.btc.WalletFacade$$Lambda$1/833474933.execute(Unknown Source)
at com.google.bitcoin.core.Wallet.queueOnKeysAdded(Wallet.java:3301)
at com.google.bitcoin.core.Wallet.addKeys(Wallet.java:2024)
at com.google.bitcoin.core.Wallet.addKey(Wallet.java:1996)
at io.bitsquare.btc.WalletFacade.getNewAddressInfo(WalletFacade.java:383)
*/
}
@After
public void tearDown()
{
//walletFacade.shutDown();
}
@Test
public void testStringToDouble()
{
// AddressEntry addressEntry = walletFacade.getUnusedTradeAddressInfo();
// assertFalse("no tx", walletFacade.isUnusedTradeAddressBalanceAboveCreationFee());
/* Transaction tx = new Transaction(walletFacade.getWallet().getNetworkParameters());
WalletTransaction walletTransaction = new WalletTransaction(WalletTransaction.Pool.PENDING, tx);
walletFacade.getWallet().addWalletTransaction(walletTransaction);
assertFalse("tx unfunded, pending", walletFacade.isUnusedTradeAddressBalanceAboveCreationFee()); */
}
}