Search in sources :

Example 6 with OS_TYPE

use of com.vaklinov.zcashui.OSUtil.OS_TYPE in project zencash-swing-wallet-ui by ZencashOfficial.

the class TransactionsDetailPanel method getTransactionsDataFromWallet.

// TODO: duplication with dashboard ...
private String[][] getTransactionsDataFromWallet() throws WalletCallException, IOException, InterruptedException {
    // Get available public+private transactions and unify them.
    String[][] publicTransactions = this.clientCaller.getWalletPublicTransactions();
    String[][] zReceivedTransactions = this.clientCaller.getWalletZReceivedTransactions();
    String[][] allTransactions = new String[publicTransactions.length + zReceivedTransactions.length][];
    int i = 0;
    for (String[] t : publicTransactions) {
        allTransactions[i++] = t;
    }
    for (String[] t : zReceivedTransactions) {
        allTransactions[i++] = t;
    }
    // Sort transactions by date
    Arrays.sort(allTransactions, new Comparator<String[]>() {

        public int compare(String[] o1, String[] o2) {
            Date d1 = new Date(0);
            if ((!o1[4].equals("N/A")) && Util.isNumeric(o1[4])) {
                d1 = new Date(Long.valueOf(o1[4]).longValue() * 1000L);
            }
            Date d2 = new Date(0);
            if (!o2[4].equals("N/A") && Util.isNumeric(o2[4])) {
                d2 = new Date(Long.valueOf(o2[4]).longValue() * 1000L);
            }
            if (d1.equals(d2)) {
                return 0;
            } else {
                return d2.compareTo(d1);
            }
        }
    });
    // Confirmation symbols
    String confirmed = "\u2690";
    String notConfirmed = "\u2691";
    // Windows does not support the flag symbol (Windows 7 by default)
    // TODO: isolate OS-specific symbol codes in a separate class
    OS_TYPE os = OSUtil.getOSType();
    if (os == OS_TYPE.WINDOWS) {
        confirmed = " \u25B7";
        notConfirmed = " \u25B6";
    }
    DecimalFormat df = new DecimalFormat("########0.00######");
    // Change the direction and date etc. attributes for presentation purposes
    for (String[] trans : allTransactions) {
        // Direction
        if (trans[1].equals("receive")) {
            trans[1] = "\u21E8 IN";
        } else if (trans[1].equals("send")) {
            trans[1] = "\u21E6 OUT";
        } else if (trans[1].equals("generate")) {
            trans[1] = "\u2692\u2699 MINED";
        } else if (trans[1].equals("immature")) {
            trans[1] = "\u2696 Immature";
        }
        ;
        // Date
        if ((!trans[4].equals("N/A")) && Util.isNumeric(trans[4])) {
            trans[4] = new Date(Long.valueOf(trans[4]).longValue() * 1000L).toLocaleString();
        }
        // Amount
        try {
            double amount = Double.valueOf(trans[3]);
            if (amount < 0d) {
                amount = -amount;
            }
            trans[3] = df.format(amount);
        } catch (NumberFormatException nfe) {
            Log.error("Error occurred while formatting amount: " + trans[3] + " - " + nfe.getMessage() + "!");
        }
        // Confirmed?
        try {
            boolean isConfirmed = !trans[2].trim().equals("0");
            trans[2] = isConfirmed ? (langUtil.getString("transactions.detail.panel.yes", confirmed)) : (langUtil.getString("transactions.detail.panel.no", notConfirmed));
        } catch (NumberFormatException nfe) {
            Log.error("Error occurred while formatting confirmations: " + trans[2] + " - " + nfe.getMessage() + "!");
        }
    }
    return allTransactions;
}
Also used : OS_TYPE(com.vaklinov.zcashui.OSUtil.OS_TYPE) DecimalFormat(java.text.DecimalFormat) Date(java.util.Date)

Example 7 with OS_TYPE

use of com.vaklinov.zcashui.OSUtil.OS_TYPE in project zencash-swing-wallet-ui by ZencashOfficial.

the class AddressesPanel method getAddressBalanceDataFromWallet.

private String[][] getAddressBalanceDataFromWallet() throws WalletCallException, IOException, InterruptedException {
    // Z Addresses - they are OK
    String[] zAddresses = clientCaller.getWalletZAddresses();
    // T Addresses listed with the list received by addr comamnd
    String[] tAddresses = this.clientCaller.getWalletAllPublicAddresses();
    Set<String> tStoredAddressSet = new HashSet<>();
    for (String address : tAddresses) {
        tStoredAddressSet.add(address);
    }
    // T addresses with unspent outputs - just in case they are different
    String[] tAddressesWithUnspentOuts = this.clientCaller.getWalletPublicAddressesWithUnspentOutputs();
    Set<String> tAddressSetWithUnspentOuts = new HashSet<>();
    for (String address : tAddressesWithUnspentOuts) {
        tAddressSetWithUnspentOuts.add(address);
    }
    // Combine all known T addresses
    Set<String> tAddressesCombined = new HashSet<>();
    tAddressesCombined.addAll(tStoredAddressSet);
    tAddressesCombined.addAll(tAddressSetWithUnspentOuts);
    String[][] addressBalances = new String[zAddresses.length + tAddressesCombined.size()][];
    // Format double numbers - else sometimes we get exponential notation 1E-4 ZEN
    DecimalFormat df = new DecimalFormat("########0.00######");
    String confirmed = "\u2690";
    String notConfirmed = "\u2691";
    // Windows does not support the flag symbol (Windows 7 by default)
    // TODO: isolate OS-specific symbol codes in a separate class
    OS_TYPE os = OSUtil.getOSType();
    if (os == OS_TYPE.WINDOWS) {
        confirmed = " \u25B7";
        notConfirmed = " \u25B6";
    }
    int i = 0;
    for (String address : tAddressesCombined) {
        String addressToDisplay = address;
        // Make sure the current address is not watch-only or invalid
        if (!this.validationMap.containsKey(address)) {
            boolean validationResult = this.clientCaller.isWatchOnlyOrInvalidAddress(address);
            this.validationMap.put(address, new Boolean(validationResult));
            if (validationResult) {
                JOptionPane.showMessageDialog(this.parentFrame, langUtil.getString("panel.address.option.pane.validation.error.text", address), langUtil.getString("panel.address.option.pane.validation.error.title"), JOptionPane.ERROR_MESSAGE);
            }
        }
        boolean watchOnlyOrInvalid = this.validationMap.get(address).booleanValue();
        if (watchOnlyOrInvalid) {
            Log.error("The following address is invalid or a watch-only address: {0}. It will not be displayed!", address);
            addressToDisplay = "<INVALID OR WATCH-ONLY ADDRESS> !!!";
        }
        // End of check for invalid/watch only addresses
        String confirmedBalance = this.clientCaller.getBalanceForAddress(address);
        String unconfirmedBalance = this.clientCaller.getUnconfirmedBalanceForAddress(address);
        boolean isConfirmed = (confirmedBalance.equals(unconfirmedBalance));
        String balanceToShow = df.format(Double.valueOf(isConfirmed ? confirmedBalance : unconfirmedBalance));
        addressBalances[i++] = new String[] { this.labelStorage.getLabel(addressToDisplay), balanceToShow, isConfirmed ? (langUtil.getString("panel.address.option.pane.yes", confirmed)) : (langUtil.getString("panel.address.option.pane.no", notConfirmed)), addressToDisplay };
    }
    for (String address : zAddresses) {
        String confirmedBalance = this.clientCaller.getBalanceForAddress(address);
        String unconfirmedBalance = this.clientCaller.getUnconfirmedBalanceForAddress(address);
        boolean isConfirmed = (confirmedBalance.equals(unconfirmedBalance));
        String balanceToShow = df.format(Double.valueOf(isConfirmed ? confirmedBalance : unconfirmedBalance));
        addressBalances[i++] = new String[] { this.labelStorage.getLabel(address), balanceToShow, isConfirmed ? (langUtil.getString("panel.address.option.pane.yes", confirmed)) : (langUtil.getString("panel.address.option.pane.no", notConfirmed)), address };
    }
    return addressBalances;
}
Also used : OS_TYPE(com.vaklinov.zcashui.OSUtil.OS_TYPE) DecimalFormat(java.text.DecimalFormat) HashSet(java.util.HashSet)

Aggregations

OS_TYPE (com.vaklinov.zcashui.OSUtil.OS_TYPE)7 IOException (java.io.IOException)3 JsonObject (com.eclipsesource.json.JsonObject)2 WalletCallException (com.vaklinov.zcashui.ZCashClientCaller.WalletCallException)2 File (java.io.File)2 DecimalFormat (java.text.DecimalFormat)2 Date (java.util.Date)2 JsonArray (com.eclipsesource.json.JsonArray)1 JsonValue (com.eclipsesource.json.JsonValue)1 NetworkAndBlockchainInfo (com.vaklinov.zcashui.ZCashClientCaller.NetworkAndBlockchainInfo)1 DaemonInfo (com.vaklinov.zcashui.ZCashInstallationObserver.DaemonInfo)1 InstallationDetectionException (com.vaklinov.zcashui.ZCashInstallationObserver.InstallationDetectionException)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 InterruptedIOException (java.io.InterruptedIOException)1 OutputStream (java.io.OutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1