• 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

96.83
/Transfer/Sources/ScheduleTransferPresenter.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
#if !COCOAPODS
20
import Common
21
import TransferMethodRepository
22
import TransferRepository
23
#endif
24
import HyperwalletSDK
25

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

37
final class ScheduleTransferPresenter {
38
    private weak var view: ScheduleTransferView?
39
    private(set) var sectionData = [ScheduleTransferSectionData]()
7✔
40
    private var transferMethod: HyperwalletTransferMethod
41
    private var transfer: HyperwalletTransfer
42
    private var didFxQuoteChange: Bool
43
    private let pageName = "transfer-funds:review-transfer"
44
    private let pageGroup = "transfer-funds"
45
    private var transferSourceCellConfiguration: TransferSourceCellConfiguration
46

47
    /// Initialize ScheduleTransferPresenter
48
    init(
49
        view: ScheduleTransferView,
50
        transferMethod: HyperwalletTransferMethod,
51
        transfer: HyperwalletTransfer,
52
        didFxQuoteChange: Bool,
53
        transferSourceCellConfiguration: TransferSourceCellConfiguration) {
7✔
54
        self.view = view
7✔
55
        self.transferMethod = transferMethod
7✔
56
        self.transfer = transfer
7✔
57
        self.didFxQuoteChange = didFxQuoteChange
7✔
58
        self.transferSourceCellConfiguration = transferSourceCellConfiguration
7✔
59
        initializeSections()
7✔
60
    }
7✔
61

62
    private lazy var transferRepository = {
2✔
63
        TransferRepositoryFactory.shared.transferRepository()
2✔
64
    }()
2✔
65

66
    private func initializeSections() {
7✔
67
        sectionData.removeAll()
7✔
68

7✔
69
        let confirmTransferSourceSection =
7✔
70
            ScheduleTransferSectionSourceData(transferSourceCellConfiguration: transferSourceCellConfiguration)
7✔
71
        sectionData.append(confirmTransferSourceSection)
7✔
72

7✔
73
        let confirmTransferDestinationSection = ScheduleTransferDestinationData(transferMethod: transferMethod)
7✔
74
        sectionData.append(confirmTransferDestinationSection)
7✔
75

7✔
76
        if let foreignExchanges = transfer.foreignExchanges {
7✔
77
            let scheduleTransferForeignExchangesSection =
6✔
78
                ScheduleTransferForeignExchangeData(foreignExchanges: foreignExchanges)
6✔
79
            sectionData.append(scheduleTransferForeignExchangesSection)
6✔
80
        }
7✔
81

7✔
82
        let scheduleTransferSummaryData = ScheduleTransferSummaryData(
7✔
83
            transfer: transfer,
7✔
84
            didFxQuoteChange: didFxQuoteChange)
7✔
85
        sectionData.append(scheduleTransferSummaryData)
7✔
86

7✔
87
        if let scheduleTransferNotesData = ScheduleTransferNotesData(transfer: transfer) {
7✔
88
            sectionData.append(scheduleTransferNotesData)
6✔
89
        }
7✔
90

7✔
91
        let scheduleTransferButtonData = ScheduleTransferButtonData()
7✔
92
        sectionData.append(scheduleTransferButtonData)
7✔
93
    }
7✔
94

95
    func scheduleTransfer() {
4✔
96
        view?.showLoading()
4✔
97
        transferRepository.scheduleTransfer(transfer) { [weak self] (result) in
4✔
98
            guard let strongSelf = self, let view = strongSelf.view else {
4✔
99
                return
×
100
            }
4✔
101
            view.hideLoading()
4✔
102
            switch result {
4✔
103
            case .failure(let error):
4✔
104
                view.showError(error, pageName: strongSelf.pageName, pageGroup: strongSelf.pageGroup) {
2✔
105
                    strongSelf.scheduleTransfer()
2✔
106
                }
2✔
107

4✔
108
            case .success(let resultStatusTransition):
4✔
109
                guard let statusTransition = resultStatusTransition else {
2✔
110
                    return
×
111
                }
2✔
112
                view.showConfirmation(handler: { () -> Void in
2✔
113
                    view.notifyTransferScheduled(statusTransition)
2✔
114
                })
2✔
115
            }
4✔
116
        }
4✔
117
    }
4✔
118
}
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