@@ -302,22 +302,48 @@ final class SelectTransferMethodTypePresenter {
302
302
303
303
private func loadSelectedCountry( _ countries: [ HyperwalletCountry ] ,
304
304
with userCountry: String ? ) {
305
+ var defaultCurrencyCode : String ?
305
306
if let userCountry = userCountry, countries. contains ( where: { $0. value == userCountry } ) {
306
307
selectedCountry = userCountry
307
308
} else if let country = countries. first, let countryValue = country. value {
308
309
selectedCountry = countryValue
309
310
}
311
+ if !selectedCountry. isEmpty{
312
+ if let country = countries. first ( where: { $0. code == selectedCountry } ) {
313
+ defaultCurrencyCode = country. defaultCurrencyCode
314
+ }
315
+ }
310
316
}
311
317
312
318
private func loadCurrency( _ keys: HyperwalletTransferMethodConfigurationKey ? ) {
313
- guard let firstCurrency = keys? . currencies ( from: selectedCountry) ? . first,
314
- let currencyCode = firstCurrency. code else {
315
- view? . showAlert ( message: String ( format: " no_currency_available_error_message " . localized ( ) , selectedCountry) )
316
- return
317
- }
318
- selectedCurrency = currencyCode
319
- view? . reloadCountryCurrencyData ( )
320
- }
319
+ guard let countries = keys? . countries ( ) ,
320
+ let country = countries. first ( where: { $0. code == selectedCountry } ) else {
321
+ // Handle the case when country is not found
322
+ let errorMessage = String ( format: " no_country_found_error_message " . localized ( ) , selectedCountry ?? " Unknown Country " )
323
+ view? . showAlert ( message: errorMessage)
324
+ return
325
+ }
326
+ // Check if the country has a defaultCurrencyCode
327
+ if let defaultCurrencyCode = country. defaultCurrencyCode {
328
+ // If the defaultCurrencyCode exists, use it
329
+ selectedCurrency = defaultCurrencyCode
330
+ } else {
331
+ // If the defaultCurrencyCode is nil, fall back to the first currency in the currencyList
332
+ if let firstCurrency = keys? . currencies ( from: selectedCountry) ? . first,
333
+ let currencyCode = firstCurrency. code {
334
+ selectedCurrency = currencyCode
335
+ } else {
336
+ // Show an alert if no currency is found
337
+ let errorMessage = String ( format: " no_currency_available_error_message " . localized ( ) , selectedCountry ?? " Unknown Country " )
338
+ view? . showAlert ( message: errorMessage)
339
+ return
340
+ }
341
+ }
342
+
343
+ // Reload the view with the updated currency data
344
+ view? . reloadCountryCurrencyData ( )
345
+ }
346
+
321
347
322
348
private func loadTransferMethodTypesFeesAndProcessingTimes(
323
349
_ transferMethodTypes: [ HyperwalletTransferMethodType ] ? ) {
0 commit comments