-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow user to switch between accounts when the account number is ente…
…red instead of voucher code
- Loading branch information
Showing
17 changed files
with
496 additions
and
133 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
59 changes: 0 additions & 59 deletions
59
ios/MullvadVPN/Coordinators/AccountRedeemingVoucherCoordinator.swift
This file was deleted.
Oops, something went wrong.
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
115 changes: 115 additions & 0 deletions
115
ios/MullvadVPN/Coordinators/CreateAccountVoucherCoordinator.swift
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,115 @@ | ||
// | ||
// CreateAccountVoucherCoordinator.swift | ||
// MullvadVPN | ||
// | ||
// Created by Mojgan on 2023-07-03. | ||
// Copyright © 2023 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import MullvadREST | ||
import Routing | ||
import UIKit | ||
|
||
public class CreateAccountVoucherCoordinator: Coordinator, Presentable { | ||
private let navigationController: RootContainerViewController | ||
private let viewController: RedeemVoucherViewController | ||
private let interactor: CreateAccountVoucherInteractor | ||
|
||
private var accountNumber: String? | ||
private lazy var accountNumberInputErrorView = { | ||
VerifiedAccountView { | ||
self.logout() | ||
} | ||
}() | ||
|
||
var didFinish: ((CreateAccountVoucherCoordinator) -> Void)? | ||
var didCancel: ((CreateAccountVoucherCoordinator) -> Void)? | ||
var didLogout: ((CreateAccountVoucherCoordinator) -> Void)? | ||
|
||
/** | ||
Name of notification posted when current account number changes. | ||
*/ | ||
static let didChangePreferredAccountNumber = Notification | ||
.Name(rawValue: "CreateAccountVoucherCoordinatorDidChangeAccountNumber") | ||
|
||
/** | ||
User info key passed along with `didChangePreferredAccountNumber` notification that contains string value that | ||
indicates the new account number. | ||
*/ | ||
static let preferredAccountNumberUserInfoKey = "preferredAccountNumber" | ||
|
||
public var presentedViewController: UIViewController { | ||
viewController | ||
} | ||
|
||
init( | ||
navigationController: RootContainerViewController, | ||
tunnelManager: TunnelManager, | ||
accountsProxy: REST.AccountsProxy | ||
) { | ||
self.navigationController = navigationController | ||
interactor = CreateAccountVoucherInteractor(tunnelManager: tunnelManager, accountsProxy: accountsProxy) | ||
viewController = RedeemVoucherViewController(interactor: interactor) | ||
} | ||
|
||
func start() { | ||
viewController.delegate = self | ||
interactor.didInputAccountNumber = { [weak self] value in | ||
guard let self else { return } | ||
accountNumberInputErrorView.fadeIn() | ||
accountNumber = value | ||
} | ||
navigationController.pushViewController(viewController, animated: true) | ||
} | ||
|
||
private func logout() { | ||
let alertController = CustomAlertViewController(icon: .spinner) | ||
presentedViewController.present(alertController, animated: true, completion: { | ||
self.interactor.logout { [weak self] in | ||
alertController.dismiss(animated: true, completion: { | ||
self?.accountNumber.flatMap { | ||
guard let self else { return } | ||
self.didLogout?(self) | ||
self.notify(accountNumber: $0) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
/// Posts `didChangePreferredAccountNumber` notification. | ||
private func notify(accountNumber: String) { | ||
NotificationCenter.default.post( | ||
name: Self.didChangePreferredAccountNumber, | ||
object: self, | ||
userInfo: [Self.preferredAccountNumberUserInfoKey: accountNumber] | ||
) | ||
} | ||
} | ||
|
||
extension CreateAccountVoucherCoordinator: RedeemVoucherViewControllerDelegate { | ||
func redeemVoucherDidSucceed(_ controller: RedeemVoucherViewController, with response: REST.SubmitVoucherResponse) { | ||
let coordinator = AddCreditSucceededCoordinator( | ||
purchaseType: .redeemingVoucher, | ||
timeAdded: response.timeAdded, | ||
navigationController: navigationController | ||
) | ||
|
||
coordinator.didFinish = { [weak self] coordinator in | ||
coordinator.removeFromParent() | ||
guard let self else { return } | ||
didFinish?(self) | ||
} | ||
|
||
addChild(coordinator) | ||
coordinator.start() | ||
} | ||
|
||
func redeemVoucherDidCancel(_ controller: RedeemVoucherViewController) { | ||
didCancel?(self) | ||
} | ||
|
||
func viewForInputingAccountNumberAsVoucher(_ controller: RedeemVoucherViewController) -> UIView? { | ||
accountNumberInputErrorView | ||
} | ||
} |
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
Oops, something went wrong.