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