Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect tx link to tx explorer - fixes #5548 #5563

Merged
merged 4 commits into from Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
* 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.components;

import bisq.desktop.util.GUIUtil;

import bisq.core.locale.Res;
import bisq.core.user.BlockChainExplorer;
import bisq.core.user.Preferences;

import bisq.common.util.Utilities;

import de.jensd.fx.fontawesome.AwesomeDude;
import de.jensd.fx.fontawesome.AwesomeIcon;

import com.jfoenix.controls.JFXTextField;

import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.AnchorPane;

import lombok.Getter;
import lombok.Setter;

import javax.annotation.Nullable;

public class ExplorerAddressTextField extends AnchorPane {
private static Preferences preferences;

public static void setPreferences(Preferences preferences) {
ExplorerAddressTextField.preferences = preferences;
}
This conversation was marked as resolved.
Show resolved Hide resolved

@Getter
private final TextField textField;
private final Label copyIcon, blockExplorerIcon, missingAddressWarningIcon;
@Setter
private boolean isBsq;


///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////

public ExplorerAddressTextField() {
copyIcon = new Label();
copyIcon.setLayoutY(3);
copyIcon.getStyleClass().addAll("icon", "highlight");
copyIcon.setTooltip(new Tooltip(Res.get("txIdTextField.copyIcon.tooltip")));
This conversation was marked as resolved.
Show resolved Hide resolved
AwesomeDude.setIcon(copyIcon, AwesomeIcon.COPY);
AnchorPane.setRightAnchor(copyIcon, 30.0);

Tooltip tooltip = new Tooltip(Res.get("txIdTextField.blockExplorerIcon.tooltip"));
This conversation was marked as resolved.
Show resolved Hide resolved

blockExplorerIcon = new Label();
blockExplorerIcon.getStyleClass().addAll("icon", "highlight");
blockExplorerIcon.setTooltip(tooltip);
AwesomeDude.setIcon(blockExplorerIcon, AwesomeIcon.EXTERNAL_LINK);
blockExplorerIcon.setMinWidth(20);
AnchorPane.setRightAnchor(blockExplorerIcon, 52.0);
AnchorPane.setTopAnchor(blockExplorerIcon, 4.0);

missingAddressWarningIcon = new Label();
missingAddressWarningIcon.getStyleClass().addAll("icon", "error-icon");
AwesomeDude.setIcon(missingAddressWarningIcon, AwesomeIcon.WARNING_SIGN);
missingAddressWarningIcon.setTooltip(new Tooltip(Res.get("txIdTextField.missingTx.warning.tooltip")));
This conversation was marked as resolved.
Show resolved Hide resolved
missingAddressWarningIcon.setMinWidth(20);
AnchorPane.setRightAnchor(missingAddressWarningIcon, 52.0);
AnchorPane.setTopAnchor(missingAddressWarningIcon, 4.0);
missingAddressWarningIcon.setVisible(false);
missingAddressWarningIcon.setManaged(false);

textField = new JFXTextField();
textField.setId("address-text-field");
textField.setEditable(false);
textField.setTooltip(tooltip);
AnchorPane.setRightAnchor(textField, 80.0);
AnchorPane.setLeftAnchor(textField, 0.0);
textField.focusTraversableProperty().set(focusTraversableProperty().get());
getChildren().addAll(textField, missingAddressWarningIcon, blockExplorerIcon, copyIcon);
}

public void setup(@Nullable String addressId) {
This conversation was marked as resolved.
Show resolved Hide resolved
if (addressId == null) {
textField.setText(Res.get("shared.na"));
textField.setId("address-text-field-error");
blockExplorerIcon.setVisible(false);
blockExplorerIcon.setManaged(false);
copyIcon.setVisible(false);
copyIcon.setManaged(false);
missingAddressWarningIcon.setVisible(true);
missingAddressWarningIcon.setManaged(true);
return;
}

textField.setText(addressId);
textField.setOnMouseClicked(mouseEvent -> openBlockExplorer(addressId));
blockExplorerIcon.setOnMouseClicked(mouseEvent -> openBlockExplorer(addressId));
copyIcon.setOnMouseClicked(e -> Utilities.copyToClipboard(addressId));
}

public void cleanup() {
textField.setOnMouseClicked(null);
blockExplorerIcon.setOnMouseClicked(null);
copyIcon.setOnMouseClicked(null);
textField.setText("");
}

///////////////////////////////////////////////////////////////////////////////////////////
// Private
///////////////////////////////////////////////////////////////////////////////////////////

private void openBlockExplorer(String addressId) {
This conversation was marked as resolved.
Show resolved Hide resolved
if (preferences != null) {
BlockChainExplorer blockChainExplorer = isBsq ?
preferences.getBsqBlockChainExplorer() :
preferences.getBlockChainExplorer();
GUIUtil.openWebPage(blockChainExplorer.addressUrl + addressId, false);
}
}
}
2 changes: 2 additions & 0 deletions desktop/src/main/java/bisq/desktop/main/MainViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import bisq.desktop.app.BisqApp;
import bisq.desktop.common.model.ViewModel;
import bisq.desktop.components.ExplorerAddressTextField;
import bisq.desktop.components.TxIdTextField;
import bisq.desktop.main.overlays.Overlay;
import bisq.desktop.main.overlays.notifications.NotificationCenter;
Expand Down Expand Up @@ -205,6 +206,7 @@ public MainViewModel(BisqSetup bisqSetup,
this.corruptedStorageFileHandler = corruptedStorageFileHandler;

TxIdTextField.setPreferences(preferences);
ExplorerAddressTextField.setPreferences(preferences);

TxIdTextField.setWalletService(btcWalletService);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package bisq.desktop.main.overlays.windows;

import bisq.desktop.components.BisqTextArea;
import bisq.desktop.components.ExplorerAddressTextField;
import bisq.desktop.components.TxIdTextField;
import bisq.desktop.main.MainView;
import bisq.desktop.main.overlays.Overlay;
import bisq.desktop.util.DisplayUtils;
Expand Down Expand Up @@ -45,6 +47,7 @@

import bisq.common.UserThread;
import bisq.common.crypto.PubKeyRing;
import bisq.common.util.Tuple2;

import org.bitcoinj.core.Utils;

Expand Down Expand Up @@ -256,7 +259,7 @@ private void addContent() {
addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.delayedPayoutTxId"), dispute.getDelayedPayoutTxId());

if (dispute.getDonationAddressOfDelayedPayoutTx() != null) {
addLabelTxIdTextField(gridPane, ++rowIndex, Res.get("shared.delayedPayoutTxReceiverAddress"),
addLabelExplorerAddressTextField(gridPane, ++rowIndex, Res.get("shared.delayedPayoutTxReceiverAddress"),
dispute.getDonationAddressOfDelayedPayoutTx());
}

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

package bisq.desktop.main.presentation;

import bisq.desktop.components.ExplorerAddressTextField;
import bisq.desktop.components.TxIdTextField;
import bisq.desktop.main.shared.PriceFeedComboBoxItem;
import bisq.desktop.util.GUIUtil;
Expand Down Expand Up @@ -94,6 +95,7 @@ public MarketPricePresentation(BtcWalletService btcWalletService,
this.preferences = preferences;

TxIdTextField.setPreferences(preferences);
ExplorerAddressTextField.setPreferences(preferences);

// TODO
TxIdTextField.setWalletService(btcWalletService);
Expand Down
19 changes: 19 additions & 0 deletions desktop/src/main/java/bisq/desktop/util/FormBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import bisq.desktop.components.BisqTextField;
import bisq.desktop.components.BsqAddressTextField;
import bisq.desktop.components.BusyAnimation;
import bisq.desktop.components.ExplorerAddressTextField;
import bisq.desktop.components.ExternalHyperlink;
import bisq.desktop.components.FundsTextField;
import bisq.desktop.components.HyperlinkWithIcon;
Expand Down Expand Up @@ -699,6 +700,24 @@ public static Tuple2<Label, TxIdTextField> addLabelTxIdTextField(GridPane gridPa
return new Tuple2<>(label, txTextField);
}

///////////////////////////////////////////////////////////////////////////////////////////
// Label + ExplorerAddressTextField
///////////////////////////////////////////////////////////////////////////////////////////
public static void addLabelExplorerAddressTextField(GridPane gridPane,
int rowIndex,
String title,
String address) {
Label label = addLabel(gridPane, rowIndex, title, 0);
label.getStyleClass().add("confirmation-label");
GridPane.setHalignment(label, HPos.LEFT);

ExplorerAddressTextField addressTextField = new ExplorerAddressTextField();
addressTextField.setup(address);
GridPane.setRowIndex(addressTextField, rowIndex);
GridPane.setColumnIndex(addressTextField, 1);
gridPane.getChildren().add(addressTextField);
}


///////////////////////////////////////////////////////////////////////////////////////////
// Label + InputTextField
Expand Down