Skip to content

Commit

Permalink
Improve UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ManfredKarrer committed Oct 20, 2018
1 parent b47678d commit 4fd641f
Show file tree
Hide file tree
Showing 36 changed files with 500 additions and 314 deletions.
1 change: 1 addition & 0 deletions common/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ message PersistableEnvelope {
UserPayload user_payload = 10;
PaymentAccountList payment_account_list = 11;

// deprecated
// BsqState bsq_state = 12; // not used but as other non-dao data have a higher index number we leave it to make clear that we cannot change following indexes

AccountAgeWitnessStore account_age_witness_store = 13;
Expand Down
110 changes: 96 additions & 14 deletions core/src/main/java/bisq/core/dao/DaoFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import bisq.core.dao.state.blockchain.TxOutput;
import bisq.core.dao.state.blockchain.TxOutputKey;
import bisq.core.dao.state.blockchain.TxType;
import bisq.core.dao.state.governance.Issuance;
import bisq.core.dao.state.governance.Param;
import bisq.core.dao.state.period.DaoPhase;
import bisq.core.dao.state.period.PeriodService;
Expand All @@ -80,6 +81,8 @@
import java.util.Optional;
import java.util.Set;

import lombok.extern.slf4j.Slf4j;

import javax.annotation.Nullable;


Expand All @@ -90,6 +93,7 @@
* Provides a facade to interact with the Dao domain. Hides complexity and domain details to clients (e.g. UI or APIs)
* by providing a reduced API and/or aggregating subroutines.
*/
@Slf4j
public class DaoFacade implements DaoSetupService {
private final ProposalListPresentation proposalListPresentation;
private final BallotListService ballotListService;
Expand Down Expand Up @@ -212,13 +216,11 @@ public ObservableList<Proposal> getActiveOrMyUnconfirmedProposals() {
// Creation of Proposal and proposalTransaction
public ProposalWithTransaction getCompensationProposalWithTransaction(String name,
String link,
Coin requestedBsq,
String bsqAddress)
Coin requestedBsq)
throws ValidationException, InsufficientMoneyException, TxException {
return compensationProposalService.createProposalWithTransaction(name,
link,
requestedBsq,
bsqAddress);
requestedBsq);
}

public ProposalWithTransaction getParamProposalWithTransaction(String name,
Expand Down Expand Up @@ -358,16 +360,92 @@ public void publishBlindVote(Coin stake, ResultHandler resultHandler, ExceptionH
// Use case: Presentation of phases
///////////////////////////////////////////////////////////////////////////////////////////

public int getFirstBlockOfPhase(int height, DaoPhase.Phase phase) {
return periodService.getFirstBlockOfPhase(height, phase);
}

public int getLastBlockOfPhase(int height, DaoPhase.Phase phase) {
return periodService.getLastBlockOfPhase(height, phase);
}

public int getDurationForPhase(DaoPhase.Phase phase) {
return periodService.getDurationForPhase(phase, daoStateService.getChainHeight());
// Because last block in request and voting phases must not be used fo making a tx as it will get confirmed in the
// next block which would be already the next phase we hide that last block to the user and add it to the break.
public int getFirstBlockOfPhaseForDisplay(int height, DaoPhase.Phase phase) {
int firstBlock = periodService.getFirstBlockOfPhase(height, phase);
switch (phase) {
case UNDEFINED:
break;
case PROPOSAL:
break;
case BREAK1:
firstBlock++;
break;
case BLIND_VOTE:
break;
case BREAK2:
firstBlock++;
break;
case VOTE_REVEAL:
break;
case BREAK3:
firstBlock++;
break;
case RESULT:
break;
}

return firstBlock;
}

// Because last block in request and voting phases must not be used fo making a tx as it will get confirmed in the
// next block which would be already the next phase we hide that last block to the user and add it to the break.
public int getLastBlockOfPhaseForDisplay(int height, DaoPhase.Phase phase) {
int lastBlock = periodService.getLastBlockOfPhase(height, phase);
switch (phase) {
case UNDEFINED:
break;
case PROPOSAL:
lastBlock--;
break;
case BREAK1:
break;
case BLIND_VOTE:
lastBlock--;
break;
case BREAK2:
break;
case VOTE_REVEAL:
lastBlock--;
break;
case BREAK3:
break;
case RESULT:
break;
}
return lastBlock;
}

// Because last block in request and voting phases must not be used fo making a tx as it will get confirmed in the
// next block which would be already the next phase we hide that last block to the user and add it to the break.
public int getDurationForPhaseForDisplay(DaoPhase.Phase phase) {
int duration = periodService.getDurationForPhase(phase, daoStateService.getChainHeight());
switch (phase) {
case UNDEFINED:
break;
case PROPOSAL:
duration--;
break;
case BREAK1:
duration++;
break;
case BLIND_VOTE:
duration--;
break;
case BREAK2:
duration++;
break;
case VOTE_REVEAL:
duration--;
break;
case BREAK3:
duration++;
break;
case RESULT:
break;
}
return duration;
}

// listeners for phase change
Expand Down Expand Up @@ -439,6 +517,10 @@ public Coin getGenesisTotalSupply() {
return daoStateService.getGenesisTotalSupply();
}

public Set<Issuance> getIssuanceSet() {
return daoStateService.getIssuanceSet();
}

public Set<Tx> getFeeTxs() {
return daoStateService.getBurntFeeTxs();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,8 @@ private void persist() {
}

private boolean canRemoveProposal(Proposal proposal, DaoStateService daoStateService, PeriodService periodService) {
return daoStateService.getTx(proposal.getTxId())
.filter(tx -> isTxInProposalPhaseAndCycle(tx, periodService, daoStateService))
.isPresent();
boolean inPhase = periodService.isInPhase(daoStateService.getChainHeight(), DaoPhase.Phase.PROPOSAL);
return isMine(proposal) && inPhase;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ public CompensationProposalService(BsqWalletService bsqWalletService,

public ProposalWithTransaction createProposalWithTransaction(String name,
String link,
Coin requestedBsq,
String bsqAddress)
Coin requestedBsq)
throws ValidationException, InsufficientMoneyException, TxException {
this.requestedBsq = requestedBsq;
this.bsqAddress = bsqAddress;
this.bsqAddress = "B" + bsqWalletService.getUnusedAddress().toBase58();

return super.createProposalWithTransaction(name, link);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,18 @@ public void validateParamValue(Param param, long paramValue) throws ChangeParamV
break;
case DEFAULT_TAKER_FEE_BSQ:
break;
case MIN_MAKER_FEE_BSQ:
break;
case MIN_TAKER_FEE_BSQ:
break;
case DEFAULT_MAKER_FEE_BTC:
break;
case DEFAULT_TAKER_FEE_BTC:
break;
case MIN_MAKER_FEE_BTC:
break;
case MIN_TAKER_FEE_BTC:
break;

case PROPOSAL_FEE:
break;
Expand Down
25 changes: 15 additions & 10 deletions core/src/main/java/bisq/core/dao/state/governance/Param.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,21 @@ public enum Param {
PHASE_RESULT(2);

// See: https://github.com/bisq-network/proposals/issues/46
/*
PHASE_UNDEFINED(0),
PHASE_PROPOSAL(3600), // 24 days
PHASE_BREAK1(150), // 1 day
PHASE_BLIND_VOTE(600), // 4 days
PHASE_BREAK2(10), // 10 blocks
PHASE_VOTE_REVEAL(300), // 2 days
PHASE_BREAK3(10), // 10 blocks
PHASE_RESULT(10); // 10 block
*/
// The last block in the proposal and vote phases are not shown to the user as he cannot make a tx there as it would be
// confirmed in the next block which would be the following break phase. To hide that complexity we show only the
// blocks where the user can be active. To have still round numbers for the durations we add 1 block to those
// phases and subtract 1 block from the following breaks.
// So in the UI the user will see 3600 blocks and the last
// block of the technical 3601 blocks is displayed as part of the break1 phase.
/* PHASE_UNDEFINED(0),
PHASE_PROPOSAL(3601), // 24 days
PHASE_BREAK1(149), // 1 day
PHASE_BLIND_VOTE(601), // 4 days
PHASE_BREAK2(9), // 10 blocks
PHASE_VOTE_REVEAL(301), // 2 days
PHASE_BREAK3(9), // 10 blocks
PHASE_RESULT(10); // 10 block*/


@Getter
private long defaultValue;
Expand Down
42 changes: 37 additions & 5 deletions core/src/main/java/bisq/core/util/BSFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,15 @@ public String formatCoin(Coin coin, int decimalPlaces) {
return formatCoin(coin, decimalPlaces, false, 0);
}

public String formatCoin(long value, MonetaryFormat coinFormat) {
return formatCoin(Coin.valueOf(value), -1, false, 0, coinFormat);
}

public String formatCoin(Coin coin, int decimalPlaces, boolean decimalAligned, int maxNumberOfDigits) {
return formatCoin(coin, decimalPlaces, decimalAligned, maxNumberOfDigits, coinFormat);
}

public String formatCoin(Coin coin, int decimalPlaces, boolean decimalAligned, int maxNumberOfDigits, MonetaryFormat coinFormat) {
String formattedCoin = "";

if (coin != null) {
Expand All @@ -122,6 +129,14 @@ public String formatCoin(Coin coin, int decimalPlaces, boolean decimalAligned, i
}

public String formatCoinWithCode(Coin coin) {
return formatCoinWithCode(coin, coinFormat);
}

public String formatCoinWithCode(long value, MonetaryFormat coinFormat) {
return formatCoinWithCode(Coin.valueOf(value), coinFormat);
}

public String formatCoinWithCode(Coin coin, MonetaryFormat coinFormat) {
if (coin != null) {
try {
// we don't use the code feature from coinFormat as it does automatic switching between mBTC and BTC and
Expand All @@ -137,6 +152,10 @@ public String formatCoinWithCode(Coin coin) {
}

public Coin parseToCoin(String input) {
return parseToCoin(input, coinFormat);
}

public Coin parseToCoin(String input, MonetaryFormat coinFormat) {
if (input != null && input.length() > 0) {
try {
return coinFormat.parse(cleanDoubleInput(input));
Expand Down Expand Up @@ -458,9 +477,13 @@ public String languageCodesToString(List<String> languageLocales) {
}

public String formatDateTime(Date date) {
return formatDateTime(date,
DateFormat.getDateInstance(DateFormat.DEFAULT, getLocale()),
DateFormat.getTimeInstance(DateFormat.DEFAULT, getLocale()));
}

public String formatDateTime(Date date, DateFormat dateFormatter, DateFormat timeFormatter) {
if (date != null) {
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, getLocale());
DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.DEFAULT, getLocale());
return dateFormatter.format(date) + " " + timeFormatter.format(date);
} else {
return "";
Expand Down Expand Up @@ -564,10 +587,10 @@ public String formatAccountAge(long durationMillis) {
}

public String formatDurationAsWords(long durationMillis) {
return formatDurationAsWords(durationMillis, false);
return formatDurationAsWords(durationMillis, false, true);
}

public static String formatDurationAsWords(long durationMillis, boolean showSeconds) {
public String formatDurationAsWords(long durationMillis, boolean showSeconds, boolean showZeroValues) {
String format = "";
String second = Res.get("time.second");
String minute = Res.get("time.minute");
Expand All @@ -593,10 +616,19 @@ public static String formatDurationAsWords(long durationMillis, boolean showSeco
duration = StringUtils.replacePattern(duration, "^1 " + minutes + "|\\b1 " + minutes, "1 " + minute);
duration = StringUtils.replacePattern(duration, "^1 " + hours + "|\\b1 " + hours, "1 " + hour);
duration = StringUtils.replacePattern(duration, "^1 " + days + "|\\b1 " + days, "1 " + day);

if (!showZeroValues) {
duration = duration.replace(", 0 seconds", "");
duration = duration.replace(", 0 minutes", "");
duration = duration.replace(", 0 hours", "");
duration = duration.replace("0 days", "");
duration = duration.replace("0 hours, ", "");
duration = duration.replace("0 minutes, ", "");
duration = duration.replace("0 seconds", "");
}
return duration.trim();
}


public String booleanToYesNo(boolean value) {
return value ? Res.get("shared.yes") : Res.get("shared.no");
}
Expand Down
21 changes: 11 additions & 10 deletions core/src/main/java/bisq/core/util/BsqFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ public class BsqFormatter extends BSFormatter {
private final String prefix = "B";
private final DecimalFormat amountFormat = new DecimalFormat("###,###,###.##");
private final DecimalFormat marketCapFormat = new DecimalFormat("###,###,###");
private final MonetaryFormat btcCoinFormat;

@Inject
private BsqFormatter() {
super();

btcCoinFormat = super.coinFormat;

final String baseCurrencyCode = BisqEnvironment.getBaseCurrencyNetwork().getCurrencyCode();
switch (baseCurrencyCode) {
case "BTC":
Expand Down Expand Up @@ -104,29 +107,27 @@ public String formatMarketCap(MarketPrice bsqPriceMarketPrice, MarketPrice fiatM
}
}


public String formatBtcSatoshi(long satoshi) {
return satoshi + " BTC Satoshi";
public String formatBTCWithCode(long satoshi) {
return super.formatCoinWithCode(satoshi, btcCoinFormat);
}

public Coin parseSatoshiToBtc(String satoshi) {
try {
return Coin.valueOf(Long.valueOf(satoshi));
} catch (Throwable e) {
return Coin.ZERO;
}
public Coin parseToBTC(String input) {
return super.parseToCoin(input, btcCoinFormat);
}


public String formatParamValue(Param param, long value) {
switch (param) {
case UNDEFINED:
return Res.get("shared.na");

case DEFAULT_MAKER_FEE_BSQ:
case DEFAULT_TAKER_FEE_BSQ:
case MIN_MAKER_FEE_BSQ:
case MIN_TAKER_FEE_BSQ:
case DEFAULT_MAKER_FEE_BTC:
case DEFAULT_TAKER_FEE_BTC:
case MIN_MAKER_FEE_BTC:
case MIN_TAKER_FEE_BTC:
return formatToPercentWithSymbol(value / 10000d);

case PROPOSAL_FEE:
Expand Down
Loading

0 comments on commit 4fd641f

Please sign in to comment.