Search in sources :

Example 1 with BSFormatter

use of io.bitsquare.gui.util.BSFormatter 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 2 with BSFormatter

use of io.bitsquare.gui.util.BSFormatter in project bitsquare by bitsquare.

the class BtcValidatorTest method testIsValid.

@Test
public void testIsValid() {
    BtcValidator validator = new BtcValidator(new BSFormatter());
    assertTrue(validator.validate("1").isValid);
    assertTrue(validator.validate("0,1").isValid);
    assertTrue(validator.validate("0.1").isValid);
    assertTrue(validator.validate(",1").isValid);
    assertTrue(validator.validate(".1").isValid);
    assertTrue(validator.validate("0.12345678").isValid);
    assertTrue(validator.validate(Coin.SATOSHI.toPlainString()).isValid);
    assertFalse(validator.validate(null).isValid);
    assertFalse(validator.validate("").isValid);
    assertFalse(validator.validate("0").isValid);
    assertFalse(validator.validate("0.0").isValid);
    assertFalse(validator.validate("0,1,1").isValid);
    assertFalse(validator.validate("0.1.1").isValid);
    assertFalse(validator.validate("0,000.1").isValid);
    assertFalse(validator.validate("0.000,1").isValid);
    assertFalse(validator.validate("0.123456789").isValid);
    assertFalse(validator.validate("-1").isValid);
// assertFalse(validator.validate(NetworkParameters.MAX_MONEY.toPlainString()).isValid);
}
Also used : BSFormatter(io.bitsquare.gui.util.BSFormatter) Test(org.junit.Test)

Aggregations

BSFormatter (io.bitsquare.gui.util.BSFormatter)2 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 AddressFormatException (org.bitcoinj.core.AddressFormatException)1 Coin (org.bitcoinj.core.Coin)1 Test (org.junit.Test)1