Skip to content

Commit

Permalink
MOB-2043 - Handle email in activate mpc wallet deep link event (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg-Pecheneg authored May 27, 2024
1 parent 48e14fd commit 9d68774
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ extension ActivateMPCWalletFlow {

enum FlowResult {
case activated(UDWallet)
case restart
}

static let viewsTopOffset: CGFloat = 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ActivateMPCWalletRootView: View {
var body: some View {
NavigationViewWithCustomTitle(content: {
ZStack {
MPCEnterCredentialsInAppView()
MPCEnterCredentialsInAppView(preFilledEmail: viewModel.preFilledEmail)
.environmentObject(viewModel)
.navigationBarTitleDisplayMode(.inline)
.navigationDestination(for: ActivateMPCWalletFlow.NavigationDestination.self) { destination in
Expand All @@ -39,8 +39,10 @@ struct ActivateMPCWalletRootView: View {
.allowsHitTesting(!viewModel.isLoading)
}

init(activationResultCallback: @escaping ActivateMPCWalletFlow.FlowResultCallback) {
self._viewModel = StateObject(wrappedValue: ActivateMPCWalletViewModel(activationResultCallback: activationResultCallback))
init(preFilledEmail: String?,
activationResultCallback: @escaping ActivateMPCWalletFlow.FlowResultCallback) {
self._viewModel = StateObject(wrappedValue: ActivateMPCWalletViewModel(preFilledEmail: preFilledEmail,
activationResultCallback: activationResultCallback))
}
}

Expand All @@ -55,5 +57,6 @@ private extension ActivateMPCWalletRootView {
}

#Preview {
ActivateMPCWalletRootView(activationResultCallback: { _ in })
ActivateMPCWalletRootView(preFilledEmail: nil,
activationResultCallback: { _ in })
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ import SwiftUI
@MainActor
final class ActivateMPCWalletViewModel: ObservableObject {

let preFilledEmail: String?
let activationResultCallback: ActivateMPCWalletFlow.FlowResultCallback
@Published var navPath: [ActivateMPCWalletFlow.NavigationDestination] = []
@Published var navigationState: NavigationStateManager?
@Published var isLoading = false
@Published var error: Error?
private var credentials: MPCActivateCredentials?

init(activationResultCallback: @escaping ActivateMPCWalletFlow.FlowResultCallback) {
init(preFilledEmail: String?,
activationResultCallback: @escaping ActivateMPCWalletFlow.FlowResultCallback) {
self.preFilledEmail = preFilledEmail
self.activationResultCallback = activationResultCallback
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import SwiftUI
struct MPCEnterCredentialsInAppView: View {

@EnvironmentObject var viewModel: ActivateMPCWalletViewModel


let preFilledEmail: String?

var body: some View {
MPCEnterCredentialsView(analyticsName: .mpcEnterCredentialsInApp,
MPCEnterCredentialsView(mode: preFilledEmail == nil ? .freeInput : .strictEmail(preFilledEmail!),
analyticsName: .mpcEnterCredentialsInApp,
credentialsCallback: didEnterCredentials)
.padding(.top, ActivateMPCWalletFlow.viewsTopOffset)
}
Expand All @@ -26,5 +29,5 @@ private extension MPCEnterCredentialsInAppView {
}

#Preview {
MPCEnterCredentialsInAppView()
MPCEnterCredentialsInAppView(preFilledEmail: nil)
}
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ private extension SettingsView {
connectNewWallet()
case .createNewWallet:
createNewWallet()
case .activateMPC:
activateMPCWallet()
case .activateMPC(let preFilledEmail):
activateMPCWallet(preFilledEmail: preFilledEmail)
}
}

Expand Down Expand Up @@ -545,7 +545,7 @@ private extension SettingsView {
case .connect:
connectNewWallet()
case .mpc:
activateMPCWallet()
activateMPCWallet(preFilledEmail: nil)
}
}
}
Expand Down Expand Up @@ -578,24 +578,18 @@ private extension SettingsView {
}
}

func activateMPCWallet() {
func activateMPCWallet(preFilledEmail: String?) {
guard udFeatureFlagsService.valueFor(flag: .isMPCWalletEnabled),
let view = appContext.coreAppCoordinator.topVC else { return }

UDRouter().showActivateMPCWalletScreen(activationResultCallback: handleMPCActivationResult, in: view)
UDRouter().showActivateMPCWalletScreen(preFilledEmail: preFilledEmail,
activationResultCallback: handleMPCActivationResult, in: view)
}

func handleMPCActivationResult(_ result: ActivateMPCWalletFlow.FlowResult) {
switch result {
case .activated(let wallet):
addWalletAfterAdded(wallet)
case .restart:
Task {
guard let view = appContext.coreAppCoordinator.topVC else { return }

await view.presentingViewController?.dismiss(animated: true)
activateMPCWallet()
}
}
}

Expand Down Expand Up @@ -630,7 +624,7 @@ private extension SettingsView {
extension SettingsView {
enum InitialAction {
case none
case importWallet, connectWallet, createNewWallet, activateMPC
case importWallet, connectWallet, createNewWallet, activateMPC(preFilledEmail: String?)
case showAllAddWalletOptionsPullUp, showImportWalletOptionsPullUp
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ private extension CoreAppCoordinator {
Task { await router.showDomainProfile(domain, wallet: wallet, preRequestedAction: action) }
case .showPublicDomainProfile(let publicDomainDisplayInfo, let wallet, let action):
Task { await router.showPublicDomainProfileFromDeepLink(of: publicDomainDisplayInfo, by: wallet, preRequestedAction: action) }
case .activateMPCWallet:
router.runAddWalletFlow(initialAction: .activateMPC)
case .activateMPCWallet(let email):
router.runAddWalletFlow(initialAction: .activateMPC(preFilledEmail: email))
}
default: return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ extension DeepLinksService: DeepLinksServiceProtocol {
}
} else if let domainName = DomainProfileLinkValidator.getUDmeDomainName(in: components) {
tryHandleUDDomainProfileDeepLink(domainName: domainName, params: components.queryItems, receivedState: receivedState)
} else if isActivateMPCWalletDeepLink(components: components) {
notifyWaitersWith(event: .activateMPCWallet,
receivedState: receivedState)
} else if tryHandleActivateMPCWalletDeepLink(components: components,
receivedState: receivedState) {
return
} else {
tryHandleWCDeepLink(from: components, incomingURL: incomingURL, receivedState: receivedState)
}
Expand Down Expand Up @@ -194,14 +194,18 @@ private extension DeepLinksService {
receivedState: receivedState)
}

func isActivateMPCWalletDeepLink(components: NSURLComponents) -> Bool {
func tryHandleActivateMPCWalletDeepLink(components: NSURLComponents,
receivedState: ExternalEventReceivedState) -> Bool {
guard let path = components.path,
let host = components.host else { return false }

let pathComponents = path.components(separatedBy: "/")

if Constants.udMeHosts.contains(host),
pathComponents.last == ud_me_MPC_path {
let email = components.queryItems?.first(where: { $0.name == "email" })?.value
notifyWaitersWith(event: .activateMPCWallet(email: email),
receivedState: receivedState)
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum DeepLinkEvent: Equatable {
case mintDomainsVerificationCode(email: String, code: String)
case showUserDomainProfile(domain: DomainDisplayInfo, wallet: WalletEntity, action: PreRequestedProfileAction?)
case showPublicDomainProfile(publicDomainDisplayInfo: PublicDomainDisplayInfo, wallet: WalletEntity, action: PreRequestedProfileAction?)
case activateMPCWallet
case activateMPCWallet(email: String?)
}

protocol DeepLinksServiceProtocol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,11 @@ class UDRouter: DomainProfileSignatureValidator {
viewController.present(vc, animated: true)
}

func showActivateMPCWalletScreen(activationResultCallback: @escaping ActivateMPCWalletFlow.FlowResultCallback,
func showActivateMPCWalletScreen(preFilledEmail: String?,
activationResultCallback: @escaping ActivateMPCWalletFlow.FlowResultCallback,
in viewController: UIViewController) {
let view = ActivateMPCWalletRootView(activationResultCallback: activationResultCallback)
let view = ActivateMPCWalletRootView(preFilledEmail: preFilledEmail,
activationResultCallback: activationResultCallback)
let vc = UIHostingController(rootView: view)
viewController.present(vc, animated: true)
}
Expand Down

0 comments on commit 9d68774

Please sign in to comment.