@@ -146,30 +146,13 @@ public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationK
146146 if (!mView .isActive ()) {
147147 return ;
148148 }
149- List <Currency > currencies = key .getCurrencies (countryCode ) != null ?
150- new ArrayList <>(key .getCurrencies (countryCode )) :
151- new ArrayList <Currency >();
152-
153- Country selectedCountry = null ;
154- for (Country country : key .getCountries ()) {
155- if (country .getCode ().equals (countryCode )) {
156- selectedCountry = country ;
157- break ;
158- }
159- }
160- // Attempt to get the default currency code for the selected country
161- String selectedCurrencyCode = getDefaultCurrencyCode (selectedCountry , key , countryCode );
149+ String selectedCurrencyCode = getDefaultCurrencyCode (key , countryCode );
162150
163151 if (selectedCurrencyCode == null ) {
164- // If no default currency code is found, use the first currency in the list
165- selectedCurrencyCode = currencies .get (0 ).getCode ();
152+ return ;
166153 }
167-
168- // Show the selected country and currency in the UI
169154 mView .showTransferMethodCountry (countryCode );
170155 mView .showTransferMethodCurrency (selectedCurrencyCode );
171-
172- // Load fee, processing time, and other transfer methods
173156 loadFeeAndProcessingTimeAndShowTransferMethods (countryCode , selectedCurrencyCode , user );
174157 }
175158
@@ -284,24 +267,13 @@ public void onKeysLoaded(@Nullable HyperwalletTransferMethodConfigurationKey key
284267 if (!mView .isActive ()) {
285268 return ;
286269 }
287- Set <Currency > currencyCodes = key .getCurrencies (countryCode ) != null ?
288- key .getCurrencies (countryCode ) : new HashSet <Currency >();
289- // Find the country based on the country code
290- Country selectedCountry = null ;
291- for (Country country : key .getCountries ()) {
292- if (country .getCode ().equals (countryCode )) {
293- selectedCountry = country ;
294- break ;
295- }
296- }
297- // Attempt to get the default currency code for the selected country
298- String selectedDefaultCurrencyCode = getDefaultCurrencyCode (selectedCountry , key , countryCode );
270+ String selectedDefaultCurrencyCode = getDefaultCurrencyCode (key , countryCode );
299271
300272 if (selectedDefaultCurrencyCode == null ) {
301- // If no default currency code is found, use the first currency in the list
302- selectedDefaultCurrencyCode = currencyCodes .iterator ().next ().getCode (); // Get the first currency code
273+ return ;
303274 }
304-
275+ Set <Currency > currencyCodes = key .getCurrencies (countryCode ) != null ?
276+ key .getCurrencies (countryCode ) : new HashSet <Currency >();
305277 TreeMap <String , String > currencyNameCodeMap = new TreeMap <>();
306278 String selectedCurrencyName = null ;
307279 for (Currency currency : currencyCodes ) {
@@ -324,22 +296,28 @@ public void onError(@NonNull final Errors errors) {
324296 }
325297
326298 // Helper method to get the DefaultCurrencyCode
327- private String getDefaultCurrencyCode (@ NonNull Country country , @ Nullable HyperwalletTransferMethodConfigurationKey keys ,
328- @ NonNull String countryCode ) {
329- //Get the default currency code from the selected country
330- String defaultCurrencyCode = country .getDefaultCurrency ();
331- // If the country has a default currency code, check if it's in the list of available currencies
299+ private String getDefaultCurrencyCode (@ NonNull final HyperwalletTransferMethodConfigurationKey keys , @ NonNull final String countryCode ) {
300+ Country selectedCountry = null ;
301+ for (Country country : keys .getCountries ()) {
302+ if (country .getCode ().equals (countryCode )) {
303+ selectedCountry = country ;
304+ break ;
305+ }
306+ }
307+ if (selectedCountry == null ) {
308+ return null ;
309+ }
310+ Set <Currency > currencies = keys .getCurrencies (countryCode );
311+ String defaultCurrencyCode = selectedCountry .getDefaultCurrency ();
332312 if (defaultCurrencyCode != null ) {
333- Set <Currency > currencies = keys .getCurrencies (countryCode );
334313 for (Currency currency : currencies ) {
335314 if (currency .getCode ().equals (defaultCurrencyCode )) {
336- return currency .getCode (); // Return the country's currency code, if it exists in the list
315+ return currency .getCode ();
337316 }
338317 }
339318 }
340- // If the default currency is not found, return the first currency from the list (if available)
341319 if (!keys .getCurrencies (countryCode ).isEmpty ()) {
342- return keys .getCurrencies (countryCode ).iterator ().next ().getCode (); // Return the first currency code in the list
320+ return keys .getCurrencies (countryCode ).iterator ().next ().getCode ();
343321 }
344322 return null ;
345323 }
0 commit comments