Skip to content

Commit a4c9e23

Browse files
DTPOMERSER-1275 - iOS UI SDK - Create Transfer Method: List default currency per selected country (#385)
* Changed carfile with new version. select default currency code. * addressed review comments. Used existing Locale for error message. * Update Cartfile * DTPOMERSER-1275 Update core-sdk version * created new method to get default currency. Used that method in already existing method to avoid if and else conditions. * updated error message. * Address lint error * Increase test coverage to test default currency code * Update readme * Update changlog --------- Co-authored-by: Gustavo Meyer <[email protected]>
1 parent 17860ee commit a4c9e23

File tree

7 files changed

+85
-61
lines changed

7 files changed

+85
-61
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Changelog
22
=========
3+
[1.0.1](https://github.com/hyperwallet/hyperwallet-ios-ui-sdk/releases/tag/1.0.0-beta21)
4+
-------------------
5+
- Automatically select the default currency code based on the country's configuration
6+
37
[1.0.0-beta21](https://github.com/hyperwallet/hyperwallet-ios-ui-sdk/releases/tag/1.0.0-beta21)
48
-------------------
59
- Update privacy manifest

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"

Cartfile.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
github "JanGorman/Hippolyte" "1.4.1"
22
github "httpswift/swifter" "1.5.0"
33
github "hyperwallet/hyperwallet-ios-insight" "1.0.0-beta08"
4-
github "hyperwallet/hyperwallet-ios-sdk" "1.0.0-beta20"
4+
github "hyperwallet/hyperwallet-ios-sdk" "1.0.1"

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ Adding one or more of these frameworks allows users to explore the particular fu
3434
### Carthage
3535
Specify it in your Cartfile:
3636
```ogdl
37-
github "hyperwallet/hyperwallet-ios-ui-sdk" "1.0.0-beta21"
37+
github "hyperwallet/hyperwallet-ios-ui-sdk" "1.0.1"
3838
```
3939
Add desired modules using the `Linked Frameworks and Libraries` option to make them available in the app.
4040
Use `import <module-name>` to add the dependency within a file
4141

4242
### CocoaPods
4343
- Install a specific framework (install one or more frameworks based on your requirement)
4444
```ruby
45-
pod "HyperwalletUISDK/TransferMethod", "1.0.0-beta21"
46-
pod "HyperwalletUISDK/Transfer", "1.0.0-beta21"
47-
pod "HyperwalletUISDK/Receipt", "1.0.0-beta21"
45+
pod "HyperwalletUISDK/TransferMethod", "1.0.1"
46+
pod "HyperwalletUISDK/Transfer", "1.0.1"
47+
pod "HyperwalletUISDK/Receipt", "1.0.1"
4848
```
4949
- To install all available modules (TransferMethod, Transfer, Receipt)
5050
```ruby
51-
pod 'HyperwalletUISDK', '~> 1.0.0-beta21'
51+
pod 'HyperwalletUISDK', '~> 1.0.1'
5252
```
5353
Use `import HyperwalletUISDK` to add the dependency within a file.
5454

TransferMethod/Sources/SelectTransferMethodTypePresenter.swift

Lines changed: 71 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,31 @@ final class SelectTransferMethodTypePresenter {
6464
private let linkTransferMethod = "select-transfer-method"
6565
private var selectedTransferMethodType = ""
6666
private var hyperwalletInsights: HyperwalletInsightsProtocol
67-
67+
6868
private lazy var transferMethodConfigurationRepository = {
6969
TransferMethodRepositoryFactory.shared.transferMethodConfigurationRepository()
7070
}()
71-
71+
7272
private lazy var userRepository: UserRepository = {
7373
UserRepositoryFactory.shared.userRepository()
7474
}()
75-
75+
7676
private(set) var sectionData = [HyperwalletTransferMethodType]()
77-
77+
7878
/// Initialize SelectTransferMethodPresenter
7979
init(_ view: SelectTransferMethodTypeView,
8080
_ hyperwalletInsights: HyperwalletInsightsProtocol = HyperwalletInsights.shared) {
8181
self.view = view
8282
self.hyperwalletInsights = hyperwalletInsights
8383
}
84-
84+
8585
/// Return the countryCurrency item composed by the tuple (title and value)
8686
func getCountryCurrencyConfiguration(indexPath: IndexPath) -> CountryCurrencyCellConfiguration {
8787
let title = countryCurrencySectionData[indexPath.row]
8888
return CountryCurrencyCellConfiguration(title: title.localized(),
8989
value: countryCurrencyValues(at: indexPath.row))
9090
}
91-
91+
9292
/// Display all the select Country or Currency based on the index
9393
func performShowSelectCountryOrCurrencyView(index: Int) {
9494
transferMethodConfigurationRepository.getKeys(completion: self.getKeysHandler(
@@ -100,18 +100,18 @@ final class SelectTransferMethodTypePresenter {
100100
}
101101
}))
102102
}
103-
103+
104104
/// Loads the transferMethodKeys from core SDK and display the default transfer methods
105105
///
106106
/// - Parameter forceUpdate: Forces to refresh the data
107107
func loadTransferMethodKeys(_ forceUpdate: Bool = false) {
108108
view?.showLoading()
109-
109+
110110
if forceUpdate {
111111
userRepository.refreshUser()
112112
transferMethodConfigurationRepository.refreshKeys()
113113
}
114-
114+
115115
userRepository.getUser { [weak self] getUserResult in
116116
guard let strongSelf = self, let view = strongSelf.view else {
117117
return
@@ -124,7 +124,7 @@ final class SelectTransferMethodTypePresenter {
124124
pageGroup: strongSelf.pageGroup) {
125125
strongSelf.loadTransferMethodKeys()
126126
}
127-
127+
128128
case .success(let user):
129129
strongSelf.transferMethodConfigurationRepository
130130
.getKeys(completion: strongSelf.getKeysHandler(
@@ -148,11 +148,11 @@ final class SelectTransferMethodTypePresenter {
148148
view.hideLoading()
149149
strongSelf.loadTransferMethodKeys()
150150
})
151-
)
151+
)
152152
}
153153
}
154154
}
155-
155+
156156
/// Navigate to AddTransferMethodController
157157
func navigateToAddTransferMethod(_ index: Int) {
158158
if let transferMethodTypeCode = self.sectionData[index].code {
@@ -163,45 +163,45 @@ final class SelectTransferMethodTypePresenter {
163163
guard let strongSelf = self else {
164164
return
165165
}
166-
166+
167167
if case let .success(user) = getUserResult,
168-
let profileType = user?.profileType?.rawValue {
168+
let profileType = user?.profileType?.rawValue {
169169
strongSelf.view?
170170
.navigateToAddTransferMethodController(
171171
country: strongSelf.selectedCountry,
172172
currency: strongSelf.selectedCurrency,
173173
profileType: profileType,
174174
transferMethodTypeCode: strongSelf.selectedTransferMethodType
175-
)
175+
)
176176
}
177177
}
178178
}
179-
179+
180180
private func countryCurrencyValues(at index: Int) -> String {
181181
return (index == 0
182-
? Locale.current.localizedString(forRegionCode: selectedCountry) ?? selectedCountry
183-
: selectedCurrency)
182+
? Locale.current.localizedString(forRegionCode: selectedCountry) ?? selectedCountry
183+
: selectedCurrency)
184184
}
185-
185+
186186
private func getKeysHandler(
187187
success: @escaping ((HyperwalletTransferMethodConfigurationKey?) -> Void),
188188
failure: (() -> Void)? = nil)
189-
-> (Result<HyperwalletTransferMethodConfigurationKey?, HyperwalletErrorType>) -> Void {
189+
-> (Result<HyperwalletTransferMethodConfigurationKey?, HyperwalletErrorType>) -> Void {
190190
return { [weak self] (result) in
191191
guard let strongSelf = self, let view = strongSelf.view else {
192192
return
193193
}
194-
194+
195195
switch result {
196196
case .failure(let error):
197197
view.showError(error, pageName: strongSelf.pageName, pageGroup: strongSelf.pageGroup, failure)
198-
198+
199199
case .success(let keyResult):
200200
success(keyResult)
201201
}
202202
}
203203
}
204-
204+
205205
/// Shows the Select Country View
206206
private func showSelectCountryView(_ countries: [GenericCellConfiguration]?) {
207207
if let countries = countries {
@@ -212,7 +212,7 @@ final class SelectTransferMethodTypePresenter {
212212
filterContentHandler: filterContentHandler())
213213
}
214214
}
215-
215+
216216
/// Shows the Select Currency View
217217
private func showSelectCurrencyView(_ currencies: [GenericCellConfiguration]?) {
218218
if let currencies = currencies {
@@ -223,7 +223,7 @@ final class SelectTransferMethodTypePresenter {
223223
filterContentHandler: filterContentHandler())
224224
}
225225
}
226-
226+
227227
private func selectCountryHandler() -> SelectTransferMethodTypeView.SelectItemHandler {
228228
return { (country) in
229229
if let country = country.value {
@@ -240,7 +240,7 @@ final class SelectTransferMethodTypePresenter {
240240
}))
241241
}
242242
}
243-
243+
244244
private func selectCurrencyHandler() -> SelectTransferMethodTypeView.SelectItemHandler {
245245
return { [weak self](currency) in
246246
guard let strongSelf = self
@@ -259,47 +259,47 @@ final class SelectTransferMethodTypePresenter {
259259

260260
private func retrieveTransferMethodTypesFeesAndProcessingTimes(
261261
completion: @escaping ([HyperwalletTransferMethodType]?) -> Void) {
262-
transferMethodConfigurationRepository
263-
.getTransferMethodTypesFeesAndProcessingTimes(country: selectedCountry,
264-
currency: selectedCurrency) { [weak self] (result) in
265-
guard let strongSelf = self, let view = strongSelf.view else {
266-
return
267-
}
268-
view.hideLoading()
269-
switch result {
270-
case .failure(let error):
271-
view.showError(error, pageName: strongSelf.pageName, pageGroup: strongSelf.pageGroup) {
272-
strongSelf.loadTransferMethodKeys()
262+
transferMethodConfigurationRepository
263+
.getTransferMethodTypesFeesAndProcessingTimes(country: selectedCountry,
264+
currency: selectedCurrency) { [weak self] (result) in
265+
guard let strongSelf = self, let view = strongSelf.view else {
266+
return
267+
}
268+
view.hideLoading()
269+
switch result {
270+
case .failure(let error):
271+
view.showError(error, pageName: strongSelf.pageName, pageGroup: strongSelf.pageGroup) {
272+
strongSelf.loadTransferMethodKeys()
273+
}
274+
275+
case .success(let keyResult):
276+
completion(keyResult?.transferMethodTypes(countryCode: strongSelf.selectedCountry,
277+
currencyCode: strongSelf.selectedCurrency))
273278
}
274-
275-
case .success(let keyResult):
276-
completion(keyResult?.transferMethodTypes(countryCode: strongSelf.selectedCountry,
277-
currencyCode: strongSelf.selectedCurrency))
278279
}
279-
}
280-
}
281-
280+
}
281+
282282
private func filterContentHandler() -> SelectTransferMethodTypeView.FilterContentHandler {
283283
return {(items, searchText) in
284284
items.filter {
285285
$0.title?.lowercased().contains(searchText.lowercased()) ?? false ||
286-
$0.value?.lowercased().contains(searchText.lowercased()) ?? false
286+
$0.value?.lowercased().contains(searchText.lowercased()) ?? false
287287
}
288288
}
289289
}
290-
290+
291291
private func countryMarkCellHandler() -> SelectTransferMethodTypeView.MarkCellHandler {
292292
return { [weak self] item in
293293
self?.selectedCountry == item.value
294294
}
295295
}
296-
296+
297297
private func currencyMarkCellHandler() -> SelectTransferMethodTypeView.MarkCellHandler {
298298
return { [weak self] item in
299299
self?.selectedCurrency == item.value
300300
}
301301
}
302-
302+
303303
private func loadSelectedCountry(_ countries: [HyperwalletCountry],
304304
with userCountry: String?) {
305305
if let userCountry = userCountry, countries.contains(where: { $0.value == userCountry }) {
@@ -308,17 +308,36 @@ final class SelectTransferMethodTypePresenter {
308308
selectedCountry = countryValue
309309
}
310310
}
311-
311+
312312
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))
313+
guard let countries = keys?.countries(),
314+
let country = countries.first(where: { $0.code == selectedCountry }),
315+
let currencyCode = getCurrencyCode(country, keys) else {
316+
// Handle the case when country is not found
317+
view?.showAlert(message:
318+
String(format: "no_currency_available_error_message".localized(), selectedCountry))
316319
return
317320
}
321+
322+
// Define selected currency
318323
selectedCurrency = currencyCode
324+
325+
// Reload the view with the updated currency data
319326
view?.reloadCountryCurrencyData()
320327
}
328+
329+
private func getCurrencyCode(_ country: HyperwalletCountry,
330+
_ keys: HyperwalletTransferMethodConfigurationKey?) -> String? {
331+
if let defaultCurrencyCode = country.defaultCurrencyCode,
332+
let defaultCurrency = keys?.currencies(from: selectedCountry)?
333+
.first(where: { $0.code == defaultCurrencyCode }) {
334+
// retun the country's default currency, if it present on the currency list
335+
return defaultCurrency.code
336+
}
321337

338+
return keys?.currencies(from: selectedCountry)?.first?.code
339+
}
340+
322341
private func loadTransferMethodTypesFeesAndProcessingTimes(
323342
_ transferMethodTypes: [HyperwalletTransferMethodType]?) {
324343
guard let transferMethodTypes = transferMethodTypes,

TransferMethod/Tests/Responses/TransferMethodConfigurationKeysResponse.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
{
191191
"code": "US",
192192
"name": "UNITED STATES",
193+
"defaultCurrencyCode": "USD",
193194
"currencies": {
194195
"nodes": [
195196
{

TransferMethod/Tests/SelectTransferMethodTypePresenterTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ class SelectTransferMethodTypePresenterTests: XCTestCase {
227227

228228
// Then
229229
XCTAssertEqual(presenter.selectedCountry, "US", "The country should be US")
230-
XCTAssertEqual(presenter.selectedCurrency, "CAD", "The currency should be CAD")
230+
XCTAssertEqual(presenter.selectedCurrency, "USD", "The currency should be CAD")
231231
XCTAssertTrue(mockView.isNavigateToAddTransferMethodControllerPerformed,
232232
"The navigateToAddTransferMethodControllerPerformed should be performed")
233233

234234
XCTAssertEqual(mockView.profileType, "INDIVIDUAL", "The profileType should be INDIVIDUAL")
235235
XCTAssertEqual(presenter.countryCurrencySectionData.count, 2, "The countryCurrencyCount should be 2")
236-
XCTAssertEqual(presenter.sectionData.count, 1, "The transferMethodTypesCount should be 1")
236+
XCTAssertEqual(presenter.sectionData.count, 3, "The transferMethodTypesCount should be 3")
237237
XCTAssertTrue(hyperwalletInsightsMock.didTrackClick, "HyperwalletInsights.trackClick should be called")
238238
XCTAssertNotNil(presenter.getCountryCurrencyConfiguration(indexPath: indexPath),
239239
"The country currency cell configuration should not be nil")

0 commit comments

Comments
 (0)