use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.
the class LockedView method initialize.
@Override
public void initialize() {
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableView.setPlaceholder(new Label("No funds are locked in trades"));
setDateColumnCellFactory();
setDetailsColumnCellFactory();
setAddressColumnCellFactory();
setBalanceColumnCellFactory();
addressColumn.setComparator((o1, o2) -> o1.getAddressString().compareTo(o2.getAddressString()));
detailsColumn.setComparator((o1, o2) -> o1.getTrade().getId().compareTo(o2.getTrade().getId()));
balanceColumn.setComparator((o1, o2) -> o1.getBalance().compareTo(o2.getBalance()));
dateColumn.setComparator((o1, o2) -> {
if (getTradable(o1).isPresent() && getTradable(o2).isPresent())
return getTradable(o2).get().getDate().compareTo(getTradable(o1).get().getDate());
else
return 0;
});
tableView.getSortOrder().add(dateColumn);
dateColumn.setSortType(TableColumn.SortType.DESCENDING);
balanceListener = new BalanceListener() {
@Override
public void onBalanceChanged(Coin balance, Transaction tx) {
updateList();
}
};
openOfferListChangeListener = c -> updateList();
tradeListChangeListener = c -> updateList();
}
use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.
the class MainViewModel method updateAvailableBalance.
private void updateAvailableBalance() {
Coin totalAvailableBalance = Coin.valueOf(tradeManager.getAddressEntriesForAvailableBalanceStream().mapToLong(addressEntry -> walletService.getBalanceForAddress(addressEntry.getAddress()).getValue()).sum());
availableBalance.set(formatter.formatCoinWithCode(totalAvailableBalance));
}
use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.
the class MainViewModel method updateLockedBalance.
private void updateLockedBalance() {
Coin sum = Coin.valueOf(tradeManager.getLockedTradeStream().mapToLong(trade -> {
Coin lockedTradeAmount = walletService.getOrCreateAddressEntry(trade.getId(), AddressEntry.Context.MULTI_SIG).getCoinLockedInMultiSig();
return lockedTradeAmount != null ? lockedTradeAmount.getValue() : 0;
}).sum());
lockedBalance.set(formatter.formatCoinWithCode(sum));
}
use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.
the class PendingTradesDataModel method tryOpenDispute.
private void tryOpenDispute(boolean isSupportTicket) {
if (getTrade() != null) {
Transaction depositTx = getTrade().getDepositTx();
if (depositTx != null) {
doOpenDispute(isSupportTicket, getTrade().getDepositTx());
} else {
log.info("Trade.depositTx is null. We try to find the tx in our wallet.");
List<Transaction> candidates = new ArrayList<>();
List<Transaction> transactions = walletService.getWallet().getRecentTransactions(100, true);
transactions.stream().forEach(transaction -> {
Coin valueSentFromMe = transaction.getValueSentFromMe(walletService.getWallet());
if (!valueSentFromMe.isZero()) {
candidates.addAll(transaction.getOutputs().stream().filter(transactionOutput -> !transactionOutput.isMine(walletService.getWallet())).filter(transactionOutput -> transactionOutput.getScriptPubKey().isPayToScriptHash()).map(transactionOutput -> transaction).collect(Collectors.toList()));
}
});
if (candidates.size() == 1)
doOpenDispute(isSupportTicket, candidates.get(0));
else if (candidates.size() > 1)
new SelectDepositTxWindow().transactions(candidates).onSelect(transaction -> doOpenDispute(isSupportTicket, transaction)).closeButtonText("Cancel").show();
else
log.error("Trade.depositTx is null and we did not find any MultiSig transaction.");
}
} else {
log.error("Trade is null");
}
}
use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.
the class ClosedTradesView method initialize.
@Override
public void initialize() {
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableView.setPlaceholder(new Label("No closed trades available"));
setTradeIdColumnCellFactory();
setDirectionColumnCellFactory();
setAmountColumnCellFactory();
setPriceColumnCellFactory();
setVolumeColumnCellFactory();
setDateColumnCellFactory();
setMarketColumnCellFactory();
setStateColumnCellFactory();
setAvatarColumnCellFactory();
tradeIdColumn.setComparator((o1, o2) -> o1.getTradable().getId().compareTo(o2.getTradable().getId()));
dateColumn.setComparator((o1, o2) -> o1.getTradable().getDate().compareTo(o2.getTradable().getDate()));
directionColumn.setComparator((o1, o2) -> o1.getTradable().getOffer().getDirection().compareTo(o2.getTradable().getOffer().getDirection()));
marketColumn.setComparator((o1, o2) -> model.getMarketLabel(o1).compareTo(model.getMarketLabel(o2)));
priceColumn.setComparator((o1, o2) -> {
final Tradable tradable1 = o1.getTradable();
final Tradable tradable2 = o2.getTradable();
Fiat price1 = null;
Fiat price2 = null;
if (tradable1 != null)
price1 = tradable1 instanceof Trade ? ((Trade) tradable1).getTradePrice() : tradable1.getOffer().getPrice();
if (tradable2 != null)
price2 = tradable2 instanceof Trade ? ((Trade) tradable2).getTradePrice() : tradable2.getOffer().getPrice();
return price1 != null && price2 != null ? price1.compareTo(price2) : 0;
});
volumeColumn.setComparator((o1, o2) -> {
if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
Fiat tradeVolume1 = ((Trade) o1.getTradable()).getTradeVolume();
Fiat tradeVolume2 = ((Trade) o2.getTradable()).getTradeVolume();
return tradeVolume1 != null && tradeVolume2 != null ? tradeVolume1.compareTo(tradeVolume2) : 0;
} else
return 0;
});
amountColumn.setComparator((o1, o2) -> {
if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
Coin amount1 = ((Trade) o1.getTradable()).getTradeAmount();
Coin amount2 = ((Trade) o2.getTradable()).getTradeAmount();
return amount1 != null && amount2 != null ? amount1.compareTo(amount2) : 0;
} else
return 0;
});
avatarColumn.setComparator((o1, o2) -> {
if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
NodeAddress tradingPeerNodeAddress1 = ((Trade) o1.getTradable()).getTradingPeerNodeAddress();
NodeAddress tradingPeerNodeAddress2 = ((Trade) o2.getTradable()).getTradingPeerNodeAddress();
String address1 = tradingPeerNodeAddress1 != null ? tradingPeerNodeAddress1.hostName : "";
String address2 = tradingPeerNodeAddress2 != null ? tradingPeerNodeAddress2.hostName : "";
return address1 != null && address2 != null ? address1.compareTo(address2) : 0;
} else
return 0;
});
stateColumn.setComparator((o1, o2) -> model.getState(o1).compareTo(model.getState(o2)));
dateColumn.setSortType(TableColumn.SortType.DESCENDING);
tableView.getSortOrder().add(dateColumn);
exportButton.setText("Export to csv");
}
Aggregations