Search in sources :

Example 11 with Coin

use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.

the class TakeOfferDataModel method wouldCreateDustForOfferer.

boolean wouldCreateDustForOfferer() {
    //noinspection SimplifiableIfStatement
    if (amountAsCoin.get() != null && offer != null) {
        Coin customAmount = offer.getAmount().subtract(amountAsCoin.get());
        Coin dustAndFee = FeePolicy.getFixedTxFeeForTrades().add(Transaction.MIN_NONDUST_OUTPUT);
        return customAmount.isPositive() && customAmount.isLessThan(dustAndFee);
    } else {
        return true;
    }
}
Also used : Coin(org.bitcoinj.core.Coin)

Example 12 with Coin

use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.

the class TakeOfferDataModel method updateBalance.

void updateBalance() {
    Coin tradeWalletBalance = walletService.getBalanceForAddress(addressEntry.getAddress());
    if (useSavingsWallet) {
        Coin savingWalletBalance = walletService.getSavingWalletBalance();
        totalAvailableBalance = savingWalletBalance.add(tradeWalletBalance);
        if (totalToPayAsCoin.get() != null) {
            if (totalAvailableBalance.compareTo(totalToPayAsCoin.get()) > 0)
                balance.set(totalToPayAsCoin.get());
            else
                balance.set(totalAvailableBalance);
        }
    } else {
        balance.set(tradeWalletBalance);
    }
    if (totalToPayAsCoin.get() != null) {
        missingCoin.set(totalToPayAsCoin.get().subtract(balance.get()));
        if (missingCoin.get().isNegative())
            missingCoin.set(Coin.ZERO);
    }
    log.debug("missingCoin " + missingCoin.get().toFriendlyString());
    isWalletFunded.set(isBalanceSufficient(balance.get()));
    if (totalToPayAsCoin.get() != null && isWalletFunded.get() && walletFundedNotification == null && !DevFlags.DEV_MODE) {
        walletFundedNotification = new Notification().headLine("Trading wallet update").notification("Your trading wallet is sufficiently funded.\n" + "Amount: " + formatter.formatCoinWithCode(totalToPayAsCoin.get())).autoClose();
        walletFundedNotification.show();
    }
}
Also used : Coin(org.bitcoinj.core.Coin) Notification(io.bitsquare.gui.main.overlays.notifications.Notification)

Example 13 with Coin

use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.

the class DisputeSummaryWindow method calculatePayoutAmounts.

private void calculatePayoutAmounts(DisputeResult.DisputeFeePolicy feePayment) {
    Contract contract = dispute.getContract();
    Coin refund = FeePolicy.getSecurityDeposit(dispute.getContract().offer);
    Coin winnerRefund;
    Coin loserRefund;
    switch(feePayment) {
        case SPLIT:
            winnerRefund = refund.divide(2L);
            loserRefund = winnerRefund;
            arbitratorPayoutAmount = refund;
            break;
        case WAIVE:
            winnerRefund = refund;
            loserRefund = refund;
            arbitratorPayoutAmount = Coin.ZERO;
            break;
        case LOSER:
        default:
            winnerRefund = refund;
            loserRefund = Coin.ZERO;
            arbitratorPayoutAmount = refund;
            break;
    }
    winnerPayoutAmount = contract.getTradeAmount().add(winnerRefund);
    loserPayoutAmount = loserRefund;
    stalematePayoutAmount = contract.getTradeAmount().divide(2L).add(winnerRefund);
}
Also used : Coin(org.bitcoinj.core.Coin) Contract(io.bitsquare.trade.Contract)

Example 14 with Coin

use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.

the class DisputeSummaryWindow method applyTradeAmountRadioButtonStates.

private void applyTradeAmountRadioButtonStates() {
    Coin buyerPayoutAmount = disputeResult.getBuyerPayoutAmount();
    Coin sellerPayoutAmount = disputeResult.getSellerPayoutAmount();
    buyerPayoutAmountInputTextField.setText(formatter.formatCoin(buyerPayoutAmount));
    sellerPayoutAmountInputTextField.setText(formatter.formatCoin(sellerPayoutAmount));
    arbitratorPayoutAmountInputTextField.setText(formatter.formatCoin(disputeResult.getArbitratorPayoutAmount()));
    if (buyerPayoutAmount.equals(winnerPayoutAmount) && sellerPayoutAmount.equals(loserPayoutAmount)) {
        buyerIsWinnerRadioButton.setSelected(true);
    } else if (sellerPayoutAmount.equals(winnerPayoutAmount) && buyerPayoutAmount.equals(loserPayoutAmount)) {
        sellerIsWinnerRadioButton.setSelected(true);
    } else if (sellerPayoutAmount.equals(buyerPayoutAmount)) {
        shareRadioButton.setSelected(true);
    } else {
        customRadioButton.setSelected(true);
    }
}
Also used : Coin(org.bitcoinj.core.Coin)

Example 15 with Coin

use of org.bitcoinj.core.Coin in project bitsquare by bitsquare.

the class DisputeSummaryWindow method isPayoutAmountValid.

private boolean isPayoutAmountValid() {
    Coin buyerAmount = formatter.parseToCoin(buyerPayoutAmountInputTextField.getText());
    Coin sellerAmount = formatter.parseToCoin(sellerPayoutAmountInputTextField.getText());
    Coin arbitratorAmount = formatter.parseToCoin(arbitratorPayoutAmountInputTextField.getText());
    Coin securityDeposit = FeePolicy.getSecurityDeposit(dispute.getContract().offer);
    Coin tradeAmount = dispute.getContract().getTradeAmount();
    Coin available = tradeAmount.add(securityDeposit).add(securityDeposit);
    Coin totalAmount = buyerAmount.add(sellerAmount).add(arbitratorAmount);
    return (totalAmount.compareTo(available) == 0);
}
Also used : Coin(org.bitcoinj.core.Coin)

Aggregations

Coin (org.bitcoinj.core.Coin)35 AddressEntry (io.bitsquare.btc.AddressEntry)13 WalletService (io.bitsquare.btc.WalletService)13 Transaction (org.bitcoinj.core.Transaction)11 Popup (io.bitsquare.gui.main.overlays.popups.Popup)9 BalanceListener (io.bitsquare.btc.listeners.BalanceListener)8 Offer (io.bitsquare.trade.offer.Offer)7 Address (org.bitcoinj.core.Address)6 BSFormatter (io.bitsquare.gui.util.BSFormatter)5 Trade (io.bitsquare.trade.Trade)5 Inject (com.google.inject.Inject)4 Log (io.bitsquare.app.Log)4 UserThread (io.bitsquare.common.UserThread)4 DevFlags (io.bitsquare.app.DevFlags)3 Dispute (io.bitsquare.arbitration.Dispute)3 DisputeManager (io.bitsquare.arbitration.DisputeManager)3 TradeWalletService (io.bitsquare.btc.TradeWalletService)3 MarketPrice (io.bitsquare.btc.pricefeed.MarketPrice)3 PriceFeedService (io.bitsquare.btc.pricefeed.PriceFeedService)3 CurrencyUtil (io.bitsquare.locale.CurrencyUtil)3