mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-24 06:44:19 -04:00
fixed confirmation display
This commit is contained in:
parent
c2db60be67
commit
9af3f6aeba
7 changed files with 252 additions and 266 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue