• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hyperwallet / hyperwallet-ios-ui-sdk / 4735069856

pending completion
4735069856

push

github

Gustavo Meyer
DTPOMERSER-84 - Address swift lint

2255 of 2353 relevant lines covered (95.84%)

17.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.08
/TransferMethod/Sources/ListTransferMethodPresenter.swift
1
//
2
// Copyright 2018 - Present Hyperwallet
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5
// and associated documentation files (the "Software"), to deal in the Software without restriction,
6
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
7
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in all copies or
11
// substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
14
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18

19
import HyperwalletSDK
20
#if !COCOAPODS
21
import Common
22
import TransferMethodRepository
23
#endif
24

25
protocol ListTransferMethodView: AnyObject {
26
    func showLoading()
27
    func hideLoading()
28
    func showProcessing()
29
    func dismissProcessing(handler: @escaping () -> Void)
30
    func showConfirmation(handler: @escaping (() -> Void))
31
    func reloadData()
32
    func notifyTransferMethodDeactivated(_ hyperwalletStatusTransition: HyperwalletStatusTransition)
33
    func showError(_ error: HyperwalletErrorType,
34
                   pageName: String,
35
                   pageGroup: String,
36
                   _ retry: (() -> Void)?)
37
}
38

39
final class ListTransferMethodPresenter {
40
    private weak var view: ListTransferMethodView?
41
    private let pageGroup = "transfer-method"
42
    private let pageName = "transfer-method:add:list-transfer-method"
43
    private (set) var sectionData = [HyperwalletTransferMethod]()
12✔
44
    private lazy var transferMethodRepository = {
12✔
45
        TransferMethodRepositoryFactory.shared.transferMethodRepository()
12✔
46
    }()
12✔
47

48
    /// Initialize ListTransferMethodPresenter
49
    init(view: ListTransferMethodView) {
12✔
50
        self.view = view
12✔
51
    }
12✔
52

53
    func deactivateTransferMethod(at index: Int) {
9✔
54
        if transferMethodExists(at: index) {
9✔
55
            deactivateTransferMethod(sectionData[index])
9✔
56
        }
9✔
57
    }
9✔
58

59
    func showUpdateTransferMethod(at index: Int, parentController: UIViewController) {
×
60
        if transferMethodExists(at: index),
×
61
        let token = sectionData[index].token {
×
62
            let coordinator = HyperwalletUI.shared
×
63
                    .updateTransferMethodCoordinator(token, parentController: parentController)
×
64
            coordinator.navigate()
×
65
        }
×
66
    }
×
67

68
    /// Deactivate the selected Transfer Method
69
    private func deactivateTransferMethod(_ transferMethod: HyperwalletTransferMethod) {
159✔
70
        view?.showProcessing()
159✔
71

159✔
72
        transferMethodRepository.deactivateTransferMethod(transferMethod) { [weak self] (result) in
159✔
73
            guard let strongSelf = self, let view = strongSelf.view else {
157✔
74
                return
×
75
            }
157✔
76

157✔
77
            switch result {
157✔
78
            case .failure(let error):
157✔
79
                view.dismissProcessing(handler: {
150✔
80
                    view.showError(error, pageName: strongSelf.pageName, pageGroup: strongSelf.pageGroup) {
150✔
81
                        strongSelf.deactivateTransferMethod(transferMethod)
150✔
82
                    }
150✔
83
                })
150✔
84

157✔
85
            case .success(let resultStatusTransition):
157✔
86
                guard let statusTransition = resultStatusTransition else {
7✔
87
                    return
×
88
                }
7✔
89
                view.showConfirmation(handler: { () -> Void in
7✔
90
                    strongSelf.listTransferMethods(true)
7✔
91
                    view.notifyTransferMethodDeactivated(statusTransition)
7✔
92
                })
7✔
93
            }
157✔
94
        }
157✔
95
    }
159✔
96

97
    /// Get the list of all Activated transfer methods from core SDK
98
    /// - Parameter forceUpdate: Forces to refresh the data
99
    func listTransferMethods(_ forceUpdate: Bool = true) {
22✔
100
        view?.showLoading()
22✔
101
        if forceUpdate {
22✔
102
            transferMethodRepository.refreshTransferMethods()
22✔
103
        }
22✔
104

22✔
105
        transferMethodRepository.listTransferMethods { [weak self] (result) in
22✔
106
            guard let strongSelf = self, let view = strongSelf.view else {
22✔
107
                return
×
108
            }
22✔
109
            view.hideLoading()
22✔
110

22✔
111
            switch result {
22✔
112
            case .failure(let error):
22✔
113
                view.showError(error, pageName: strongSelf.pageName, pageGroup: strongSelf.pageGroup) {
3✔
114
                    strongSelf.listTransferMethods()
3✔
115
                }
3✔
116

22✔
117
            case .success(let resultPageList):
22✔
118
                if let data = resultPageList?.data {
19✔
119
                    strongSelf.sectionData = data
18✔
120
                } else {
19✔
121
                    strongSelf.sectionData = []
1✔
122
                }
19✔
123

19✔
124
                view.reloadData()
19✔
125
            }
22✔
126
        }
22✔
127
    }
22✔
128

129
    func transferMethodExists(at index: Int) -> Bool {
12✔
130
        return sectionData.indices.contains(index)
12✔
131
    }
12✔
132
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc