Skip to content

Commit c1e8e00

Browse files
author
guillaumedebavelaere
committed
Cimb - Yahoo screen - Implements trading 1FA
1 parent ece3666 commit c1e8e00

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

ExampleApp/AppDelegate.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
219219

220220
private func handleExampleVerify1FA(verify1FACallbackUrl: URL, host: String) {
221221
let VERIFY_1FA = "complete1FA"
222+
let YAHOO_HOST = "completeYahoo1FA"
222223
if var topViewController = UIApplication.shared.keyWindow?.rootViewController {
223224
while let presentedViewController = topViewController.presentedViewController {
224225
topViewController = presentedViewController
@@ -235,6 +236,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
235236
onTopmostViewController: topViewController,
236237
verify1FACallbackUrl: verify1FACallbackUrl
237238
)
239+
case YAHOO_HOST:
240+
TradeItSDK.yahooLauncher.handleVerify1FACallback(
241+
onTopmostViewController: topViewController,
242+
verify1FACallbackUrl: verify1FACallbackUrl
243+
)
238244
default:
239245
print("=====> ERROR: Received unknown verify 1 FA callback URL host: \(host)")
240246
}

TradeItIosTicketSDK2/TradeItYahooLauncher.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,31 @@ import SafariServices
9898
}
9999
}
100100

101+
public func handleVerify1FACallback(
102+
onTopmostViewController topMostViewController: UIViewController,
103+
verify1FACallbackUrl: URL
104+
) {
105+
print("=====> handleVerify1FACallback: \(verify1FACallbackUrl.absoluteString)")
106+
107+
var originalViewController: UIViewController?
108+
109+
// Check for the OAuth "popup" screen
110+
if topMostViewController is SFSafariViewController {
111+
originalViewController = topMostViewController.presentingViewController
112+
}
113+
114+
if let tradeItYahooTradePreviewViewController = originalViewController?.childViewControllers.last as? TradeItYahooTradePreviewViewController {
115+
if let originalViewController = originalViewController {
116+
originalViewController.dismiss(
117+
animated: true,
118+
completion: {
119+
tradeItYahooTradePreviewViewController.handleTradeSecurityResponse()
120+
}
121+
)
122+
}
123+
}
124+
}
125+
101126
public func launchTrading(
102127
fromViewController viewController: UIViewController,
103128
withOrder order: TradeItOrder,

TradeItIosTicketSDK2/TradeItYahooTradePreviewViewController.swift

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,10 @@ class TradeItYahooTradePreviewViewController: TradeItYahooViewController, UITabl
109109

110110
self.fireViewEventNotification(view: .submitted)
111111
},
112-
{ securityQuestion, answerSecurityQuestion, cancelSecurityQuestion in
113-
self.alertManager.promptUserToAnswerSecurityQuestion(
114-
securityQuestion,
115-
onViewController: self,
116-
onAnswerSecurityQuestion: answerSecurityQuestion,
117-
onCancelSecurityQuestion: cancelSecurityQuestion
118-
)
112+
{ url, complete1FA in
113+
self.tradeSecurityHandler = complete1FA
114+
let safariViewController = SFSafariViewController(url: url)
115+
self.present(safariViewController, animated: true, completion: nil)
119116
},
120117
{ errorResult in
121118
activityView.hide(animated: true)
@@ -240,7 +237,20 @@ class TradeItYahooTradePreviewViewController: TradeItYahooViewController, UITabl
240237
}
241238

242239
// MARK: Private
243-
240+
241+
private var tradeSecurityHandler: (() -> Void)?
242+
internal func handleTradeSecurityResponse() {
243+
if let tradeSecurityHandler = self.tradeSecurityHandler {
244+
tradeSecurityHandler()
245+
} else {
246+
return self.alertManager.showError(
247+
TradeItErrorResult.tradeError(withSystemMessage: "Trade could not be submitted please try again."),
248+
onViewController: self
249+
)
250+
}
251+
252+
}
253+
244254
private func updatePlaceOrderButtonStatus() {
245255
if allAcknowledgementsAccepted() {
246256
self.actionButton.enable()

0 commit comments

Comments
 (0)