Skip to content

Commit

Permalink
Adapt create offer process to new navigation structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ripcurlx committed Apr 7, 2022
1 parent 924e92a commit a8189d7
Show file tree
Hide file tree
Showing 27 changed files with 362 additions and 178 deletions.
9 changes: 5 additions & 4 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ shared.dontRemoveOffer=Don't remove offer
shared.editOffer=Edit offer
shared.duplicateOffer=Duplicate offer
shared.openLargeQRWindow=Open large QR code window
shared.tradingAccount=Trading account
shared.chooseTradingAccount=Choose trading account
shared.faq=Visit FAQ page
shared.yesCancel=Yes, cancel
shared.nextStep=Next step
shared.selectTradingAccount=Select trading account
shared.fundFromSavingsWalletButton=Transfer funds from Bisq wallet
shared.fundFromExternalWalletButton=Open your external wallet for funding
shared.openDefaultWalletFailed=Failed to open a Bitcoin wallet application. Are you sure you have one installed?
Expand Down Expand Up @@ -198,6 +197,7 @@ shared.iConfirm=I confirm
shared.openURL=Open {0}
shared.fiat=Fiat
shared.crypto=Crypto
shared.otherAssets=other assets
shared.all=All
shared.edit=Edit
shared.advancedOptions=Advanced options
Expand Down Expand Up @@ -379,7 +379,7 @@ offerbook.volume={0} (min - max)
offerbook.deposit=Deposit BTC (%)
offerbook.deposit.help=Deposit paid by each trader to guarantee the trade. Will be returned when the trade is completed.

offerbook.createNewOffer=Create new offer
offerbook.createNewOffer=Create new offer to {0} {1}
offerbook.createOfferDisabled.tooltip=You can only create one offer at a time

offerbook.takeOfferButton.tooltip=Take offer for {0}
Expand All @@ -393,7 +393,7 @@ offerbook.withdrawFundsHint=Offer has been removed. Funds are not reserved for t
You can send Available funds to an external wallet at the {0} screen.

offerbook.warning.noTradingAccountForCurrency.headline=No payment account for selected currency
offerbook.warning.noTradingAccountForCurrency.msg=You don't have a payment account set up for the selected currency.\n\nWould you like to create an offer for another currency instead?
offerbook.warning.noTradingAccountForCurrency.msg=You don't have a payment account set up for the selected currency.
offerbook.warning.noMatchingAccount.headline=No matching payment account.
offerbook.warning.noMatchingAccount.msg=This offer uses a payment method you haven't set up yet. \n\nWould you like to set up a new payment account now?
offerbook.warning.noMatchingBsqAccount.msg=This offer uses BSQ as a payment method you haven't set up yet. \n\nWould you like to automatically create an account now?
Expand Down Expand Up @@ -490,6 +490,7 @@ createOffer.buyBsq.popupMessage=Trading fees are paid to fund the Bisq DAO. Fees

# new entries
createOffer.placeOfferButton=Review: Place offer to {0} bitcoin
createOffer.placeOfferButtonAltcoin=Review: Place offer to {0} {1}
createOffer.createOfferFundWalletInfo.headline=Fund your offer
# suppress inspection "TrailingSpacesInProperty"
createOffer.createOfferFundWalletInfo.tradeAmount=- Trade amount: {0} \n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

package bisq.desktop.main.offer;

public interface Closable {
public interface ClosableView {
public void setCloseHandler(OfferView.CloseHandler closeHandler);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import bisq.core.offer.Offer;

public interface InitializableWithData {
public interface InitializableViewWithTakeOfferData {

public void initWithData(Offer offer);

Expand Down
204 changes: 86 additions & 118 deletions desktop/src/main/java/bisq/desktop/main/offer/OfferView.java

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions desktop/src/main/java/bisq/desktop/main/offer/SelectableView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.desktop.main.offer;

public interface SelectableView {
public void onTabSelected(boolean isSelected);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package bisq.desktop.main.offer.bisq_v1;

import bisq.desktop.Navigation;
import bisq.desktop.main.offer.offerbook.BsqOfferBookViewModel;
import bisq.desktop.main.offer.offerbook.TopAltcoinOfferBookViewModel;
import bisq.desktop.util.DisplayUtils;
import bisq.desktop.util.GUIUtil;

Expand Down Expand Up @@ -81,13 +83,16 @@

import java.util.Comparator;
import java.util.Date;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import lombok.Getter;

import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;

import static bisq.core.payment.payload.PaymentMethod.HAL_CASH_ID;
Expand Down Expand Up @@ -247,7 +252,7 @@ public boolean initWithData(OfferDirection direction, TradeCurrency tradeCurrenc
if (account != null) {
this.paymentAccount = account;
} else {
Optional<PaymentAccount> paymentAccountOptional = paymentAccounts.stream().findAny();
Optional<PaymentAccount> paymentAccountOptional = getAnyPaymentAccount();
if (paymentAccountOptional.isPresent()) {
this.paymentAccount = paymentAccountOptional.get();

Expand Down Expand Up @@ -277,6 +282,18 @@ public boolean initWithData(OfferDirection direction, TradeCurrency tradeCurrenc
return true;
}

@NotNull
private Optional<PaymentAccount> getAnyPaymentAccount() {
if (CurrencyUtil.isFiatCurrency(tradeCurrency.getCode())) {
return paymentAccounts.stream().filter(paymentAccount1 -> !paymentAccount1.getPaymentMethod().isAltcoin()).findAny();
} else {
return paymentAccounts.stream().filter(paymentAccount1 -> paymentAccount1.getPaymentMethod().isAltcoin() &&
paymentAccount1.getTradeCurrency().isPresent() &&
!Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), BsqOfferBookViewModel.BSQ.getCode()) &&
!Objects.equals(paymentAccount1.getTradeCurrency().get().getCode(), TopAltcoinOfferBookViewModel.TOP_ALTCOIN.getCode())).findAny();
}
}

protected PaymentAccount getPreselectedPaymentAccount() {
return preferences.getSelectedPaymentAccountForCreateOffer();
}
Expand Down Expand Up @@ -405,7 +422,7 @@ void onCurrencySelected(TradeCurrency tradeCurrency) {

Optional<TradeCurrency> tradeCurrencyOptional = preferences.getTradeCurrenciesAsObservable()
.stream().filter(e -> e.getCode().equals(code)).findAny();
if (!tradeCurrencyOptional.isPresent()) {
if (tradeCurrencyOptional.isEmpty()) {
if (CurrencyUtil.isCryptoCurrency(code)) {
CurrencyUtil.getCryptoCurrency(code).ifPresent(preferences::addCryptoCurrency);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import bisq.desktop.main.dao.DaoView;
import bisq.desktop.main.dao.wallet.BsqWalletView;
import bisq.desktop.main.dao.wallet.receive.BsqReceiveView;
import bisq.desktop.main.offer.ClosableView;
import bisq.desktop.main.offer.OfferView;
import bisq.desktop.main.offer.SelectableView;
import bisq.desktop.main.overlays.notifications.Notification;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.overlays.windows.OfferDetailsWindow;
Expand Down Expand Up @@ -104,6 +106,7 @@
import javafx.event.EventHandler;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

import javafx.util.StringConverter;

Expand All @@ -125,7 +128,7 @@
import static bisq.desktop.util.FormBuilder.*;
import static javafx.beans.binding.Bindings.createStringBinding;

public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> extends ActivatableViewAndModel<AnchorPane, M> {
public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> extends ActivatableViewAndModel<AnchorPane, M> implements ClosableView, SelectableView {
protected final Navigation navigation;
private final Preferences preferences;
private final OfferDetailsWindow offerDetailsWindow;
Expand All @@ -137,7 +140,7 @@ public abstract class MutableOfferView<M extends MutableOfferViewModel<?>> exten
private TitledGroupBg payFundsTitledGroupBg, setDepositTitledGroupBg, paymentTitledGroupBg;
protected TitledGroupBg amountTitledGroupBg;
private BusyAnimation waitingForFundsSpinner;
private AutoTooltipButton nextButton, cancelButton1, cancelButton2, placeOfferButton;
private AutoTooltipButton nextButton, cancelButton1, cancelButton2, placeOfferButton, fundFromSavingsWalletButton;
private Button priceTypeToggleButton;
private InputTextField fixedPriceTextField, marketBasedPriceTextField, triggerPriceInputTextField;
protected InputTextField amountTextField, minAmountTextField, volumeTextField, buyerSecurityDepositInputTextField;
Expand Down Expand Up @@ -217,7 +220,7 @@ protected void initialize() {
balanceTextField.setFormatter(model.getBtcFormatter());

paymentAccountsComboBox.setConverter(GUIUtil.getPaymentAccountsComboBoxStringConverter());
paymentAccountsComboBox.setButtonCell(GUIUtil.getComboBoxButtonCell(Res.get("shared.selectTradingAccount"),
paymentAccountsComboBox.setButtonCell(GUIUtil.getComboBoxButtonCell(Res.get("shared.chooseTradingAccount"),
paymentAccountsComboBox, false));
paymentAccountsComboBox.setCellFactory(model.getPaymentAccountListCellFactory(paymentAccountsComboBox));

Expand Down Expand Up @@ -252,9 +255,9 @@ protected void doActivate() {
addressTextField.setAddress(model.getAddressAsString());
addressTextField.setPaymentLabel(model.getPaymentLabel());

paymentAccountsComboBox.setItems(model.getDataModel().getPaymentAccounts());
paymentAccountsComboBox.getSelectionModel().select(model.getPaymentAccount());
currencyComboBox.getSelectionModel().select(model.getTradeCurrency());
paymentAccountsComboBox.setItems(getPaymentAccounts());
paymentAccountsComboBox.getSelectionModel().select(model.getPaymentAccount());

onPaymentAccountsComboBoxSelected();

Expand Down Expand Up @@ -327,14 +330,30 @@ public void initWithData(OfferDirection direction, TradeCurrency tradeCurrency,
}).show();
}

if (direction == OfferDirection.BUY) {
String placeOfferButtonLabel;

if (OfferViewUtil.isShownAsBuyOffer(direction, tradeCurrency)) {
placeOfferButton.setId("buy-button-big");
placeOfferButton.updateText(Res.get("createOffer.placeOfferButton", Res.get("shared.buy")));
if (CurrencyUtil.isFiatCurrency(tradeCurrency.getCode())) {
placeOfferButtonLabel = Res.get("createOffer.placeOfferButton", Res.get("shared.buy"));
} else {
placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"), tradeCurrency.getName());
}
placeOfferButton.updateText(placeOfferButtonLabel);
nextButton.setId("buy-button");
fundFromSavingsWalletButton.setId("buy-button");
} else {
placeOfferButton.setId("sell-button-big");
placeOfferButton.updateText(Res.get("createOffer.placeOfferButton", Res.get("shared.sell")));
if (CurrencyUtil.isFiatCurrency(tradeCurrency.getCode())) {
placeOfferButtonLabel = Res.get("createOffer.placeOfferButton", Res.get("shared.sell"));
} else {
placeOfferButtonLabel = Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.sell"), tradeCurrency.getName());
}
nextButton.setId("sell-button");
fundFromSavingsWalletButton.setId("sell-button");
}


updatePriceToggle();

if (!model.getDataModel().isMakerFeeValid() && model.getDataModel().getMakerFee() != null)
Expand Down Expand Up @@ -771,6 +790,15 @@ private void createListeners() {
marketBasedPriceTextField.clear();
volumeTextField.clear();
triggerPriceInputTextField.clear();
if (!CurrencyUtil.isFiatCurrency(newValue)) {
if (model.isShownAsBuyOffer()) {
placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.buy"),
model.getTradeCurrency().getName()));
} else {
placeOfferButton.updateText(Res.get("createOffer.placeOfferButtonAltcoin", Res.get("shared.sell"),
model.getTradeCurrency().getName()));
}
}
};

placeOfferCompletedListener = (o, oldValue, newValue) -> {
Expand Down Expand Up @@ -1031,7 +1059,7 @@ private void addGridPane() {
}

private void addPaymentGroup() {
paymentTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, "Buy BTC with Fiat");
paymentTitledGroupBg = addTitledGroupBg(gridPane, gridRow, 1, Res.get("shared.chooseTradingAccount"));
GridPane.setColumnSpan(paymentTitledGroupBg, 2);

HBox paymentGroupBox = new HBox();
Expand All @@ -1040,7 +1068,7 @@ private void addPaymentGroup() {
paymentGroupBox.setPadding(new Insets(10, 0, 18, 0));

final Tuple3<VBox, Label, ComboBox<PaymentAccount>> tradingAccountBoxTuple = addTopLabelComboBox(
Res.get("shared.tradingAccount"), Res.get("shared.selectTradingAccount"));
Res.get("shared.chooseTradingAccount"), Res.get("shared.chooseTradingAccount"));
final Tuple3<VBox, Label, ComboBox<TradeCurrency>> currencyBoxTuple = addTopLabelComboBox(
Res.get("shared.currency"), Res.get("list.currency.select"));

Expand Down Expand Up @@ -1234,7 +1262,7 @@ private void addFundingGroup() {
fundingHBox.setVisible(false);
fundingHBox.setManaged(false);
fundingHBox.setSpacing(10);
Button fundFromSavingsWalletButton = new AutoTooltipButton(Res.get("shared.fundFromSavingsWalletButton"));
fundFromSavingsWalletButton = new AutoTooltipButton(Res.get("shared.fundFromSavingsWalletButton"));
fundFromSavingsWalletButton.setDefaultButton(true);
fundFromSavingsWalletButton.getStyleClass().add("action-button");
fundFromSavingsWalletButton.setOnAction(e -> model.fundFromSavingsWallet());
Expand Down Expand Up @@ -1553,4 +1581,18 @@ private GridPane createInfoPopover() {
model.getTotalToPayInfo());
return infoGridPane;
}

///////////////////////////////////////////////////////////////////////////////////////////
// Helpers
///////////////////////////////////////////////////////////////////////////////////////////

private ObservableList<PaymentAccount> getPaymentAccounts() {
return filterPaymentAccounts(model.getDataModel().getPaymentAccounts());
}

///////////////////////////////////////////////////////////////////////////////////////////
// Abstract Methods
///////////////////////////////////////////////////////////////////////////////////////////

protected abstract ObservableList<PaymentAccount> filterPaymentAccounts(ObservableList<PaymentAccount> paymentAccounts);
}
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,10 @@ CoinFormatter getBtcFormatter() {
return btcFormatter;
}

public boolean isShownAsBuyOffer() {
return OfferViewUtil.isShownAsBuyOffer(dataModel.getDirection(), dataModel.getTradeCurrency());
}

public boolean isSellOffer() {
return dataModel.getDirection() == OfferDirection.SELL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.core.offer.Offer;
import bisq.core.offer.OfferDirection;

Expand Down Expand Up @@ -118,10 +119,18 @@ private static void openBuyBsqOfferBook(Navigation navigation) {
}

public static boolean isShownAsSellOffer(Offer offer) {
return CurrencyUtil.isFiatCurrency(offer.getCurrencyCode()) == (offer.getDirection() == OfferDirection.SELL);
return isShownAsSellOffer(offer.getCurrencyCode(), offer.getDirection());
}

public static boolean isShownAsSellOffer(String currencyCode, OfferDirection direction) {
return CurrencyUtil.isFiatCurrency(currencyCode) == (direction == OfferDirection.SELL);
}

public static boolean isShownAsBuyOffer(Offer offer) {
return !isShownAsSellOffer(offer);
}

public static boolean isShownAsBuyOffer(OfferDirection direction, TradeCurrency tradeCurrency) {
return !isShownAsSellOffer(tradeCurrency.getCode(), direction);
}
}
Loading

0 comments on commit a8189d7

Please sign in to comment.