Skip to content

Commit

Permalink
hook login metrics correctly and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jrainville committed Jan 28, 2025
1 parent 7d042fe commit 67a41aa
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
38 changes: 20 additions & 18 deletions src/app/modules/onboarding/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export io_interface
logScope:
topics = "onboarding-module"

type SecondaryFlow* {.pure} = enum
type OnboardingFlow* {.pure} = enum
Unknown = 0,
CreateProfileWithPassword,
CreateProfileWithSeedphrase,
Expand All @@ -30,9 +30,9 @@ type SecondaryFlow* {.pure} = enum
LoginWithSeedphrase,
LoginWithSyncing,
LoginWithKeycard,
ActualLogin, # TODO get the real name and value for this when it's implemented on the front-end

type LoginMethod* {.pure} = enum
Unknown = 0,
Password,
Keycard,

Expand All @@ -49,7 +49,7 @@ type
controller: Controller
localPairingStatus: LocalPairingStatus
loginFlow: LoginMethod
currentFlow: SecondaryFlow
onboardingFlow: OnboardingFlow
exportedKeys: KeycardExportedKeysDto

proc newModule*[T](
Expand All @@ -64,6 +64,8 @@ proc newModule*[T](
result.delegate = delegate
result.view = view.newView(result)
result.viewVariant = newQVariant(result.view)
result.onboardingFlow = OnboardingFlow.Unknown
result.loginFlow = LoginMethod.Unknown
result.controller = controller.newController(
result,
events,
Expand Down Expand Up @@ -136,26 +138,26 @@ method loadMnemonic*[T](self: Module[T], mnemonic: string) =

method finishOnboardingFlow*[T](self: Module[T], flowInt: int, dataJson: string): string =
try:
self.currentFlow = SecondaryFlow(flowInt)
self.onboardingFlow = OnboardingFlow(flowInt)

let data = parseJson(dataJson)
let password = data["password"].str
let seedPhrase = data["seedphrase"].str

var err = ""

case self.currentFlow:
case self.onboardingFlow:
# CREATE PROFILE FLOWS
of SecondaryFlow.CreateProfileWithPassword:
of OnboardingFlow.CreateProfileWithPassword:
err = self.controller.createAccountAndLogin(password)
of SecondaryFlow.CreateProfileWithSeedphrase:
of OnboardingFlow.CreateProfileWithSeedphrase:
err = self.controller.restoreAccountAndLogin(
password,
seedPhrase,
recoverAccount = false,
keycardInstanceUID = "",
)
of SecondaryFlow.CreateProfileWithKeycardNewSeedphrase:
of OnboardingFlow.CreateProfileWithKeycardNewSeedphrase:
# New user with a seedphrase we showed them
let keycardEvent = self.view.getKeycardEvent()
err = self.controller.restoreAccountAndLogin(
Expand All @@ -164,7 +166,7 @@ method finishOnboardingFlow*[T](self: Module[T], flowInt: int, dataJson: string)
recoverAccount = false,
keycardInstanceUID = keycardEvent.keycardInfo.instanceUID,
)
of SecondaryFlow.CreateProfileWithKeycardExistingSeedphrase:
of OnboardingFlow.CreateProfileWithKeycardExistingSeedphrase:
# New user who entered their own seed phrase
let keycardEvent = self.view.getKeycardEvent()
err = self.controller.restoreAccountAndLogin(
Expand All @@ -175,29 +177,29 @@ method finishOnboardingFlow*[T](self: Module[T], flowInt: int, dataJson: string)
)

# LOGIN FLOWS
of SecondaryFlow.LoginWithSeedphrase:
of OnboardingFlow.LoginWithSeedphrase:
err = self.controller.restoreAccountAndLogin(
password,
seedPhrase,
recoverAccount = true,
keycardInstanceUID = "",
)
of SecondaryFlow.LoginWithSyncing:
of OnboardingFlow.LoginWithSyncing:
# The pairing was already done directly through inputConnectionStringForBootstrapping, we can login
self.controller.loginLocalPairingAccount(
self.localPairingStatus.account,
self.localPairingStatus.password,
self.localPairingStatus.chatKey,
)
of SecondaryFlow.LoginWithKeycard:
of OnboardingFlow.LoginWithKeycard:
err = self.controller.restoreKeycardAccountAndLogin(
self.view.getKeycardEvent().keycardInfo.keyUID,
self.view.getKeycardEvent().keycardInfo.instanceUID,
self.exportedKeys,
recoverAccount = true
)
else:
raise newException(ValueError, "Unknown flow: " & $self.currentFlow)
raise newException(ValueError, "Unknown flow: " & $self.onboardingFlow)

return err
except Exception as e:
Expand All @@ -218,20 +220,20 @@ method loginRequested*[T](self: Module[T], keyUid: string, loginFlow: int, dataJ
self.authorize(data["pin"].str)
# We will continue the flow when the card is authorized in onKeycardStateUpdated
else:
raise newException(ValueError, "Unknown flow: " & $self.currentFlow)
raise newException(ValueError, "Unknown flow: " & $self.onboardingFlow)

except Exception as e:
error "Error finishing Onboarding Flow", msg = e.msg
error "Error finishing Login Flow", msg = e.msg
self.view.accountLoginFailed(e.msg, wrongPassword = false)

proc finishAppLoading2[T](self: Module[T]) =
self.delegate.appReady()

# TODO get the flow to send the right metric
var eventType = "user-logged-in"
if self.currentFlow != SecondaryFlow.ActualLogin:
if self.loginFlow == LoginMethod.Unknown:
eventType = "onboarding-completed"
singletonInstance.globalEvents.addCentralizedMetricIfEnabled(eventType,
$(%*{"flowType": repr(self.currentFlow)}))
$(%*{"flowType": repr(self.onboardingFlow)}))

self.controller.stopKeycardService()

Expand Down
5 changes: 3 additions & 2 deletions ui/StatusQ/src/onboarding/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OnboardingEnums
Login
};

enum class SecondaryFlow {
enum class OnboardingFlow {
Unknown,

CreateProfileWithPassword,
Expand All @@ -25,6 +25,7 @@ class OnboardingEnums
};

enum class LoginMethod {
Unknown,
Password,
Keycard,
};
Expand Down Expand Up @@ -60,7 +61,7 @@ class OnboardingEnums

private:
Q_ENUM(PrimaryFlow)
Q_ENUM(SecondaryFlow)
Q_ENUM(OnboardingFlow)
Q_ENUM(LoginMethod)
Q_ENUM(KeycardState)
Q_ENUM(AddKeyPairState)
Expand Down
16 changes: 8 additions & 8 deletions ui/app/AppLayouts/Onboarding2/OnboardingFlow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ SQUtils.QObject {
CreateProfilePage {
onCreateProfileWithPasswordRequested: createNewProfileFlow.init()
onCreateProfileWithSeedphraseRequested: {
d.flow = Onboarding.SecondaryFlow.CreateProfileWithSeedphrase
d.flow = Onboarding.OnboardingFlow.CreateProfileWithSeedphrase
useRecoveryPhraseFlow.init()
}
onCreateProfileWithEmptyKeycardRequested: keycardCreateProfileFlow.init()
Expand All @@ -143,7 +143,7 @@ SQUtils.QObject {
onLoginWithKeycardRequested: loginWithKeycardFlow.init()

onLoginWithSeedphraseRequested: {
d.flow = Onboarding.SecondaryFlow.LoginWithSeedphrase
d.flow = Onboarding.OnboardingFlow.LoginWithSeedphrase
useRecoveryPhraseFlow.init()
}
}
Expand All @@ -157,7 +157,7 @@ SQUtils.QObject {

onFinished: (password) => {
root.setPasswordRequested(password)
d.flow = Onboarding.SecondaryFlow.CreateProfileWithPassword
d.flow = Onboarding.OnboardingFlow.CreateProfileWithPassword
d.pushOrSkipBiometricsPage()
}
}
Expand Down Expand Up @@ -205,8 +205,8 @@ SQUtils.QObject {

onFinished: (withNewSeedphrase) => {
d.flow = withNewSeedphrase
? Onboarding.SecondaryFlow.CreateProfileWithKeycardNewSeedphrase
: Onboarding.SecondaryFlow.CreateProfileWithKeycardExistingSeedphrase
? Onboarding.OnboardingFlow.CreateProfileWithKeycardNewSeedphrase
: Onboarding.OnboardingFlow.CreateProfileWithKeycardExistingSeedphrase

d.pushOrSkipBiometricsPage()
}
Expand All @@ -223,12 +223,12 @@ SQUtils.QObject {
root.syncProceedWithConnectionString(connectionString)

onLoginWithSeedphraseRequested: {
d.flow = Onboarding.SecondaryFlow.LoginWithSeedphrase
d.flow = Onboarding.OnboardingFlow.LoginWithSeedphrase
useRecoveryPhraseFlow.init()
}

onFinished: {
d.flow = Onboarding.SecondaryFlow.LoginWithSyncing
d.flow = Onboarding.OnboardingFlow.LoginWithSyncing
d.pushOrSkipBiometricsPage()
}
}
Expand All @@ -253,7 +253,7 @@ SQUtils.QObject {
onExportKeysRequested: root.exportKeysRequested()

onFinished: {
d.flow = Onboarding.SecondaryFlow.LoginWithKeycard
d.flow = Onboarding.OnboardingFlow.LoginWithKeycard
d.pushOrSkipBiometricsPage()
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/AppLayouts/Onboarding2/OnboardingLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Page {

signal shareUsageDataRequested(bool enabled)

// flow: Onboarding.SecondaryFlow
// flow: Onboarding.OnboardingFlow
signal finished(int flow, var data)

// -> "keyUid:string": User ID to login; "method:int": password or keycard (cf Onboarding.LoginMethod.*) enum;
Expand Down
7 changes: 2 additions & 5 deletions ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -446,23 +446,20 @@ StatusWindow {
onboardingStore: onboardingStore

onFinished: (flow, data) => {
console.log("!!! ONBOARDING FINISHED; flow:", flow, "; data:", JSON.stringify(data))

let error = onboardingStore.finishOnboardingFlow(flow, data)

if (error != "") {
// We should never be here since everything should be validated already
console.error("!!! ONBOARDING FINISHED WITH ERROR:", error)
// TODO show error
return
}
console.log("!!! Onboarding completed!")
stack.clear()
stack.push(splashScreenV2, { runningProgressAnimation: true })
}

onLoginRequested: function (keyUid, method, data) {
onboardingStore.loginRequested(keyUid, method, data)
stack.push(splashScreenV2, { runningProgressAnimation: true })
onboardingStore.loginRequested(keyUid, method, data)
}

onShareUsageDataRequested: {
Expand Down

0 comments on commit 67a41aa

Please sign in to comment.