-
Notifications
You must be signed in to change notification settings - Fork 87
feat(onbaording): implement basic functions for the new onboarding #17003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,25 +5,59 @@ import view, controller | |
|
||
import app/global/global_singleton | ||
import app/core/eventemitter | ||
import app_service/service/general/service as general_service | ||
import app_service/service/accounts/service as accounts_service | ||
import app_service/service/devices/service as devices_service | ||
import app_service/service/keycardV2/service as keycard_serviceV2 | ||
|
||
export io_interface | ||
|
||
logScope: | ||
topics = "onboarding-module" | ||
|
||
type PrimaryFlow* {.pure} = enum | ||
Unknown = 0, | ||
CreateProfile, | ||
Login | ||
Comment on lines
+18
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Soo, do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe not indeed. I still didn't have access to the C++ enum, so now that I'm rebased on top of it, maybe we can simplify some more There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like you're right. The QML only provides the secondary flow, which is sufficient anyway:
I'll get rid of the primary flow complexity |
||
|
||
type SecondaryFlow* {.pure} = enum | ||
Unknown = 0, | ||
CreateProfileWithPassword, | ||
CreateProfileWithSeedphrase, | ||
CreateProfileWithKeycard, | ||
CreateProfileWithKeycardNewSeedphrase, | ||
CreateProfileWithKeycardExistingSeedphrase, | ||
LoginWithSeedphrase, | ||
LoginWithSyncing, | ||
LoginWithKeycard | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My idea was to use the C++ enum here as the only source of truth (which I created in the other PR which is not merged yet ofc), and also in QML. Perhaps later :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yeah. I didn't find an enum that was usable, so I created one, but I have nothing against getting rid of this one to share the same you have once I integrate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not exactly but with my slightly limited NIM knowledge, it should be possible 😆 |
||
|
||
type | ||
Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface | ||
delegate: T | ||
view: View | ||
viewVariant: QVariant | ||
controller: Controller | ||
|
||
proc newModule*[T](delegate: T, events: EventEmitter): Module[T] = | ||
proc newModule*[T]( | ||
delegate: T, | ||
events: EventEmitter, | ||
generalService: general_service.Service, | ||
accountsService: accounts_service.Service, | ||
devicesService: devices_service.Service, | ||
keycardServiceV2: keycard_serviceV2.Service, | ||
): Module[T] = | ||
result = Module[T]() | ||
result.delegate = delegate | ||
result.view = view.newView(result) | ||
result.viewVariant = newQVariant(result.view) | ||
result.controller = controller.newController(result, events) | ||
result.controller = controller.newController( | ||
result, | ||
events, | ||
generalService, | ||
accountsService, | ||
devicesService, | ||
keycardServiceV2, | ||
) | ||
|
||
{.push warning[Deprecated]: off.} | ||
|
||
|
@@ -46,4 +80,83 @@ method load*[T](self: Module[T]) = | |
self.controller.init() | ||
self.delegate.onboardingDidLoad() | ||
|
||
method setPin*[T](self: Module[T], pin: string): bool = | ||
self.controller.setPin(pin) | ||
|
||
method getPasswordStrengthScore*[T](self: Module[T], password, userName: string): int = | ||
self.controller.getPasswordStrengthScore(password, userName) | ||
|
||
method validMnemonic*[T](self: Module[T], mnemonic: string): bool = | ||
self.controller.validMnemonic(mnemonic) | ||
|
||
method getMnemonic*[T](self: Module[T]): string = | ||
self.controller.getMnemonic() | ||
|
||
method validateLocalPairingConnectionString*[T](self: Module[T], connectionString: string): bool = | ||
self.controller.validateLocalPairingConnectionString(connectionString) | ||
|
||
method inputConnectionStringForBootstrapping*[T](self: Module[T], connectionString: string) = | ||
self.controller.inputConnectionStringForBootstrapping(connectionString) | ||
|
||
method finishOnboardingFlow*[T](self: Module[T], primaryFlowInt, secondaryFlowInt: int, dataJson: string): string = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, I like the simplicity 👍 |
||
try: | ||
let primaryFlow = PrimaryFlow(primaryFlowInt) | ||
let secondaryFlow = SecondaryFlow(secondaryFlowInt) | ||
|
||
let data = parseJson(dataJson) | ||
let password = data["password"].str | ||
let seedPhrase = data["seedPhrase"].str | ||
|
||
var err = "" | ||
|
||
# CREATE PROFILE PRIMARY FLOW | ||
if primaryFlow == PrimaryFlow.CreateProfile: | ||
case secondaryFlow: | ||
of SecondaryFlow.CreateProfileWithPassword: | ||
err = self.controller.createAccountAndLogin(password) | ||
of SecondaryFlow.CreateProfileWithSeedphrase: | ||
err = self.controller.restoreAccountAndLogin( | ||
password, | ||
seedPhrase, | ||
recoverAccount = false, | ||
keycardInstanceUID = "", | ||
) | ||
of SecondaryFlow.CreateProfileWithKeycard: | ||
# TODO implement keycard function | ||
discard | ||
of SecondaryFlow.CreateProfileWithKeycardNewSeedphrase: | ||
# TODO implement keycard function | ||
discard | ||
of SecondaryFlow.CreateProfileWithKeycardExistingSeedphrase: | ||
# TODO implement keycard function | ||
discard | ||
else: | ||
raise newException(ValueError, "Unknown secondary flow for CreateProfile: " & $secondaryFlow) | ||
|
||
# LOGIN PRIMARY FLOW | ||
elif primaryFlow == PrimaryFlow.Login: | ||
case secondaryFlow: | ||
of SecondaryFlow.LoginWithSeedphrase: | ||
err = self.controller.restoreAccountAndLogin( | ||
password, | ||
seedPhrase, | ||
recoverAccount = true, | ||
keycardInstanceUID = "", | ||
) | ||
of SecondaryFlow.LoginWithSyncing: | ||
self.controller.inputConnectionStringForBootstrapping(data["connectionString"].str) | ||
of SecondaryFlow.LoginWithKeycard: | ||
# TODO implement keycard function | ||
discard | ||
else: | ||
raise newException(ValueError, "Unknown secondary flow for Login: " & $secondaryFlow) | ||
if err != "": | ||
raise newException(ValueError, err) | ||
else: | ||
raise newException(ValueError, "Unknown primary flow: " & $primaryFlow) | ||
|
||
except Exception as e: | ||
error "Error finishing Onboarding Flow", msg = e.msg | ||
return e.msg | ||
|
||
{.pop.} |
Uh oh!
There was an error while loading. Please reload this page.