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