diff --git a/Permanent/Modules/Authentication/Screens/VerifyIdentity/AuthVerifyIdentityViewModel.swift b/Permanent/Modules/Authentication/Screens/VerifyIdentity/AuthVerifyIdentityViewModel.swift index 53e566d2..9a20471e 100644 --- a/Permanent/Modules/Authentication/Screens/VerifyIdentity/AuthVerifyIdentityViewModel.swift +++ b/Permanent/Modules/Authentication/Screens/VerifyIdentity/AuthVerifyIdentityViewModel.swift @@ -29,17 +29,18 @@ class AuthVerifyIdentityViewModel: ObservableObject { return } containerViewModel.isLoading = true - AuthenticationManager.shared.verify2FA(code: pinCode) { result in + AuthenticationManager.shared.verify2FA(code: pinCode) {[weak self] result in DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { - self.digitsDisabled = false + self?.digitsDisabled = false } - self.containerViewModel.isLoading = false + self?.containerViewModel.isLoading = false switch result { case .success: handler(.success) + self?.trackLoginEvent() case .error(_): - self.pinCode = "" - self.containerViewModel.displayErrorBanner(bannerErrorMessage: .invalidPinCode) + self?.pinCode = "" + self?.containerViewModel.displayErrorBanner(bannerErrorMessage: .invalidPinCode) handler(.invalidPinCode) } } @@ -63,4 +64,13 @@ class AuthVerifyIdentityViewModel: ObservableObject { } } } + + func trackLoginEvent() { + guard let accountId = AuthenticationManager.shared.session?.account.accountID, + let payload = EventsPayloadBuilder.build(accountId: accountId, + eventAction: AccountEventAction.login, + entityId: String(accountId)) else { return } + let updateAccountOperation = APIOperation(EventsEndpoint.sendEvent(eventsPayload: payload)) + updateAccountOperation.execute(in: APIRequestDispatcher()) {_ in} + } }