From a2f07927990f72944cd2c0063f37900b65cc0d55 Mon Sep 17 00:00:00 2001 From: napoly Date: Sat, 11 Feb 2023 11:56:22 +0100 Subject: [PATCH] reject payment accounts with duplicate names --- .../java/bisq/core/api/CorePaymentAccountsService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/api/CorePaymentAccountsService.java b/core/src/main/java/bisq/core/api/CorePaymentAccountsService.java index 2f07eb44a1..951480fd41 100644 --- a/core/src/main/java/bisq/core/api/CorePaymentAccountsService.java +++ b/core/src/main/java/bisq/core/api/CorePaymentAccountsService.java @@ -86,7 +86,6 @@ class CorePaymentAccountsService { List tradeCurrencies = paymentAccount.getTradeCurrencies(); if (singleTradeCurrency != null) { paymentAccount.setSelectedTradeCurrency(singleTradeCurrency); - return; } else if (tradeCurrencies != null && !tradeCurrencies.isEmpty()) { if (tradeCurrencies.contains(CurrencyUtil.getDefaultTradeCurrency())) { paymentAccount.setSelectedTradeCurrency(CurrencyUtil.getDefaultTradeCurrency()); @@ -135,6 +134,7 @@ class CorePaymentAccountsService { String address, boolean tradeInstant) { accountService.checkAccountOpen(); + verifyAccountNameUnique(accountName); verifyCryptoCurrencyAddress(currencyCode.toUpperCase(), address); AssetAccount cryptoCurrencyAccount = tradeInstant ? (InstantCryptoCurrencyAccount) PaymentAccountFactory.getPaymentAccount(PaymentMethod.BLOCK_CHAINS_INSTANT) @@ -145,7 +145,6 @@ class CorePaymentAccountsService { Optional cryptoCurrency = getCryptoCurrency(currencyCode.toUpperCase()); cryptoCurrency.ifPresent(cryptoCurrencyAccount::setSingleTradeCurrency); 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 {}.", cryptoCurrencyAccount.getId(), cryptoCurrencyAccount.getPaymentAccountPayload().getPaymentMethodId()); @@ -173,6 +172,12 @@ class CorePaymentAccountsService { 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) { Asset asset = getAsset(cryptoCurrencyCode);