Search in sources :

Example 1 with AddressEntryException

use of io.bitsquare.btc.AddressEntryException 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)

Aggregations

AddressEntry (io.bitsquare.btc.AddressEntry)1 AddressEntryException (io.bitsquare.btc.AddressEntryException)1 WalletService (io.bitsquare.btc.WalletService)1 Popup (io.bitsquare.gui.main.overlays.popups.Popup)1 BSFormatter (io.bitsquare.gui.util.BSFormatter)1 AddressFormatException (org.bitcoinj.core.AddressFormatException)1 Coin (org.bitcoinj.core.Coin)1