Skip to content

Commit

Permalink
Merge pull request #31 from anonymousbitcoin/bug/url
Browse files Browse the repository at this point in the history
Added "View on browser" For governance objects
  • Loading branch information
kaypon committed Oct 29, 2018
2 parents d7d2697 + e65f077 commit 5e6a8c0
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build-mac.sh
Expand Up @@ -8,7 +8,7 @@
# set up your app name, version number, and background image file name
APP_NAME="AnonymousDesktopWallet"
APP_DISPLAY_NAME="Anon Desktop Wallet"
VERSION="1.1.1"
VERSION="1.1.2"
APP_EXE="${APP_DISPLAY_NAME}.app/Contents/MacOS/JavaAppLauncher"
VOL_NAME="${APP_NAME}_${VERSION}"
DMG_TMP="${VOL_NAME}-temp.dmg"
Expand Down
Expand Up @@ -434,7 +434,7 @@ public synchronized String[][] getGobjectList() throws WalletCallException, IOEx
JsonArray objResponse = this.executeCommandAndGetJsonArray("masternode", "mymasternodes");
JsonObject gobjResponse = this.executeCommandAndGetJsonObject("gobject", "list");

String[][] lastArr = new String[gobjResponse.size()][7];
String[][] finalGobjectList = new String[gobjResponse.size()][8];

int i = 0;
for (String memberName : gobjResponse.names()) {
Expand All @@ -445,31 +445,33 @@ public synchronized String[][] getGobjectList() throws WalletCallException, IOEx

String hash = gobjResponse.get(memberName).asObject().get("Hash").toString().replace("\"", "");

String[] last = dataStringObject.substring(dataStringObject.lastIndexOf("{") + 1).replace("]", "").replace("\"end_epoch\":", " ").replace(",\"name\":", " ").replace(",\"payment_address\":", " ").replace(",\"payment_amount\":", " ").replace(",\"start_epoch\":", " ").replace(",\"type\":", " ").replace(",\"url\":", " ").replace("}", "").replace("\"created_at\":", " ").replace("\"type\":", " ").split(" ");
String[] gobjectListAsArray = dataStringObject.substring(dataStringObject.lastIndexOf("{") + 1).replace("]", "").replace("\"end_epoch\":", " ").replace(",\"name\":", " ").replace(",\"payment_address\":", " ").replace(",\"payment_amount\":", " ").replace(",\"start_epoch\":", " ").replace(",\"type\":", " ").replace(",\"url\":", " ").replace("}", "").replace("\"created_at\":", " ").replace("\"type\":", " ").split(" ");

List<String> lastAr = new ArrayList<String>(Arrays.asList(last));
lastAr.removeAll(Arrays.asList("", null, " "));
List<String> gobjecListAsList = new ArrayList<String>(Arrays.asList(gobjectListAsArray));
gobjecListAsList.removeAll(Arrays.asList("", null, " "));

lastArr[i][0] = hash;
lastArr[i][1] = lastAr.get(0) != null ? lastAr.get(0).replace("\"", "") : "null";
lastArr[i][2] = lastAr.get(1) != null ? lastAr.get(1).replace("\"", "") : "null";
lastArr[i][3] = lastAr.get(2) != null ? lastAr.get(2).replace("\"", "") : "null";
lastArr[i][4] = lastAr.get(3) != null ? lastAr.get(3).replace("\"", "") : "null";
lastArr[i][5] = lastAr.get(4) != null ? lastAr.get(4).replace("\"", "") : "null";
lastArr[i][6] = lastAr.get(5) != null ? lastAr.get(5).replace("\"", "") : "null";
finalGobjectList[i][0] = hash;
finalGobjectList[i][1] = gobjecListAsList.get(0) != null ? gobjecListAsList.get(0).replace("\"", "") : "null";
finalGobjectList[i][2] = gobjecListAsList.get(1) != null ? gobjecListAsList.get(1).replace("\"", "") : "null";
finalGobjectList[i][3] = gobjecListAsList.get(2) != null ? gobjecListAsList.get(2).replace("\"", "") : "null";
finalGobjectList[i][4] = gobjecListAsList.get(3) != null ? gobjecListAsList.get(3).replace("\"", "") : "null";
finalGobjectList[i][5] = gobjecListAsList.get(4) != null ? gobjecListAsList.get(4).replace("\"", "") : "null";
finalGobjectList[i][6] = gobjecListAsList.get(5) != null ? gobjecListAsList.get(5).replace("\"", "") : "null";
finalGobjectList[i][7] = gobjecListAsList.get(6) != null ? gobjecListAsList.get(6).replace("\"", "") : "null";
i++;
}

if (gobjResponse.size() == 0){
String[][] noMNArr = new String[1][];
noMNArr[0] = new String[7];
noMNArr[0] = new String[8];
noMNArr[0][0] = "No Governance Objects";
noMNArr[0][1] = "";
noMNArr[0][2] = "";
noMNArr[0][3] = "";
noMNArr[0][4] = "";
noMNArr[0][5] = "";
// noMNArr[0][6] = "";
noMNArr[0][6] = "";
noMNArr[0][7] = "";

return noMNArr;
};
Expand All @@ -488,7 +490,7 @@ public synchronized String[][] getGobjectList() throws WalletCallException, IOEx
finalArr[j][5] = trans.get(5).toString().replace("\"", "");
}

return lastArr;
return finalGobjectList;
}

public synchronized String[][] getWalletPublicTransactions()
Expand Down
Expand Up @@ -23,7 +23,7 @@
* This Java source file was generated by the Gradle 'init' task.
*/
public class ANONWalletUI extends JFrame {
private static final String VERSION = "1.1.1";
private static final String VERSION = "1.1.2";
private ANONInstallationObserver installationObserver;
private ANONClientCaller clientCaller;
private StatusUpdateErrorReporter errorReporter;
Expand Down
Expand Up @@ -397,9 +397,9 @@ private void updateGovernancesTable()

private JTable createGovernancesTable(String rowData[][])
throws WalletCallException, IOException, InterruptedException {
String columnNames[] = {LOCAL_MSG_GOVERNANCE_HASH, LOCAL_MSG_GOVERNANCE_STARTEPOCH, LOCAL_MSG_GOVERNANCE_NAME, LOCAL_MSG_GOVERNANCE_PAYMENTADDRESS, LOCAL_MSG_GOVERNANCE_PAYMENTAMOUNT, LOCAL_MSG_GOVERNANCE_ENDEPOCH, LOCAL_MSG_GOVERNANCE_TYPE};
String columnNames[] = {LOCAL_MSG_GOVERNANCE_HASH, LOCAL_MSG_GOVERNANCE_STARTEPOCH, LOCAL_MSG_GOVERNANCE_NAME, LOCAL_MSG_GOVERNANCE_PAYMENTADDRESS, LOCAL_MSG_GOVERNANCE_PAYMENTAMOUNT, LOCAL_MSG_GOVERNANCE_ENDEPOCH, LOCAL_MSG_GOVERNANCE_TYPE, "URL"};

JTable table = new MasternodeTable(
JTable table = new GovernanceTable(
rowData, columnNames, this.parentFrame, this.clientCaller, this.installationObserver);
table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
table.getColumnModel().getColumn(0).setPreferredWidth(300);
Expand All @@ -408,6 +408,7 @@ private JTable createGovernancesTable(String rowData[][])
table.getColumnModel().getColumn(3).setPreferredWidth(200);
table.getColumnModel().getColumn(4).setPreferredWidth(180);
table.getColumnModel().getColumn(5).setPreferredWidth(100);
table.getColumnModel().getColumn(6).setPreferredWidth(100);

return table;

Expand Down
150 changes: 150 additions & 0 deletions src/main/java/org/anonymous/wallets/fullnode/ui/GovernanceTable.java
@@ -0,0 +1,150 @@
package org.anonymous.wallets.fullnode.ui;

import org.anonymous.wallets.fullnode.daemon.ANONClientCaller;
import org.anonymous.wallets.fullnode.daemon.ANONInstallationObserver;
import org.anonymous.wallets.fullnode.util.Log;
import org.anonymous.wallets.fullnode.util.Util;

import javax.swing.*;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;

/**
* Table to be used for transactions - specifically.
*
* @author Ivan Vaklinov <ivan@vaklinov.com>
*/
public class GovernanceTable extends DataTable {

private static final String LOCAL_MSG_SHOW_DETAILS = Util.local("LOCAL_MSG_SHOW_DETAILS");
private static final String LOCAL_MSG_VIEW_ON_EXPLORER = Util.local("LOCAL_MSG_VIEW_ON_EXPLORER");
private static final String LOCAL_MSG_SHOW_MEMO = Util.local("LOCAL_MSG_SHOW_MEMO");
private static final String LOCAL_MSG_NO_MEMO = Util.local("LOCAL_MSG_NO_MEMO");
private static final String LOCAL_MSG_NO_MEMO_TITLE = Util.local("LOCAL_MSG_NO_MEMO_TITLE");
private static final String LOCAL_MSG_MEMO_DETAIL_1 = Util.local("LOCAL_MSG_MEMO_DETAIL_1");
private static final String LOCAL_MSG_MEMO_DETAIL_2 = Util.local("LOCAL_MSG_MEMO_DETAIL_2");
private static final String LOCAL_MSG_NO_MEMO_DETAIL = Util.local("LOCAL_MSG_NO_MEMO_DETAIL");
private static final String LOCAL_MSG_MEMO = Util.local("LOCAL_MSG_MEMO");
private static final String LOCAL_MSG_TXN_DETAILS = Util.local("LOCAL_MSG_TXN_DETAILS");
private static final String LOCAL_MSG_TXN_DETAILS_1 = Util.local("LOCAL_MSG_TXN_DETAILS_1");
private static final String LOCAL_MSG_TXN_NAME = Util.local("LOCAL_MSG_TXN_NAME");
private static final String LOCAL_MSG_TXN_VALUE = Util.local("LOCAL_MSG_TXN_VALUE");
private static final String LOCAL_MSG_TXN_CLOSE = Util.local("LOCAL_MSG_TXN_CLOSE");

private static final String BLOCK_EXPLORER_URL = "https://explorer.anonfork.io/insight/";
private static final String BLOCK_EXPLORER_TEST_URL = "https://texplorer.anonfork.io/insight/";

public GovernanceTable(final Object[][] rowData, final Object[] columnNames, final JFrame parent,
final ANONClientCaller caller, final ANONInstallationObserver installationObserver) {
super(rowData, columnNames);

JMenuItem showInExplorer = new JMenuItem("View on Browser");
popupMenu.add(showInExplorer);

showInExplorer.addActionListener(e -> {
if ((lastRow >= 0) && (lastColumn >= 0)) {
try {
String data = GovernanceTable.this.getModel().getValueAt(lastRow, lastColumn).toString();
data = data.replaceAll("\"", ""); // In case it has quotes

Log.info("Transaction ID for block explorer is: " + data);
String urlPrefix = BLOCK_EXPLORER_URL;
if (installationObserver.isOnTestNet()) {
urlPrefix = BLOCK_EXPLORER_TEST_URL;
}
if (lastColumn == 3) {
Desktop.getDesktop().browse(new URL(urlPrefix + "/address/" + data).toURI());
} else if(lastColumn == 7) {
Desktop.getDesktop().browse(new URL(data).toURI());
} else {
Desktop.getDesktop().browse(new URL(urlPrefix + data).toURI());
}

} catch (Exception ex) {
Log.error("Unexpected error: ", ex);
}
} else {
// Log perhaps
}
});
} // End constructor

private static class DetailsDialog extends JDialog {
public DetailsDialog(JFrame parent, Map<String, String> details) throws UnsupportedEncodingException {

this.setTitle(LOCAL_MSG_TXN_DETAILS);
this.setSize(700, 310);
this.setLocation(100, 100);
this.setLocationRelativeTo(parent);
this.setModal(true);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

this.getContentPane().setLayout(new BorderLayout(0, 0));

JPanel tempPanel = new JPanel(new BorderLayout(0, 0));
tempPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
JLabel infoLabel = new JLabel("<html><span style=\"font-size:0.97em;\">"
+ LOCAL_MSG_TXN_DETAILS_1 + "</span>");
infoLabel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
tempPanel.add(infoLabel, BorderLayout.CENTER);
this.getContentPane().add(tempPanel, BorderLayout.NORTH);

String[] columns = new String[]{LOCAL_MSG_TXN_NAME, LOCAL_MSG_TXN_VALUE};
String[][] data = new String[details.size()][2];
int i = 0;
int maxPreferredWidth = 400;
for (Entry<String, String> ent : details.entrySet()) {
if (maxPreferredWidth < (ent.getValue().length() * 7)) {
maxPreferredWidth = ent.getValue().length() * 7;
}

data[i][0] = ent.getKey();
data[i][1] = ent.getValue();
i++;
}



Arrays.sort(data, new Comparator<String[]>() {
public int compare(String[] o1, String[] o2) {
return o1[0].compareTo(o2[0]);
}

public boolean equals(Object obj) {
return false;
}
});

DataTable table = new DataTable(data, columns);
table.getColumnModel().getColumn(0).setPreferredWidth(200);
table.getColumnModel().getColumn(1).setPreferredWidth(maxPreferredWidth);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JScrollPane tablePane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

this.getContentPane().add(tablePane, BorderLayout.CENTER);

// Lower close button
JPanel closePanel = new JPanel();
closePanel.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3));
JButton closeButton = new JButton(LOCAL_MSG_TXN_CLOSE);
closePanel.add(closeButton);
this.getContentPane().add(closePanel, BorderLayout.SOUTH);

closeButton.addActionListener(e -> {
DetailsDialog.this.setVisible(false);
DetailsDialog.this.dispose();
});
}
}
}

0 comments on commit 5e6a8c0

Please sign in to comment.