use of io.bisq.core.trade.Trade in project bisq-api by mrosseel.
the class BisqProxy method paymentStarted.
public CompletableFuture<Void> paymentStarted(String tradeId) {
final CompletableFuture<Void> futureResult = new CompletableFuture<>();
Trade trade;
try {
trade = getTrade(tradeId);
} catch (NotFoundException e) {
return failFuture(futureResult, e);
}
if (!Trade.State.DEPOSIT_CONFIRMED_IN_BLOCK_CHAIN.equals(trade.getState())) {
return failFuture(futureResult, new ValidationException("Trade is not in the correct state to start payment: " + trade.getState()));
}
TradeProtocol tradeProtocol = trade.getTradeProtocol();
ResultHandler resultHandler = () -> futureResult.complete(null);
ErrorMessageHandler errorResultHandler = message -> futureResult.completeExceptionally(new RuntimeException(message));
if (trade instanceof BuyerAsMakerTrade) {
((BuyerAsMakerProtocol) tradeProtocol).onFiatPaymentStarted(resultHandler, errorResultHandler);
} else {
((BuyerAsTakerProtocol) tradeProtocol).onFiatPaymentStarted(resultHandler, errorResultHandler);
}
return futureResult;
}
use of io.bisq.core.trade.Trade 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;
}
use of io.bisq.core.trade.Trade in project bisq-api by mrosseel.
the class BisqProxy method moveFundsToBisqWallet.
public void moveFundsToBisqWallet(String tradeId) {
final Trade trade = getTrade(tradeId);
btcWalletService.swapTradeEntryToAvailableEntry(trade.getId(), AddressEntry.Context.TRADE_PAYOUT);
// TODO do we need to handle this ui stuff? --> handleTradeCompleted();
tradeManager.addTradeToClosedTrades(trade);
}
use of io.bisq.core.trade.Trade in project bisq-api by mrosseel.
the class BisqProxy method updateLockedBalance.
// TODO copied from MainViewModel - refactor !
private Coin updateLockedBalance() {
Stream<Trade> lockedTrades = Stream.concat(closedTradableManager.getLockedTradesStream(), failedTradesManager.getLockedTradesStream());
lockedTrades = Stream.concat(lockedTrades, tradeManager.getLockedTradesStream());
Coin sum = Coin.valueOf(lockedTrades.mapToLong(trade -> {
final Optional<AddressEntry> addressEntryOptional = btcWalletService.getAddressEntry(trade.getId(), AddressEntry.Context.MULTI_SIG);
if (addressEntryOptional.isPresent())
return addressEntryOptional.get().getCoinLockedInMultiSig().getValue();
else
return 0;
}).sum());
return sum;
}
use of io.bisq.core.trade.Trade in project bisq-api by mrosseel.
the class MainViewModelHeadless 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.DEV_MODE) {
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;
}
Aggregations