orders section, offer table

This commit is contained in:
Manfred Karrer 2014-06-25 22:50:45 +02:00
parent 47833d6602
commit a91346252e
36 changed files with 1329 additions and 962 deletions

View File

@ -105,7 +105,7 @@
<dependency>
<groupId>com.google</groupId>
<artifactId>bitcoinj</artifactId>
<version>0.11.2</version>
<version>0.11</version>
</dependency>
<dependency>

View File

@ -19,37 +19,36 @@ import java.util.*;
public class AddressBasedCoinSelector extends DefaultCoinSelector
{
private static final Logger log = LoggerFactory.getLogger(AddressBasedCoinSelector.class);
private String tradeUID;
private NetworkParameters params;
private AddressInfo addressInfo;
private AddressEntry addressEntry;
private boolean includePending;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
public AddressBasedCoinSelector()
/*public AddressBasedCoinSelector(NetworkParameters params, AddressInfo addressInfo)
{
this(params, addressInfo, false);
} */
}
public AddressBasedCoinSelector(NetworkParameters params, AddressInfo addressInfo)
public AddressBasedCoinSelector(NetworkParameters params, AddressEntry addressEntry, boolean includePending)
{
this.params = params;
this.addressInfo = addressInfo;
this.addressEntry = addressEntry;
this.includePending = includePending;
}
public AddressBasedCoinSelector(String tradeUID)
{
this.tradeUID = tradeUID;
}
/**
* Sub-classes can override this to just customize whether transactions are usable, but keep age sorting.
*/
protected boolean shouldSelect(Transaction tx)
{
return isSelectable(tx);
if (includePending)
return isInBlockChainOrPending(tx);
else
return isInBlockChain(tx);
}
protected boolean matchesRequiredAddress(TransactionOutput transactionOutput)
@ -57,7 +56,7 @@ public class AddressBasedCoinSelector extends DefaultCoinSelector
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isSentToP2SH())
{
Address addressOutput = transactionOutput.getScriptPubKey().getToAddress(params);
if (addressInfo != null && addressOutput.equals(addressInfo.getAddress()))
if (addressEntry != null && addressOutput.equals(addressEntry.getAddress()))
{
return true;
}
@ -130,17 +129,38 @@ public class AddressBasedCoinSelector extends DefaultCoinSelector
}
public static boolean isSelectable(Transaction tx)
private static boolean isInBlockChainOrPending(Transaction tx)
{
// Pick chain-included transactions and transactions that are pending.
TransactionConfidence confidence = tx.getConfidence();
TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
return type.equals(TransactionConfidence.ConfidenceType.BUILDING) ||
type.equals(TransactionConfidence.ConfidenceType.PENDING) &&
// In regtest mode we expect to have only one peer, so we won't see transactions propagate.
// TODO: The value 1 below dates from a time when transactions we broadcast *to* were counted, set to 0
(confidence.numBroadcastPeers() > 1 || tx.getParams() == RegTestParams.get());
}
private static boolean isInBlockChain(Transaction tx)
{
// Only pick chain-included transactions.
TransactionConfidence confidence = tx.getConfidence();
TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
return type.equals(TransactionConfidence.ConfidenceType.BUILDING);
}
/*
public static boolean isSelectable(Transaction tx)
{
// Only pick chain-included transactions, or transactions that are ours and pending.
TransactionConfidence confidence = tx.getConfidence();
TransactionConfidence.ConfidenceType type = confidence.getConfidenceType();
return type.equals(TransactionConfidence.ConfidenceType.BUILDING) ||
type.equals(TransactionConfidence.ConfidenceType.PENDING) &&
confidence.getSource().equals(TransactionConfidence.Source.SELF) &&
// In regtest mode we expect to have only one peer, so we won't see transactions propagate.
// TODO: The value 1 below dates from a time when transactions we broadcast *to* were counted, set to 0
(confidence.numBroadcastPeers() > 1 || tx.getParams() == RegTestParams.get());
}
*/
}

View File

@ -7,15 +7,13 @@ import com.google.bitcoin.core.Utils;
import java.io.Serializable;
public class AddressInfo implements Serializable
public class AddressEntry implements Serializable
{
private static final long serialVersionUID = 5501603992599920416L;
public static enum AddressContext
{
REGISTRATION_FEE,
CREATE_OFFER_FEE,
TAKE_OFFER_FEE,
TRADE,
ARBITRATOR_DEPOSIT
}
@ -26,7 +24,7 @@ public class AddressInfo implements Serializable
private AddressContext addressContext;
public AddressInfo(ECKey key, NetworkParameters params, AddressContext addressContext)
public AddressEntry(ECKey key, NetworkParameters params, AddressContext addressContext)
{
this.key = key;
this.params = params;

View File

@ -3,7 +3,6 @@ package io.bitsquare.btc;
import com.google.bitcoin.core.NetworkParameters;
import com.google.bitcoin.core.Wallet;
import com.google.bitcoin.crypto.KeyCrypter;
import com.google.bitcoin.wallet.CoinSelector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -14,8 +13,6 @@ public class BitSquareWallet extends Wallet implements Serializable
private static final Logger log = LoggerFactory.getLogger(BitSquareWallet.class);
private static final long serialVersionUID = -6231929674475881549L;
private transient CoinSelector coinSelector = new AddressBasedCoinSelector();
public BitSquareWallet(NetworkParameters params)
{
super(params);

View File

@ -16,8 +16,9 @@ public class FeePolicy
public static BigInteger CREATE_OFFER_FEE = Utils.toNanoCoins("0.001");
public static BigInteger TAKE_OFFER_FEE = CREATE_OFFER_FEE;
private static final String registrationFee = "mvkDXt4QmN4Nq9dRUsRigBCaovde9nLkZR";
private static final String offerFee = "n2upbsaKAe4PD3cc4JfS7UCqPC5oNd7Ckg";
private static final String registrationFeeAddress = "mvkDXt4QmN4Nq9dRUsRigBCaovde9nLkZR";
private static final String createOfferFeeAddress = "n2upbsaKAe4PD3cc4JfS7UCqPC5oNd7Ckg";
private static final String takeOfferFeeAddress = "n2upbsaKAe4PD3cc4JfS7UCqPC5oNd7Ckg";
private final NetworkParameters params;
@ -27,12 +28,12 @@ public class FeePolicy
this.params = params;
}
//TODO
//TODO other users or dev address? use donation option list? (dev, other users, wikileaks, tor, sub projects (bitcoinj, tomp2p,...)...)
public Address getAddressForRegistrationFee()
{
try
{
return new Address(params, registrationFee);
return new Address(params, registrationFeeAddress);
} catch (AddressFormatException e)
{
e.printStackTrace();
@ -40,12 +41,25 @@ public class FeePolicy
}
}
//TODO
public Address getAddressForOfferFee()
//TODO get address form arbitrator list
public Address getAddressForCreateOfferFee()
{
try
{
return new Address(params, offerFee);
return new Address(params, createOfferFeeAddress);
} catch (AddressFormatException e)
{
e.printStackTrace();
return null;
}
}
//TODO get address form the intersection of both traders arbitrator lists
public Address getAddressForTakeOfferFee()
{
try
{
return new Address(params, takeOfferFeeAddress);
} catch (AddressFormatException e)
{
e.printStackTrace();

View File

@ -52,7 +52,7 @@ public class WalletFacade
private List<DownloadListener> downloadListeners = new ArrayList<>();
private List<ConfidenceListener> confidenceListeners = new ArrayList<>();
private List<BalanceListener> balanceListeners = new ArrayList<>();
private List<AddressInfo> addressInfoList = new ArrayList<>();
private List<AddressEntry> addressEntryList = new ArrayList<>();
///////////////////////////////////////////////////////////////////////////////////////////
@ -102,13 +102,14 @@ public class WalletFacade
// Now configure and start the appkit. This will take a second or two - we could show a temporary splash screen
// or progress widget to keep the user engaged whilst we initialise, but we don't.
walletAppKit.setDownloadListener(new BlockChainDownloadListener()).setBlockingStartup(false).setUserAgent("BitSquare", "0.1");
walletAppKit.setDownloadListener(new BlockChainDownloadListener());
walletAppKit.setBlockingStartup(false);
walletAppKit.setUserAgent("BitSquare", "0.1");
walletAppKit.startAsync();
walletAppKit.awaitRunning();
wallet = (BitSquareWallet) walletAppKit.wallet();
wallet.allowSpendingUnconfirmedTransactions();
//walletAppKit.peerGroup().setMaxConnections(11);
@ -162,21 +163,18 @@ public class WalletFacade
};
wallet.addEventListener(walletEventListener);
List<AddressInfo> savedAddressInfoList = (List<AddressInfo>) storage.read("addressInfoList");
if (savedAddressInfoList != null)
List<AddressEntry> savedAddressEntryList = (List<AddressEntry>) storage.read("addressInfoList");
if (savedAddressEntryList != null)
{
addressInfoList = savedAddressInfoList;
addressEntryList = savedAddressEntryList;
}
else
{
ECKey registrationKey = wallet.getKeys().get(0);
AddressInfo registrationAddressInfo = new AddressInfo(registrationKey, params, AddressInfo.AddressContext.REGISTRATION_FEE);
addressInfoList.add(registrationAddressInfo);
AddressEntry registrationAddressEntry = new AddressEntry(registrationKey, params, AddressEntry.AddressContext.REGISTRATION_FEE);
addressEntryList.add(registrationAddressEntry);
saveAddressInfoList();
getNewOfferFeeAddressInfo();
getNewTakerFeeAddressInfo();
getNewTradeAddressInfo();
}
}
@ -197,7 +195,7 @@ public class WalletFacade
private void saveAddressInfoList()
{
// use wallet extension?
storage.write("addressInfoList", addressInfoList);
storage.write("addressInfoList", addressEntryList);
}
@ -284,45 +282,35 @@ public class WalletFacade
// Get AddressInfo objects
///////////////////////////////////////////////////////////////////////////////////////////
public List<AddressInfo> getAddressInfoList()
public List<AddressEntry> getAddressEntryList()
{
return addressInfoList;
return addressEntryList;
}
public AddressInfo getRegistrationAddressInfo()
public AddressEntry getRegistrationAddressInfo()
{
return getAddressInfoByAddressContext(AddressInfo.AddressContext.REGISTRATION_FEE);
return getAddressInfoByAddressContext(AddressEntry.AddressContext.REGISTRATION_FEE);
}
public AddressInfo getCreateOfferFeeAddressInfo()
public AddressEntry getArbitratorDepositAddressInfo()
{
return getAddressInfoByAddressContext(AddressInfo.AddressContext.CREATE_OFFER_FEE);
AddressEntry arbitratorDepositAddressEntry = getAddressInfoByAddressContext(AddressEntry.AddressContext.ARBITRATOR_DEPOSIT);
if (arbitratorDepositAddressEntry == null)
arbitratorDepositAddressEntry = getNewArbitratorDepositAddressInfo();
return arbitratorDepositAddressEntry;
}
public AddressInfo getTakerFeeAddressInfo()
public AddressEntry getUnusedTradeAddressInfo()
{
return getAddressInfoByAddressContext(AddressInfo.AddressContext.TAKE_OFFER_FEE);
}
public AddressInfo getArbitratorDepositAddressInfo()
{
AddressInfo arbitratorDepositAddressInfo = getAddressInfoByAddressContext(AddressInfo.AddressContext.ARBITRATOR_DEPOSIT);
if (arbitratorDepositAddressInfo == null)
arbitratorDepositAddressInfo = getNewArbitratorDepositAddressInfo();
return arbitratorDepositAddressInfo;
}
private AddressInfo getUnusedTradeAddressInfo()
{
if (addressInfoList != null)
if (addressEntryList != null)
{
List<AddressInfo> filteredList = Lists.newArrayList(Collections2.filter(addressInfoList, new Predicate<AddressInfo>()
List<AddressEntry> filteredList = Lists.newArrayList(Collections2.filter(addressEntryList, new Predicate<AddressEntry>()
{
@Override
public boolean apply(@Nullable AddressInfo addressInfo)
public boolean apply(@Nullable AddressEntry addressInfo)
{
return (addressInfo != null && addressInfo.getAddressContext().equals(AddressInfo.AddressContext.TRADE) && addressInfo.getTradeId() == null);
return (addressInfo != null && addressInfo.getAddressContext().equals(AddressEntry.AddressContext.TRADE) && addressInfo.getTradeId() == null);
}
}));
@ -334,14 +322,14 @@ public class WalletFacade
return getNewTradeAddressInfo();
}
private AddressInfo getAddressInfoByAddressContext(AddressInfo.AddressContext addressContext)
private AddressEntry getAddressInfoByAddressContext(AddressEntry.AddressContext addressContext)
{
if (addressInfoList != null)
if (addressEntryList != null)
{
List<AddressInfo> filteredList = Lists.newArrayList(Collections2.filter(addressInfoList, new Predicate<AddressInfo>()
List<AddressEntry> filteredList = Lists.newArrayList(Collections2.filter(addressEntryList, new Predicate<AddressEntry>()
{
@Override
public boolean apply(@Nullable AddressInfo addressInfo)
public boolean apply(@Nullable AddressEntry addressInfo)
{
return (addressInfo != null && addressContext != null && addressInfo.getAddressContext() != null && addressInfo.getAddressContext().equals(addressContext));
}
@ -355,17 +343,17 @@ public class WalletFacade
return null;
}
public AddressInfo getAddressInfoByTradeID(String tradeId)
public AddressEntry getAddressInfoByTradeID(String tradeId)
{
for (AddressInfo addressInfo : addressInfoList)
for (AddressEntry addressEntry : addressEntryList)
{
if (addressInfo.getTradeId() != null && addressInfo.getTradeId().equals(tradeId))
return addressInfo;
if (addressEntry.getTradeId() != null && addressEntry.getTradeId().equals(tradeId))
return addressEntry;
}
AddressInfo addressInfo = getUnusedTradeAddressInfo();
addressInfo.setTradeId(tradeId);
return addressInfo;
AddressEntry addressEntry = getUnusedTradeAddressInfo();
addressEntry.setTradeId(tradeId);
return addressEntry;
}
@ -373,34 +361,24 @@ public class WalletFacade
// Create new AddressInfo objects
///////////////////////////////////////////////////////////////////////////////////////////
public AddressInfo getNewTradeAddressInfo()
public AddressEntry getNewTradeAddressInfo()
{
return getNewAddressInfo(AddressInfo.AddressContext.TRADE);
return getNewAddressInfo(AddressEntry.AddressContext.TRADE);
}
private AddressInfo getNewAddressInfo(AddressInfo.AddressContext addressContext)
private AddressEntry getNewAddressInfo(AddressEntry.AddressContext addressContext)
{
ECKey key = new ECKey();
wallet.addKey(key);
AddressInfo addressInfo = new AddressInfo(key, params, addressContext);
addressInfoList.add(addressInfo);
AddressEntry addressEntry = new AddressEntry(key, params, addressContext);
addressEntryList.add(addressEntry);
saveAddressInfoList();
return addressInfo;
return addressEntry;
}
private AddressInfo getNewOfferFeeAddressInfo()
private AddressEntry getNewArbitratorDepositAddressInfo()
{
return getNewAddressInfo(AddressInfo.AddressContext.CREATE_OFFER_FEE);
}
private AddressInfo getNewTakerFeeAddressInfo()
{
return getNewAddressInfo(AddressInfo.AddressContext.TAKE_OFFER_FEE);
}
private AddressInfo getNewArbitratorDepositAddressInfo()
{
return getNewAddressInfo(AddressInfo.AddressContext.ARBITRATOR_DEPOSIT);
return getNewAddressInfo(AddressEntry.AddressContext.ARBITRATOR_DEPOSIT);
}
@ -422,21 +400,26 @@ public class WalletFacade
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();
}
}
else
{
return null;
}
}
}
}
return null;
}
public boolean isRegistrationFeeConfirmed()
{
TransactionConfidence transactionConfidence = getConfidenceForAddress(getRegistrationAddressInfo().getAddress());
return transactionConfidence != null && transactionConfidence.getConfidenceType().equals(TransactionConfidence.ConfidenceType.BUILDING);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Balance
@ -444,7 +427,7 @@ public class WalletFacade
public BigInteger getBalanceForAddress(Address address)
{
LinkedList<TransactionOutput> all = wallet.calculateAllSpendCandidates(false);
LinkedList<TransactionOutput> all = wallet.calculateAllSpendCandidates(true);
BigInteger value = BigInteger.ZERO;
for (TransactionOutput transactionOutput : all)
{
@ -475,6 +458,29 @@ public class WalletFacade
return getBalanceForAddress(getArbitratorDepositAddressInfo().getAddress());
}
public boolean isRegistrationFeeBalanceNonZero()
{
return getRegistrationBalance().compareTo(BigInteger.ZERO) > 0;
}
public boolean isRegistrationFeeBalanceSufficient()
{
return getRegistrationBalance().compareTo(FeePolicy.ACCOUNT_REGISTRATION_FEE) >= 0;
}
public boolean isUnusedTradeAddressBalanceAboveCreationFee()
{
AddressEntry unUsedAddressEntry = getUnusedTradeAddressInfo();
BigInteger unUsedAddressInfoBalance = getBalanceForAddress(unUsedAddressEntry.getAddress());
return unUsedAddressInfoBalance.compareTo(FeePolicy.CREATE_OFFER_FEE) > 0;
}
public boolean isUnusedTradeAddressBalanceAboveTakeOfferFee()
{
AddressEntry unUsedAddressEntry = getUnusedTradeAddressInfo();
BigInteger unUsedAddressInfoBalance = getBalanceForAddress(unUsedAddressEntry.getAddress());
return unUsedAddressInfoBalance.compareTo(FeePolicy.TAKE_OFFER_FEE) > 0;
}
///////////////////////////////////////////////////////////////////////////////////////////
// TODO
@ -509,7 +515,8 @@ public class WalletFacade
tx.addOutput(fee, feePolicy.getAddressForRegistrationFee());
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
sendRequest.coinSelector = new AddressBasedCoinSelector(params, getRegistrationAddressInfo());
// we don't allow spending of unconfirmed tx as with fake registrations we would open up doors for spam and market manipulation with fake offers
sendRequest.coinSelector = new AddressBasedCoinSelector(params, getRegistrationAddressInfo(), false);
sendRequest.changeAddress = getRegistrationAddressInfo().getAddress();
Wallet.SendResult sendResult = wallet.sendCoins(sendRequest);
Futures.addCallback(sendResult.broadcastComplete, callback);
@ -518,16 +525,17 @@ public class WalletFacade
printInputs("payRegistrationFee", tx);
}
public String payCreateOfferFee(FutureCallback<Transaction> callback) throws InsufficientMoneyException
public String payCreateOfferFee(String offerId, FutureCallback<Transaction> callback) throws InsufficientMoneyException
{
Transaction tx = new Transaction(params);
BigInteger fee = FeePolicy.CREATE_OFFER_FEE.subtract(FeePolicy.TX_FEE);
log.trace("fee: " + BtcFormatter.btcToString(fee));
tx.addOutput(fee, feePolicy.getAddressForOfferFee());
tx.addOutput(fee, feePolicy.getAddressForCreateOfferFee());
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
sendRequest.coinSelector = new AddressBasedCoinSelector(params, getCreateOfferFeeAddressInfo());
sendRequest.changeAddress = getCreateOfferFeeAddressInfo().getAddress();
// 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, getAddressInfoByTradeID(offerId), true);
sendRequest.changeAddress = getAddressInfoByTradeID(offerId).getAddress();
Wallet.SendResult sendResult = wallet.sendCoins(sendRequest);
Futures.addCallback(sendResult.broadcastComplete, callback);
@ -537,16 +545,17 @@ public class WalletFacade
return tx.getHashAsString();
}
public String payTakeOfferFee(FutureCallback<Transaction> callback) throws InsufficientMoneyException
public String payTakeOfferFee(String offerId, FutureCallback<Transaction> callback) throws InsufficientMoneyException
{
Transaction tx = new Transaction(params);
BigInteger fee = FeePolicy.TAKE_OFFER_FEE.subtract(FeePolicy.TX_FEE);
log.trace("fee: " + BtcFormatter.btcToString(fee));
tx.addOutput(fee, feePolicy.getAddressForOfferFee());
tx.addOutput(fee, feePolicy.getAddressForTakeOfferFee());
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
sendRequest.coinSelector = new AddressBasedCoinSelector(params, getTakerFeeAddressInfo());
sendRequest.changeAddress = getTakerFeeAddressInfo().getAddress();
// 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, getAddressInfoByTradeID(offerId), true);
sendRequest.changeAddress = getAddressInfoByTradeID(offerId).getAddress();
Wallet.SendResult sendResult = wallet.sendCoins(sendRequest);
Futures.addCallback(sendResult.broadcastComplete, callback);
@ -583,10 +592,11 @@ public class WalletFacade
tx.addOutput(offererInputAmount, multiSigOutputScript);
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
AddressInfo addressInfo = getAddressInfoByTradeID(tradeId);
addressInfo.setTradeId(tradeId);
sendRequest.coinSelector = new AddressBasedCoinSelector(params, addressInfo);
sendRequest.changeAddress = addressInfo.getAddress();
AddressEntry addressEntry = getAddressInfoByTradeID(tradeId);
addressEntry.setTradeId(tradeId);
// 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, addressEntry, true);
sendRequest.changeAddress = addressEntry.getAddress();
wallet.completeTx(sendRequest);
// The completeTx() call signs the input, but we don't want to pass over a signed tx so we remove the
@ -641,10 +651,11 @@ public class WalletFacade
tempTx.addOutput(takerInputAmount, multiSigOutputScript);
Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tempTx);
AddressInfo addressInfo = getAddressInfoByTradeID(tradeId);
addressInfo.setTradeId(tradeId);
sendRequest.coinSelector = new AddressBasedCoinSelector(params, addressInfo);
sendRequest.changeAddress = addressInfo.getAddress();
AddressEntry addressEntry = getAddressInfoByTradeID(tradeId);
addressEntry.setTradeId(tradeId);
// 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, addressEntry, true);
sendRequest.changeAddress = addressEntry.getAddress();
wallet.completeTx(sendRequest);
printInputs("tempTx", tempTx);

View File

@ -55,7 +55,6 @@ public class MainController implements Initializable, NavigationController
private ToggleGroup toggleGroup;
private ToggleButton prevToggleButton;
private Image prevToggleButtonIcon;
private Pane setupView;
private NetworkSyncPane networkSyncPane;
private ToggleButton buyButton, sellButton, homeButton, msgButton, ordersButton, historyButton, fundsButton, settingsButton;
private Pane msgButtonHolder, buyButtonHolder, sellButtonHolder, ordersButtonButtonHolder;
@ -127,8 +126,8 @@ public class MainController implements Initializable, NavigationController
//homeButton.fire();
//settingsButton.fire();
//fundsButton.fire();
sellButton.fire();
// ordersButton.fire();
// sellButton.fire();
ordersButton.fire();
// homeButton.fire();
// msgButton.fire();
@ -196,17 +195,6 @@ public class MainController implements Initializable, NavigationController
@Override
public ChildController navigateToView(String fxmlView, String title)
{
if (setupView != null)
{
anchorPane.getChildren().add(networkSyncPane);
anchorPane.setVisible(true);
rootContainer.getChildren().remove(setupView);
setupView = null;
buildNavigation();
}
if (childController != null)
childController.cleanup();

View File

@ -21,6 +21,10 @@ public interface NavigationController
public static final String ARBITRATOR_OVERVIEW = "/io/bitsquare/gui/arbitrators/overview/ArbitratorOverviewView.fxml";
public static final String ARBITRATOR_REGISTRATION = "/io/bitsquare/gui/arbitrators/registration/ArbitratorRegistrationView.fxml";
public static final String CLOSED_TRADE = "/io/bitsquare/gui/orders/closed/ClosedTradeView.fxml";
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";
ChildController navigateToView(String fxmlView);
ChildController navigateToView(String fxmlView, String title);

View File

@ -0,0 +1,129 @@
package io.bitsquare.gui.components;
import io.bitsquare.di.GuiceFXMLLoader;
import io.bitsquare.gui.ChildController;
import io.bitsquare.gui.NavigationController;
import io.bitsquare.locale.Localisation;
import io.bitsquare.storage.Storage;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
import javafx.scene.control.SingleSelectionModel;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class LazyLoadingTabPane extends TabPane
{
private String storageId;
private NavigationController navigationController;
private String[] tabContentFXMLUrls;
private Storage storage;
SingleSelectionModel<Tab> selectionModel;
private ChildController childController;
private Map<Integer, Node> views = new HashMap<>();
private Map<Integer, ChildController> controllers = new HashMap<>();
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
public LazyLoadingTabPane()
{
super();
}
public void initialize(NavigationController navigationController, Storage storage, String... tabContentFXMLUrls)
{
if (tabContentFXMLUrls.length == 0)
throw new IllegalArgumentException("No tabContentFXMLUrls defined");
this.tabContentFXMLUrls = tabContentFXMLUrls;
this.navigationController = navigationController;
this.tabContentFXMLUrls = tabContentFXMLUrls;
this.storage = storage;
storageId = navigationController.getClass().getName() + ".selectedTabIndex";
selectionModel = getSelectionModel();
selectionModel.selectedItemProperty().addListener(new ChangeListener<Tab>()
{
@Override
public void changed(ObservableValue<? extends Tab> observableValue, Tab oldTab, Tab newTab)
{
onTabSelectedIndexChanged();
}
});
Object indexObject = storage.read(storageId);
if (indexObject != null)
selectionModel.select((int) indexObject);
onTabSelectedIndexChanged();
}
public void cleanup()
{
if (childController != null)
childController.cleanup();
}
public ChildController navigateToView(String fxmlView)
{
for (int i = 0; i < tabContentFXMLUrls.length; i++)
{
if (tabContentFXMLUrls[i].equals(fxmlView))
{
selectionModel.select(i);
return childController;
}
i++;
}
return null;
}
private void onTabSelectedIndexChanged()
{
int index = selectionModel.getSelectedIndex();
if (index < tabContentFXMLUrls.length && index > -1)
{
if (childController != null)
childController.cleanup();
Node view = null;
if (index < views.size())
{
view = views.get(index);
childController = controllers.get(index);
}
if (view == null)
{
String fxmlView = tabContentFXMLUrls[index];
final GuiceFXMLLoader loader = new GuiceFXMLLoader(getClass().getResource(fxmlView), Localisation.getResourceBundle());
try
{
view = loader.load();
views.put(index, view);
childController = loader.getController();
childController.setNavigationController(navigationController);
controllers.put(index, childController);
} catch (IOException e)
{
e.printStackTrace();
}
}
selectionModel.getSelectedItem().setContent(view);
childController.setNavigationController(navigationController);
storage.write(storageId, index);
}
}
}

View File

@ -346,7 +346,7 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
degProgress = (int) (360 * control.getProgress());
arcShape.setLength(-degProgress);
indicator.setOpacity(control.getProgress() == 0 ? 0.2 : 1);
indicator.setOpacity(control.getProgress() == 0 ? 0 : 1);
requestLayout();
}
@ -368,7 +368,7 @@ public class ConfidenceProgressIndicatorSkin extends BehaviorSkinBase<Confidence
final double areaH = control.getHeight() - top - bottom /*- textGap - doneTextHeight*/;
final double radiusW = areaW / 2;
final double radiusH = areaH / 2;
final double radius = Math.floor(Math.min(radiusW, radiusH));
final double radius = Math.round(Math.min(radiusW, radiusH)); // use round instead of floor
final double centerX = snapPosition(left + radiusW);
final double centerY = snapPosition(top + radius);

View File

@ -1,37 +1,33 @@
package io.bitsquare.gui.funds;
import com.google.bitcoin.core.Address;
import io.bitsquare.btc.AddressInfo;
import io.bitsquare.btc.AddressEntry;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class AddressListItem
{
private final StringProperty addressString = new SimpleStringProperty();
private AddressInfo addressInfo;
private AddressEntry addressEntry;
public AddressListItem(AddressInfo addressInfo)
public AddressListItem(AddressEntry addressEntry)
{
this.addressInfo = addressInfo;
this.addressEntry = addressEntry;
this.addressString.set(getAddress().toString());
}
public final String getLabel()
{
switch (addressInfo.getAddressContext())
switch (addressEntry.getAddressContext())
{
case REGISTRATION_FEE:
return "Registration fee";
case CREATE_OFFER_FEE:
return "Create offer fee";
case TAKE_OFFER_FEE:
return "Take offer fee";
case TRADE:
if (addressInfo.getTradeId() != null)
return "Trade ID: " + addressInfo.getTradeId();
if (addressEntry.getTradeId() != null)
return "Trade ID: " + addressEntry.getTradeId();
else
return "Unused";
return "Trade (not used yet)";
case ARBITRATOR_DEPOSIT:
return "Arbitration deposit";
}
@ -46,11 +42,11 @@ public class AddressListItem
public Address getAddress()
{
return addressInfo.getAddress();
return addressEntry.getAddress();
}
public AddressInfo getAddressInfo()
public AddressEntry getAddressEntry()
{
return addressInfo;
return addressEntry;
}
}

View File

@ -4,7 +4,7 @@ import com.google.bitcoin.core.TransactionConfidence;
import com.google.inject.Inject;
import de.jensd.fx.fontawesome.AwesomeDude;
import de.jensd.fx.fontawesome.AwesomeIcon;
import io.bitsquare.btc.AddressInfo;
import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.BtcFormatter;
import io.bitsquare.btc.WalletFacade;
import io.bitsquare.btc.listeners.BalanceListener;
@ -23,7 +23,6 @@ import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.MouseEvent;
import javafx.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -74,12 +73,12 @@ public class FundsController implements Initializable, ChildController
setCopyColumnCellFactory();
setConfidenceColumnCellFactory();
List<AddressInfo> addressInfoList = walletFacade.getAddressInfoList();
List<AddressEntry> addressEntryList = walletFacade.getAddressEntryList();
for (int i = 0; i < addressInfoList.size(); i++)
for (int i = 0; i < addressEntryList.size(); i++)
{
AddressInfo addressInfo = addressInfoList.get(i);
addressList.add(new AddressListItem(addressInfo));
AddressEntry addressEntry = addressEntryList.get(i);
addressList.add(new AddressListItem(addressEntry));
}
addressesTable.setItems(addressList);
@ -109,8 +108,8 @@ public class FundsController implements Initializable, ChildController
@FXML
public void onAddNewTradeAddress(ActionEvent actionEvent)
{
AddressInfo addressInfo = walletFacade.getNewTradeAddressInfo();
addressList.add(new AddressListItem(addressInfo));
AddressEntry addressEntry = walletFacade.getNewTradeAddressInfo();
addressList.add(new AddressListItem(addressEntry));
}
@ -118,7 +117,6 @@ public class FundsController implements Initializable, ChildController
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
private void setLabelColumnCellFactory()
{
labelColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper(addressListItem.getValue()));
@ -129,7 +127,7 @@ public class FundsController implements Initializable, ChildController
{
return new TableCell<String, AddressListItem>()
{
Label label;
Hyperlink hyperlink;
@Override
public void updateItem(final AddressListItem item, boolean empty)
@ -138,27 +136,23 @@ public class FundsController implements Initializable, ChildController
if (item != null)
{
label = new Label(item.getLabel());
if (item.getAddressInfo().getTradeId() != null)
hyperlink = new Hyperlink(item.getLabel());
hyperlink.setId("id-link");
if (item.getAddressEntry().getTradeId() != null)
{
setId("funds-link-cell");
Tooltip tooltip = new Tooltip(item.getAddressEntry().getTradeId());
Tooltip.install(hyperlink, tooltip);
Tooltip tooltip = new Tooltip(item.getAddressInfo().getTradeId());
Tooltip.install(label, tooltip);
label.setUnderline(true);
label.setStyle("-fx-cursor: hand");
label.setOnMouseClicked(new EventHandler<MouseEvent>()
hyperlink.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(MouseEvent mouseEvent)
public void handle(ActionEvent event)
{
log.info("Show trade details " + item.getAddressInfo().getTradeId());
log.info("Show trade details " + item.getAddressEntry().getTradeId());
}
});
}
setGraphic(label);
setGraphic(hyperlink);
}
else
{
@ -231,7 +225,9 @@ public class FundsController implements Initializable, ChildController
Label copyIcon = new Label();
{
setId("funds-link-cell");
//setId("hyperlink");
copyIcon.getStyleClass().add("copy-icon");
//copyIcon.getStyleClass().setAll("copy-icon");
AwesomeDude.setIcon(copyIcon, AwesomeIcon.COPY);
Tooltip.install(copyIcon, new Tooltip("Copy address to clipboard"));
}
@ -319,13 +315,16 @@ public class FundsController implements Initializable, ChildController
private void updateBalance(BigInteger balance, Label balanceLabel)
{
if (balance != null)
{
balanceLabel.setText(BtcFormatter.btcToString(balance));
}
}
private void updateConfidence(TransactionConfidence confidence, ConfidenceProgressIndicator progressIndicator, Tooltip tooltip)
{
if (confidence != null)
{
//log.debug("Type numBroadcastPeers getDepthInBlocks " + confidence.getConfidenceType() + " / " + confidence.numBroadcastPeers() + " / " + confidence.getDepthInBlocks());
switch (confidence.getConfidenceType())
{
case UNKNOWN:
@ -342,8 +341,11 @@ public class FundsController implements Initializable, ChildController
break;
case DEAD:
tooltip.setText("Transaction is invalid.");
progressIndicator.setProgress(0);
break;
}
progressIndicator.setPrefSize(24, 24);
}
}
}

View File

@ -14,7 +14,7 @@
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>
</padding>
<TableView fx:id="addressesTable" id="funds-table" VBox.vgrow="ALWAYS">
<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">

View File

@ -51,14 +51,6 @@
-fx-text-alignment: left;
}
#copy-icon {
-fx-cursor: hand;
}
#copy-icon:hover {
-fx-text-fill: #0096c9;
}
.text-field:readonly {
-fx-text-fill: #000000;
-fx-background-color: #ffffff;
@ -79,54 +71,72 @@
-fx-background-color: transparent;
}
/* order book table */
#orderbook-table .table-cell {
-fx-alignment: center;
}
#orderbook-table .column-header .label {
-fx-alignment-alignment: center;
}
#orderbook-table .focus {
-fx-alignment: center;
}
/* funds table */
#funds-table .table-cell {
-fx-alignment: center;
}
#funds-table .column-header .label {
-fx-alignment-alignment: center;
}
#funds-table .focus {
-fx-alignment: center;
}
#funds-table .table-row-cell:selected .text {
-fx-fill: white;
}
#funds-table .table-row-cell:selected .text:hover {
-fx-fill: black;
}
#funds-link-cell .text:hover {
-fx-fill: black;
}
#funds-link-cell .text {
.copy-icon {
-fx-fill: #0096c9;
-fx-cursor: hand;
}
.copy-icon:hover {
-fx-fill: black;
}
#funds-confidence {
-fx-progress-color: dimgrey;
}
/* .table-view */
.table-view .table-cell {
-fx-alignment: center;
}
.table-view .column-header .label {
-fx-alignment-alignment: center;
}
.table-view .focus {
-fx-alignment: center;
}
.table-view .table-row-cell:selected .text {
-fx-fill: white;
}
.table-view .table-row-cell:selected .button .text {
-fx-fill: black;
}
.table-view .table-row-cell .copy-icon .text {
-fx-fill: #0096c9;
}
.table-view .table-row-cell .copy-icon .text:hover {
-fx-fill: black;
}
.table-view .table-row-cell:selected .copy-icon .text {
-fx-fill: white;
}
.table-view .table-row-cell:selected .copy-icon .text:hover {
-fx-fill: black;
}
.table-view .table-row-cell .hyperlink .text {
-fx-fill: #0096c9;
}
.table-view .table-row-cell .hyperlink .text:hover {
-fx-fill: black;
}
.table-view .table-row-cell:selected .hyperlink .text {
-fx-fill: white;
}
.table-view .table-row-cell:selected .hyperlink .text:hover {
-fx-fill: black;
}
/* forms */
#form-header-text {
-fx-font-weight: bold;
@ -161,7 +171,7 @@
-fx-background-color: transparent;
}
/* tableview */
/* table-view */
.table-view:focused {
-fx-background-color: transparent;
}

View File

@ -205,14 +205,12 @@ public class CreateOfferController implements Initializable, ChildController
offer.setOfferFeePaymentTxID(transaction.getHashAsString());
setupSuccessScreen(transaction);
placeOfferTitle.setText("Transaction sent:");
try
{
log.info("send offer to P2P orderbook");
messageFacade.addOffer(offer);
trading.addOffer(offer);
} catch (IOException e)
{
Popups.openErrorPopup("Could not publish offer", "Could not publish offer. " + e.getMessage());
Popups.openErrorPopup("Error on adding offer", "Could not add offer to orderbook. " + e.getMessage());
}
}
@ -224,9 +222,10 @@ public class CreateOfferController implements Initializable, ChildController
placeOfferButton.setDisable(false);
}
};
try
{
trading.placeNewOffer(offer, callback);
walletFacade.payCreateOfferFee(offer.getId(), callback);
placeOfferButton.setDisable(true);
} catch (InsufficientMoneyException e1)
{

View File

@ -6,6 +6,7 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.inject.Inject;
import io.bitsquare.bank.BankAccountTypeInfo;
import io.bitsquare.btc.BtcFormatter;
import io.bitsquare.btc.FeePolicy;
import io.bitsquare.btc.WalletFacade;
import io.bitsquare.gui.ChildController;
import io.bitsquare.gui.MainController;
@ -44,6 +45,7 @@ import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.util.Callback;
import org.controlsfx.control.action.Action;
import org.controlsfx.dialog.Dialog;
import org.controlsfx.dialog.Dialogs;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -111,67 +113,6 @@ public class OrderBookController implements Initializable, ChildController
// Interface implementation: Initializable
///////////////////////////////////////////////////////////////////////////////////////////
private boolean isRegistered()
{
if (user.getAccountID() == null)
{
Dialogs.CommandLink settingsCommandLink = new Dialogs.CommandLink("Open settings", "You need to configure your settings before you can actively trade.");
Dialogs.CommandLink depositFeeCommandLink = new Dialogs.CommandLink("Deposit funds", "You need to pay the registration fee before you can actively trade. That is needed as prevention against fraud.");
Dialogs.CommandLink sendRegistrationCommandLink = new Dialogs.CommandLink("Publish registration", "When settings are configured and the fee deposit is done your registration transaction will be published to the Bitcoin \nnetwork.");
List<Dialogs.CommandLink> commandLinks = Arrays.asList(settingsCommandLink, depositFeeCommandLink, sendRegistrationCommandLink);
boolean settingsValid = settings.getAcceptedLanguageLocales().size() > 0;
settingsValid &= settings.getAcceptedCountries().size() > 0;
settingsValid &= settings.getAcceptedArbitrators().size() > 0;
settingsValid &= user.getCurrentBankAccount() != null;
boolean registrationFeeDeposited = walletFacade.getRegistrationBalance().compareTo(BigInteger.ZERO) > 0;
int selectedIndex = settingsValid ? (registrationFeeDeposited ? 2 : 1) : 0;
Action registrationMissingAction = Popups.openRegistrationMissingPopup("Registration missing", "Please follow these steps:", "You need to register before you can place an offer.", commandLinks, selectedIndex);
if (registrationMissingAction == settingsCommandLink)
{
MainController.getInstance().navigateToView(NavigationController.SETTINGS);
}
else if (registrationMissingAction == depositFeeCommandLink)
{
MainController.getInstance().navigateToView(NavigationController.FUNDS);
}
else if (registrationMissingAction == sendRegistrationCommandLink)
{
FutureCallback<Transaction> callback = new FutureCallback<Transaction>()
{
@Override
public void onSuccess(Transaction transaction)
{
log.debug("payRegistrationFee onSuccess");
log.info("payRegistrationFee onSuccess txid:" + transaction.getHashAsString());
}
@Override
public void onFailure(Throwable t)
{
log.debug("payRegistrationFee onFailure");
}
};
try
{
walletFacade.payRegistrationFee(user.getStringifiedBankAccounts(), callback);
user.setAccountID(walletFacade.getRegistrationAddressInfo().toString());
user.setMessagePubKeyAsHex(DSAKeyUtil.getHexStringFromPublicKey(messageFacade.getPubKey()));
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.");
}
}
return false;
}
return true;
}
@Override
public void initialize(URL url, ResourceBundle rb)
{
@ -228,13 +169,7 @@ public class OrderBookController implements Initializable, ChildController
}
});
createOfferButton.setOnAction(e -> {
if (isRegistered())
{
ChildController nextController = navigationController.navigateToView(NavigationController.CREATE_OFFER, "Create offer");
((CreateOfferController) nextController).setOrderBookFilter(orderBookFilter);
}
});
createOfferButton.setOnAction(e -> createOffer());
//TODO do polling until broadcast works
setupPolling();
@ -284,6 +219,138 @@ public class OrderBookController implements Initializable, ChildController
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
private boolean isRegistered()
{
return user.getAccountID() != null;
}
private boolean areSettingsValid()
{
return settings.getAcceptedLanguageLocales().size() > 0 &&
settings.getAcceptedCountries().size() > 0 &&
settings.getAcceptedArbitrators().size() > 0 &&
user.getCurrentBankAccount() != null;
}
private void showRegistrationDialog()
{
int selectedIndex = -1;
if (areSettingsValid())
{
if (walletFacade.isRegistrationFeeBalanceNonZero())
{
if (walletFacade.isRegistrationFeeBalanceSufficient())
{
if (walletFacade.isRegistrationFeeConfirmed())
{
selectedIndex = 2;
}
else
{
Action response = Popups.openErrorPopup("Registration fee not confirmed yet", "The registration fee transaction has not been confirmed yet in the blockchain. Please wait until it has at least 1 confirmation.");
if (response == Dialog.Actions.OK)
{
MainController.getInstance().navigateToView(NavigationController.FUNDS);
}
}
}
else
{
Action response = Popups.openErrorPopup("Missing registration fee", "You have not funded the full registration fee of " + BtcFormatter.btcToString(FeePolicy.ACCOUNT_REGISTRATION_FEE) + " BTC.");
if (response == Dialog.Actions.OK)
{
MainController.getInstance().navigateToView(NavigationController.FUNDS);
}
}
}
else
{
selectedIndex = 1;
}
}
else
{
selectedIndex = 0;
}
if (selectedIndex >= 0)
{
Dialogs.CommandLink settingsCommandLink = new Dialogs.CommandLink("Open settings", "You need to configure your settings before you can actively trade.");
Dialogs.CommandLink depositFeeCommandLink = new Dialogs.CommandLink("Deposit funds", "You need to pay the registration fee before you can actively trade. That is needed as prevention against fraud.");
Dialogs.CommandLink sendRegistrationCommandLink = new Dialogs.CommandLink("Publish registration", "When settings are configured and the fee deposit is done your registration transaction will be published to the Bitcoin \nnetwork.");
List<Dialogs.CommandLink> commandLinks = Arrays.asList(settingsCommandLink, depositFeeCommandLink, sendRegistrationCommandLink);
Action registrationMissingAction = Popups.openRegistrationMissingPopup("Not registered yet", "Please follow these steps:", "You need to register before you can place an offer.", commandLinks, selectedIndex);
if (registrationMissingAction == settingsCommandLink)
{
MainController.getInstance().navigateToView(NavigationController.SETTINGS);
}
else if (registrationMissingAction == depositFeeCommandLink)
{
MainController.getInstance().navigateToView(NavigationController.FUNDS);
}
else if (registrationMissingAction == sendRegistrationCommandLink)
{
payRegistrationFee();
}
}
}
private void payRegistrationFee()
{
FutureCallback<Transaction> callback = new FutureCallback<Transaction>()
{
@Override
public void onSuccess(Transaction transaction)
{
log.debug("payRegistrationFee onSuccess");
log.info("payRegistrationFee onSuccess txid:" + transaction.getHashAsString());
}
@Override
public void onFailure(Throwable t)
{
log.debug("payRegistrationFee onFailure");
}
};
try
{
walletFacade.payRegistrationFee(user.getStringifiedBankAccounts(), callback);
user.setAccountID(walletFacade.getRegistrationAddressInfo().toString());
user.setMessagePubKeyAsHex(DSAKeyUtil.getHexStringFromPublicKey(messageFacade.getPubKey()));
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.");
}
}
private void createOffer()
{
if (isRegistered())
{
if (walletFacade.isUnusedTradeAddressBalanceAboveCreationFee())
{
ChildController nextController = navigationController.navigateToView(NavigationController.CREATE_OFFER, "Create offer");
((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.getInstance().navigateToView(NavigationController.FUNDS);
}
}
}
else
{
showRegistrationDialog();
}
}
private void takeOffer(Offer offer)
{
if (isRegistered())
@ -297,6 +364,10 @@ public class OrderBookController implements Initializable, ChildController
takerTradeController.initWithData(offer, requestedAmount);
}
else
{
showRegistrationDialog();
}
}
private void removeOffer(Offer offer)
@ -349,6 +420,7 @@ public class OrderBookController implements Initializable, ChildController
});
}
///////////////////////////////////////////////////////////////////////////////////////////
// Table columns
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -21,12 +21,12 @@ public class OrderBookListItem
public OrderBookListItem(Offer offer)
{
this.offer = offer;
this.price.set(BitSquareFormatter.formatPrice(offer.getPrice()));
double amountAsBtcDouble = BtcFormatter.satoshiToBTC(offer.getAmount());
double minAmountAsBtcDouble = BtcFormatter.satoshiToBTC(offer.getMinAmount());
this.price.set(BitSquareFormatter.formatPrice(offer.getPrice()));
this.amount.set(BitSquareFormatter.formatAmountWithMinAmount(amountAsBtcDouble, minAmountAsBtcDouble));
this.volume.set(BitSquareFormatter.formatVolumeWithMinVolume(offer.getVolume(), offer.getMinVolume()));
}

View File

@ -43,7 +43,7 @@
<Button fx:id="createOfferButton" text="Create new offer" AnchorPane.topAnchor="10.0"
AnchorPane.rightAnchor="10.0"/>
<TableView fx:id="orderBookTable" id="orderbook-table" AnchorPane.leftAnchor="10.0"
<TableView fx:id="orderBookTable" AnchorPane.leftAnchor="10.0"
AnchorPane.topAnchor="45.0" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="10.0">
<columns>
<TableColumn text="Amount (Min.)" fx:id="amountColumn" minWidth="120">

View File

@ -221,9 +221,9 @@ public class TakerTradeController implements Initializable, ChildController
// offerId = tradeId
// we don't want to create the trade before the balance check
AddressInfo addressInfo = walletFacade.getAddressInfoByTradeID(offer.getId());
log.debug("balance " + walletFacade.getBalanceForAddress(addressInfo.getAddress()).toString());
if (getTotalToPay().compareTo(walletFacade.getBalanceForAddress(addressInfo.getAddress())) > 0)
AddressEntry addressEntry = walletFacade.getAddressInfoByTradeID(offer.getId());
log.debug("balance " + walletFacade.getBalanceForAddress(addressEntry.getAddress()).toString());
if (getTotalToPay().compareTo(walletFacade.getBalanceForAddress(addressEntry.getAddress())) > 0)
{
Popups.openErrorPopup("Insufficient money", "You don't have enough funds for that trade.");
return;

View File

@ -1,82 +1,26 @@
package io.bitsquare.gui.orders;
import com.google.bitcoin.core.ECKey;
import com.google.bitcoin.core.Transaction;
import com.google.bitcoin.core.Wallet;
import com.google.bitcoin.core.WalletEventListener;
import com.google.bitcoin.script.Script;
import com.google.inject.Inject;
import de.jensd.fx.fontawesome.AwesomeDude;
import de.jensd.fx.fontawesome.AwesomeIcon;
import io.bitsquare.bank.BankAccount;
import io.bitsquare.bank.BankAccountTypeInfo;
import io.bitsquare.btc.BtcFormatter;
import io.bitsquare.btc.FeePolicy;
import io.bitsquare.btc.WalletFacade;
import io.bitsquare.gui.ChildController;
import io.bitsquare.gui.NavigationController;
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
import io.bitsquare.gui.util.BitSquareFormatter;
import io.bitsquare.gui.util.ConfidenceDisplay;
import io.bitsquare.gui.util.Icons;
import io.bitsquare.locale.Country;
import io.bitsquare.locale.Localisation;
import io.bitsquare.trade.Direction;
import io.bitsquare.trade.Offer;
import io.bitsquare.trade.Trade;
import io.bitsquare.trade.Trading;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import io.bitsquare.gui.components.LazyLoadingTabPane;
import io.bitsquare.storage.Storage;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigInteger;
import java.net.URL;
import java.util.*;
import java.util.ResourceBundle;
public class OrdersController implements Initializable, ChildController
public class OrdersController implements Initializable, ChildController, NavigationController
{
private static final Logger log = LoggerFactory.getLogger(OrdersController.class);
private Storage storage;
private Trading trading;
private WalletFacade walletFacade;
private Trade currentTrade;
private NavigationController navigationController;
private Image buyIcon = Icons.getIconImage(Icons.BUY);
private Image sellIcon = Icons.getIconImage(Icons.SELL);
private ConfidenceDisplay confidenceDisplay;
@FXML
private VBox rootContainer;
@FXML
private TableView openTradesTable;
@FXML
private TableColumn<String, TradesTableItem> directionColumn, countryColumn, bankAccountTypeColumn, priceColumn, amountColumn, volumeColumn, statusColumn, selectColumn;
@FXML
private ConfidenceProgressIndicator progressIndicator;
@FXML
private Label txTitleLabel, txHeaderLabel, confirmationLabel, txIDCopyIcon, holderNameCopyIcon, primaryBankAccountIDCopyIcon, secondaryBankAccountIDCopyIcon, bankAccountDetailsHeaderLabel,
bankAccountTypeTitleLabel, holderNameTitleLabel, primaryBankAccountIDTitleLabel, secondaryBankAccountIDTitleLabel;
@FXML
private TextField txTextField, bankAccountTypeTextField, holderNameTextField, primaryBankAccountIDTextField, secondaryBankAccountIDTextField;
@FXML
private Button bankTransferInitedButton;
private LazyLoadingTabPane tabPane;
///////////////////////////////////////////////////////////////////////////////////////////
@ -84,10 +28,9 @@ public class OrdersController implements Initializable, ChildController
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public OrdersController(Trading trading, WalletFacade walletFacade)
public OrdersController(Storage storage)
{
this.trading = trading;
this.walletFacade = walletFacade;
this.storage = storage;
}
@ -98,58 +41,7 @@ public class OrdersController implements Initializable, ChildController
@Override
public void initialize(URL url, ResourceBundle rb)
{
Map<String, Trade> trades = trading.getTrades();
List<Trade> tradeList = new ArrayList<>(trades.values());
ObservableList<TradesTableItem> tradeItems = FXCollections.observableArrayList();
for (Iterator<Trade> iterator = tradeList.iterator(); iterator.hasNext(); )
{
Trade trade = iterator.next();
tradeItems.add(new TradesTableItem(trade));
}
setCountryColumnCellFactory();
setBankAccountTypeColumnCellFactory();
setDirectionColumnCellFactory();
setSelectColumnCellFactory();
openTradesTable.setItems(tradeItems);
openTradesTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
openTradesTable.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
if (newValue instanceof TradesTableItem)
{
showTradeDetails((TradesTableItem) newValue);
}
});
trading.getNewTradeProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observableValue, String oldTradeUid, String newTradeUid)
{
Trade newTrade = trading.getTrades().get(newTradeUid);
tradeItems.add(new TradesTableItem(newTrade));
}
});
initCopyIcons();
if (tradeItems.size() > 0)
{
openTradesTable.getSelectionModel().select(0);
}
tradeItems.addListener(new ListChangeListener<TradesTableItem>()
{
@Override
public void onChanged(Change<? extends TradesTableItem> change)
{
if (openTradesTable.getSelectionModel().getSelectedItem() == null && tradeItems.size() > 0)
{
openTradesTable.getSelectionModel().select(0);
}
}
});
tabPane.initialize(this, storage, NavigationController.OFFER, NavigationController.PENDING_TRADE, NavigationController.CLOSED_TRADE);
}
@ -160,380 +52,38 @@ public class OrdersController implements Initializable, ChildController
@Override
public void setNavigationController(NavigationController navigationController)
{
this.navigationController = navigationController;
}
@Override
public void cleanup()
{
tabPane.cleanup();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: NavigationController
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public ChildController navigateToView(String fxmlView)
{
return navigateToView(fxmlView, "");
}
@Override
public ChildController navigateToView(String fxmlView, String title)
{
return tabPane.navigateToView(fxmlView);
}
///////////////////////////////////////////////////////////////////////////////////////////
// GUI handlers
///////////////////////////////////////////////////////////////////////////////////////////
public void bankTransferInited(ActionEvent actionEvent)
{
trading.onBankTransferInited(currentTrade.getId());
bankTransferInitedButton.setDisable(true);
}
public void close(ActionEvent actionEvent)
{
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
private void showTradeDetails(TradesTableItem tradesTableItem)
{
fillData(tradesTableItem.getTrade());
}
private void updateTx(Transaction transaction)
{
txTextField.setText(transaction.getHashAsString());
confidenceDisplay = new ConfidenceDisplay(walletFacade.getWallet(), confirmationLabel, transaction, progressIndicator);
int depthInBlocks = transaction.getConfidence().getDepthInBlocks();
bankTransferInitedButton.setDisable(depthInBlocks == 0);
walletFacade.getWallet().addEventListener(new WalletEventListener()
{
@Override
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
{
int depthInBlocks = tx.getConfidence().getDepthInBlocks();
bankTransferInitedButton.setDisable(depthInBlocks == 0);
}
@Override
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
{
}
@Override
public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
{
}
@Override
public void onReorganize(Wallet wallet)
{
}
@Override
public void onWalletChanged(Wallet wallet)
{
}
@Override
public void onKeysAdded(Wallet wallet, List<ECKey> keys)
{
}
@Override
public void onScriptsAdded(Wallet wallet, List<Script> scripts)
{
}
});
}
private void fillData(Trade trade)
{
currentTrade = trade;
Transaction transaction = trade.getDepositTransaction();
if (transaction == null)
{
trade.getDepositTxChangedProperty().addListener(new ChangeListener<Boolean>()
{
@Override
public void changed(ObservableValue<? extends Boolean> observableValue, Boolean aBoolean, Boolean aBoolean2)
{
updateTx(trade.getDepositTransaction());
}
});
}
else
{
updateTx(trade.getDepositTransaction());
}
// back details
if (trade.getContract() != null)
{
setBankData(trade);
}
else
{
trade.getContractChangedProperty().addListener(new ChangeListener<Boolean>()
{
@Override
public void changed(ObservableValue<? extends Boolean> observableValue, Boolean aBoolean, Boolean aBoolean2)
{
setBankData(trade);
}
});
}
// state
trade.getStateChangedProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observableValue, String aString, String aString2)
{
setState(trade);
}
});
}
private void setState(Trade trade)
{
if (trade.getState() == Trade.State.COMPLETED)
{
Transaction transaction = trade.getPayoutTransaction();
confidenceDisplay.destroy();
confidenceDisplay = new ConfidenceDisplay(walletFacade.getWallet(), confirmationLabel, transaction, progressIndicator);
txTextField.setText(transaction.getHashAsString());
txHeaderLabel.setText("Payout transaction");
txTitleLabel.setText("Payout transaction ID:");
bankAccountDetailsHeaderLabel.setText("Summary");
bankAccountTypeTitleLabel.setText("You have bought (BTC):");
holderNameTitleLabel.setText("You have payed (" + trade.getOffer().getCurrency() + "):");
primaryBankAccountIDTitleLabel.setText("Total fees (offer fee + tx fee):");
secondaryBankAccountIDTitleLabel.setText("Refunded collateral:");
String fiatPayed = BitSquareFormatter.formatVolume(trade.getOffer().getPrice() * BtcFormatter.satoshiToBTC(trade.getTradeAmount()));
bankAccountTypeTextField.setText(BtcFormatter.btcToString(trade.getTradeAmount()));
holderNameTextField.setText(fiatPayed);
primaryBankAccountIDTextField.setText(BtcFormatter.btcToString(FeePolicy.CREATE_OFFER_FEE.add(FeePolicy.TX_FEE)));
secondaryBankAccountIDTextField.setText(BtcFormatter.btcToString(trade.getCollateralAmount()));
holderNameCopyIcon.setVisible(false);
primaryBankAccountIDCopyIcon.setVisible(false);
secondaryBankAccountIDCopyIcon.setVisible(false);
bankTransferInitedButton.setVisible(false);
}
}
private void setBankData(Trade trade)
{
BankAccount bankAccount = trade.getContract().getTakerBankAccount();
bankAccountTypeTextField.setText(bankAccount.getBankAccountTypeInfo().getType().toString());
holderNameTextField.setText(bankAccount.getAccountHolderName());
primaryBankAccountIDTextField.setText(bankAccount.getAccountPrimaryID());
secondaryBankAccountIDTextField.setText(bankAccount.getAccountSecondaryID());
}
private void initCopyIcons()
{
AwesomeDude.setIcon(txIDCopyIcon, AwesomeIcon.COPY);
txIDCopyIcon.setOnMouseClicked(e -> {
Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
content.putString(txTextField.getText());
clipboard.setContent(content);
});
AwesomeDude.setIcon(holderNameCopyIcon, AwesomeIcon.COPY);
holderNameCopyIcon.setOnMouseClicked(e -> {
Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
content.putString(holderNameTextField.getText());
clipboard.setContent(content);
});
AwesomeDude.setIcon(primaryBankAccountIDCopyIcon, AwesomeIcon.COPY);
primaryBankAccountIDCopyIcon.setOnMouseClicked(e -> {
Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
content.putString(primaryBankAccountIDTextField.getText());
clipboard.setContent(content);
});
AwesomeDude.setIcon(secondaryBankAccountIDCopyIcon, AwesomeIcon.COPY);
secondaryBankAccountIDCopyIcon.setOnMouseClicked(e -> {
Clipboard clipboard = Clipboard.getSystemClipboard();
ClipboardContent content = new ClipboardContent();
content.putString(secondaryBankAccountIDTextField.getText());
clipboard.setContent(content);
});
}
///////////////////////////////////////////////////////////////////////////////////////////
// Table columns
///////////////////////////////////////////////////////////////////////////////////////////
private void setCountryColumnCellFactory()
{
countryColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper(offer.getValue()));
countryColumn.setCellFactory(new Callback<TableColumn<String, TradesTableItem>, TableCell<String, TradesTableItem>>()
{
@Override
public TableCell<String, TradesTableItem> call(TableColumn<String, TradesTableItem> directionColumn)
{
return new TableCell<String, TradesTableItem>()
{
final HBox hBox = new HBox();
{
hBox.setSpacing(3);
hBox.setAlignment(Pos.CENTER);
setGraphic(hBox);
}
@Override
public void updateItem(final TradesTableItem tradesTableItem, boolean empty)
{
super.updateItem(tradesTableItem, empty);
hBox.getChildren().clear();
if (tradesTableItem != null)
{
Country country = tradesTableItem.getTrade().getOffer().getBankAccountCountry();
try
{
hBox.getChildren().add(Icons.getIconImageView("/images/countries/" + country.getCode().toLowerCase() + ".png"));
} catch (Exception e)
{
log.warn("Country icon not found: " + "/images/countries/" + country.getCode().toLowerCase() + ".png country name: " + country.getName());
}
Tooltip.install(this, new Tooltip(country.getName()));
}
}
};
}
});
}
private void setBankAccountTypeColumnCellFactory()
{
bankAccountTypeColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper(offer.getValue()));
bankAccountTypeColumn.setCellFactory(new Callback<TableColumn<String, TradesTableItem>, TableCell<String, TradesTableItem>>()
{
@Override
public TableCell<String, TradesTableItem> call(TableColumn<String, TradesTableItem> directionColumn)
{
return new TableCell<String, TradesTableItem>()
{
@Override
public void updateItem(final TradesTableItem tradesTableItem, boolean empty)
{
super.updateItem(tradesTableItem, empty);
if (tradesTableItem != null)
{
BankAccountTypeInfo.BankAccountType bankAccountType = tradesTableItem.getTrade().getOffer().getBankAccountType();
setText(Localisation.get(bankAccountType.toString()));
}
else
{
setText("");
}
}
};
}
});
}
private void setDirectionColumnCellFactory()
{
directionColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper(offer.getValue()));
directionColumn.setCellFactory(new Callback<TableColumn<String, TradesTableItem>, TableCell<String, TradesTableItem>>()
{
@Override
public TableCell<String, TradesTableItem> call(TableColumn<String, TradesTableItem> directionColumn)
{
return new TableCell<String, TradesTableItem>()
{
final ImageView iconView = new ImageView();
final Button button = new Button();
{
button.setGraphic(iconView);
button.setMinWidth(70);
}
@Override
public void updateItem(final TradesTableItem tradesTableItem, boolean empty)
{
super.updateItem(tradesTableItem, empty);
if (tradesTableItem != null)
{
String title;
Image icon;
Offer offer = tradesTableItem.getTrade().getOffer();
if (offer.getDirection() == Direction.SELL)
{
icon = buyIcon;
title = BitSquareFormatter.formatDirection(Direction.BUY, true);
}
else
{
icon = sellIcon;
title = BitSquareFormatter.formatDirection(Direction.SELL, true);
}
button.setDisable(true);
iconView.setImage(icon);
button.setText(title);
setGraphic(button);
}
else
{
setGraphic(null);
}
}
};
}
});
}
private void setSelectColumnCellFactory()
{
selectColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper(offer.getValue()));
selectColumn.setCellFactory(new Callback<TableColumn<String, TradesTableItem>, TableCell<String, TradesTableItem>>()
{
@Override
public TableCell<String, TradesTableItem> call(TableColumn<String, TradesTableItem> directionColumn)
{
return new TableCell<String, TradesTableItem>()
{
final Button button = new Button("Select");
@Override
public void updateItem(final TradesTableItem tradesTableItem, boolean empty)
{
super.updateItem(tradesTableItem, empty);
if (tradesTableItem != null)
{
button.setOnAction(event -> showTradeDetails(tradesTableItem));
setGraphic(button);
}
else
{
setGraphic(null);
}
}
};
}
});
}
}

View File

@ -1,156 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator?>
<?import javafx.geometry.*?>
<?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.*?>
<VBox fx:id="rootContainer" fx:controller="io.bitsquare.gui.orders.OrdersController" spacing="10" AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" AnchorPane.rightAnchor="0"
AnchorPane.topAnchor="0" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label id="headline-label" text="Open trades">
<VBox.margin>
<Insets left="10.0" top="10.0"/>
</VBox.margin>
</Label>
<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.orders.OrdersController">
<TableView id="orderbook-table" fx:id="openTradesTable" prefHeight="150.0">
<columns>
<TableColumn fx:id="amountColumn" minWidth="120" text="Amount (Min.)">
<cellValueFactory>
<PropertyValueFactory property="amount"/>
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="priceColumn" minWidth="70" text="Price">
<cellValueFactory>
<PropertyValueFactory property="price"/>
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="volumeColumn" minWidth="130" text="Volume (Min.)">
<cellValueFactory>
<PropertyValueFactory property="volume"/>
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="countryColumn" minWidth="60" text="Country"/>
<TableColumn fx:id="bankAccountTypeColumn" minWidth="140" text="Bank transfer type"/>
<TableColumn fx:id="directionColumn" minWidth="80" sortable="false" text="Offer type"/>
<TableColumn fx:id="statusColumn" minWidth="80" text="Status">
<cellValueFactory>
<PropertyValueFactory property="status"/>
</cellValueFactory>
</TableColumn>
<LazyLoadingTabPane fx:id="tabPane" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<TableColumn fx:id="selectColumn" minWidth="60" sortable="false" text=""/>
</columns>
<VBox.margin>
<Insets left="10.0" right="10.0"/>
</VBox.margin>
</TableView>
<Tab text="Open offers" closable="false"/>
<Tab text="Pending trades" closable="false"/>
<Tab text="Closed trades" closable="false"/>
<Label text="After you received 1 blockchain confirmation you are safe to start the bank transfer.">
<VBox.margin>
<Insets bottom="10.0" left="10.0" top="10.0"/>
</VBox.margin>
</Label>
<GridPane hgap="5.0" vgap="5.0">
<children>
<!-- row 0 -->
<Label fx:id="txHeaderLabel" id="headline-label" text="Deposit transaction" GridPane.columnSpan="2" GridPane.halignment="LEFT"/>
<!-- row 1 -->
<Label fx:id="txTitleLabel" text="Deposit transaction ID:" GridPane.rowIndex="1"/>
<TextField fx:id="txTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Label fx:id="txIDCopyIcon" id="copy-icon" minWidth="10" GridPane.columnIndex="2" GridPane.rowIndex="1">
<padding>
<Insets bottom="0.0" left="0.0" right="0.0" top="-1.0"/>
</padding>
<tooltip>
<Tooltip text="Copy address to clipboard"/>
</tooltip>
</Label>
<ConfidenceProgressIndicator fx:id="progressIndicator" visible="false" progress="0" GridPane.columnIndex="3" GridPane.halignment="LEFT" GridPane.rowIndex="1"
GridPane.rowSpan="2" GridPane.valignment="TOP">
<GridPane.margin>
<Insets top="2.0"/>
</GridPane.margin>
</ConfidenceProgressIndicator>
<Label fx:id="confirmationLabel" visible="false" GridPane.columnIndex="4" GridPane.rowIndex="1"/>
<!-- row 2 -->
<Label fx:id="bankAccountDetailsHeaderLabel" id="headline-label" text="Bank details" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.halignment="LEFT"
GridPane.rowIndex="2"/>
<!-- row 3 -->
<Label fx:id="bankAccountTypeTitleLabel" text="Bank account type:" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
<TextField fx:id="bankAccountTypeTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<!-- row 4 -->
<Label fx:id="holderNameTitleLabel" text="Holder name:" GridPane.columnIndex="0" GridPane.rowIndex="4"/>
<TextField fx:id="holderNameTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<Label fx:id="holderNameCopyIcon" id="copy-icon" minWidth="10" GridPane.columnIndex="2" GridPane.rowIndex="4">
<padding>
<Insets bottom="0.0" left="0.0" right="0.0" top="-1.0"/>
</padding>
<tooltip>
<Tooltip text="Copy address to clipboard"/>
</tooltip>
</Label>
<!-- row 5 -->
<Label fx:id="primaryBankAccountIDTitleLabel" text="Primary bank account ID:" GridPane.columnIndex="0" GridPane.rowIndex="5"/>
<TextField fx:id="primaryBankAccountIDTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="5"/>
<Label fx:id="primaryBankAccountIDCopyIcon" id="copy-icon" minWidth="10" GridPane.columnIndex="2" GridPane.rowIndex="5">
<padding>
<Insets bottom="0.0" left="0.0" right="0.0" top="-1.0"/>
</padding>
<tooltip>
<Tooltip text="Copy address to clipboard"/>
</tooltip>
</Label>
<!-- row 6 -->
<Label fx:id="secondaryBankAccountIDTitleLabel" text="Secondary bank account ID:" GridPane.columnIndex="0" GridPane.rowIndex="6"/>
<TextField fx:id="secondaryBankAccountIDTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="6"/>
<Label fx:id="secondaryBankAccountIDCopyIcon" id="copy-icon" minWidth="10" GridPane.columnIndex="2" GridPane.rowIndex="6">
<padding>
<Insets bottom="0.0" left="0.0" right="0.0" top="-1.0"/>
</padding>
<tooltip>
<Tooltip text="Copy address to clipboard"/>
</tooltip>
</Label>
<!-- row 7 -->
<Button fx:id="bankTransferInitedButton" defaultButton="true" onAction="#bankTransferInited" disable="true" text="Bank transfer inited"
GridPane.columnIndex="1"
GridPane.rowIndex="7"/>
</children>
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES"/>
<ColumnConstraints hgrow="ALWAYS"/>
<ColumnConstraints fillWidth="false" hgrow="SOMETIMES" minWidth="20"/>
<ColumnConstraints fillWidth="false" hgrow="SOMETIMES" minWidth="20" prefWidth="20"/>
<ColumnConstraints fillWidth="false" hgrow="SOMETIMES"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints/>
</rowConstraints>
<VBox.margin>
<Insets left="10.0" right="10.0"/>
</VBox.margin>
</GridPane>
</children>
</VBox>
</LazyLoadingTabPane>
</AnchorPane>

View File

@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import javafx.scene.layout.*?>
<VBox fx:id="rootContainer" fx:controller="io.bitsquare.gui.orders.OrdersController2" spacing="10" AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" AnchorPane.rightAnchor="0"
AnchorPane.topAnchor="0" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label id="headline-label" text="Open trades">
<VBox.margin>
<Insets left="10.0" top="10.0"/>
</VBox.margin>
</Label>
<TableView id="orderbook-table" fx:id="openTradesTable" prefHeight="150.0">
<columns>
<TableColumn fx:id="amountColumn" minWidth="120" text="Amount (Min.)">
<cellValueFactory>
<PropertyValueFactory property="amount"/>
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="priceColumn" minWidth="70" text="Price">
<cellValueFactory>
<PropertyValueFactory property="price"/>
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="volumeColumn" minWidth="130" text="Volume (Min.)">
<cellValueFactory>
<PropertyValueFactory property="volume"/>
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="countryColumn" minWidth="60" text="Country"/>
<TableColumn fx:id="bankAccountTypeColumn" minWidth="140" text="Bank transfer type"/>
<TableColumn fx:id="directionColumn" minWidth="80" sortable="false" text="Offer type"/>
<TableColumn fx:id="statusColumn" minWidth="80" text="Status">
<cellValueFactory>
<PropertyValueFactory property="status"/>
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="selectColumn" minWidth="60" sortable="false" text=""/>
</columns>
<VBox.margin>
<Insets left="10.0" right="10.0"/>
</VBox.margin>
</TableView>
<Label text="After you received 1 blockchain confirmation you are safe to start the bank transfer.">
<VBox.margin>
<Insets bottom="10.0" left="10.0" top="10.0"/>
</VBox.margin>
</Label>
<GridPane hgap="5.0" vgap="5.0">
<children>
<!-- row 0 -->
<Label fx:id="txHeaderLabel" id="headline-label" text="Deposit transaction" GridPane.columnSpan="2" GridPane.halignment="LEFT"/>
<!-- row 1 -->
<Label fx:id="txTitleLabel" text="Deposit transaction ID:" GridPane.rowIndex="1"/>
<TextField fx:id="txTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Label fx:id="txIDCopyIcon" id="copy-icon" minWidth="10" GridPane.columnIndex="2" GridPane.rowIndex="1">
<padding>
<Insets bottom="0.0" left="0.0" right="0.0" top="-1.0"/>
</padding>
<tooltip>
<Tooltip text="Copy address to clipboard"/>
</tooltip>
</Label>
<ConfidenceProgressIndicator fx:id="progressIndicator" visible="false" progress="0" GridPane.columnIndex="3" GridPane.halignment="LEFT" GridPane.rowIndex="1"
GridPane.rowSpan="2" GridPane.valignment="TOP">
<GridPane.margin>
<Insets top="2.0"/>
</GridPane.margin>
</ConfidenceProgressIndicator>
<Label fx:id="confirmationLabel" visible="false" GridPane.columnIndex="4" GridPane.rowIndex="1"/>
<!-- row 2 -->
<Label fx:id="bankAccountDetailsHeaderLabel" id="headline-label" text="Bank details" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.halignment="LEFT"
GridPane.rowIndex="2"/>
<!-- row 3 -->
<Label fx:id="bankAccountTypeTitleLabel" text="Bank account type:" GridPane.columnIndex="0" GridPane.rowIndex="3"/>
<TextField fx:id="bankAccountTypeTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<!-- row 4 -->
<Label fx:id="holderNameTitleLabel" text="Holder name:" GridPane.columnIndex="0" GridPane.rowIndex="4"/>
<TextField fx:id="holderNameTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<Label fx:id="holderNameCopyIcon" id="copy-icon" minWidth="10" GridPane.columnIndex="2" GridPane.rowIndex="4">
<padding>
<Insets bottom="0.0" left="0.0" right="0.0" top="-1.0"/>
</padding>
<tooltip>
<Tooltip text="Copy address to clipboard"/>
</tooltip>
</Label>
<!-- row 5 -->
<Label fx:id="primaryBankAccountIDTitleLabel" text="Primary bank account ID:" GridPane.columnIndex="0" GridPane.rowIndex="5"/>
<TextField fx:id="primaryBankAccountIDTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="5"/>
<Label fx:id="primaryBankAccountIDCopyIcon" id="copy-icon" minWidth="10" GridPane.columnIndex="2" GridPane.rowIndex="5">
<padding>
<Insets bottom="0.0" left="0.0" right="0.0" top="-1.0"/>
</padding>
<tooltip>
<Tooltip text="Copy address to clipboard"/>
</tooltip>
</Label>
<!-- row 6 -->
<Label fx:id="secondaryBankAccountIDTitleLabel" text="Secondary bank account ID:" GridPane.columnIndex="0" GridPane.rowIndex="6"/>
<TextField fx:id="secondaryBankAccountIDTextField" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="6"/>
<Label fx:id="secondaryBankAccountIDCopyIcon" id="copy-icon" minWidth="10" GridPane.columnIndex="2" GridPane.rowIndex="6">
<padding>
<Insets bottom="0.0" left="0.0" right="0.0" top="-1.0"/>
</padding>
<tooltip>
<Tooltip text="Copy address to clipboard"/>
</tooltip>
</Label>
<!-- row 7 -->
<Button fx:id="bankTransferInitedButton" defaultButton="true" onAction="#bankTransferInited" disable="true" text="Bank transfer inited"
GridPane.columnIndex="1"
GridPane.rowIndex="7"/>
</children>
<columnConstraints>
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES"/>
<ColumnConstraints hgrow="ALWAYS"/>
<ColumnConstraints fillWidth="false" hgrow="SOMETIMES" minWidth="20"/>
<ColumnConstraints fillWidth="false" hgrow="SOMETIMES" minWidth="20" prefWidth="20"/>
<ColumnConstraints fillWidth="false" hgrow="SOMETIMES"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES"/>
<RowConstraints/>
</rowConstraints>
<VBox.margin>
<Insets left="10.0" right="10.0"/>
</VBox.margin>
</GridPane>
</children>
</VBox>

View File

@ -0,0 +1,65 @@
package io.bitsquare.gui.orders.closed;
import com.google.inject.Inject;
import io.bitsquare.gui.ChildController;
import io.bitsquare.gui.NavigationController;
import javafx.fxml.Initializable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URL;
import java.util.ResourceBundle;
public class ClosedTradeController implements Initializable, ChildController
{
private static final Logger log = LoggerFactory.getLogger(ClosedTradeController.class);
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public ClosedTradeController()
{
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: Initializable
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: ChildController
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void setNavigationController(NavigationController navigationController)
{
log.debug("setNavigationController" + this);
}
@Override
public void cleanup()
{
log.debug("cleanup" + this);
}
///////////////////////////////////////////////////////////////////////////////////////////
// GUI Event handlers
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Private Methods
///////////////////////////////////////////////////////////////////////////////////////////
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?>
<AnchorPane fx:controller="io.bitsquare.gui.orders.closed.ClosedTradeController" AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" AnchorPane.rightAnchor="0"
AnchorPane.topAnchor="0" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox spacing="20" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label id="headline-label" text="Closed"/>
</children>
</VBox>
</children>
</AnchorPane>

View File

@ -0,0 +1,208 @@
package io.bitsquare.gui.orders.offer;
import com.google.inject.Inject;
import io.bitsquare.gui.ChildController;
import io.bitsquare.gui.NavigationController;
import io.bitsquare.gui.util.Icons;
import io.bitsquare.trade.Offer;
import io.bitsquare.trade.Trading;
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.image.ImageView;
import javafx.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
public class OfferController implements Initializable, ChildController
{
private static final Logger log = LoggerFactory.getLogger(OfferController.class);
protected ObservableList<OfferListItem> offerListItems = FXCollections.observableArrayList();
@FXML
private TableColumn<String, OfferListItem> offerIdColumn, dateColumn, amountColumn, priceColumn, volumeColumn, removeColumn;
@FXML
private TableView offerTable;
private Trading trading;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public OfferController(Trading trading)
{
this.trading = trading;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: Initializable
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void initialize(URL url, ResourceBundle rb)
{
setOfferIdColumnColumnCellFactory();
setRemoveColumnCellFactory();
Map<String, Offer> offerMap = trading.getOffers();
List<Offer> offerList = new ArrayList<>(offerMap.values());
for (int i = 0; i < offerList.size(); i++)
{
offerListItems.add(new OfferListItem(offerList.get(i)));
}
offerTable.setItems(offerListItems);
offerTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: ChildController
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void setNavigationController(NavigationController navigationController)
{
log.debug("setNavigationController" + this);
}
@Override
public void cleanup()
{
log.debug("cleanup" + this);
}
///////////////////////////////////////////////////////////////////////////////////////////
// GUI Event handlers
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Private Methods
///////////////////////////////////////////////////////////////////////////////////////////
private void removeOffer(Offer offer)
{
try
{
trading.removeOffer(offer);
} catch (IOException e)
{
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Table columns
///////////////////////////////////////////////////////////////////////////////////////////
private void setOfferIdColumnColumnCellFactory()
{
offerIdColumn.setCellValueFactory((offerListItem) -> new ReadOnlyObjectWrapper(offerListItem.getValue()));
offerIdColumn.setCellFactory(new Callback<TableColumn<String, OfferListItem>, TableCell<String, OfferListItem>>()
{
@Override
public TableCell<String, OfferListItem> call(TableColumn<String, OfferListItem> column)
{
return new TableCell<String, OfferListItem>()
{
Hyperlink hyperlink;
@Override
public void updateItem(final OfferListItem item, boolean empty)
{
super.updateItem(item, empty);
if (item != null)
{
hyperlink = new Hyperlink(item.getOfferId());
//hyperlink.getStyleClass().setAll("aaa");
if (item != null)
{
Tooltip tooltip = new Tooltip(item.getOfferId());
Tooltip.install(hyperlink, tooltip);
hyperlink.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
log.info("Show offer details " + item.getOfferId());
}
});
/* hyperlink.setOnMouseEntered(new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent event)
{
log.info("Show offer details " + item.getOfferId());
}
}); */
}
setGraphic(hyperlink);
}
else
{
setGraphic(null);
setId(null);
}
}
};
}
});
}
private void setRemoveColumnCellFactory()
{
removeColumn.setCellValueFactory((offerListItem) -> new ReadOnlyObjectWrapper(offerListItem.getValue()));
removeColumn.setCellFactory(new Callback<TableColumn<String, OfferListItem>, TableCell<String, OfferListItem>>()
{
@Override
public TableCell<String, OfferListItem> call(TableColumn<String, OfferListItem> directionColumn)
{
return new TableCell<String, OfferListItem>()
{
final ImageView iconView = Icons.getIconImageView(Icons.REMOVE);
final Button button = new Button();
{
button.setText("Remove");
button.setGraphic(iconView);
button.setMinWidth(70);
}
@Override
public void updateItem(final OfferListItem offerListItem, boolean empty)
{
super.updateItem(offerListItem, empty);
if (offerListItem != null)
{
button.setOnAction(event -> removeOffer(offerListItem.getOffer()));
setGraphic(button);
}
else
{
setGraphic(null);
}
}
};
}
});
}
}

View File

@ -0,0 +1,77 @@
package io.bitsquare.gui.orders.offer;
import io.bitsquare.btc.BtcFormatter;
import io.bitsquare.gui.util.BitSquareFormatter;
import io.bitsquare.trade.Offer;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import java.text.DateFormat;
import java.util.Locale;
/**
* Wrapper for observable properties used by orderbook table view
*/
public class OfferListItem
{
protected final StringProperty price = new SimpleStringProperty();
protected final StringProperty amount = new SimpleStringProperty();
protected final StringProperty date = new SimpleStringProperty();
protected final StringProperty volume = new SimpleStringProperty();
private final String offerId;
protected Offer offer;
public OfferListItem(Offer offer)
{
this.offer = offer;
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.getDefault());
DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, Locale.getDefault());
this.date.set(dateFormatter.format(offer.getCreationDate()) + " " + timeFormatter.format(offer.getCreationDate()));
this.price.set(BitSquareFormatter.formatPrice(offer.getPrice()));
double amountAsBtcDouble = BtcFormatter.satoshiToBTC(offer.getAmount());
double minAmountAsBtcDouble = BtcFormatter.satoshiToBTC(offer.getMinAmount());
this.amount.set(BitSquareFormatter.formatAmountWithMinAmount(amountAsBtcDouble, minAmountAsBtcDouble));
this.volume.set(BitSquareFormatter.formatVolumeWithMinVolume(offer.getVolume(), offer.getMinVolume()));
this.offerId = offer.getId();
}
public Offer getOffer()
{
return offer;
}
// called form table columns
public final StringProperty dateProperty()
{
return this.date;
}
public final StringProperty priceProperty()
{
return this.price;
}
public final StringProperty amountProperty()
{
return this.amount;
}
public final StringProperty volumeProperty()
{
return this.volume;
}
public String getOfferId()
{
return offerId;
}
}

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.VBox?>
<VBox spacing="10" fx:controller="io.bitsquare.gui.orders.offer.OfferController" 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="offerTable" VBox.vgrow="ALWAYS">
<columns>
<TableColumn text="Offer ID" fx:id="offerIdColumn" minWidth="100" sortable="false">
<cellValueFactory>
<PropertyValueFactory property="offerId"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="Date" fx:id="dateColumn" minWidth="100" sortable="false">
<cellValueFactory>
<PropertyValueFactory property="date"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="Amount (Min.)" fx:id="amountColumn" minWidth="70" sortable="false">
<cellValueFactory>
<PropertyValueFactory property="amount"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="Price" fx:id="priceColumn" minWidth="70" sortable="false">
<cellValueFactory>
<PropertyValueFactory property="price"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="Volume (Min.)" fx:id="volumeColumn" minWidth="70" sortable="false">
<cellValueFactory>
<PropertyValueFactory property="price"/>
</cellValueFactory>
</TableColumn>
<TableColumn text="Status" fx:id="removeColumn" minWidth="70" sortable="false"/>
</columns>
</TableView>
</VBox>

View File

@ -0,0 +1,65 @@
package io.bitsquare.gui.orders.pending;
import com.google.inject.Inject;
import io.bitsquare.gui.ChildController;
import io.bitsquare.gui.NavigationController;
import javafx.fxml.Initializable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.URL;
import java.util.ResourceBundle;
public class PendingTradeController implements Initializable, ChildController
{
private static final Logger log = LoggerFactory.getLogger(PendingTradeController.class);
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public PendingTradeController()
{
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: Initializable
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void initialize(URL url, ResourceBundle rb)
{
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: ChildController
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void setNavigationController(NavigationController navigationController)
{
log.debug("setNavigationController" + this);
}
@Override
public void cleanup()
{
log.debug("cleanup" + this);
}
///////////////////////////////////////////////////////////////////////////////////////////
// GUI Event handlers
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Private Methods
///////////////////////////////////////////////////////////////////////////////////////////
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?>
<AnchorPane fx:controller="io.bitsquare.gui.orders.pending.PendingTradeController" AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0" AnchorPane.rightAnchor="0"
AnchorPane.topAnchor="0" xmlns="http://javafx.com/javafx/8"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<VBox spacing="20" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Label id="headline-label" text="Pending"/>
</children>
</VBox>
</children>
</AnchorPane>

View File

@ -1,4 +1,4 @@
package io.bitsquare.gui.orders;
package io.bitsquare.gui.orders.pending;
import io.bitsquare.gui.market.orderbook.OrderBookListItem;
import io.bitsquare.trade.Trade;

View File

@ -7,9 +7,10 @@ import java.util.List;
public class Popups
{
public static void openErrorPopup(String title, String message)
public static Action openErrorPopup(String title, String message)
{
Dialogs.create()
return Dialogs.create()
.title(title)
.message(message)
.nativeTitleBar()

View File

@ -133,5 +133,4 @@ public class Settings implements Serializable
return minCollateral;
}
}

View File

@ -7,34 +7,32 @@ import io.bitsquare.user.Arbitrator;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.Currency;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.*;
public class Offer implements Serializable
{
private static final long serialVersionUID = -971164804305475826L;
// key attributes for lookup
private Direction direction;
private Currency currency;
private final Direction direction;
private final Currency currency;
private String id;
private final String id;
private final Date creationDate;
private double price;
private BigInteger amount;
private BigInteger minAmount;
private String messagePubKeyAsHex;
private BankAccountTypeInfo.BankAccountType bankAccountType;
private Country bankAccountCountry;
private final BigInteger amount;
private final BigInteger minAmount;
private final String messagePubKeyAsHex;
private final BankAccountTypeInfo.BankAccountType bankAccountType;
private final Country bankAccountCountry;
private int collateral;
private List<Country> acceptedCountries;
private List<Locale> acceptedLanguageLocales;
private final int collateral;
private final List<Country> acceptedCountries;
private final List<Locale> acceptedLanguageLocales;
private String offerFeePaymentTxID;
private String bankAccountUID;
private Arbitrator arbitrator;
private final String bankAccountUID;
private final Arbitrator arbitrator;
///////////////////////////////////////////////////////////////////////////////////////////
@ -67,9 +65,11 @@ public class Offer implements Serializable
this.arbitrator = arbitrator;
this.collateral = collateral;
this.acceptedCountries = acceptedCountries;
this.acceptedLanguageLocales = acceptedLanguageLocales;
this.id = UUID.randomUUID().toString();
creationDate = new Date();
id = UUID.randomUUID().toString();
}
@ -193,4 +193,9 @@ public class Offer implements Serializable
", arbitrator=" + arbitrator +
'}';
}
public Date getCreationDate()
{
return creationDate;
}
}

View File

@ -1,10 +1,8 @@
package io.bitsquare.trade;
import com.google.bitcoin.core.InsufficientMoneyException;
import com.google.bitcoin.core.Transaction;
import com.google.bitcoin.core.TransactionConfidence;
import com.google.bitcoin.core.Utils;
import com.google.common.util.concurrent.FutureCallback;
import com.google.inject.Inject;
import io.bitsquare.btc.BlockChainFacade;
import io.bitsquare.btc.WalletFacade;
@ -91,24 +89,28 @@ public class Trading
{
}
private void saveOffers()
{
storage.write(storageKey + ".offers", myOffers);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Offer, trade, contract
///////////////////////////////////////////////////////////////////////////////////////////
public void placeNewOffer(Offer offer, FutureCallback<Transaction> callback) throws InsufficientMoneyException
public void addOffer(Offer offer) throws IOException
{
if (myOffers.containsKey(offer.getId()))
throw new IllegalStateException("offers contains already a offer with the ID " + offer.getId());
myOffers.put(offer.getId(), offer);
walletFacade.payCreateOfferFee(callback);
saveOffers();
messageFacade.addOffer(offer);
}
public void removeOffer(Offer offer) throws IOException
{
myOffers.remove(offer.getId());
storage.write(storageKey + ".offers", myOffers);
saveOffers();
messageFacade.removeOffer(offer);
}
public Trade createTrade(Offer offer)
@ -230,6 +232,11 @@ public class Trading
return trades;
}
public Map<String, Offer> getOffers()
{
return myOffers;
}
public Offer getOffer(String offerUID)
{
return myOffers.get(offerUID.toString());

View File

@ -219,7 +219,7 @@ public class TakerPaymentProtocol
{
// Pay the offer fee
takerPaymentProtocolListener.onProgress(getProgress());
walletFacade.payTakeOfferFee(callback);
walletFacade.payTakeOfferFee(trade.getId(), callback);
} catch (InsufficientMoneyException e)
{
takerPaymentProtocolListener.onProgress(getProgress());

View File

@ -0,0 +1,57 @@
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()); */
}
}