Search in sources :

Example 31 with Coin

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();*/
}
Also used : Coin(org.bitcoinj.core.Coin) Popup(io.bitsquare.gui.main.overlays.popups.Popup)

Example 32 with Coin

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);
}
Also used : Coin(org.bitcoinj.core.Coin) Offer(io.bitsquare.trade.offer.Offer)

Example 33 with Coin

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());
}
Also used : Coin(org.bitcoinj.core.Coin) BalanceListener(io.bitsquare.btc.listeners.BalanceListener) Transaction(org.bitcoinj.core.Transaction) PaymentAccount(io.bitsquare.payment.PaymentAccount)

Example 34 with Coin

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

the class BuyerStep5View method reviewWithdrawal.

private void reviewWithdrawal() {
    Coin senderAmount = trade.getPayoutAmount();
    WalletService walletService = model.dataModel.walletService;
    AddressEntry fromAddressesEntry = walletService.getOrCreateAddressEntry(trade.getId(), AddressEntry.Context.TRADE_PAYOUT);
    String fromAddresses = fromAddressesEntry.getAddressString();
    String toAddresses = withdrawAddressTextField.getText();
    // TODO at some error situation it can be tha the funds are already paid out and we get stuck here
    // need handling to remove the trade (planned for next release)
    Coin balance = walletService.getBalanceForAddress(fromAddressesEntry.getAddress());
    try {
        Coin requiredFee = walletService.getRequiredFee(fromAddresses, toAddresses, senderAmount, AddressEntry.Context.TRADE_PAYOUT);
        Coin receiverAmount = senderAmount.subtract(requiredFee);
        if (balance.isZero()) {
            new Popup().warning("Your funds have already been withdrawn.\nPlease check the transaction history.").show();
            model.dataModel.tradeManager.addTradeToClosedTrades(trade);
        } else {
            if (toAddresses.isEmpty()) {
                validateWithdrawAddress();
            } else if (Restrictions.isAboveFixedTxFeeForTradesAndDust(senderAmount)) {
                if (DevFlags.DEV_MODE) {
                    doWithdrawal(receiverAmount);
                } else {
                    BSFormatter formatter = model.formatter;
                    String key = "reviewWithdrawalAtTradeComplete";
                    if (!DevFlags.DEV_MODE && preferences.showAgain(key)) {
                        new Popup().headLine("Confirm withdrawal request").confirmation("Sending: " + formatter.formatCoinWithCode(senderAmount) + "\n" + "From address: " + fromAddresses + "\n" + "To receiving address: " + toAddresses + ".\n" + "Required transaction fee is: " + formatter.formatCoinWithCode(requiredFee) + "\n\n" + "The recipient will receive: " + formatter.formatCoinWithCode(receiverAmount) + "\n\n" + "Are you sure you want to proceed with the withdrawal?").closeButtonText("Cancel").onClose(() -> {
                            useSavingsWalletButton.setDisable(false);
                            withdrawToExternalWalletButton.setDisable(false);
                        }).actionButtonText("Yes").onAction(() -> doWithdrawal(receiverAmount)).dontShowAgainId(key, preferences).show();
                    } else {
                        doWithdrawal(receiverAmount);
                    }
                }
            } else {
                new Popup().warning("The amount to transfer is lower than the transaction fee and the min. possible tx value (dust).").show();
            }
        }
    } catch (AddressFormatException e) {
        validateWithdrawAddress();
    } catch (AddressEntryException e) {
        log.error(e.getMessage());
    }
}
Also used : Coin(org.bitcoinj.core.Coin) AddressFormatException(org.bitcoinj.core.AddressFormatException) AddressEntryException(io.bitsquare.btc.AddressEntryException) AddressEntry(io.bitsquare.btc.AddressEntry) Popup(io.bitsquare.gui.main.overlays.popups.Popup) BSFormatter(io.bitsquare.gui.util.BSFormatter) WalletService(io.bitsquare.btc.WalletService)

Example 35 with Coin

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

the class BuyerStep5View method doWithdrawal.

private void doWithdrawal(Coin receiverAmount) {
    String toAddress = withdrawAddressTextField.getText();
    ResultHandler resultHandler = this::handleTradeCompleted;
    FaultHandler faultHandler = (errorMessage, throwable) -> {
        useSavingsWalletButton.setDisable(false);
        withdrawToExternalWalletButton.setDisable(false);
        if (throwable != null && throwable.getMessage() != null)
            new Popup().error(errorMessage + "\n\n" + throwable.getMessage()).show();
        else
            new Popup().error(errorMessage).show();
    };
    if (model.dataModel.walletService.getWallet().isEncrypted()) {
        UserThread.runAfter(() -> model.dataModel.walletPasswordWindow.onAesKey(aesKey -> doWithdrawRequest(toAddress, receiverAmount, aesKey, resultHandler, faultHandler)).show(), 300, TimeUnit.MILLISECONDS);
    } else
        doWithdrawRequest(toAddress, receiverAmount, null, resultHandler, faultHandler);
}
Also used : TradeStepView(io.bitsquare.gui.main.portfolio.pendingtrades.steps.TradeStepView) Button(javafx.scene.control.Button) Popup(io.bitsquare.gui.main.overlays.popups.Popup) MainView(io.bitsquare.gui.main.MainView) Coin(org.bitcoinj.core.Coin) Restrictions(io.bitsquare.btc.Restrictions) Tuple2(io.bitsquare.common.util.Tuple2) FundsView(io.bitsquare.gui.main.funds.FundsView) DevFlags(io.bitsquare.app.DevFlags) PendingTradesViewModel(io.bitsquare.gui.main.portfolio.pendingtrades.PendingTradesViewModel) Insets(javafx.geometry.Insets) WalletService(io.bitsquare.btc.WalletService) Layout(io.bitsquare.gui.util.Layout) ResultHandler(io.bitsquare.common.handlers.ResultHandler) KeyParameter(org.spongycastle.crypto.params.KeyParameter) AddressEntry(io.bitsquare.btc.AddressEntry) GridPane(javafx.scene.layout.GridPane) Log(io.bitsquare.app.Log) BSFormatter(io.bitsquare.gui.util.BSFormatter) HBox(javafx.scene.layout.HBox) AddressFormatException(org.bitcoinj.core.AddressFormatException) InputTextField(io.bitsquare.gui.components.InputTextField) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) UserThread(io.bitsquare.common.UserThread) TimeUnit(java.util.concurrent.TimeUnit) AddressEntryException(io.bitsquare.btc.AddressEntryException) FormBuilder(io.bitsquare.gui.util.FormBuilder) Notification(io.bitsquare.gui.main.overlays.notifications.Notification) FaultHandler(io.bitsquare.common.handlers.FaultHandler) ChangeListener(javafx.beans.value.ChangeListener) TransactionsView(io.bitsquare.gui.main.funds.transactions.TransactionsView) Popup(io.bitsquare.gui.main.overlays.popups.Popup) ResultHandler(io.bitsquare.common.handlers.ResultHandler) FaultHandler(io.bitsquare.common.handlers.FaultHandler)

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