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

hyperwallet / hyperwallet-ios-ui-sdk / 5360366649

pending completion
5360366649

push

github

web-flow
Rename polaris.yaml to polaris.yml (#345)

2252 of 2341 relevant lines covered (96.2%)

20.52 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) {
308✔
70
        view?.showProcessing()
308✔
71

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

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

304✔
85
            case .success(let resultStatusTransition):
304✔
86
                guard let statusTransition = resultStatusTransition else {
5✔
87
                    return
×
88
                }
5✔
89
                view.showConfirmation(handler: { () -> Void in
5✔
90
                    strongSelf.listTransferMethods(true)
5✔
91
                    view.notifyTransferMethodDeactivated(statusTransition)
5✔
92
                })
5✔
93
            }
304✔
94
        }
304✔
95
    }
308✔
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) {
23✔
100
        view?.showLoading()
23✔
101
        if forceUpdate {
23✔
102
            transferMethodRepository.refreshTransferMethods()
23✔
103
        }
23✔
104

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

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

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

17✔
124
                view.reloadData()
17✔
125
            }
23✔
126
        }
23✔
127
    }
23✔
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