@@ -9,17 +9,14 @@ import app_service/service/general/service as general_service
9
9
import app_service/ service/ accounts/ service as accounts_service
10
10
import app_service/ service/ devices/ service as devices_service
11
11
import app_service/ service/ keycardV2/ service as keycard_serviceV2
12
+ from app_service/ service/ settings/ dto/ settings import SettingsDto
13
+ from app_service/ service/ accounts/ dto/ accounts import AccountDto
12
14
13
15
export io_interface
14
16
15
17
logScope:
16
18
topics = " onboarding-module"
17
19
18
- type PrimaryFlow * {.pure } = enum
19
- Unknown = 0 ,
20
- CreateProfile ,
21
- Login
22
-
23
20
type SecondaryFlow * {.pure } = enum
24
21
Unknown = 0 ,
25
22
CreateProfileWithPassword ,
37
34
view: View
38
35
viewVariant: QVariant
39
36
controller: Controller
37
+ localPairingStatus: LocalPairingStatus
40
38
41
39
proc newModule * [T](
42
40
delegate: T,
@@ -67,6 +65,7 @@ method delete*[T](self: Module[T]) =
67
65
self.controller.delete
68
66
69
67
method onAppLoaded * [T](self: Module [T]) =
68
+ self.view.appLoaded ()
70
69
singletonInstance.engine.setRootContextProperty (" onboardingModule" , newQVariant ())
71
70
self.view.delete
72
71
self.view = nil
@@ -98,65 +97,93 @@ method validateLocalPairingConnectionString*[T](self: Module[T], connectionStrin
98
97
method inputConnectionStringForBootstrapping * [T](self: Module [T], connectionString: string ) =
99
98
self.controller.inputConnectionStringForBootstrapping (connectionString)
100
99
101
- method finishOnboardingFlow * [T](self: Module [T], primaryFlowInt, secondaryFlowInt : int , dataJson: string ): string =
100
+ method finishOnboardingFlow * [T](self: Module [T], flowInt : int , dataJson: string ): string =
102
101
try :
103
- let primaryFlow = PrimaryFlow (primaryFlowInt)
104
- let secondaryFlow = SecondaryFlow (secondaryFlowInt)
102
+ let flow = SecondaryFlow (flowInt)
105
103
106
104
let data = parseJson (dataJson)
107
105
let password = data[" password" ].str
108
- let seedPhrase = data[" seedPhrase " ].str
106
+ let seedPhrase = data[" seedphrase " ].str
109
107
110
108
var err = " "
111
109
112
- # CREATE PROFILE PRIMARY FLOW
113
- if primaryFlow == PrimaryFlow .CreateProfile :
114
- case secondaryFlow:
115
- of SecondaryFlow .CreateProfileWithPassword :
116
- err = self.controller.createAccountAndLogin (password)
117
- of SecondaryFlow .CreateProfileWithSeedphrase :
118
- err = self.controller.restoreAccountAndLogin (
119
- password,
120
- seedPhrase,
121
- recoverAccount = false ,
122
- keycardInstanceUID = " " ,
123
- )
124
- of SecondaryFlow .CreateProfileWithKeycard :
125
- # TODO implement keycard function
126
- discard
127
- of SecondaryFlow .CreateProfileWithKeycardNewSeedphrase :
128
- # TODO implement keycard function
129
- discard
130
- of SecondaryFlow .CreateProfileWithKeycardExistingSeedphrase :
131
- # TODO implement keycard function
132
- discard
133
- else :
134
- raise newException (ValueError , " Unknown secondary flow for CreateProfile: " & $ secondaryFlow)
135
-
136
- # LOGIN PRIMARY FLOW
137
- elif primaryFlow == PrimaryFlow .Login :
138
- case secondaryFlow:
139
- of SecondaryFlow .LoginWithSeedphrase :
140
- err = self.controller.restoreAccountAndLogin (
141
- password,
142
- seedPhrase,
143
- recoverAccount = true ,
144
- keycardInstanceUID = " " ,
145
- )
146
- of SecondaryFlow .LoginWithSyncing :
147
- self.controller.inputConnectionStringForBootstrapping (data[" connectionString" ].str)
148
- of SecondaryFlow .LoginWithKeycard :
149
- # TODO implement keycard function
150
- discard
151
- else :
152
- raise newException (ValueError , " Unknown secondary flow for Login: " & $ secondaryFlow)
153
- if err != " " :
154
- raise newException (ValueError , err)
155
- else :
156
- raise newException (ValueError , " Unknown primary flow: " & $ primaryFlow)
157
-
110
+ case flow:
111
+ # CREATE PROFILE FLOWS
112
+ of SecondaryFlow .CreateProfileWithPassword :
113
+ err = self.controller.createAccountAndLogin (password)
114
+ of SecondaryFlow .CreateProfileWithSeedphrase :
115
+ err = self.controller.restoreAccountAndLogin (
116
+ password,
117
+ seedPhrase,
118
+ recoverAccount = false ,
119
+ keycardInstanceUID = " " ,
120
+ )
121
+ of SecondaryFlow .CreateProfileWithKeycard :
122
+ # TODO implement keycard function
123
+ discard
124
+ of SecondaryFlow .CreateProfileWithKeycardNewSeedphrase :
125
+ # TODO implement keycard function
126
+ discard
127
+ of SecondaryFlow .CreateProfileWithKeycardExistingSeedphrase :
128
+ # TODO implement keycard function
129
+ discard
130
+
131
+ # LOGIN FLOWS
132
+ of SecondaryFlow .LoginWithSeedphrase :
133
+ err = self.controller.restoreAccountAndLogin (
134
+ password,
135
+ seedPhrase,
136
+ recoverAccount = true ,
137
+ keycardInstanceUID = " " ,
138
+ )
139
+ of SecondaryFlow .LoginWithSyncing :
140
+ # The pairing was already done directly through inputConnectionStringForBootstrapping, we can login
141
+ self.controller.loginLocalPairingAccount (
142
+ self.localPairingStatus.account,
143
+ self.localPairingStatus.password,
144
+ self.localPairingStatus.chatKey,
145
+ )
146
+ of SecondaryFlow .LoginWithKeycard :
147
+ # TODO implement keycard function
148
+ discard
149
+ else :
150
+ raise newException (ValueError , " Unknown flow: " & $ flow)
151
+
152
+ return err
158
153
except Exception as e:
159
154
error " Error finishing Onboarding Flow" , msg = e.msg
160
155
return e.msg
161
156
157
+ proc finishAppLoading2 [T](self: Module [T]) =
158
+ self.delegate.appReady ()
159
+
160
+ # TODO get the flow to send the right metric
161
+ # let currStateObj = self.view.currentStartupStateObj()
162
+ # if not currStateObj.isNil:
163
+ # var eventType = "user-logged-in"
164
+ # if currStateObj.flowType() != FlowType.AppLogin:
165
+ # eventType = "onboarding-completed"
166
+ # singletonInstance.globalEvents.addCentralizedMetricIfEnabled(eventType,
167
+ # $(%*{"flowType": currStateObj.flowType()}))
168
+
169
+ self.delegate.finishAppLoading ()
170
+
171
+ method onNodeLogin * [T](self: Module [T], error: string , account: AccountDto , settings: SettingsDto ) =
172
+ if error.len != 0 :
173
+ # TODO : Handle error
174
+ echo " ERROR from onNodeLogin: " , error
175
+ return
176
+
177
+ self.controller.setLoggedInAccount (account)
178
+
179
+ if self.localPairingStatus != nil and self.localPairingStatus.installation != nil and self.localPairingStatus.installation.id != " " :
180
+ # We tried to login by pairing, so finilize the process
181
+ self.controller.finishPairingThroughSeedPhraseProcess (self.localPairingStatus.installation.id)
182
+
183
+ self.finishAppLoading2 ()
184
+
185
+ method onLocalPairingStatusUpdate * [T](self: Module [T], status: LocalPairingStatus ) =
186
+ self.localPairingStatus = status
187
+ self.view.setSyncState (status.state.int )
188
+
162
189
{.pop .}
0 commit comments