@@ -146,30 +146,13 @@ public void onKeysLoaded(@Nullable final HyperwalletTransferMethodConfigurationK
146
146
if (!mView .isActive ()) {
147
147
return ;
148
148
}
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 );
162
150
163
151
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 ;
166
153
}
167
-
168
- // Show the selected country and currency in the UI
169
154
mView .showTransferMethodCountry (countryCode );
170
155
mView .showTransferMethodCurrency (selectedCurrencyCode );
171
-
172
- // Load fee, processing time, and other transfer methods
173
156
loadFeeAndProcessingTimeAndShowTransferMethods (countryCode , selectedCurrencyCode , user );
174
157
}
175
158
@@ -284,24 +267,13 @@ public void onKeysLoaded(@Nullable HyperwalletTransferMethodConfigurationKey key
284
267
if (!mView .isActive ()) {
285
268
return ;
286
269
}
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 );
299
271
300
272
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 ;
303
274
}
304
-
275
+ Set <Currency > currencyCodes = key .getCurrencies (countryCode ) != null ?
276
+ key .getCurrencies (countryCode ) : new HashSet <Currency >();
305
277
TreeMap <String , String > currencyNameCodeMap = new TreeMap <>();
306
278
String selectedCurrencyName = null ;
307
279
for (Currency currency : currencyCodes ) {
@@ -324,22 +296,28 @@ public void onError(@NonNull final Errors errors) {
324
296
}
325
297
326
298
// 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 ();
332
312
if (defaultCurrencyCode != null ) {
333
- Set <Currency > currencies = keys .getCurrencies (countryCode );
334
313
for (Currency currency : currencies ) {
335
314
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 ();
337
316
}
338
317
}
339
318
}
340
- // If the default currency is not found, return the first currency from the list (if available)
341
319
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 ();
343
321
}
344
322
return null ;
345
323
}
0 commit comments