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());
}
}
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);
}
Aggregations