Fix tradestate problem

This commit is contained in:
Manfred Karrer 2014-11-19 20:36:03 +01:00
parent c9bed48a53
commit c57aba7992
3 changed files with 12 additions and 18 deletions

View File

@ -157,7 +157,6 @@ class ProcessStepBarSkin<T> extends BehaviorSkinBase<ProcessStepBar<T>, Behavior
}
public void open() {
log.debug("select " + processStepItem.getLabel());
BorderStroke borderStroke = new BorderStroke(Colors.LIGHT_GREY, BorderStrokeStyle.SOLID, null,
new BorderWidths(borderWidth, borderWidth, borderWidth, borderWidth), Insets.EMPTY);
this.setBorder(new Border(borderStroke));
@ -165,7 +164,6 @@ class ProcessStepBarSkin<T> extends BehaviorSkinBase<ProcessStepBar<T>, Behavior
}
public void current() {
log.debug("select " + processStepItem.getLabel());
BorderStroke borderStroke = new BorderStroke(Colors.GREEN, BorderStrokeStyle.SOLID, null,
new BorderWidths(borderWidth, borderWidth, borderWidth, borderWidth), Insets.EMPTY);
this.setBorder(new Border(borderStroke));
@ -173,7 +171,6 @@ class ProcessStepBarSkin<T> extends BehaviorSkinBase<ProcessStepBar<T>, Behavior
}
public void past() {
log.debug("deSelect " + processStepItem.getLabel());
BorderStroke borderStroke = new BorderStroke(Color.valueOf("#444444"), BorderStrokeStyle.SOLID, null,
new BorderWidths(borderWidth, borderWidth, borderWidth, borderWidth), Insets.EMPTY);
this.setBorder(new Border(borderStroke));

View File

@ -157,6 +157,8 @@ class PendingTradesModel extends UIModel {
isOfferer = getTrade().getOffer().getMessagePublicKey().equals(user.getMessagePublicKey());
Trade trade = getTrade();
trade.stateProperty().addListener(stateChangeListener);
tradeState.set(trade.stateProperty().get());
if (trade.getDepositTx() != null)
txId.set(trade.getDepositTx().getHashAsString());
@ -169,16 +171,6 @@ class PendingTradesModel extends UIModel {
walletService.addTxConfidenceListener(txConfidenceListener);
updateConfidence(walletService.getConfidenceForTxId(txId.get()));
trade.stateProperty().addListener(stateChangeListener);
// It might be that we receive first the DEPOSIT_CONFIRMED (coming form bitcoin network)
// and then the OFFERER_ACCEPTED (coming from tomP2P network.
// So we don't allow to overwrite the already set DEPOSIT_CONFIRMED as that will only be possible if
// the offer has already accepted
// TODO: The Trade.State handling should be refactored to remove that unclear situation
if (tradeState.get() != Trade.State.DEPOSIT_CONFIRMED)
tradeState.set(trade.stateProperty().get());
trade.faultProperty().addListener(faultChangeListener);
fault.set(trade.faultProperty().get());
}
@ -312,9 +304,11 @@ class PendingTradesModel extends UIModel {
///////////////////////////////////////////////////////////////////////////////////////////
private void updateConfidence(TransactionConfidence confidence) {
log.debug("confidence " + confidence);
if (confidence != null &&
confidence.getConfidenceType() == TransactionConfidence.ConfidenceType.BUILDING
&& getTrade().getState() == Trade.State.DEPOSIT_PUBLISHED) {
&& (getTrade().getState() == Trade.State.DEPOSIT_PUBLISHED ||
getTrade().getState() == Trade.State.OFFERER_ACCEPTED)) {
// only set it once when actual state is DEPOSIT_PUBLISHED, and remove listener afterwards
getTrade().setState(Trade.State.DEPOSIT_CONFIRMED);
walletService.removeTxConfidenceListener(txConfidenceListener);

View File

@ -22,6 +22,7 @@ import io.bitsquare.gui.PresentationModel;
import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.gui.util.validation.BtcAddressValidator;
import io.bitsquare.locale.BSResources;
import io.bitsquare.trade.Trade;
import org.bitcoinj.core.Coin;
import org.bitcoinj.utils.Fiat;
@ -240,14 +241,16 @@ public class PendingTradesPM extends PresentationModel<PendingTradesModel> {
return btcAddressValidator;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private
///////////////////////////////////////////////////////////////////////////////////////////
private void updateState() {
if (model.tradeState.get() != null) {
log.debug("tradeState " + model.tradeState.get());
switch (model.tradeState.get()) {
Trade.State tradeState = model.tradeState.get();
log.trace("tradeState " + tradeState);
if (tradeState != null) {
switch (tradeState) {
case DEPOSIT_PUBLISHED:
state.set(model.isOfferer() ? State.OFFERER_BUYER_WAIT_TX_CONF : State.TAKER_SELLER_WAIT_TX_CONF);
break;
@ -266,7 +269,7 @@ public class PendingTradesPM extends PresentationModel<PendingTradesModel> {
// TODO error states not implemented yet
break;
default:
log.warn("unhandled state " + model.tradeState.get());
log.warn("unhandled state " + tradeState);
break;
}
}