Skip to content

Commit a1814e3

Browse files
committed
Load Default currency code.
1 parent 5797a4e commit a1814e3

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github "hyperwallet/hyperwallet-ios-sdk" "1.0.0-beta20"
1+
github "hyperwallet/hyperwallet-ios-sdk" "1.0.1"
22
github "hyperwallet/hyperwallet-ios-insight" "1.0.0-beta08"

TransferMethod/Sources/SelectTransferMethodTypePresenter.swift

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,22 +302,48 @@ final class SelectTransferMethodTypePresenter {
302302

303303
private func loadSelectedCountry(_ countries: [HyperwalletCountry],
304304
with userCountry: String?) {
305+
var defaultCurrencyCode: String?
305306
if let userCountry = userCountry, countries.contains(where: { $0.value == userCountry }) {
306307
selectedCountry = userCountry
307308
} else if let country = countries.first, let countryValue = country.value {
308309
selectedCountry = countryValue
309310
}
311+
if !selectedCountry.isEmpty{
312+
if let country = countries.first(where: { $0.code == selectedCountry }) {
313+
defaultCurrencyCode = country.defaultCurrencyCode
314+
}
315+
}
310316
}
311317

312318
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+
321347

322348
private func loadTransferMethodTypesFeesAndProcessingTimes(
323349
_ transferMethodTypes: [HyperwalletTransferMethodType]?) {

0 commit comments

Comments
 (0)