use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.
the class ReservedView method initialize.
@Override
public void initialize() {
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableView.setPlaceholder(new Label("No funds are reserved in open offers"));
setDateColumnCellFactory();
setDetailsColumnCellFactory();
setAddressColumnCellFactory();
setBalanceColumnCellFactory();
addressColumn.setComparator((o1, o2) -> o1.getAddressString().compareTo(o2.getAddressString()));
detailsColumn.setComparator((o1, o2) -> o1.getOpenOffer().getId().compareTo(o2.getOpenOffer().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 DisputeSummaryWindow method applyCustomAmounts.
private void applyCustomAmounts(InputTextField inputTextField) {
Coin securityDeposit = FeePolicy.getSecurityDeposit(dispute.getContract().offer);
Coin tradeAmount = dispute.getContract().getTradeAmount();
Coin buyerAmount = formatter.parseToCoin(buyerPayoutAmountInputTextField.getText());
Coin sellerAmount = formatter.parseToCoin(sellerPayoutAmountInputTextField.getText());
Coin arbitratorAmount = formatter.parseToCoin(arbitratorPayoutAmountInputTextField.getText());
Coin available = tradeAmount.add(securityDeposit).add(securityDeposit);
Coin totalAmount = buyerAmount.add(sellerAmount).add(arbitratorAmount);
if (totalAmount.compareTo(available) > 0) {
new Popup<>().warning("Amount entered exceeds available amount of " + available.toFriendlyString() + ".\n" + "We adjust this input field to the max possible value.").show();
if (inputTextField == buyerPayoutAmountInputTextField) {
buyerAmount = available.subtract(sellerAmount).subtract(arbitratorAmount);
inputTextField.setText(formatter.formatCoin(buyerAmount));
} else if (inputTextField == sellerPayoutAmountInputTextField) {
sellerAmount = available.subtract(buyerAmount).subtract(arbitratorAmount);
inputTextField.setText(formatter.formatCoin(sellerAmount));
} else if (inputTextField == arbitratorPayoutAmountInputTextField) {
arbitratorAmount = available.subtract(sellerAmount).subtract(buyerAmount);
inputTextField.setText(formatter.formatCoin(arbitratorAmount));
}
}
disputeResult.setBuyerPayoutAmount(buyerAmount);
disputeResult.setSellerPayoutAmount(sellerAmount);
disputeResult.setArbitratorPayoutAmount(arbitratorAmount);
if (buyerAmount.compareTo(sellerAmount) == 0)
disputeResult.setWinner(DisputeResult.Winner.STALE_MATE);
else if (buyerAmount.compareTo(sellerAmount) > 0)
disputeResult.setWinner(DisputeResult.Winner.BUYER);
else
disputeResult.setWinner(DisputeResult.Winner.SELLER);
}
use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.
the class TakeOfferView method onClose.
// called form parent as the view does not get notified when the tab is closed
public void onClose() {
Coin balance = model.dataModel.balance.get();
if (balance != null && balance.isPositive() && !model.takeOfferCompleted.get() && !DevFlags.DEV_MODE) {
model.dataModel.swapTradeToSavings();
new Popup().information("You had already funded that offer.\n" + "Your funds have been moved to your local Bitsquare wallet and are available for " + "withdrawal in the \"Funds/Available for withdrawal\" screen.").actionButtonText("Go to \"Funds/Available for withdrawal\"").onAction(() -> navigation.navigateTo(MainView.class, FundsView.class, WithdrawalView.class)).show();
}
// TODO need other implementation as it is displayed also if there are old funds in the wallet
/*
if (model.dataModel.isWalletFunded.get())
new Popup().warning("You have already funds paid in.\nIn the <Funds/Open for withdrawal> section you can withdraw those funds.").show();*/
}
use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.
the class OfferBookViewModel method getAmount.
String getAmount(OfferBookListItem item) {
Offer offer = item.getOffer();
Coin amount = offer.getAmount();
Coin minAmount = offer.getMinAmount();
if (amount.equals(minAmount))
return formatter.formatAmount(offer);
else
return formatter.formatAmountWithMinAmount(offer);
}
use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.
the class TakeOfferDataModel method initWithData.
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
// called before activate
void initWithData(Offer offer) {
this.offer = offer;
tradePrice = offer.getPrice();
addressEntry = walletService.getOrCreateAddressEntry(offer.getId(), AddressEntry.Context.OFFER_FUNDING);
checkNotNull(addressEntry, "addressEntry must not be null");
ObservableList<PaymentAccount> possiblePaymentAccounts = getPossiblePaymentAccounts();
checkArgument(!possiblePaymentAccounts.isEmpty(), "possiblePaymentAccounts.isEmpty()");
paymentAccount = possiblePaymentAccounts.get(0);
amountAsCoin.set(offer.getAmount());
if (DevFlags.DEV_MODE)
amountAsCoin.set(offer.getAmount());
calculateVolume();
calculateTotalToPay();
balanceListener = new BalanceListener(addressEntry.getAddress()) {
@Override
public void onBalanceChanged(Coin balance, Transaction tx) {
updateBalance();
/*if (isMainNet.get()) {
SettableFuture<Coin> future = blockchainService.requestFee(tx.getHashAsString());
Futures.addCallback(future, new FutureCallback<Coin>() {
public void onSuccess(Coin fee) {
UserThread.execute(() -> setFeeFromFundingTx(fee));
}
public void onFailure(@NotNull Throwable throwable) {
UserThread.execute(() -> new Popup()
.warning("We did not get a response for the request of the mining fee used " +
"in the funding transaction.\n\n" +
"Are you sure you used a sufficiently high fee of at least " +
formatter.formatCoinWithCode(FeePolicy.getMinRequiredFeeForFundingTx()) + "?")
.actionButtonText("Yes, I used a sufficiently high fee.")
.onAction(() -> setFeeFromFundingTx(FeePolicy.getMinRequiredFeeForFundingTx()))
.closeButtonText("No. Let's cancel that payment.")
.onClose(() -> setFeeFromFundingTx(Coin.NEGATIVE_SATOSHI))
.show());
}
});
} else {
setFeeFromFundingTx(FeePolicy.getMinRequiredFeeForFundingTx());
isFeeFromFundingTxSufficient.set(feeFromFundingTx.compareTo(FeePolicy.getMinRequiredFeeForFundingTx()) >= 0);
}*/
}
};
offer.resetState();
if (!preferences.getUseStickyMarketPrice())
priceFeedService.setCurrencyCode(offer.getCurrencyCode());
}
Aggregations