mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-03-15 10:26:37 -04:00
fixed confirmation display
This commit is contained in:
parent
c2db60be67
commit
9af3f6aeba
@ -1,13 +1,12 @@
|
||||
package io.bitsquare.gui.funds;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.script.Script;
|
||||
import com.google.inject.Inject;
|
||||
import de.jensd.fx.fontawesome.AwesomeDude;
|
||||
import de.jensd.fx.fontawesome.AwesomeIcon;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.ChildController;
|
||||
import io.bitsquare.gui.NavigationController;
|
||||
import io.bitsquare.gui.util.ConfidenceDisplay;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.Label;
|
||||
@ -19,18 +18,15 @@ import javafx.scene.input.ClipboardContent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class FundsController implements Initializable, ChildController
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(FundsController.class);
|
||||
private WalletFacade walletFacade;
|
||||
private ConfidenceDisplay confidenceDisplay;
|
||||
|
||||
@FXML
|
||||
private TextField tradingAccountTextField, balanceTextField;
|
||||
@ -43,8 +39,6 @@ public class FundsController implements Initializable, ChildController
|
||||
public FundsController(WalletFacade walletFacade)
|
||||
{
|
||||
this.walletFacade = walletFacade;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,47 +57,7 @@ public class FundsController implements Initializable, ChildController
|
||||
clipboard.setContent(content);
|
||||
});
|
||||
|
||||
updateBalance(walletFacade.getBalance());
|
||||
|
||||
walletFacade.getWallet().addEventListener(new WalletEventListener()
|
||||
{
|
||||
@Override
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
updateBalance(newBalance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
|
||||
{
|
||||
updateConfidence(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReorganize(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalletChanged(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(Wallet wallet, List<ECKey> keys)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScriptsAdded(Wallet wallet, List<Script> scripts)
|
||||
{
|
||||
}
|
||||
});
|
||||
confidenceDisplay = new ConfidenceDisplay(walletFacade.getWallet(), confirmationLabel, balanceTextField, progressIndicator);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -116,73 +70,5 @@ public class FundsController implements Initializable, ChildController
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void updateBalance(BigInteger balance)
|
||||
{
|
||||
if (balance.compareTo(BigInteger.ZERO) == 0)
|
||||
{
|
||||
confirmationLabel.setText("");
|
||||
progressIndicator.setOpacity(0);
|
||||
progressIndicator.setProgress(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
progressIndicator.setOpacity(1);
|
||||
progressIndicator.setProgress(-1);
|
||||
Set<Transaction> transactions = walletFacade.getWallet().getTransactions(false);
|
||||
Transaction latestTransaction = null;
|
||||
for (Iterator<Transaction> iterator = transactions.iterator(); iterator.hasNext(); )
|
||||
{
|
||||
Transaction transaction = iterator.next();
|
||||
if (latestTransaction != null)
|
||||
{
|
||||
if (transaction.getUpdateTime().compareTo(latestTransaction.getUpdateTime()) > 0)
|
||||
{
|
||||
latestTransaction = transaction;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
latestTransaction = transaction;
|
||||
}
|
||||
}
|
||||
if (latestTransaction != null)
|
||||
{
|
||||
updateConfidence(latestTransaction);
|
||||
}
|
||||
}
|
||||
balanceTextField.setText(Utils.bitcoinValueToFriendlyString(balance));
|
||||
}
|
||||
|
||||
private void updateConfidence(Transaction tx)
|
||||
{
|
||||
TransactionConfidence confidence = tx.getConfidence();
|
||||
double progressIndicatorSize = 50;
|
||||
switch (confidence.getConfidenceType())
|
||||
{
|
||||
case UNKNOWN:
|
||||
confirmationLabel.setText("");
|
||||
progressIndicator.setProgress(0);
|
||||
break;
|
||||
case PENDING:
|
||||
confirmationLabel.setText("Seen by " + confidence.numBroadcastPeers() + " peer(s) / 0 confirmations");
|
||||
progressIndicator.setProgress(-1.0);
|
||||
progressIndicatorSize = 20;
|
||||
break;
|
||||
case BUILDING:
|
||||
confirmationLabel.setText("Confirmed in " + confidence.getDepthInBlocks() + " block(s)");
|
||||
progressIndicator.setProgress(Math.min(1, (double) confidence.getDepthInBlocks() / 6.0));
|
||||
break;
|
||||
case DEAD:
|
||||
confirmationLabel.setText("Transaction is invalid.");
|
||||
break;
|
||||
}
|
||||
|
||||
progressIndicator.setMaxHeight(progressIndicatorSize);
|
||||
progressIndicator.setPrefHeight(progressIndicatorSize);
|
||||
progressIndicator.setMaxWidth(progressIndicatorSize);
|
||||
progressIndicator.setPrefWidth(progressIndicatorSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
<children>
|
||||
<Label text="Trading account address:"/>
|
||||
<TextField fx:id="tradingAccountTextField" editable="false" GridPane.columnIndex="1"/>
|
||||
<Label fx:id="copyIcon" minWidth="10" GridPane.columnIndex="2">
|
||||
<Label fx:id="copyIcon" GridPane.columnIndex="2">
|
||||
<padding>
|
||||
<Insets bottom="0.0" left="0.0" right="0.0" top="-1.0"/>
|
||||
</padding>
|
||||
@ -33,6 +33,7 @@
|
||||
</ProgressIndicator>
|
||||
<Label fx:id="confirmationLabel" text="Checking confirmations..." GridPane.columnIndex="3" GridPane.rowIndex="1"/>
|
||||
|
||||
|
||||
<Label text="dummy for layout progressIndicator" visible="false" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
|
||||
|
||||
</children>
|
||||
@ -40,7 +41,7 @@
|
||||
<columnConstraints>
|
||||
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES"/>
|
||||
<ColumnConstraints hgrow="ALWAYS"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES" prefWidth="20.0"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES" prefWidth="20.0" minWidth="20.0"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES"/>
|
||||
</columnConstraints>
|
||||
|
@ -1,7 +1,8 @@
|
||||
package io.bitsquare.gui.market.createOffer;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.script.Script;
|
||||
import com.google.bitcoin.core.InsufficientMoneyException;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.bitcoin.core.Utils;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.inject.Inject;
|
||||
import io.bitsquare.btc.BtcFormatter;
|
||||
@ -9,10 +10,7 @@ import io.bitsquare.btc.Fees;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.ChildController;
|
||||
import io.bitsquare.gui.NavigationController;
|
||||
import io.bitsquare.gui.util.Converter;
|
||||
import io.bitsquare.gui.util.Formatter;
|
||||
import io.bitsquare.gui.util.Localisation;
|
||||
import io.bitsquare.gui.util.Popups;
|
||||
import io.bitsquare.gui.util.*;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.settings.Settings;
|
||||
import io.bitsquare.trade.Direction;
|
||||
@ -34,7 +32,6 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.IOException;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class CreateOfferController implements Initializable, ChildController
|
||||
@ -49,6 +46,7 @@ public class CreateOfferController implements Initializable, ChildController
|
||||
private User user;
|
||||
private Direction direction;
|
||||
private Offer offer;
|
||||
private ConfidenceDisplay confidenceDisplay;
|
||||
|
||||
@FXML
|
||||
private AnchorPane rootContainer;
|
||||
@ -198,6 +196,15 @@ public class CreateOfferController implements Initializable, ChildController
|
||||
offer.setOfferFeePaymentTxID(transaction.getHashAsString());
|
||||
setupSuccessScreen(transaction);
|
||||
placeOfferTitle.setText("Transaction sent:");
|
||||
|
||||
try
|
||||
{
|
||||
log.info("send offer to P2P orderbook");
|
||||
messageFacade.addOffer(offer);
|
||||
} catch (IOException e)
|
||||
{
|
||||
Popups.openErrorPopup("Could not publish offer", "Could not publish offer. " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -211,14 +218,10 @@ public class CreateOfferController implements Initializable, ChildController
|
||||
try
|
||||
{
|
||||
trading.placeNewOffer(offer, callback);
|
||||
messageFacade.addOffer(offer);
|
||||
placeOfferButton.setDisable(true);
|
||||
} catch (InsufficientMoneyException e1)
|
||||
{
|
||||
Popups.openErrorPopup("Not enough money available", "There is not enough money available. Please pay in first to your wallet. " + e1.getMessage());
|
||||
} catch (IOException e1)
|
||||
{
|
||||
Popups.openErrorPopup("Could not publish offer", "Could not publish offer. " + e1.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -246,77 +249,7 @@ public class CreateOfferController implements Initializable, ChildController
|
||||
|
||||
txTextField.setText(newTransaction.getHashAsString());
|
||||
|
||||
updateConfidence(newTransaction);
|
||||
|
||||
walletFacade.getWallet().addEventListener(new WalletEventListener()
|
||||
{
|
||||
@Override
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
|
||||
{
|
||||
updateConfidence(newTransaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReorganize(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalletChanged(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(Wallet wallet, List<ECKey> keys)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScriptsAdded(Wallet wallet, List<Script> scripts)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateConfidence(Transaction tx)
|
||||
{
|
||||
TransactionConfidence confidence = tx.getConfidence();
|
||||
double progressIndicatorSize = 20;
|
||||
switch (confidence.getConfidenceType())
|
||||
{
|
||||
case UNKNOWN:
|
||||
confirmationLabel.setText("");
|
||||
progressIndicator.setProgress(0);
|
||||
progressIndicatorSize = 50;
|
||||
break;
|
||||
case PENDING:
|
||||
confirmationLabel.setText("Seen by " + confidence.numBroadcastPeers() + " peer(s) / 0 confirmations");
|
||||
progressIndicator.setProgress(-1.0);
|
||||
break;
|
||||
case BUILDING:
|
||||
confirmationLabel.setText("Confirmed in " + confidence.getDepthInBlocks() + " block(s)");
|
||||
progressIndicator.setProgress(Math.min(1, (double) confidence.getDepthInBlocks() / 6.0));
|
||||
progressIndicatorSize = 50;
|
||||
break;
|
||||
case DEAD:
|
||||
confirmationLabel.setText("Transaction is invalid.");
|
||||
break;
|
||||
}
|
||||
|
||||
progressIndicator.setMaxHeight(progressIndicatorSize);
|
||||
progressIndicator.setPrefHeight(progressIndicatorSize);
|
||||
progressIndicator.setMaxWidth(progressIndicatorSize);
|
||||
progressIndicator.setPrefWidth(progressIndicatorSize);
|
||||
confidenceDisplay = new ConfidenceDisplay(walletFacade.getWallet(), confirmationLabel, newTransaction, progressIndicator);
|
||||
}
|
||||
|
||||
private void updateVolume()
|
||||
|
@ -65,13 +65,13 @@
|
||||
<Label fx:id="txTitleLabel" text="Transaction ID:" visible="false" GridPane.rowIndex="12"/>
|
||||
<TextField fx:id="txTextField" visible="false" editable="false" GridPane.columnIndex="1" GridPane.rowIndex="12"/>
|
||||
<ProgressIndicator fx:id="progressIndicator" id="confidence-progress-indicator" visible="false" progress="0" GridPane.columnIndex="2" GridPane.halignment="LEFT"
|
||||
GridPane.rowIndex="12"
|
||||
GridPane.rowSpan="2" GridPane.valignment="TOP">
|
||||
GridPane.rowIndex="12" GridPane.rowSpan="2" GridPane.valignment="TOP">
|
||||
<GridPane.margin>
|
||||
<Insets top="2.0"/>
|
||||
</GridPane.margin>
|
||||
</ProgressIndicator>
|
||||
<Label fx:id="confirmationLabel" visible="false" text="Checking confirmations..." GridPane.columnIndex="3" GridPane.rowIndex="12"/>
|
||||
<Label fx:id="confirmationLabel" text="Checking confirmations..." visible="false" GridPane.columnIndex="3" GridPane.rowIndex="12"/>
|
||||
|
||||
|
||||
<Button fx:id="closeButton" visible="false" defaultButton="true" onAction="#onClose" text="Close" GridPane.columnIndex="1" GridPane.rowIndex="13"/>
|
||||
|
||||
|
@ -11,6 +11,7 @@ import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.gui.ChildController;
|
||||
import io.bitsquare.gui.NavigationController;
|
||||
import io.bitsquare.gui.components.NetworkSyncPane;
|
||||
import io.bitsquare.gui.util.ConfidenceDisplay;
|
||||
import io.bitsquare.gui.util.Localisation;
|
||||
import io.bitsquare.gui.util.Popups;
|
||||
import io.bitsquare.gui.util.Verification;
|
||||
@ -33,7 +34,10 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.Currency;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class SetupController implements Initializable, ChildController
|
||||
{
|
||||
@ -44,6 +48,7 @@ public class SetupController implements Initializable, ChildController
|
||||
private NavigationController navigationController;
|
||||
private MessageFacade messageFacade;
|
||||
private final Storage storage;
|
||||
private ConfidenceDisplay confidenceDisplay;
|
||||
|
||||
@FXML
|
||||
private AnchorPane rootContainer;
|
||||
@ -54,7 +59,7 @@ public class SetupController implements Initializable, ChildController
|
||||
@FXML
|
||||
private TextField registrationAddressTextField, balanceTextField, accountTitle, accountHolderName, accountPrimaryID, accountSecondaryID;
|
||||
@FXML
|
||||
private Button createAccountButton, addBankAccountButton;
|
||||
private Button createAccountButton, addBankAccountButton, paymentDoneButton;
|
||||
@FXML
|
||||
private Accordion accordion;
|
||||
@FXML
|
||||
@ -209,20 +214,20 @@ public class SetupController implements Initializable, ChildController
|
||||
clipboard.setContent(content);
|
||||
});
|
||||
|
||||
updateBalance(walletFacade.getAccountRegistrationBalance());
|
||||
confidenceDisplay = new ConfidenceDisplay(walletFacade.getAccountRegistrationWallet(), confirmationLabel, balanceTextField, progressIndicator);
|
||||
paymentDoneButton.setDisable(walletFacade.getAccountRegistrationBalance().compareTo(BigInteger.ZERO) == 0);
|
||||
|
||||
walletFacade.getAccountRegistrationWallet().addEventListener(new WalletEventListener()
|
||||
{
|
||||
@Override
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
updateBalance(newBalance);
|
||||
paymentDoneButton.setDisable(newBalance.compareTo(BigInteger.ZERO) == 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
|
||||
{
|
||||
updateConfidence(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -350,60 +355,6 @@ public class SetupController implements Initializable, ChildController
|
||||
// Private methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
private void updateBalance(BigInteger balance)
|
||||
{
|
||||
if (balance.compareTo(BigInteger.ZERO) == 0)
|
||||
{
|
||||
confirmationLabel.setText("");
|
||||
progressIndicator.setOpacity(0);
|
||||
progressIndicator.setProgress(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
progressIndicator.setOpacity(1);
|
||||
progressIndicator.setProgress(-1);
|
||||
Set<Transaction> transactions = walletFacade.getAccountRegistrationWallet().getTransactions(false);
|
||||
for (Iterator<Transaction> iterator = transactions.iterator(); iterator.hasNext(); )
|
||||
{
|
||||
Transaction transaction = iterator.next();
|
||||
updateConfidence(transaction);
|
||||
break;
|
||||
}
|
||||
}
|
||||
balanceTextField.setText(Utils.bitcoinValueToFriendlyString(balance));
|
||||
}
|
||||
|
||||
private void updateConfidence(Transaction tx)
|
||||
{
|
||||
TransactionConfidence confidence = tx.getConfidence();
|
||||
double progressIndicatorSize = 50;
|
||||
switch (confidence.getConfidenceType())
|
||||
{
|
||||
case UNKNOWN:
|
||||
confirmationLabel.setText("");
|
||||
progressIndicator.setProgress(0);
|
||||
break;
|
||||
case PENDING:
|
||||
confirmationLabel.setText("Seen by " + confidence.numBroadcastPeers() + " peer(s) / 0 confirmations");
|
||||
progressIndicator.setProgress(-1.0);
|
||||
progressIndicatorSize = 20;
|
||||
break;
|
||||
case BUILDING:
|
||||
confirmationLabel.setText("Confirmed in " + confidence.getDepthInBlocks() + " block(s)");
|
||||
progressIndicator.setProgress(Math.min(1, (double) confidence.getDepthInBlocks() / 6.0));
|
||||
break;
|
||||
case DEAD:
|
||||
confirmationLabel.setText("Transaction is invalid.");
|
||||
break;
|
||||
}
|
||||
|
||||
progressIndicator.setMaxHeight(progressIndicatorSize);
|
||||
progressIndicator.setPrefHeight(progressIndicatorSize);
|
||||
progressIndicator.setMaxWidth(progressIndicatorSize);
|
||||
progressIndicator.setPrefWidth(progressIndicatorSize);
|
||||
}
|
||||
|
||||
private void addBankAccount()
|
||||
{
|
||||
if (verifyBankAccountData())
|
||||
|
@ -25,7 +25,7 @@
|
||||
<children>
|
||||
<Label text="Registration address:"/>
|
||||
<TextField fx:id="registrationAddressTextField" editable="false" GridPane.columnIndex="1"/>
|
||||
<Label fx:id="copyIcon" minWidth="10" GridPane.columnIndex="2">
|
||||
<Label fx:id="copyIcon" GridPane.columnIndex="2">
|
||||
<padding>
|
||||
<Insets bottom="0.0" left="0.0" right="0.0" top="-1.0"/>
|
||||
</padding>
|
||||
@ -44,7 +44,8 @@
|
||||
</ProgressIndicator>
|
||||
<Label fx:id="confirmationLabel" text="Checking confirmations..." GridPane.columnIndex="3" GridPane.rowIndex="1"/>
|
||||
|
||||
<Button defaultButton="true" onAction="#onPaymentDone" text="Payment done" GridPane.columnIndex="1" GridPane.rowIndex="2"/>
|
||||
<Button fx:id="paymentDoneButton" defaultButton="true" onAction="#onPaymentDone" text="Payment done" disable="true" GridPane.columnIndex="1"
|
||||
GridPane.rowIndex="2"/>
|
||||
<Button onAction="#onSkipPayment" text="Skip and pay later" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
|
||||
|
||||
</children>
|
||||
@ -52,7 +53,7 @@
|
||||
<columnConstraints>
|
||||
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES"/>
|
||||
<ColumnConstraints hgrow="ALWAYS"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES" prefWidth="20.0"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES" prefWidth="20.0" minWidth="20"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES"/>
|
||||
</columnConstraints>
|
||||
|
214
src/main/java/io/bitsquare/gui/util/ConfidenceDisplay.java
Normal file
214
src/main/java/io/bitsquare/gui/util/ConfidenceDisplay.java
Normal file
@ -0,0 +1,214 @@
|
||||
package io.bitsquare.gui.util;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.script.Script;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ProgressIndicator;
|
||||
import javafx.scene.control.TextField;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ConfidenceDisplay
|
||||
{
|
||||
private static final Logger log = LoggerFactory.getLogger(ConfidenceDisplay.class);
|
||||
|
||||
private Wallet wallet;
|
||||
private Label confirmationLabel;
|
||||
private TextField balanceTextField;
|
||||
private ProgressIndicator progressIndicator;
|
||||
|
||||
/**
|
||||
* We got the confidence for the actual updating tx.
|
||||
*
|
||||
* @param wallet
|
||||
* @param confirmationLabel
|
||||
* @param balanceTextField
|
||||
* @param progressIndicator
|
||||
*/
|
||||
public ConfidenceDisplay(Wallet wallet, Label confirmationLabel, TextField balanceTextField, ProgressIndicator progressIndicator)
|
||||
{
|
||||
this.wallet = wallet;
|
||||
this.confirmationLabel = confirmationLabel;
|
||||
this.balanceTextField = balanceTextField;
|
||||
this.progressIndicator = progressIndicator;
|
||||
|
||||
balanceTextField.setText("");
|
||||
confirmationLabel.setVisible(false);
|
||||
progressIndicator.setVisible(false);
|
||||
progressIndicator.setProgress(0);
|
||||
|
||||
updateBalance(wallet.getBalance());
|
||||
|
||||
wallet.addEventListener(new WalletEventListener()
|
||||
{
|
||||
@Override
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
updateBalance(newBalance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
|
||||
{
|
||||
updateConfidence(tx);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReorganize(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalletChanged(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(Wallet wallet, List<ECKey> keys)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScriptsAdded(Wallet wallet, List<Script> scripts)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param wallet
|
||||
* @param confirmationLabel
|
||||
* @param newTransaction We want the confidence for only that tx, not the lasted changed in the wallet
|
||||
* @param progressIndicator
|
||||
*/
|
||||
public ConfidenceDisplay(Wallet wallet, Label confirmationLabel, final Transaction newTransaction, ProgressIndicator progressIndicator)
|
||||
{
|
||||
this.wallet = wallet;
|
||||
this.confirmationLabel = confirmationLabel;
|
||||
this.progressIndicator = progressIndicator;
|
||||
|
||||
if (balanceTextField != null)
|
||||
balanceTextField.setText("");
|
||||
confirmationLabel.setVisible(false);
|
||||
progressIndicator.setVisible(false);
|
||||
progressIndicator.setProgress(0);
|
||||
|
||||
updateBalance(wallet.getBalance());
|
||||
|
||||
wallet.addEventListener(new WalletEventListener()
|
||||
{
|
||||
@Override
|
||||
public void onCoinsReceived(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
updateBalance(newBalance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransactionConfidenceChanged(Wallet wallet, Transaction tx)
|
||||
{
|
||||
updateConfidence(newTransaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCoinsSent(Wallet wallet, Transaction tx, BigInteger prevBalance, BigInteger newBalance)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReorganize(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalletChanged(Wallet wallet)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeysAdded(Wallet wallet, List<ECKey> keys)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScriptsAdded(Wallet wallet, List<Script> scripts)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateBalance(BigInteger balance)
|
||||
{
|
||||
if (balance.compareTo(BigInteger.ZERO) > 0)
|
||||
{
|
||||
confirmationLabel.setVisible(true);
|
||||
progressIndicator.setVisible(true);
|
||||
progressIndicator.setProgress(-1);
|
||||
|
||||
Set<Transaction> transactions = wallet.getTransactions(false);
|
||||
Transaction latestTransaction = null;
|
||||
for (Iterator<Transaction> iterator = transactions.iterator(); iterator.hasNext(); )
|
||||
{
|
||||
Transaction transaction = iterator.next();
|
||||
if (latestTransaction != null)
|
||||
{
|
||||
if (transaction.getUpdateTime().compareTo(latestTransaction.getUpdateTime()) > 0)
|
||||
{
|
||||
latestTransaction = transaction;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
latestTransaction = transaction;
|
||||
}
|
||||
}
|
||||
if (latestTransaction != null)
|
||||
{
|
||||
updateConfidence(latestTransaction);
|
||||
}
|
||||
}
|
||||
if (balanceTextField != null)
|
||||
balanceTextField.setText(Utils.bitcoinValueToFriendlyString(balance));
|
||||
}
|
||||
|
||||
private void updateConfidence(Transaction tx)
|
||||
{
|
||||
TransactionConfidence confidence = tx.getConfidence();
|
||||
double progressIndicatorSize = 50;
|
||||
switch (confidence.getConfidenceType())
|
||||
{
|
||||
case UNKNOWN:
|
||||
confirmationLabel.setText("");
|
||||
progressIndicator.setProgress(0);
|
||||
break;
|
||||
case PENDING:
|
||||
confirmationLabel.setText("Seen by " + confidence.numBroadcastPeers() + " peer(s) / 0 confirmations");
|
||||
progressIndicator.setProgress(-1.0);
|
||||
progressIndicatorSize = 20;
|
||||
break;
|
||||
case BUILDING:
|
||||
confirmationLabel.setText("Confirmed in " + confidence.getDepthInBlocks() + " block(s)");
|
||||
progressIndicator.setProgress(Math.min(1, (double) confidence.getDepthInBlocks() / 6.0));
|
||||
break;
|
||||
case DEAD:
|
||||
confirmationLabel.setText("Transaction is invalid.");
|
||||
break;
|
||||
}
|
||||
|
||||
progressIndicator.setMaxHeight(progressIndicatorSize);
|
||||
progressIndicator.setPrefHeight(progressIndicatorSize);
|
||||
progressIndicator.setMaxWidth(progressIndicatorSize);
|
||||
progressIndicator.setPrefWidth(progressIndicatorSize);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user