Skip to content

Commit

Permalink
Merge pull request #4731 from ghubstan/19-sqrrm-pr-changes
Browse files Browse the repository at this point in the history
Resolve issues found in reviewed PRs 4699, 4703, 4711 [, ...]
  • Loading branch information
sqrrm authored Nov 2, 2020
2 parents a308bef + fcdfc68 commit 84ac65b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 35 deletions.
4 changes: 2 additions & 2 deletions cli/src/main/java/bisq/cli/TableFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static String formatAddressBalanceTbl(List<AddressBalanceInfo> addressBalanceInf

static String formatOfferTable(List<OfferInfo> offerInfo, String fiatCurrency) {

// Some column values might be longer than header, so we need to calculated them.
// Some column values might be longer than header, so we need to calculate them.
int paymentMethodColWidth = getLengthOfLongestColumn(
COL_HEADER_PAYMENT_METHOD.length(),
offerInfo.stream()
Expand Down Expand Up @@ -100,7 +100,7 @@ static String formatOfferTable(List<OfferInfo> offerInfo, String fiatCurrency) {
}

static String formatPaymentAcctTbl(List<PaymentAccount> paymentAccounts) {
// Some column values might be longer than header, so we need to calculated them.
// Some column values might be longer than header, so we need to calculate them.
int nameColWidth = getLengthOfLongestColumn(
COL_HEADER_NAME.length(),
paymentAccounts.stream().map(PaymentAccount::getAccountName)
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/java/bisq/cli/TradeFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class TradeFormat {

@VisibleForTesting
public static String format(TradeInfo tradeInfo) {
// Some column values might be longer than header, so we need to calculated them.
// Some column values might be longer than header, so we need to calculate them.
int shortIdColWidth = Math.max(COL_HEADER_TRADE_SHORT_ID.length(), tradeInfo.getShortId().length());
int roleColWidth = Math.max(COL_HEADER_TRADE_ROLE.length(), tradeInfo.getRole().length());

Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/bisq/core/api/CoreTradesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.offer.Offer;
import bisq.core.offer.takeoffer.TakeOfferModel;
import bisq.core.trade.Tradable;
import bisq.core.trade.Trade;
import bisq.core.trade.TradeManager;
import bisq.core.trade.TradeUtil;
Expand Down Expand Up @@ -199,7 +200,8 @@ private Optional<Trade> getOpenTrade(String tradeId) {
}

private Optional<Trade> getClosedTrade(String tradeId) {
return closedTradableManager.getTradableById(tradeId).map(value -> (Trade) value);
Optional<Tradable> tradable = closedTradableManager.getTradableById(tradeId);
return tradable.filter((t) -> t instanceof Trade).map(value -> (Trade) value);
}

private boolean isFollowingBuyerProtocol(Trade trade) {
Expand Down
40 changes: 17 additions & 23 deletions core/src/main/java/bisq/core/api/CoreWalletsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import bisq.core.btc.wallet.BtcWalletService;
import bisq.core.btc.wallet.WalletsManager;

import bisq.common.Timer;
import bisq.common.UserThread;

import org.bitcoinj.core.Address;
import org.bitcoinj.core.TransactionConfidence;
import org.bitcoinj.crypto.KeyCrypterScrypt;
Expand All @@ -37,8 +40,6 @@

import java.util.List;
import java.util.Optional;
import java.util.Timer;
import java.util.TimerTask;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand All @@ -57,7 +58,7 @@ class CoreWalletsService {
private final BtcWalletService btcWalletService;

@Nullable
private TimerTask lockTask;
private Timer lockTimer;

@Nullable
private KeyParameter tempAesKey;
Expand Down Expand Up @@ -190,29 +191,22 @@ void unlockWallet(String password, long timeout) {
if (!walletsManager.checkAESKey(tempAesKey))
throw new IllegalStateException("incorrect password");

if (lockTask != null) {
// The user is overriding a prior unlock timeout. Cancel the existing
// lock TimerTask to prevent it from calling lockWallet() before or after the
// new timer task does.
lockTask.cancel();
// Avoid the synchronized(lock) overhead of an unnecessary lockTask.cancel()
// call the next time 'unlockwallet' is called.
lockTask = null;
if (lockTimer != null) {
// The user has called unlockwallet again, before the prior unlockwallet
// timeout has expired. He's overriding it with a new timeout value.
// Remove the existing lock timer to prevent it from calling lockwallet
// before or after the new one does.
lockTimer.stop();
lockTimer = null;
}

lockTask = new TimerTask() {
@Override
public void run() {
if (tempAesKey != null) {
// Do not try to lock wallet after timeout if the user has already
// done so via 'lockwallet'
log.info("Locking wallet after {} second timeout expired.", timeout);
tempAesKey = null;
}
lockTimer = UserThread.runAfter(() -> {
if (tempAesKey != null) {
// The unlockwallet timeout has expired; re-lock the wallet.
log.info("Locking wallet after {} second timeout expired.", timeout);
tempAesKey = null;
}
};
Timer timer = new Timer("Lock Wallet Timer");
timer.schedule(lockTask, SECONDS.toMillis(timeout));
}, timeout, SECONDS);
}

// Provided for automated wallet protection method testing, despite the
Expand Down
15 changes: 7 additions & 8 deletions core/src/main/java/bisq/core/trade/TradeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,13 @@ public String getMarketDescription(Trade trade) {
}

public String getPaymentMethodNameWithCountryCode(Trade trade) {
String paymentMethodDescription = "";
if (trade != null) {
Offer offer = trade.getOffer();
checkNotNull(offer);
checkNotNull(offer.getPaymentMethod());
paymentMethodDescription = offer.getPaymentMethodNameWithCountryCode();
}
return paymentMethodDescription;
if (trade == null)
return "";

Offer offer = trade.getOffer();
checkNotNull(offer);
checkNotNull(offer.getPaymentMethod());
return offer.getPaymentMethodNameWithCountryCode();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,22 @@ String getMarketLabel(PendingTradesListItem item) {
}

public String getRemainingTradeDurationAsWords() {
checkNotNull(dataModel.getTrade(), "model's trade must not be null");
return tradeUtil.getRemainingTradeDurationAsWords(dataModel.getTrade());
}

public double getRemainingTradeDurationAsPercentage() {
checkNotNull(dataModel.getTrade(), "model's trade must not be null");
return tradeUtil.getRemainingTradeDurationAsPercentage(dataModel.getTrade());
}

public String getDateForOpenDispute() {
checkNotNull(dataModel.getTrade(), "model's trade must not be null");
return DisplayUtils.formatDateTime(tradeUtil.getDateForOpenDispute(dataModel.getTrade()));
}

public boolean showWarning() {
checkNotNull(dataModel.getTrade(), "model's trade must not be null");
Date halfTradePeriodDate = tradeUtil.getHalfTradePeriodDate(dataModel.getTrade());
return halfTradePeriodDate != null && new Date().after(halfTradePeriodDate);
}
Expand Down

0 comments on commit 84ac65b

Please sign in to comment.