Search in sources :

Example 6 with Trade

use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.

the class NotificationCenter method onAllServicesAndViewsInitialized.

public void onAllServicesAndViewsInitialized() {
    tradeManager.getTradableList().addListener((ListChangeListener<Trade>) change -> {
        change.next();
        if (change.wasRemoved()) {
            change.getRemoved().stream().forEach(trade -> {
                String tradeId = trade.getId();
                if (disputeStateSubscriptionsMap.containsKey(tradeId)) {
                    disputeStateSubscriptionsMap.get(tradeId).unsubscribe();
                    disputeStateSubscriptionsMap.remove(tradeId);
                }
                if (tradePhaseSubscriptionsMap.containsKey(tradeId)) {
                    tradePhaseSubscriptionsMap.get(tradeId).unsubscribe();
                    tradePhaseSubscriptionsMap.remove(tradeId);
                }
            });
        }
        if (change.wasAdded()) {
            change.getAddedSubList().stream().forEach(trade -> {
                String tradeId = trade.getId();
                if (disputeStateSubscriptionsMap.containsKey(tradeId)) {
                    log.debug("We have already an entry in disputeStateSubscriptionsMap.");
                } else {
                    Subscription disputeStateSubscription = EasyBind.subscribe(trade.disputeStateProperty(), disputeState -> onDisputeStateChanged(trade, disputeState));
                    disputeStateSubscriptionsMap.put(tradeId, disputeStateSubscription);
                }
                if (tradePhaseSubscriptionsMap.containsKey(tradeId)) {
                    log.debug("We have already an entry in tradePhaseSubscriptionsMap.");
                } else {
                    Subscription tradePhaseSubscription = EasyBind.subscribe(trade.statePhaseProperty(), phase -> onTradePhaseChanged(trade, phase));
                    tradePhaseSubscriptionsMap.put(tradeId, tradePhaseSubscription);
                }
            });
        }
    });
    tradeManager.getTradableList().stream().forEach(trade -> {
        String tradeId = trade.getId();
        Subscription disputeStateSubscription = EasyBind.subscribe(trade.disputeStateProperty(), disputeState -> onDisputeStateChanged(trade, disputeState));
        disputeStateSubscriptionsMap.put(tradeId, disputeStateSubscription);
        Subscription tradePhaseSubscription = EasyBind.subscribe(trade.statePhaseProperty(), phase -> onTradePhaseChanged(trade, phase));
        tradePhaseSubscriptionsMap.put(tradeId, tradePhaseSubscription);
    });
}
Also used : Inject(com.google.inject.Inject) PendingTradesView(bisq.desktop.main.portfolio.pendingtrades.PendingTradesView) HashMap(java.util.HashMap) DisputeManager(bisq.core.arbitration.DisputeManager) ArrayList(java.util.ArrayList) DisputesView(bisq.desktop.main.disputes.DisputesView) ListChangeListener(javafx.collections.ListChangeListener) Res(bisq.core.locale.Res) SellerTrade(bisq.core.trade.SellerTrade) Map(java.util.Map) Nullable(javax.annotation.Nullable) Navigation(bisq.desktop.Navigation) MakerTrade(bisq.core.trade.MakerTrade) Trade(bisq.core.trade.Trade) DontShowAgainLookup(bisq.core.user.DontShowAgainLookup) Log(bisq.common.app.Log) Subscription(org.fxmisc.easybind.Subscription) Consumer(java.util.function.Consumer) MainView(bisq.desktop.main.MainView) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) BuyerTrade(bisq.core.trade.BuyerTrade) EasyBind(org.fxmisc.easybind.EasyBind) TraderDisputeView(bisq.desktop.main.disputes.trader.TraderDisputeView) TradeManager(bisq.core.trade.TradeManager) Preferences(bisq.core.user.Preferences) UserThread(bisq.common.UserThread) PortfolioView(bisq.desktop.main.portfolio.PortfolioView) SellerTrade(bisq.core.trade.SellerTrade) MakerTrade(bisq.core.trade.MakerTrade) Trade(bisq.core.trade.Trade) BuyerTrade(bisq.core.trade.BuyerTrade) Subscription(org.fxmisc.easybind.Subscription)

Example 7 with Trade

use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.

the class PendingTradesDataModel method onPaymentStarted.

public void onPaymentStarted(ResultHandler resultHandler, ErrorMessageHandler errorMessageHandler) {
    final Trade trade = getTrade();
    checkNotNull(trade, "trade must not be null");
    checkArgument(trade instanceof BuyerTrade, "Check failed: trade instanceof BuyerTrade");
    checkArgument(trade.getDisputeState() == Trade.DisputeState.NO_DISPUTE, "Check failed: trade.getDisputeState() == Trade.DisputeState.NONE");
    // TODO UI not impl yet
    trade.setCounterCurrencyTxId("");
    ((BuyerTrade) trade).onFiatPaymentStarted(resultHandler, errorMessageHandler);
}
Also used : SellerTrade(bisq.core.trade.SellerTrade) Trade(bisq.core.trade.Trade) BuyerTrade(bisq.core.trade.BuyerTrade) BuyerTrade(bisq.core.trade.BuyerTrade)

Example 8 with Trade

use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.

the class PendingTradesDataModel method tryOpenDispute.

private void tryOpenDispute(boolean isSupportTicket) {
    if (getTrade() != null) {
        Transaction depositTx = getTrade().getDepositTx();
        if (depositTx != null) {
            doOpenDispute(isSupportTicket, getTrade().getDepositTx());
        } else {
            log.info("Trade.depositTx is null. We try to find the tx in our wallet.");
            List<Transaction> candidates = new ArrayList<>();
            List<Transaction> transactions = btcWalletService.getRecentTransactions(100, true);
            transactions.stream().forEach(transaction -> {
                Coin valueSentFromMe = btcWalletService.getValueSentFromMeForTransaction(transaction);
                if (!valueSentFromMe.isZero()) {
                    // spending tx
                    // MS tx
                    candidates.addAll(transaction.getOutputs().stream().filter(output -> !btcWalletService.isTransactionOutputMine(output)).filter(output -> output.getScriptPubKey().isPayToScriptHash()).map(transactionOutput -> transaction).collect(Collectors.toList()));
                }
            });
            if (candidates.size() == 1)
                doOpenDispute(isSupportTicket, candidates.get(0));
            else if (candidates.size() > 1)
                new SelectDepositTxWindow().transactions(candidates).onSelect(transaction -> doOpenDispute(isSupportTicket, transaction)).closeButtonText(Res.get("shared.cancel")).show();
            else
                log.error("Trade.depositTx is null and we did not find any MultiSig transaction.");
        }
    } else {
        log.error("Trade is null");
    }
}
Also used : GUIUtil(bisq.desktop.util.GUIUtil) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) PubKeyRing(bisq.common.crypto.PubKeyRing) Transaction(org.bitcoinj.core.Transaction) Coin(org.bitcoinj.core.Coin) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Inject(com.google.inject.Inject) FXCollections(javafx.collections.FXCollections) Dispute(bisq.core.arbitration.Dispute) DisputeManager(bisq.core.arbitration.DisputeManager) NotificationCenter(bisq.desktop.main.overlays.notifications.NotificationCenter) ArrayList(java.util.ArrayList) DisputesView(bisq.desktop.main.disputes.DisputesView) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) OfferPayload(bisq.core.offer.OfferPayload) ListChangeListener(javafx.collections.ListChangeListener) Res(bisq.core.locale.Res) SellerTrade(bisq.core.trade.SellerTrade) PaymentAccountPayload(bisq.core.payment.payload.PaymentAccountPayload) ErrorMessageHandler(bisq.common.handlers.ErrorMessageHandler) KeyParameter(org.spongycastle.crypto.params.KeyParameter) Nullable(javax.annotation.Nullable) Navigation(bisq.desktop.Navigation) Popup(bisq.desktop.main.overlays.popups.Popup) Offer(bisq.core.offer.Offer) ObjectProperty(javafx.beans.property.ObjectProperty) WalletPasswordWindow(bisq.desktop.main.overlays.windows.WalletPasswordWindow) ActivatableDataModel(bisq.desktop.common.model.ActivatableDataModel) P2PService(bisq.network.p2p.P2PService) Trade(bisq.core.trade.Trade) FaultHandler(bisq.common.handlers.FaultHandler) ResultHandler(bisq.common.handlers.ResultHandler) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Log(bisq.common.app.Log) Collectors(java.util.stream.Collectors) SelectDepositTxWindow(bisq.desktop.main.overlays.windows.SelectDepositTxWindow) MainView(bisq.desktop.main.MainView) List(java.util.List) BuyerTrade(bisq.core.trade.BuyerTrade) WalletsSetup(bisq.core.btc.wallet.WalletsSetup) TradeManager(bisq.core.trade.TradeManager) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Preferences(bisq.core.user.Preferences) DisputeAlreadyOpenException(bisq.core.arbitration.DisputeAlreadyOpenException) KeyRing(bisq.common.crypto.KeyRing) ObservableList(javafx.collections.ObservableList) StringProperty(javafx.beans.property.StringProperty) ChangeListener(javafx.beans.value.ChangeListener) Coin(org.bitcoinj.core.Coin) Transaction(org.bitcoinj.core.Transaction) ArrayList(java.util.ArrayList) SelectDepositTxWindow(bisq.desktop.main.overlays.windows.SelectDepositTxWindow)

Example 9 with Trade

use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.

the class PendingTradesDataModel method doOpenDispute.

private void doOpenDispute(boolean isSupportTicket, Transaction depositTx) {
    Log.traceCall("depositTx=" + depositTx);
    byte[] depositTxSerialized = null;
    byte[] payoutTxSerialized = null;
    String depositTxHashAsString = null;
    String payoutTxHashAsString = null;
    if (depositTx != null) {
        depositTxSerialized = depositTx.bitcoinSerialize();
        depositTxHashAsString = depositTx.getHashAsString();
    } else {
        log.warn("depositTx is null");
    }
    Trade trade = getTrade();
    if (trade != null) {
        Transaction payoutTx = trade.getPayoutTx();
        if (payoutTx != null) {
            payoutTxSerialized = payoutTx.bitcoinSerialize();
            payoutTxHashAsString = payoutTx.getHashAsString();
        } else {
            log.debug("payoutTx is null at doOpenDispute");
        }
        final PubKeyRing arbitratorPubKeyRing = trade.getArbitratorPubKeyRing();
        checkNotNull(arbitratorPubKeyRing, "arbitratorPubKeyRing must no tbe null");
        Dispute dispute = new Dispute(disputeManager.getDisputeStorage(), trade.getId(), // traderId
        keyRing.getPubKeyRing().hashCode(), trade.getOffer().getDirection() == OfferPayload.Direction.BUY ? isMaker : !isMaker, isMaker, keyRing.getPubKeyRing(), trade.getDate().getTime(), trade.getContract(), trade.getContractHash(), depositTxSerialized, payoutTxSerialized, depositTxHashAsString, payoutTxHashAsString, trade.getContractAsJson(), trade.getMakerContractSignature(), trade.getTakerContractSignature(), arbitratorPubKeyRing, isSupportTicket);
        trade.setDisputeState(Trade.DisputeState.DISPUTE_REQUESTED);
        if (p2PService.isBootstrapped()) {
            sendOpenNewDisputeMessage(dispute, false);
        } else {
            new Popup<>().information(Res.get("popup.warning.notFullyConnected")).show();
        }
    } else {
        log.warn("trade is null at doOpenDispute");
    }
}
Also used : SellerTrade(bisq.core.trade.SellerTrade) Trade(bisq.core.trade.Trade) BuyerTrade(bisq.core.trade.BuyerTrade) Transaction(org.bitcoinj.core.Transaction) Popup(bisq.desktop.main.overlays.popups.Popup) PubKeyRing(bisq.common.crypto.PubKeyRing) Dispute(bisq.core.arbitration.Dispute)

Example 10 with Trade

use of bisq.core.trade.Trade in project bisq-desktop by bisq-network.

the class PendingTradesViewModel method getSecurityDeposit.

public String getSecurityDeposit() {
    Offer offer = dataModel.getOffer();
    Trade trade = dataModel.getTrade();
    if (offer != null && trade != null && trade.getTradeAmount() != null) {
        Coin securityDeposit = dataModel.isBuyer() ? offer.getBuyerSecurityDeposit() : offer.getSellerSecurityDeposit();
        String percentage = GUIUtil.getPercentageOfTradeAmount(securityDeposit, trade.getTradeAmount(), btcFormatter);
        return btcFormatter.formatCoinWithCode(securityDeposit) + percentage;
    } else {
        return "";
    }
}
Also used : Trade(bisq.core.trade.Trade) Coin(org.bitcoinj.core.Coin) Offer(bisq.core.offer.Offer)

Aggregations

Trade (bisq.core.trade.Trade)20 Coin (org.bitcoinj.core.Coin)8 Res (bisq.core.locale.Res)7 Offer (bisq.core.offer.Offer)7 OpenOffer (bisq.core.offer.OpenOffer)6 Preferences (bisq.core.user.Preferences)6 Popup (bisq.desktop.main.overlays.popups.Popup)6 GUIUtil (bisq.desktop.util.GUIUtil)6 ObservableList (javafx.collections.ObservableList)6 PrivateNotificationManager (bisq.core.alert.PrivateNotificationManager)5 AppOptionKeys (bisq.core.app.AppOptionKeys)5 DisputeManager (bisq.core.arbitration.DisputeManager)5 TradeManager (bisq.core.trade.TradeManager)5 Dispute (bisq.core.arbitration.Dispute)4 BuyerTrade (bisq.core.trade.BuyerTrade)4 SellerTrade (bisq.core.trade.SellerTrade)4 List (java.util.List)4 ListChangeListener (javafx.collections.ListChangeListener)4 Nullable (javax.annotation.Nullable)4 Transaction (org.bitcoinj.core.Transaction)4