Skip to content

Commit

Permalink
Merge pull request #5316 from chimp1984/add-pay-from-bsq-wallet-button
Browse files Browse the repository at this point in the history
Add pay from BSQ wallet button
  • Loading branch information
ripcurlx authored Mar 17, 2021
2 parents 033ec32 + 2702a7e commit 16230c7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 10 deletions.
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ portfolio.pending.step2_buyer.amountToTransfer=Amount to transfer
portfolio.pending.step2_buyer.sellersAddress=Seller''s {0} address
portfolio.pending.step2_buyer.buyerAccount=Your payment account to be used
portfolio.pending.step2_buyer.paymentStarted=Payment started
portfolio.pending.step2_buyer.fillInBsqWallet=Pay from BSQ wallet
portfolio.pending.step2_buyer.warn=You still have not done your {0} payment!\nPlease note that the trade has to be completed by {1}.
portfolio.pending.step2_buyer.openForDispute=You have not completed your payment!\nThe max. period for the trade has elapsed.\
Please contact the mediator for assistance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import bisq.core.locale.Res;

import bisq.common.app.DevEnv;
import bisq.common.util.Tuple2;

import javax.inject.Inject;

Expand All @@ -46,6 +47,8 @@
import java.util.Arrays;
import java.util.List;

import javax.annotation.Nullable;

@FxmlView
public class BsqWalletView extends ActivatableView<AnchorPane, Void> {

Expand All @@ -71,12 +74,24 @@ private BsqWalletView(CachingViewLoader viewLoader, Navigation navigation) {

@Override
public void initialize() {
listener = viewPath -> {
if (viewPath.size() != 4 || viewPath.indexOf(BsqWalletView.class) != 2)
return;

selectedViewClass = viewPath.tip();
loadView(selectedViewClass);
listener = new Navigation.Listener() {
@Override
public void onNavigationRequested(ViewPath viewPath) {
if (viewPath.size() != 4 || viewPath.indexOf(BsqWalletView.class) != 2)
return;

selectedViewClass = viewPath.tip();
loadView(selectedViewClass);
}

@Override
public void onNavigationRequested(ViewPath viewPath, @Nullable Object data) {
if (viewPath.size() != 4 || viewPath.indexOf(BsqWalletView.class) != 2)
return;

selectedViewClass = viewPath.tip();
loadView(selectedViewClass, data);
}
};

toggleGroup = new ToggleGroup();
Expand Down Expand Up @@ -126,12 +141,23 @@ protected void deactivate() {
}

private void loadView(Class<? extends View> viewClass) {
loadView(viewClass, null);
}

private void loadView(Class<? extends View> viewClass, @Nullable Object data) {
View view = viewLoader.load(viewClass);
content.getChildren().setAll(view.getRoot());

if (view instanceof BsqSendView) toggleGroup.selectToggle(send);
else if (view instanceof BsqReceiveView) toggleGroup.selectToggle(receive);
else if (view instanceof BsqTxView) toggleGroup.selectToggle(transactions);
if (view instanceof BsqSendView) {
toggleGroup.selectToggle(send);
if (data instanceof Tuple2) {
((BsqSendView) view).fillFromTradeData((Tuple2) data);
}
} else if (view instanceof BsqReceiveView) {
toggleGroup.selectToggle(receive);
} else if (view instanceof BsqTxView) {
toggleGroup.selectToggle(transactions);
}
}

public Class<? extends View> getSelectedViewClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import bisq.desktop.main.overlays.windows.TxDetailsBsq;
import bisq.desktop.main.overlays.windows.TxInputSelectionWindow;
import bisq.desktop.main.overlays.windows.WalletPasswordWindow;
import bisq.desktop.util.DisplayUtils;
import bisq.desktop.util.FormBuilder;
import bisq.desktop.util.GUIUtil;
import bisq.desktop.util.Layout;
Expand All @@ -48,6 +49,7 @@
import bisq.core.btc.wallet.WalletsManager;
import bisq.core.dao.state.model.blockchain.TxType;
import bisq.core.locale.Res;
import bisq.core.monetary.Volume;
import bisq.core.user.DontShowAgainLookup;
import bisq.core.user.Preferences;
import bisq.core.util.FormattingUtils;
Expand Down Expand Up @@ -253,6 +255,11 @@ public void onUpdateBalances(Coin availableConfirmedBalance,
setSendBtcGroupVisibleState(availableNonBsqBalance.isPositive());
}

public void fillFromTradeData(Tuple2<Volume, String> tuple) {
amountInputTextField.setText(DisplayUtils.formatVolume(tuple.first));
receiversAddressInputTextField.setText(tuple.second);
}

private void updateBsqValidator(Coin availableConfirmedBalance) {
bsqValidator.setAvailableBalance(availableConfirmedBalance);
boolean isValid = bsqAddressValidator.validate(receiversAddressInputTextField.getText()).isValid &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package bisq.desktop.main.portfolio.pendingtrades;

import bisq.desktop.Navigation;
import bisq.desktop.common.model.ActivatableWithDataModel;
import bisq.desktop.common.model.ViewModel;
import bisq.desktop.util.DisplayUtils;
Expand Down Expand Up @@ -101,6 +102,8 @@ enum SellerState implements State {
private final TradeUtil tradeUtil;
public final ClockWatcher clockWatcher;
@Getter
private final Navigation navigation;
@Getter
private final User user;

private final ObjectProperty<BuyerState> buyerState = new SimpleObjectProperty<>();
Expand All @@ -126,6 +129,7 @@ public PendingTradesViewModel(PendingTradesDataModel dataModel,
TradeUtil tradeUtil,
AccountAgeWitnessService accountAgeWitnessService,
ClockWatcher clockWatcher,
Navigation navigation,
User user) {
super(dataModel);

Expand All @@ -138,6 +142,7 @@ public PendingTradesViewModel(PendingTradesDataModel dataModel,
this.tradeUtil = tradeUtil;
this.accountAgeWitnessService = accountAgeWitnessService;
this.clockWatcher = clockWatcher;
this.navigation = navigation;
this.user = user;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package bisq.desktop.main.portfolio.pendingtrades.steps.buyer;

import bisq.desktop.components.AutoTooltipButton;
import bisq.desktop.components.BusyAnimation;
import bisq.desktop.components.TextFieldWithCopyIcon;
import bisq.desktop.components.TitledGroupBg;
Expand Down Expand Up @@ -50,6 +51,10 @@
import bisq.desktop.components.paymentmethods.UpholdForm;
import bisq.desktop.components.paymentmethods.WeChatPayForm;
import bisq.desktop.components.paymentmethods.WesternUnionForm;
import bisq.desktop.main.MainView;
import bisq.desktop.main.dao.DaoView;
import bisq.desktop.main.dao.wallet.BsqWalletView;
import bisq.desktop.main.dao.wallet.send.BsqSendView;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.main.overlays.windows.SetXmrTxKeyWindow;
import bisq.desktop.main.portfolio.pendingtrades.PendingTradesViewModel;
Expand All @@ -59,6 +64,7 @@
import bisq.desktop.util.Transitions;

import bisq.core.locale.Res;
import bisq.core.monetary.Volume;
import bisq.core.network.MessageState;
import bisq.core.offer.Offer;
import bisq.core.payment.PaymentAccount;
Expand All @@ -81,6 +87,7 @@
import bisq.common.Timer;
import bisq.common.UserThread;
import bisq.common.app.DevEnv;
import bisq.common.util.Tuple2;
import bisq.common.util.Tuple4;

import javafx.scene.control.Button;
Expand Down Expand Up @@ -108,6 +115,7 @@ public class BuyerStep2View extends TradeStepView {
private BusyAnimation busyAnimation;
private Subscription tradeStatePropertySubscription;
private Timer timeoutTimer;
private AutoTooltipButton fillBsqButton;

///////////////////////////////////////////////////////////////////////////////////////////
// Constructor, Initialisation
Expand Down Expand Up @@ -342,11 +350,23 @@ protected void addContent() {
Tuple4<Button, BusyAnimation, Label, HBox> tuple3 = addButtonBusyAnimationLabel(gridPane, ++gridRow, 0,
Res.get("portfolio.pending.step2_buyer.paymentStarted"), 10);

GridPane.setColumnSpan(tuple3.fourth, 2);
HBox hBox = tuple3.fourth;
GridPane.setColumnSpan(hBox, 2);
confirmButton = tuple3.first;
confirmButton.setOnAction(e -> onPaymentStarted());
busyAnimation = tuple3.second;
statusLabel = tuple3.third;

if (trade.getOffer().getCurrencyCode().equals("BSQ")) {
fillBsqButton = new AutoTooltipButton(Res.get("portfolio.pending.step2_buyer.fillInBsqWallet"));
hBox.getChildren().add(1, fillBsqButton);
fillBsqButton.setOnAction(e -> {
AssetsAccountPayload assetsAccountPayload = (AssetsAccountPayload) paymentAccountPayload;
Tuple2<Volume, String> data = new Tuple2<>(trade.getTradeVolume(), assetsAccountPayload.getAddress());
model.getNavigation().navigateToWithData(data, MainView.class, DaoView.class, BsqWalletView.class,
BsqSendView.class);
});
}
}

///////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 16230c7

Please sign in to comment.