-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57806b0
commit 62043ef
Showing
12 changed files
with
183 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import UIKit | ||
|
||
protocol Web3PopupViewController: UIViewController { | ||
|
||
var onDismiss: (() -> Void)? { get set } | ||
|
||
func reject() | ||
|
||
} | ||
|
||
struct Web3PopupCoordinator { | ||
|
||
private class AlertController: UIAlertController { | ||
|
||
var onDismiss: (() -> Void)? | ||
|
||
override func viewDidDisappear(_ animated: Bool) { | ||
super.viewDidDisappear(animated) | ||
onDismiss?() | ||
} | ||
|
||
} | ||
|
||
enum Popup { | ||
case unlock(UnlockWeb3WalletViewController) | ||
case request(Web3PopupViewController) | ||
case rejection(title: String, message: String) | ||
} | ||
|
||
private static var popups: [Popup] = [] | ||
|
||
static func enqueue(popup: Popup) { | ||
popups.append(popup) | ||
if popups.count == 1 { | ||
presentNextPopupIfNeeded() | ||
} | ||
} | ||
|
||
static func rejectAllPopups() { | ||
for popup in popups { | ||
switch popup { | ||
case .request(let controller): | ||
controller.reject() | ||
case .unlock, .rejection: | ||
break | ||
} | ||
} | ||
popups = [] | ||
} | ||
|
||
private static func presentNextPopupIfNeeded() { | ||
guard let container = UIApplication.homeContainerViewController else { | ||
return | ||
} | ||
guard let popup = popups.first else { | ||
return | ||
} | ||
let viewController: UIViewController | ||
switch popup { | ||
case .unlock(let controller): | ||
// TODO: Tell user subsequent request will fail if not approved | ||
controller.onDismiss = { | ||
popups.removeFirst() | ||
if controller.isUnlocked { | ||
presentNextPopupIfNeeded() | ||
} else { | ||
rejectAllPopups() | ||
} | ||
} | ||
viewController = controller | ||
case .request(let controller): | ||
controller.onDismiss = { | ||
popups.removeFirst() | ||
presentNextPopupIfNeeded() | ||
} | ||
viewController = controller | ||
case .rejection(let title, let message): | ||
let alert = AlertController(title: title, message: message, preferredStyle: .alert) | ||
alert.addAction(UIAlertAction(title: R.string.localizable.ok(), style: .cancel)) | ||
alert.onDismiss = { | ||
popups.removeFirst() | ||
presentNextPopupIfNeeded() | ||
} | ||
viewController = alert | ||
} | ||
container.presentOnTopMostPresentedController(viewController, animated: true) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.