Remove confirmation spinner where confirmation is not needed #290

This commit is contained in:
Manfred Karrer 2014-11-27 00:35:58 +01:00
parent 87d81f02bf
commit c4295bc55e
2 changed files with 137 additions and 56 deletions

View file

@ -18,14 +18,11 @@
package io.bitsquare.gui.components;
import io.bitsquare.btc.WalletService;
import io.bitsquare.btc.listeners.AddressConfidenceListener;
import io.bitsquare.btc.listeners.BalanceListener;
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
import io.bitsquare.gui.util.BSFormatter;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.TransactionConfidence;
import javafx.scene.control.*;
import javafx.scene.effect.*;
@ -35,8 +32,6 @@ import javafx.scene.paint.*;
public class BalanceTextField extends AnchorPane {
private final TextField textField;
private final Tooltip progressIndicatorTooltip;
private final ConfidenceProgressIndicator progressIndicator;
private final Effect fundedEffect = new DropShadow(BlurType.THREE_PASS_BOX, Color.GREEN, 4, 0.0, 0, 0);
private final Effect notFundedEffect = new DropShadow(BlurType.THREE_PASS_BOX, Color.ORANGERED, 4, 0.0, 0, 0);
@ -52,33 +47,14 @@ public class BalanceTextField extends AnchorPane {
textField.setFocusTraversable(false);
textField.setEditable(false);
progressIndicator = new ConfidenceProgressIndicator();
progressIndicator.setFocusTraversable(false);
progressIndicator.setPrefSize(24, 24);
progressIndicator.setId("funds-confidence");
progressIndicator.setLayoutY(1);
progressIndicator.setProgress(0);
progressIndicator.setVisible(false);
progressIndicatorTooltip = new Tooltip("-");
Tooltip.install(progressIndicator, progressIndicatorTooltip);
AnchorPane.setRightAnchor(progressIndicator, 0.0);
AnchorPane.setRightAnchor(textField, 55.0);
AnchorPane.setRightAnchor(textField, 0.0);
AnchorPane.setLeftAnchor(textField, 0.0);
getChildren().addAll(textField, progressIndicator);
getChildren().addAll(textField);
}
public void setup(WalletService walletService, Address address, BSFormatter formatter) {
this.formatter = formatter;
walletService.addAddressConfidenceListener(new AddressConfidenceListener(address) {
@Override
public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
updateConfidence(confidence);
}
});
updateConfidence(walletService.getConfidenceForAddress(address));
walletService.addBalanceListener(new BalanceListener(address) {
@Override
@ -94,36 +70,6 @@ public class BalanceTextField extends AnchorPane {
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
private void updateConfidence(TransactionConfidence confidence) {
if (confidence != null) {
switch (confidence.getConfidenceType()) {
case UNKNOWN:
progressIndicatorTooltip.setText("Unknown transaction status");
progressIndicator.setProgress(0);
break;
case PENDING:
progressIndicatorTooltip.setText(
"Seen by " + confidence.numBroadcastPeers() + " peer(s) / 0 " + "confirmations");
progressIndicator.setProgress(-1.0);
break;
case BUILDING:
progressIndicatorTooltip.setText("Confirmed in " + confidence.getDepthInBlocks() + " block(s)");
progressIndicator.setProgress(Math.min(1, (double) confidence.getDepthInBlocks() / 6.0));
break;
case DEAD:
progressIndicatorTooltip.setText("Transaction is invalid.");
progressIndicator.setProgress(0);
break;
}
if (progressIndicator.getProgress() != 0) {
progressIndicator.setVisible(true);
AnchorPane.setRightAnchor(progressIndicator, 0.0);
AnchorPane.setRightAnchor(textField, 35.0);
}
}
}
private void updateBalance(Coin balance) {
textField.setText(formatter.formatCoinWithCode(balance));
if (balance.isPositive())

View file

@ -0,0 +1,135 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare 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.
*
* Bitsquare 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 Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.gui.components;
import io.bitsquare.btc.WalletService;
import io.bitsquare.btc.listeners.AddressConfidenceListener;
import io.bitsquare.btc.listeners.BalanceListener;
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
import io.bitsquare.gui.util.BSFormatter;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.TransactionConfidence;
import javafx.scene.control.*;
import javafx.scene.effect.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
public class BalanceWithConfirmationTextField extends AnchorPane {
private final TextField textField;
private final Tooltip progressIndicatorTooltip;
private final ConfidenceProgressIndicator progressIndicator;
private final Effect fundedEffect = new DropShadow(BlurType.THREE_PASS_BOX, Color.GREEN, 4, 0.0, 0, 0);
private final Effect notFundedEffect = new DropShadow(BlurType.THREE_PASS_BOX, Color.ORANGERED, 4, 0.0, 0, 0);
private BSFormatter formatter;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
public BalanceWithConfirmationTextField() {
textField = new TextField();
textField.setFocusTraversable(false);
textField.setEditable(false);
progressIndicator = new ConfidenceProgressIndicator();
progressIndicator.setFocusTraversable(false);
progressIndicator.setPrefSize(24, 24);
progressIndicator.setId("funds-confidence");
progressIndicator.setLayoutY(1);
progressIndicator.setProgress(0);
progressIndicator.setVisible(false);
progressIndicatorTooltip = new Tooltip("-");
Tooltip.install(progressIndicator, progressIndicatorTooltip);
AnchorPane.setRightAnchor(progressIndicator, 0.0);
AnchorPane.setRightAnchor(textField, 55.0);
AnchorPane.setLeftAnchor(textField, 0.0);
getChildren().addAll(textField, progressIndicator);
}
public void setup(WalletService walletService, Address address, BSFormatter formatter) {
this.formatter = formatter;
walletService.addAddressConfidenceListener(new AddressConfidenceListener(address) {
@Override
public void onTransactionConfidenceChanged(TransactionConfidence confidence) {
updateConfidence(confidence);
}
});
updateConfidence(walletService.getConfidenceForAddress(address));
walletService.addBalanceListener(new BalanceListener(address) {
@Override
public void onBalanceChanged(Coin balance) {
updateBalance(balance);
}
});
updateBalance(walletService.getBalanceForAddress(address));
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
private void updateConfidence(TransactionConfidence confidence) {
if (confidence != null) {
switch (confidence.getConfidenceType()) {
case UNKNOWN:
progressIndicatorTooltip.setText("Unknown transaction status");
progressIndicator.setProgress(0);
break;
case PENDING:
progressIndicatorTooltip.setText(
"Seen by " + confidence.numBroadcastPeers() + " peer(s) / 0 " + "confirmations");
progressIndicator.setProgress(-1.0);
break;
case BUILDING:
progressIndicatorTooltip.setText("Confirmed in " + confidence.getDepthInBlocks() + " block(s)");
progressIndicator.setProgress(Math.min(1, (double) confidence.getDepthInBlocks() / 6.0));
break;
case DEAD:
progressIndicatorTooltip.setText("Transaction is invalid.");
progressIndicator.setProgress(0);
break;
}
if (progressIndicator.getProgress() != 0) {
progressIndicator.setVisible(true);
AnchorPane.setRightAnchor(progressIndicator, 0.0);
AnchorPane.setRightAnchor(textField, 35.0);
}
}
}
private void updateBalance(Coin balance) {
textField.setText(formatter.formatCoinWithCode(balance));
if (balance.isPositive())
textField.setEffect(fundedEffect);
else
textField.setEffect(notFundedEffect);
}
}