use of bisq.core.trade.SellerAsMakerTrade in project bisq-api by mrosseel.
the class BisqProxy method paymentReceived.
public CompletableFuture<Void> paymentReceived(String tradeId) {
final CompletableFuture<Void> futureResult = new CompletableFuture<>();
Trade trade;
try {
trade = getTrade(tradeId);
} catch (NotFoundException e) {
return failFuture(futureResult, e);
}
if (!Trade.State.SELLER_RECEIVED_FIAT_PAYMENT_INITIATED_MSG.equals(trade.getState())) {
return failFuture(futureResult, new ValidationException("Trade is not in the correct state to receive payment: " + trade.getState()));
}
TradeProtocol tradeProtocol = trade.getTradeProtocol();
if (!(tradeProtocol instanceof SellerAsTakerProtocol || tradeProtocol instanceof SellerAsMakerProtocol)) {
return failFuture(futureResult, new ValidationException("Trade is not in the correct state to receive payment: " + trade.getState()));
}
ResultHandler resultHandler = () -> futureResult.complete(null);
ErrorMessageHandler errorResultHandler = message -> futureResult.completeExceptionally(new RuntimeException(message));
// TODO I think we should check instance of tradeProtocol here instead of trade
if (trade instanceof SellerAsMakerTrade) {
((SellerAsMakerProtocol) tradeProtocol).onFiatPaymentReceived(resultHandler, errorResultHandler);
} else {
((SellerAsTakerProtocol) tradeProtocol).onFiatPaymentReceived(resultHandler, errorResultHandler);
}
return futureResult;
}
Aggregations