use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.
the class ClosedTradesView method setAvatarColumnCellFactory.
@SuppressWarnings("UnusedReturnValue")
private TableColumn<ClosedTradableListItem, ClosedTradableListItem> setAvatarColumnCellFactory() {
avatarColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
avatarColumn.setCellFactory(new Callback<TableColumn<ClosedTradableListItem, ClosedTradableListItem>, TableCell<ClosedTradableListItem, ClosedTradableListItem>>() {
@Override
public TableCell<ClosedTradableListItem, ClosedTradableListItem> call(TableColumn<ClosedTradableListItem, ClosedTradableListItem> column) {
return new TableCell<ClosedTradableListItem, ClosedTradableListItem>() {
@Override
public void updateItem(final ClosedTradableListItem newItem, boolean empty) {
super.updateItem(newItem, empty);
if (newItem != null && !empty && newItem.getTradable() instanceof Trade) {
Trade trade = (Trade) newItem.getTradable();
int numPastTrades = model.getNumPastTrades(trade);
final NodeAddress tradingPeerNodeAddress = trade.getTradingPeerNodeAddress();
final Offer offer = trade.getOffer();
String role = Res.get("peerInfoIcon.tooltip.tradePeer");
Node peerInfoIcon = new PeerInfoIcon(tradingPeerNodeAddress, role, numPastTrades, privateNotificationManager, offer, preferences, model.accountAgeWitnessService, formatter, useDevPrivilegeKeys);
setPadding(new Insets(1, 0, 0, 0));
setGraphic(peerInfoIcon);
} else {
setGraphic(null);
}
}
};
}
});
return avatarColumn;
}
use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.
the class TransactionAwareTradableFactoryTest method testCreateWhenNotOpenOfferOrTrade.
@Test
public void testCreateWhenNotOpenOfferOrTrade() {
DisputeManager manager = mock(DisputeManager.class);
TransactionAwareTradableFactory factory = new TransactionAwareTradableFactory(manager);
Tradable delegate = mock(Tradable.class);
assertFalse(delegate instanceof OpenOffer);
assertFalse(delegate instanceof Trade);
TransactionAwareTradable tradable = factory.create(delegate);
assertFalse(tradable.isRelatedToTransaction(mock(Transaction.class)));
}
use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.
the class WithdrawalView method onWithdraw.
// /////////////////////////////////////////////////////////////////////////////////////////
// UI handlers
// /////////////////////////////////////////////////////////////////////////////////////////
@FXML
public void onWithdraw() {
if (GUIUtil.isReadyForTxBroadcast(p2PService, walletsSetup)) {
try {
// We do not know sendersAmount if senderPaysFee is true. We repeat fee calculation after first attempt if senderPaysFee is true.
Transaction feeEstimationTransaction = walletService.getFeeEstimationTransactionForMultipleAddresses(fromAddresses, amountAsCoin);
if (feeExcluded && feeEstimationTransaction != null) {
sendersAmount = amountAsCoin.add(feeEstimationTransaction.getFee());
feeEstimationTransaction = walletService.getFeeEstimationTransactionForMultipleAddresses(fromAddresses, sendersAmount);
}
checkNotNull(feeEstimationTransaction, "feeEstimationTransaction must not be null");
Coin fee = feeEstimationTransaction.getFee();
sendersAmount = feeExcluded ? amountAsCoin.add(fee) : amountAsCoin;
Coin receiverAmount = feeExcluded ? amountAsCoin : amountAsCoin.subtract(fee);
if (areInputsValid()) {
int txSize = feeEstimationTransaction.bitcoinSerialize().length;
log.info("Fee for tx with size {}: {} " + Res.getBaseCurrencyCode() + "", txSize, fee.toPlainString());
if (receiverAmount.isPositive()) {
double feePerByte = CoinUtil.getFeePerByte(fee, txSize);
double kb = txSize / 1000d;
new Popup<>().headLine(Res.get("funds.withdrawal.confirmWithdrawalRequest")).confirmation(Res.get("shared.sendFundsDetailsWithFee", formatter.formatCoinWithCode(sendersAmount), withdrawFromTextField.getText(), withdrawToTextField.getText(), formatter.formatCoinWithCode(fee), feePerByte, kb, formatter.formatCoinWithCode(receiverAmount))).actionButtonText(Res.get("shared.yes")).onAction(() -> doWithdraw(sendersAmount, fee, new FutureCallback<Transaction>() {
@Override
public void onSuccess(@javax.annotation.Nullable Transaction transaction) {
if (transaction != null) {
log.debug("onWithdraw onSuccess tx ID:" + transaction.getHashAsString());
} else {
log.error("onWithdraw transaction is null");
}
List<Trade> trades = new ArrayList<>(tradeManager.getTradableList());
trades.stream().filter(Trade::isPayoutPublished).forEach(trade -> {
walletService.getAddressEntry(trade.getId(), AddressEntry.Context.TRADE_PAYOUT).ifPresent(addressEntry -> {
if (walletService.getBalanceForAddress(addressEntry.getAddress()).isZero())
tradeManager.addTradeToClosedTrades(trade);
});
});
}
@Override
public void onFailure(@NotNull Throwable t) {
log.error("onWithdraw onFailure");
}
})).closeButtonText(Res.get("shared.cancel")).show();
} else {
new Popup<>().warning(Res.get("portfolio.pending.step5_buyer.amountTooLow")).show();
}
}
} catch (InsufficientFundsException e) {
new Popup<>().warning(Res.get("funds.withdrawal.warn.amountExceeds") + "\n\nError message:\n" + e.getMessage()).show();
} catch (Throwable e) {
e.printStackTrace();
log.error(e.toString());
new Popup<>().warning(e.toString()).show();
}
} else {
GUIUtil.showNotReadyForTxBroadcastPopups(p2PService, walletsSetup);
}
}
use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.
the class MainViewModel method onBasicServicesInitialized.
private void onBasicServicesInitialized() {
log.info("onBasicServicesInitialized");
clock.start();
PaymentMethod.onAllServicesInitialized();
// disputeManager
disputeManager.onAllServicesInitialized();
disputeManager.getDisputesAsObservableList().addListener((ListChangeListener<Dispute>) change -> {
change.next();
onDisputesChangeListener(change.getAddedSubList(), change.getRemoved());
});
onDisputesChangeListener(disputeManager.getDisputesAsObservableList(), null);
// tradeManager
tradeManager.onAllServicesInitialized();
tradeManager.getTradableList().addListener((ListChangeListener<Trade>) c -> updateBalance());
tradeManager.getTradableList().addListener((ListChangeListener<Trade>) change -> onTradesChanged());
onTradesChanged();
// We handle the trade period here as we display a global popup if we reached dispute time
tradesAndUIReady = EasyBind.combine(isSplashScreenRemoved, tradeManager.pendingTradesInitializedProperty(), (a, b) -> a && b);
tradesAndUIReady.subscribe((observable, oldValue, newValue) -> {
if (newValue)
applyTradePeriodState();
});
tradeManager.setTakeOfferRequestErrorMessageHandler(errorMessage -> new Popup<>().warning(Res.get("popup.error.takeOfferRequestFailed", errorMessage)).show());
// walletService
btcWalletService.addBalanceListener(new BalanceListener() {
@Override
public void onBalanceChanged(Coin balance, Transaction tx) {
updateBalance();
}
});
openOfferManager.getObservableList().addListener((ListChangeListener<OpenOffer>) c -> updateBalance());
tradeManager.getTradableList().addListener((ListChangeListener<Trade>) c -> updateBalance());
openOfferManager.onAllServicesInitialized();
removeOffersWithoutAccountAgeWitness();
arbitratorManager.onAllServicesInitialized();
alertManager.alertMessageProperty().addListener((observable, oldValue, newValue) -> displayAlertIfPresent(newValue, false));
privateNotificationManager.privateNotificationProperty().addListener((observable, oldValue, newValue) -> displayPrivateNotification(newValue));
displayAlertIfPresent(alertManager.alertMessageProperty().get(), false);
p2PService.onAllServicesInitialized();
feeService.onAllServicesInitialized();
GUIUtil.setFeeService(feeService);
daoManager.onAllServicesInitialized(errorMessage -> new Popup<>().error(errorMessage).show());
tradeStatisticsManager.onAllServicesInitialized();
accountAgeWitnessService.onAllServicesInitialized();
priceFeedService.setCurrencyCodeOnInit();
filterManager.onAllServicesInitialized();
filterManager.addListener(filter -> {
if (filter != null) {
if (filter.getSeedNodes() != null && !filter.getSeedNodes().isEmpty())
new Popup<>().warning(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.seed"))).show();
if (filter.getPriceRelayNodes() != null && !filter.getPriceRelayNodes().isEmpty())
new Popup<>().warning(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.priceRelay"))).show();
}
});
setupBtcNumPeersWatcher();
setupP2PNumPeersWatcher();
updateBalance();
if (DevEnv.isDevMode()) {
preferences.setShowOwnOffersInOfferBook(true);
setupDevDummyPaymentAccounts();
}
fillPriceFeedComboBoxItems();
setupMarketPriceFeed();
swapPendingOfferFundingEntries();
showAppScreen.set(true);
String key = "remindPasswordAndBackup";
user.getPaymentAccountsAsObservable().addListener((SetChangeListener<PaymentAccount>) change -> {
if (!walletsManager.areWalletsEncrypted() && preferences.showAgain(key) && change.wasAdded()) {
new Popup<>().headLine(Res.get("popup.securityRecommendation.headline")).information(Res.get("popup.securityRecommendation.msg")).dontShowAgainId(key).show();
}
});
checkIfOpenOffersMatchTradeProtocolVersion();
if (walletsSetup.downloadPercentageProperty().get() == 1)
checkForLockedUpFunds();
allBasicServicesInitialized = true;
}
use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.
the class ClosedTradesView method initialize.
@Override
public void initialize() {
priceColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.price")));
amountColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amountWithCur", Res.getBaseCurrencyCode())));
volumeColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amount")));
marketColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.market")));
directionColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.offerType")));
dateColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.dateTime")));
tradeIdColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.tradeId")));
stateColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.state")));
avatarColumn.setText("");
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
tableView.setPlaceholder(new AutoTooltipLabel(Res.get("table.placeholder.noItems", Res.get("shared.trades"))));
setTradeIdColumnCellFactory();
setDirectionColumnCellFactory();
setAmountColumnCellFactory();
setPriceColumnCellFactory();
setVolumeColumnCellFactory();
setDateColumnCellFactory();
setMarketColumnCellFactory();
setStateColumnCellFactory();
setAvatarColumnCellFactory();
tradeIdColumn.setComparator(Comparator.comparing(o -> o.getTradable().getId()));
dateColumn.setComparator(Comparator.comparing(o -> o.getTradable().getDate()));
directionColumn.setComparator(Comparator.comparing(o -> o.getTradable().getOffer().getDirection()));
marketColumn.setComparator(Comparator.comparing(model::getMarketLabel));
priceColumn.setComparator((o1, o2) -> {
final Tradable tradable1 = o1.getTradable();
final Tradable tradable2 = o2.getTradable();
Price price1 = null;
Price price2 = null;
if (tradable1 != null)
price1 = tradable1 instanceof Trade ? ((Trade) tradable1).getTradePrice() : tradable1.getOffer().getPrice();
if (tradable2 != null)
price2 = tradable2 instanceof Trade ? ((Trade) tradable2).getTradePrice() : tradable2.getOffer().getPrice();
return price1 != null && price2 != null ? price1.compareTo(price2) : 0;
});
volumeColumn.setComparator((o1, o2) -> {
if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
Volume tradeVolume1 = ((Trade) o1.getTradable()).getTradeVolume();
Volume tradeVolume2 = ((Trade) o2.getTradable()).getTradeVolume();
return tradeVolume1 != null && tradeVolume2 != null ? tradeVolume1.compareTo(tradeVolume2) : 0;
} else
return 0;
});
amountColumn.setComparator((o1, o2) -> {
if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
Coin amount1 = ((Trade) o1.getTradable()).getTradeAmount();
Coin amount2 = ((Trade) o2.getTradable()).getTradeAmount();
return amount1 != null && amount2 != null ? amount1.compareTo(amount2) : 0;
} else
return 0;
});
avatarColumn.setComparator((o1, o2) -> {
if (o1.getTradable() instanceof Trade && o2.getTradable() instanceof Trade) {
NodeAddress tradingPeerNodeAddress1 = ((Trade) o1.getTradable()).getTradingPeerNodeAddress();
NodeAddress tradingPeerNodeAddress2 = ((Trade) o2.getTradable()).getTradingPeerNodeAddress();
String address1 = tradingPeerNodeAddress1 != null ? tradingPeerNodeAddress1.getFullAddress() : "";
String address2 = tradingPeerNodeAddress2 != null ? tradingPeerNodeAddress2.getFullAddress() : "";
return address1 != null && address2 != null ? address1.compareTo(address2) : 0;
} else
return 0;
});
stateColumn.setComparator((o1, o2) -> model.getState(o1).compareTo(model.getState(o2)));
dateColumn.setSortType(TableColumn.SortType.DESCENDING);
tableView.getSortOrder().add(dateColumn);
exportButton.setText(Res.get("shared.exportCSV"));
}
Aggregations