Skip to content

Commit

Permalink
Show restrictions based on payment method
Browse files Browse the repository at this point in the history
  • Loading branch information
ManfredKarrer committed Apr 30, 2019
1 parent c81142c commit 74344a8
Show file tree
Hide file tree
Showing 11 changed files with 152 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public AccountCreationAgeService(AccountAgeWitnessService accountAgeWitnessServi

public Coin getMyAccountMinDepositAsCoin(PaymentAccount myPaymentAccount) {
long myAccountAge = accountAgeWitnessService.getMyAccountAge(myPaymentAccount.getPaymentAccountPayload());
long phaseOnePeriod = getPhaseOnePeriod(myPaymentAccount.getPaymentMethod());
long phaseOnePeriod = getPhaseOnePeriodAsMilli();
// Restrictions.getMinBuyerSecurityDepositAsCoin() is 0.001 BTC / 5 USD
return Coin.valueOf(getMyAccountMinDepositAsCoin(myAccountAge, phaseOnePeriod, Restrictions.getMinBuyerSecurityDepositAsCoin().value));
}
Expand All @@ -84,7 +84,7 @@ public Coin getMinDepositAsCoin(Offer offer) {

long buyersAccountAge = accountAgeWitnessService.getMakersAccountAge(offer);

long phaseOnePeriod = getPhaseOnePeriod(offer.getPaymentMethod());
long phaseOnePeriod = getPhaseOnePeriodAsMilli();
// Restrictions.getMinBuyerSecurityDepositAsCoin() is 0.001 BTC / 5 USD
return Coin.valueOf(getMyAccountMinDepositAsCoin(buyersAccountAge, phaseOnePeriod, minBuyerSecurityDepositAsCoin.value));
}
Expand All @@ -106,7 +106,7 @@ public Coin getMinDepositAsCoin(Trade trade) {
}

long buyersAccountAge = accountAgeWitnessService.getAccountAge(contract.getBuyerPaymentAccountPayload(), contract.getBuyerPubKeyRing());
long phaseOnePeriod = getPhaseOnePeriod(offer.getPaymentMethod());
long phaseOnePeriod = getPhaseOnePeriodAsMilli();
// Restrictions.getMinBuyerSecurityDepositAsCoin() is 0.001 BTC / 5 USD
return Coin.valueOf(getMyAccountMinDepositAsCoin(buyersAccountAge, phaseOnePeriod, minBuyerSecurityDepositAsCoin.value));
}
Expand All @@ -129,7 +129,7 @@ public static long getMyAccountMinDepositAsCoin(long accountAge, long phaseOnePe

public double getMyAccountMinDepositAsPercent(PaymentAccount myPaymentAccount) {
long myAccountAge = accountAgeWitnessService.getMyAccountAge(myPaymentAccount.getPaymentAccountPayload());
long phaseOnePeriod = getPhaseOnePeriod(myPaymentAccount.getPaymentMethod());
long phaseOnePeriod = getPhaseOnePeriodAsMilli();
// Restrictions.getMinBuyerSecurityDepositAsPercent() is 5% of trade amount.
return getMyAccountMinDepositAsPercent(myAccountAge, phaseOnePeriod, Restrictions.getMinBuyerSecurityDepositAsPercent(myPaymentAccount));
}
Expand All @@ -146,7 +146,7 @@ public double getMinDepositAsPercent(Offer offer) {
}

long buyersAccountAge = accountAgeWitnessService.getMakersAccountAge(offer);
long phaseOnePeriod = getPhaseOnePeriod(offer.getPaymentMethod());
long phaseOnePeriod = getPhaseOnePeriodAsMilli();
return getMyAccountMinDepositAsPercent(buyersAccountAge, phaseOnePeriod, 0.1);
}

Expand All @@ -168,7 +168,7 @@ public double getMinDepositAsPercent(Trade trade) {
}

long buyersAccountAge = accountAgeWitnessService.getAccountAge(contract.getBuyerPaymentAccountPayload(), contract.getBuyerPubKeyRing());
long phaseOnePeriod = getPhaseOnePeriod(offer.getPaymentMethod());
long phaseOnePeriod = getPhaseOnePeriodAsMilli();
return getMyAccountMinDepositAsPercent(buyersAccountAge, phaseOnePeriod, 0.1);
}

Expand Down Expand Up @@ -225,7 +225,7 @@ public long getDelay(Trade trade) {
}

long buyersAccountAge = accountAgeWitnessService.getAccountAge(contract.getBuyerPaymentAccountPayload(), contract.getBuyerPubKeyRing());
long requiredAccountAge = getPhaseOnePeriod(offer.getPaymentMethod());
long requiredAccountAge = getPhaseOnePeriodAsMilli();

return getDelayInDays(buyersAccountAge, requiredAccountAge) * DateUtils.MILLIS_PER_DAY;
}
Expand All @@ -243,7 +243,7 @@ public long getDelayForOffer(Offer offer) {
}

long buyersAccountAge = accountAgeWitnessService.getMakersAccountAge(offer);
long requiredAccountAge = getPhaseOnePeriod(offer.getPaymentMethod());
long requiredAccountAge = getPhaseOnePeriodAsMilli();
return getDelayInDays(buyersAccountAge, requiredAccountAge) * DateUtils.MILLIS_PER_DAY;
}

Expand All @@ -264,7 +264,7 @@ public long getDelayForMyOffer(PaymentAccount myPaymentAccount, String currencyC
}

long myAccountAge = accountAgeWitnessService.getMyAccountAge(myPaymentAccount.getPaymentAccountPayload());
long requiredAccountAge = getPhaseOnePeriod(myPaymentAccount.getPaymentMethod());
long requiredAccountAge = getPhaseOnePeriodAsMilli();
return getDelayInDays(myAccountAge, requiredAccountAge) * DateUtils.MILLIS_PER_DAY;
}

Expand All @@ -280,7 +280,7 @@ public long getDelayForMyPaymentAccount(PaymentAccount myPaymentAccount, String
}

long myAccountAge = accountAgeWitnessService.getMyAccountAge(myPaymentAccount.getPaymentAccountPayload());
long requiredAccountAge = getPhaseOnePeriod(myPaymentAccount.getPaymentMethod());
long requiredAccountAge = getPhaseOnePeriodAsMilli();
return getDelayInDays(myAccountAge, requiredAccountAge) * DateUtils.MILLIS_PER_DAY;
}

Expand All @@ -294,36 +294,6 @@ public Date getDelayedTradePayoutDate(Trade trade) {
return new Date(delay + now);
}

/**
* @param paymentMethod The paymentMethod which determines the max. period
* @return The period ofr phase one in ms (day units)
*/
public long getPhaseOnePeriod(PaymentMethod paymentMethod) {
switch (paymentMethod.getId()) {
case PaymentMethod.BLOCK_CHAINS_ID:
case PaymentMethod.BLOCK_CHAINS_INSTANT_ID:

case PaymentMethod.US_POSTAL_MONEY_ORDER_ID:
case PaymentMethod.HAL_CASH_ID:
case PaymentMethod.F2F_ID:
case PaymentMethod.MONEY_GRAM_ID:
case PaymentMethod.WESTERN_UNION_ID:

case PaymentMethod.SWISH_ID:
case PaymentMethod.PERFECT_MONEY_ID:
case PaymentMethod.ALI_PAY_ID:
case PaymentMethod.WECHAT_PAY_ID:
case PaymentMethod.ADVANCED_CASH_ID:
case PaymentMethod.PROMPT_PAY_ID:
case PaymentMethod.CASH_DEPOSIT_ID:
return 0;

default:
// All other bank transfer methods
return getPhaseOnePeriodAsMilli();
}
}


///////////////////////////////////////////////////////////////////////////////////////////
// Is in phase one period
Expand Down Expand Up @@ -378,7 +348,7 @@ public boolean tradeInPhaseOnePeriod(Trade trade) {
}

long buyersAccountAge = accountAgeWitnessService.getAccountAge(contract.getBuyerPaymentAccountPayload(), contract.getBuyerPubKeyRing());
long requiredAccountAge = getPhaseOnePeriod(offer.getPaymentMethod());
long requiredAccountAge = getPhaseOnePeriodAsMilli();
return buyersAccountAge < requiredAccountAge;
}

Expand Down Expand Up @@ -448,7 +418,7 @@ private boolean accountInPhaseOnePeriod(PaymentMethod paymentMethod,
return false;
}

long requiredAccountAge = getPhaseOnePeriod(paymentMethod);
long requiredAccountAge = getPhaseOnePeriodAsMilli();
return accountAge < requiredAccountAge;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,43 @@ public AccountScoreService(AccountCreationAgeService accountCreationAgeService,
// API
///////////////////////////////////////////////////////////////////////////////////////////

public long getPhaseOnePeriod(PaymentMethod paymentMethod) {
return accountCreationAgeService.getPhaseOnePeriod(paymentMethod);
public long getPhaseOnePeriodAsMilli() {
return accountCreationAgeService.getPhaseOnePeriodAsMilli();
}

public boolean ignoreRestrictions(Coin tradeAmount) {
return tradeAmount.value <= LOW_AMOUNT_THRESHOLD;
}

public boolean ignoreRestrictions(Offer offer) {
return ignoreRestrictions(offer.getPaymentMethod()) || ignoreRestrictions(offer.getAmount());
}

public boolean ignoreRestrictions(PaymentMethod paymentMethod) {
switch (paymentMethod.getId()) {
case PaymentMethod.BLOCK_CHAINS_ID:
case PaymentMethod.BLOCK_CHAINS_INSTANT_ID:

case PaymentMethod.US_POSTAL_MONEY_ORDER_ID:
case PaymentMethod.HAL_CASH_ID:
case PaymentMethod.F2F_ID:
case PaymentMethod.MONEY_GRAM_ID:
case PaymentMethod.WESTERN_UNION_ID:

case PaymentMethod.SWISH_ID:
case PaymentMethod.PERFECT_MONEY_ID:
case PaymentMethod.ALI_PAY_ID:
case PaymentMethod.WECHAT_PAY_ID:
case PaymentMethod.ADVANCED_CASH_ID:
case PaymentMethod.PROMPT_PAY_ID:
case PaymentMethod.CASH_DEPOSIT_ID:
return true;

default:
// All other bank transfer methods
return false;
}
}

///////////////////////////////////////////////////////////////////////////////////////////
// Is in phase one period
Expand Down Expand Up @@ -498,8 +527,4 @@ private AccountScoreCategory getAccountScoreCategory(long accountAge, boolean is
return AccountScoreCategory.BRONZE;
}
}

private long getPhaseOnePeriodAsMilli() {
return accountCreationAgeService.getPhaseOnePeriodAsMilli();
}
}
4 changes: 2 additions & 2 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ payment.revolut.phoneNr=Registered phone no.
payment.promptPay.promptPayId=Citizen ID/Tax ID or phone no.
payment.supportedCurrencies=Supported currencies
payment.limitations=Limitations
payment.accountAgeTitle=Account age
payment.accountAgeTitle=Account level
payment.salt=Salt for account age verification
payment.error.noHexSalt=The salt need to be in HEX format.\n\
It is only recommended to edit the salt field if you want to transfer the salt from an old account to keep your account age. \
Expand All @@ -2634,7 +2634,7 @@ payment.accountNr=Account number
payment.emailOrMobile=Email or mobile nr
payment.useCustomAccountName=Use custom account name
payment.maxPeriod=Max. allowed trade period
payment.accountAge=Account age: {0} / Buyer''s min. account age: {1}
payment.accountAge=Account age: {0} / {1}
payment.maxPeriodAndTradeLimits=Max. trade duration: {0} / Max. trade limit: {1}
payment.currencyWithSymbol=Currency: {0}
payment.nameOfAcceptedBank=Name of accepted bank
Expand Down
95 changes: 53 additions & 42 deletions desktop/src/main/java/bisq/desktop/components/PeerInfoIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,31 @@ private PeerInfoIcon(NodeAddress nodeAddress,
categoryIcon = new Label();
categoryIcon.setLayoutX(-20);
categoryIcon.setLayoutY(5);
categoryIcon.setVisible(false);
categoryIcon.setManaged(false);

delayIcon = new Label();
AwesomeDude.setIcon(delayIcon, AwesomeIcon.TIME);
delayIcon.setLayoutX(-40);
delayIcon.setLayoutY(5);
AwesomeDude.setIcon(delayIcon, AwesomeIcon.TIME);
delayIcon.setVisible(false);
delayIcon.setManaged(false);

delayLabel = new Label();
delayLabel.setLayoutX(-53);
delayLabel.setLayoutY(20);
delayLabel.setMinWidth(40);
delayLabel.setMaxWidth(40);
delayLabel.getStyleClass().add("delay-label");
delayLabel.setVisible(false);
delayLabel.setManaged(false);

signIcon = new Label();
AwesomeDude.setIcon(signIcon, AwesomeIcon.SHIELD);
signIcon.setLayoutX(-60);
signIcon.setLayoutY(5);
AwesomeDude.setIcon(signIcon, AwesomeIcon.SHIELD);
signIcon.setVisible(false);
signIcon.setManaged(false);

getChildren().addAll(outerBackground, innerBackground, avatarImageView, tagPane, numTradesPane, categoryIcon, delayIcon, delayLabel, signIcon);

Expand Down Expand Up @@ -376,46 +384,49 @@ protected void updatePeerInfoIcon() {
numTradesPane.setVisible(numTrades > 0);

tagPane.setVisible(!tag.isEmpty());
Optional<ScoreInfo> optionalScoreInfo;
if (trade == null) {
optionalScoreInfo = accountScoreService.getScoreInfoForMaker(offer);
} else {
optionalScoreInfo = accountScoreService.getScoreInfoForBuyer(trade);
}
boolean isScoreInfoPresent = optionalScoreInfo.isPresent();
categoryIcon.setVisible(isScoreInfoPresent);
categoryIcon.setManaged(isScoreInfoPresent);
delayIcon.setVisible(isScoreInfoPresent);
delayIcon.setManaged(isScoreInfoPresent);
signIcon.setVisible(isScoreInfoPresent);
signIcon.setManaged(isScoreInfoPresent);

if (isScoreInfoPresent) {
//TODO just dummy impl.
ScoreInfo scoreInfo = optionalScoreInfo.get();
boolean canSign = scoreInfo.isCanSign();
signIcon.setVisible(canSign);
signIcon.setManaged(canSign);

long requiredDelay = scoreInfo.getRequiredDelay();
String age = Utilities.toTruncatedString(formatter.formatAccountAge(requiredDelay), 8);
delayLabel.setText(age);

boolean requireDelay = requiredDelay > 0;
delayIcon.setVisible(requireDelay);
delayIcon.setManaged(requireDelay);
delayLabel.setVisible(requireDelay);
delayLabel.setManaged(requireDelay);

if (scoreInfo.getAccountScoreCategory() == AccountScoreCategory.GOLD) {
categoryIcon.getStyleClass().addAll("score-gold");
AwesomeDude.setIcon(categoryIcon, AwesomeIcon.STAR);
} else if (scoreInfo.getAccountScoreCategory() == AccountScoreCategory.SILVER) {
categoryIcon.getStyleClass().addAll("score-silver");
AwesomeDude.setIcon(categoryIcon, AwesomeIcon.STAR_HALF_EMPTY);
} else if (scoreInfo.getAccountScoreCategory() == AccountScoreCategory.BRONZE) {
categoryIcon.getStyleClass().addAll("score-bronze");
AwesomeDude.setIcon(categoryIcon, AwesomeIcon.STAR_EMPTY);

if (!accountScoreService.ignoreRestrictions(offer)) {
Optional<ScoreInfo> optionalScoreInfo;
if (trade == null) {
optionalScoreInfo = accountScoreService.getScoreInfoForMaker(offer);
} else {
optionalScoreInfo = accountScoreService.getScoreInfoForBuyer(trade);
}
boolean isScoreInfoPresent = optionalScoreInfo.isPresent();
categoryIcon.setVisible(isScoreInfoPresent);
categoryIcon.setManaged(isScoreInfoPresent);
delayIcon.setVisible(isScoreInfoPresent);
delayIcon.setManaged(isScoreInfoPresent);
signIcon.setVisible(isScoreInfoPresent);
signIcon.setManaged(isScoreInfoPresent);

if (isScoreInfoPresent) {
//TODO just dummy impl.
ScoreInfo scoreInfo = optionalScoreInfo.get();
boolean canSign = scoreInfo.isCanSign();
signIcon.setVisible(canSign);
signIcon.setManaged(canSign);

long requiredDelay = scoreInfo.getRequiredDelay();
String age = Utilities.toTruncatedString(formatter.formatAccountAge(requiredDelay), 8);
delayLabel.setText(age);

boolean requireDelay = requiredDelay > 0;
delayIcon.setVisible(requireDelay);
delayIcon.setManaged(requireDelay);
delayLabel.setVisible(requireDelay);
delayLabel.setManaged(requireDelay);

if (scoreInfo.getAccountScoreCategory() == AccountScoreCategory.GOLD) {
categoryIcon.getStyleClass().addAll("score-gold");
AwesomeDude.setIcon(categoryIcon, AwesomeIcon.STAR);
} else if (scoreInfo.getAccountScoreCategory() == AccountScoreCategory.SILVER) {
categoryIcon.getStyleClass().addAll("score-silver");
AwesomeDude.setIcon(categoryIcon, AwesomeIcon.STAR_HALF_EMPTY);
} else if (scoreInfo.getAccountScoreCategory() == AccountScoreCategory.BRONZE) {
categoryIcon.getStyleClass().addAll("score-bronze");
AwesomeDude.setIcon(categoryIcon, AwesomeIcon.STAR_EMPTY);
}
}
}
}
Expand Down
Loading

0 comments on commit 74344a8

Please sign in to comment.