From 1a9cdfbdd343050de93df2f2db18b7fd6548cf07 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Thu, 16 Sep 2021 09:31:22 -0300 Subject: [PATCH] Return early when field name match fails Resolves https://github.com/bisq-network/bisq/pull/5685#discussion_r710002786 --- .../api/model/PaymentAccountTypeAdapter.java | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/core/src/main/java/bisq/core/api/model/PaymentAccountTypeAdapter.java b/core/src/main/java/bisq/core/api/model/PaymentAccountTypeAdapter.java index 85b2344de0..00b0654145 100644 --- a/core/src/main/java/bisq/core/api/model/PaymentAccountTypeAdapter.java +++ b/core/src/main/java/bisq/core/api/model/PaymentAccountTypeAdapter.java @@ -353,29 +353,29 @@ class PaymentAccountTypeAdapter extends TypeAdapter { private boolean didReadTradeCurrenciesField(JsonReader in, PaymentAccount account, String fieldName) { + if (!fieldName.equals("tradeCurrencies")) + return false; + // The PaymentAccount.tradeCurrencies field is a special case because it has // no setter, so we add currencies to the List here if the payment account // supports multiple trade currencies. - if (fieldName.equals("tradeCurrencies")) { - String fieldValue = nextStringOrNull(in); - List currencyCodes = commaDelimitedCodesToList.apply(fieldValue); - Optional> tradeCurrencies = getReconciledTradeCurrencies(currencyCodes, account); - if (tradeCurrencies.isPresent()) { - for (TradeCurrency tradeCurrency : tradeCurrencies.get()) { - account.addCurrency(tradeCurrency); - } - } else { - // Log a warning. We should not throw an exception here because the - // gson library will not pass it up to the calling Bisq object exactly as - // it would be defined here (causing confusion). Do a check in a calling - // class to make sure the tradeCurrencies field is populated in the - // PaymentAccount object, if it is required for the payment account method. - log.warn("No trade currencies were found in the {} account form.", - account.getPaymentMethod().getDisplayString()); + String fieldValue = nextStringOrNull(in); + List currencyCodes = commaDelimitedCodesToList.apply(fieldValue); + Optional> tradeCurrencies = getReconciledTradeCurrencies(currencyCodes, account); + if (tradeCurrencies.isPresent()) { + for (TradeCurrency tradeCurrency : tradeCurrencies.get()) { + account.addCurrency(tradeCurrency); } - return true; + } else { + // Log a warning. We should not throw an exception here because the + // gson library will not pass it up to the calling Bisq object exactly as + // it would be defined here (causing confusion). Do a check in a calling + // class to make sure the tradeCurrencies field is populated in the + // PaymentAccount object, if it is required for the payment account method. + log.warn("No trade currencies were found in the {} account form.", + account.getPaymentMethod().getDisplayString()); } - return false; + return true; } private Optional> getReconciledTradeCurrencies(List currencyCodes, @@ -407,22 +407,22 @@ class PaymentAccountTypeAdapter extends TypeAdapter { private boolean didReadSelectedTradeCurrencyField(JsonReader in, PaymentAccount account, String fieldName) { - if (fieldName.equals("selectedTradeCurrency")) { - String fieldValue = nextStringOrNull(in); - if (fieldValue != null && !fieldValue.isEmpty()) { - Optional tradeCurrency = getTradeCurrency(fieldValue.toUpperCase()); - if (tradeCurrency.isPresent()) { - account.setSelectedTradeCurrency(tradeCurrency.get()); - } else { - // Log an error. We should not throw an exception here because the - // gson library will not pass it up to the calling Bisq object exactly as - // it would be defined here (causing confusion). - log.error("{} is not a valid trade currency code.", fieldValue); - } + if (!fieldName.equals("selectedTradeCurrency")) + return false; + + String fieldValue = nextStringOrNull(in); + if (fieldValue != null && !fieldValue.isEmpty()) { + Optional tradeCurrency = getTradeCurrency(fieldValue.toUpperCase()); + if (tradeCurrency.isPresent()) { + account.setSelectedTradeCurrency(tradeCurrency.get()); + } else { + // Log an error. We should not throw an exception here because the + // gson library will not pass it up to the calling Bisq object exactly as + // it would be defined here (causing confusion). + log.error("{} is not a valid trade currency code.", fieldValue); } - return true; } - return false; + return true; } private boolean didReadCommonField(JsonReader in,