-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bernard Labno
committed
Jun 19, 2019
1 parent
acd687e
commit c7fa660
Showing
79 changed files
with
4,135 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
api/src/main/java/bisq/api/http/exceptions/ExperimentalFeatureException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package bisq.api.http.exceptions; | ||
|
||
public class ExperimentalFeatureException extends RuntimeException { | ||
public ExperimentalFeatureException() { | ||
super("Experimental features disabled"); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
api/src/main/java/bisq/api/http/exceptions/NotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package bisq.api.http.exceptions; | ||
|
||
public class NotFoundException extends RuntimeException { | ||
public NotFoundException(String message) { | ||
super(message); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
api/src/main/java/bisq/api/http/facade/PaymentAccountFacade.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package bisq.api.http.facade; | ||
|
||
import bisq.api.http.exceptions.NotFoundException; | ||
import bisq.api.http.model.PaymentAccountList; | ||
import bisq.api.http.model.payment.PaymentAccountHelper; | ||
|
||
import bisq.core.payment.PaymentAccount; | ||
import bisq.core.payment.PaymentAccountManager; | ||
import bisq.core.user.User; | ||
|
||
import javax.inject.Inject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class PaymentAccountFacade { | ||
|
||
private final PaymentAccountManager paymentAccountManager; | ||
private final User user; | ||
|
||
@Inject | ||
public PaymentAccountFacade(PaymentAccountManager paymentAccountManager, User user) { | ||
this.paymentAccountManager = paymentAccountManager; | ||
this.user = user; | ||
} | ||
|
||
public PaymentAccount addPaymentAccount(PaymentAccount paymentAccount) { | ||
return paymentAccountManager.addPaymentAccount(paymentAccount); | ||
} | ||
|
||
public void removePaymentAccount(String id) { | ||
PaymentAccount paymentAccount = user.getPaymentAccount(id); | ||
if (paymentAccount == null) { | ||
throw new NotFoundException("Payment account not found: " + id); | ||
} | ||
user.removePaymentAccount(paymentAccount); | ||
} | ||
|
||
public PaymentAccountList getAccountList() { | ||
PaymentAccountList paymentAccountList = new PaymentAccountList(); | ||
paymentAccountList.paymentAccounts = getPaymentAccountList().stream() | ||
.map(PaymentAccountHelper::toRestModel) | ||
.collect(Collectors.toList()); | ||
return paymentAccountList; | ||
} | ||
|
||
private List<PaymentAccount> getPaymentAccountList() { | ||
Set<PaymentAccount> paymentAccounts = user.getPaymentAccounts(); | ||
return null == paymentAccounts ? Collections.emptyList() : new ArrayList<>(paymentAccounts); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/main/java/bisq/api/http/model/PaymentAccountList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package bisq.api.http.model; | ||
|
||
import bisq.api.http.model.payment.PaymentAccount; | ||
|
||
import java.util.List; | ||
|
||
public class PaymentAccountList { | ||
|
||
public List<PaymentAccount> paymentAccounts; | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
api/src/main/java/bisq/api/http/model/payment/AbstractPaymentAccountConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package bisq.api.http.model.payment; | ||
|
||
import bisq.core.locale.CryptoCurrency; | ||
import bisq.core.locale.CurrencyUtil; | ||
import bisq.core.locale.FiatCurrency; | ||
import bisq.core.locale.TradeCurrency; | ||
import bisq.core.payment.payload.PaymentAccountPayload; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
|
||
|
||
import javax.validation.ValidationException; | ||
|
||
public abstract class AbstractPaymentAccountConverter<B extends bisq.core.payment.PaymentAccount, BP extends PaymentAccountPayload, R extends PaymentAccount> implements PaymentAccountConverter<B, BP, R> { | ||
|
||
protected void toBusinessModel(B business, R rest) { | ||
if (rest.accountName != null) | ||
business.setAccountName(rest.accountName); | ||
business.getTradeCurrencies().clear(); | ||
CurrencyConverter currencyConverter; | ||
if (rest instanceof CryptoCurrencyPaymentAccount) | ||
currencyConverter = new CryptoCurrencyConverter(); | ||
else | ||
currencyConverter = new FiatCurrencyConverter(); | ||
|
||
if (rest.selectedTradeCurrency != null) | ||
business.setSelectedTradeCurrency(currencyConverter.convert(rest.selectedTradeCurrency)); | ||
if (rest.tradeCurrencies != null) | ||
rest.tradeCurrencies.forEach(currencyCode -> business.addCurrency(currencyConverter.convert(currencyCode))); | ||
} | ||
|
||
protected void toRestModel(R rest, B business) { | ||
rest.id = business.getId(); | ||
rest.accountName = business.getAccountName(); | ||
TradeCurrency selectedTradeCurrency = business.getSelectedTradeCurrency(); | ||
if (selectedTradeCurrency != null) | ||
rest.selectedTradeCurrency = selectedTradeCurrency.getCode(); | ||
List<TradeCurrency> tradeCurrencies = business.getTradeCurrencies(); | ||
if (tradeCurrencies != null) | ||
tradeCurrencies.forEach(currency -> rest.tradeCurrencies.add(currency.getCode())); | ||
} | ||
|
||
protected void toRestModel(R rest, BP business) { | ||
rest.paymentDetails = business.getPaymentDetails(); | ||
} | ||
|
||
private interface CurrencyConverter { | ||
TradeCurrency convert(String currencyCode); | ||
} | ||
|
||
private static class FiatCurrencyConverter implements CurrencyConverter { | ||
@Override | ||
public TradeCurrency convert(String currencyCode) { | ||
return new FiatCurrency(currencyCode); | ||
} | ||
} | ||
|
||
private static class CryptoCurrencyConverter implements CurrencyConverter { | ||
@Override | ||
public TradeCurrency convert(String currencyCode) { | ||
Optional<CryptoCurrency> cryptoCurrencyOptional = CurrencyUtil.getCryptoCurrency(currencyCode); | ||
if (!cryptoCurrencyOptional.isPresent()) { | ||
throw new ValidationException("Unsupported crypto currency code: " + currencyCode); | ||
} | ||
return cryptoCurrencyOptional.get(); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
api/src/main/java/bisq/api/http/model/payment/AdvancedCashPaymentAccount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package bisq.api.http.model.payment; | ||
|
||
import bisq.core.payment.payload.PaymentMethod; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
|
||
|
||
|
||
import org.hibernate.validator.constraints.NotBlank; | ||
|
||
@JsonTypeName(PaymentMethod.ADVANCED_CASH_ID) | ||
public class AdvancedCashPaymentAccount extends PaymentAccount { | ||
|
||
@NotBlank | ||
public String accountNr; | ||
|
||
public AdvancedCashPaymentAccount() { | ||
super(PaymentMethod.ADVANCED_CASH_ID); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
api/src/main/java/bisq/api/http/model/payment/AdvancedCashPaymentAccountConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package bisq.api.http.model.payment; | ||
|
||
import bisq.core.payment.AdvancedCashAccount; | ||
import bisq.core.payment.payload.AdvancedCashAccountPayload; | ||
|
||
public class AdvancedCashPaymentAccountConverter extends AbstractPaymentAccountConverter<AdvancedCashAccount, AdvancedCashAccountPayload, AdvancedCashPaymentAccount> { | ||
|
||
@Override | ||
public AdvancedCashAccount toBusinessModel(AdvancedCashPaymentAccount rest) { | ||
AdvancedCashAccount business = new AdvancedCashAccount(); | ||
business.init(); | ||
business.setAccountNr(rest.accountNr); | ||
toBusinessModel(business, rest); | ||
return business; | ||
} | ||
|
||
@Override | ||
public AdvancedCashPaymentAccount toRestModel(AdvancedCashAccount business) { | ||
AdvancedCashPaymentAccount rest = toRestModel((AdvancedCashAccountPayload) business.getPaymentAccountPayload()); | ||
toRestModel(rest, business); | ||
return rest; | ||
} | ||
|
||
@Override | ||
public AdvancedCashPaymentAccount toRestModel(AdvancedCashAccountPayload business) { | ||
AdvancedCashPaymentAccount rest = new AdvancedCashPaymentAccount(); | ||
rest.accountNr = business.getAccountNr(); | ||
toRestModel(rest, business); | ||
return rest; | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
api/src/main/java/bisq/api/http/model/payment/AliPayPaymentAccount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package bisq.api.http.model.payment; | ||
|
||
import bisq.core.payment.payload.PaymentMethod; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
|
||
|
||
|
||
import org.hibernate.validator.constraints.NotBlank; | ||
|
||
@JsonTypeName(PaymentMethod.ALI_PAY_ID) | ||
public class AliPayPaymentAccount extends PaymentAccount { | ||
|
||
@NotBlank | ||
public String accountNr; | ||
|
||
public AliPayPaymentAccount() { | ||
super(PaymentMethod.ALI_PAY_ID); | ||
} | ||
} |
Oops, something went wrong.