mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-23 03:59:36 +00:00
reject payment accounts with duplicate names
This commit is contained in:
parent
e2a8dc702b
commit
a2f0792799
1 changed files with 7 additions and 2 deletions
|
@ -86,7 +86,6 @@ class CorePaymentAccountsService {
|
||||||
List<TradeCurrency> tradeCurrencies = paymentAccount.getTradeCurrencies();
|
List<TradeCurrency> tradeCurrencies = paymentAccount.getTradeCurrencies();
|
||||||
if (singleTradeCurrency != null) {
|
if (singleTradeCurrency != null) {
|
||||||
paymentAccount.setSelectedTradeCurrency(singleTradeCurrency);
|
paymentAccount.setSelectedTradeCurrency(singleTradeCurrency);
|
||||||
return;
|
|
||||||
} else if (tradeCurrencies != null && !tradeCurrencies.isEmpty()) {
|
} else if (tradeCurrencies != null && !tradeCurrencies.isEmpty()) {
|
||||||
if (tradeCurrencies.contains(CurrencyUtil.getDefaultTradeCurrency())) {
|
if (tradeCurrencies.contains(CurrencyUtil.getDefaultTradeCurrency())) {
|
||||||
paymentAccount.setSelectedTradeCurrency(CurrencyUtil.getDefaultTradeCurrency());
|
paymentAccount.setSelectedTradeCurrency(CurrencyUtil.getDefaultTradeCurrency());
|
||||||
|
@ -135,6 +134,7 @@ class CorePaymentAccountsService {
|
||||||
String address,
|
String address,
|
||||||
boolean tradeInstant) {
|
boolean tradeInstant) {
|
||||||
accountService.checkAccountOpen();
|
accountService.checkAccountOpen();
|
||||||
|
verifyAccountNameUnique(accountName);
|
||||||
verifyCryptoCurrencyAddress(currencyCode.toUpperCase(), address);
|
verifyCryptoCurrencyAddress(currencyCode.toUpperCase(), address);
|
||||||
AssetAccount cryptoCurrencyAccount = tradeInstant
|
AssetAccount cryptoCurrencyAccount = tradeInstant
|
||||||
? (InstantCryptoCurrencyAccount) PaymentAccountFactory.getPaymentAccount(PaymentMethod.BLOCK_CHAINS_INSTANT)
|
? (InstantCryptoCurrencyAccount) PaymentAccountFactory.getPaymentAccount(PaymentMethod.BLOCK_CHAINS_INSTANT)
|
||||||
|
@ -145,7 +145,6 @@ class CorePaymentAccountsService {
|
||||||
Optional<CryptoCurrency> cryptoCurrency = getCryptoCurrency(currencyCode.toUpperCase());
|
Optional<CryptoCurrency> cryptoCurrency = getCryptoCurrency(currencyCode.toUpperCase());
|
||||||
cryptoCurrency.ifPresent(cryptoCurrencyAccount::setSingleTradeCurrency);
|
cryptoCurrency.ifPresent(cryptoCurrencyAccount::setSingleTradeCurrency);
|
||||||
user.addPaymentAccount(cryptoCurrencyAccount);
|
user.addPaymentAccount(cryptoCurrencyAccount);
|
||||||
if (!(cryptoCurrencyAccount instanceof AssetAccount)) accountAgeWitnessService.publishMyAccountAgeWitness(cryptoCurrencyAccount.getPaymentAccountPayload()); // TODO (woodser): applies to Haveno?
|
|
||||||
log.info("Saved crypto payment account with id {} and payment method {}.",
|
log.info("Saved crypto payment account with id {} and payment method {}.",
|
||||||
cryptoCurrencyAccount.getId(),
|
cryptoCurrencyAccount.getId(),
|
||||||
cryptoCurrencyAccount.getPaymentAccountPayload().getPaymentMethodId());
|
cryptoCurrencyAccount.getPaymentAccountPayload().getPaymentMethodId());
|
||||||
|
@ -173,6 +172,12 @@ class CorePaymentAccountsService {
|
||||||
paymentAccount.validateFormField(form, fieldId, value);
|
paymentAccount.validateFormField(form, fieldId, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void verifyAccountNameUnique(String accountName) {
|
||||||
|
if (getPaymentAccounts().stream().anyMatch(e -> e.getAccountName() != null &&
|
||||||
|
e.getAccountName().equals(accountName)))
|
||||||
|
throw new IllegalArgumentException(format("Account '%s' is already taken", accountName));
|
||||||
|
}
|
||||||
|
|
||||||
private void verifyCryptoCurrencyAddress(String cryptoCurrencyCode, String address) {
|
private void verifyCryptoCurrencyAddress(String cryptoCurrencyCode, String address) {
|
||||||
Asset asset = getAsset(cryptoCurrencyCode);
|
Asset asset = getAsset(cryptoCurrencyCode);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue