fix(@desktop/onboarding): onboarding flows for `I already use Status` path do not match figma requirements (2/2)

Continuation:
desktop app updated after we decided to remove 30 secs waiting time from `status-go` and introduce it
on the desktop app side.
This commit is contained in:
Sale Djenic 2022-12-22 12:49:27 +01:00 committed by saledjenic
parent 19ba018a1d
commit 6b6aaf3af1
11 changed files with 91 additions and 78 deletions

View File

@ -134,7 +134,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
result.globalUtilsVariant = newQVariant(singletonInstance.utils) result.globalUtilsVariant = newQVariant(singletonInstance.utils)
# Services # Services
result.generalService = general_service.newService() result.generalService = general_service.newService(statusFoundation.events, statusFoundation.threadpool)
result.activityCenterService = activity_center_service.newService(statusFoundation.events, statusFoundation.threadpool) result.activityCenterService = activity_center_service.newService(statusFoundation.events, statusFoundation.threadpool)
result.keycardService = keycard_service.newService(statusFoundation.events, statusFoundation.threadpool) result.keycardService = keycard_service.newService(statusFoundation.events, statusFoundation.threadpool)
result.nodeConfigurationService = node_configuration_service.newService(statusFoundation.fleetConfiguration, result.nodeConfigurationService = node_configuration_service.newService(statusFoundation.fleetConfiguration,

View File

@ -12,7 +12,7 @@ proc fromEvent*(T: type WakuFetchingBackupProgressSignal, event: JsonNode): Waku
result = WakuFetchingBackupProgressSignal() result = WakuFetchingBackupProgressSignal()
result.fetchingBackupProgress = initTable[string, WakuFetchingBackupProgress]() result.fetchingBackupProgress = initTable[string, WakuFetchingBackupProgress]()
if event["event"]["fetchingBackedUpDataProgress"].kind == JObject: if event["event"].hasKey("fetchingBackedUpDataProgress") and event["event"]{"fetchingBackedUpDataProgress"}.kind == JObject:
for key in event["event"]["fetchingBackedUpDataProgress"].keys: for key in event["event"]["fetchingBackedUpDataProgress"].keys:
let entity = event["event"]["fetchingBackedUpDataProgress"][key] let entity = event["event"]["fetchingBackedUpDataProgress"][key]
var details = WakuFetchingBackupProgress() var details = WakuFetchingBackupProgress()

View File

@ -107,6 +107,12 @@ proc connectToFetchingFromWakuEvents*(self: Controller) =
self.delegate.onFetchingFromWakuMessageReceived(k, v.totalNumber, v.dataNumber) self.delegate.onFetchingFromWakuMessageReceived(k, v.totalNumber, v.dataNumber)
self.connectionIds.add(handlerId) self.connectionIds.add(handlerId)
proc connectToTimeoutEventAndStratTimer*(self: Controller, timeoutInMilliseconds: int) =
var handlerId = self.events.onWithUUID(SIGNAL_GENERAL_TIMEOUT) do(e: Args):
self.delegate.moveToStartupState()
self.connectionIds.add(handlerId)
self.generalService.runTimer(timeoutInMilliseconds)
proc disconnect*(self: Controller) = proc disconnect*(self: Controller) =
self.disconnectKeychain() self.disconnectKeychain()
for id in self.connectionIds: for id in self.connectionIds:

View File

@ -323,6 +323,13 @@ proc prepareAndInitFetchingData[T](self: Module[T]) =
FetchingFromWakuSettings] FetchingFromWakuSettings]
self.view.createAndInitFetchingDataModel(listOfEntitiesWeExpectToBeSynced) self.view.createAndInitFetchingDataModel(listOfEntitiesWeExpectToBeSynced)
proc delayStartingApp[T](self: Module[T]) =
## In the following 2 cases:
## - FlowType.FirstRunOldUserImportSeedPhrase
## - FlowType.FirstRunOldUserKeycardImport
## we want to delay app start just to be sure that messages from waku will be received
self.controller.connectToTimeoutEventAndStratTimer(timeoutInMilliseconds = 30000) # delay for 30 seconds
proc logoutAndDisplayError[T](self: Module[T], error: string) = proc logoutAndDisplayError[T](self: Module[T], error: string) =
self.delegate.logout() self.delegate.logout()
self.moveToStartupState() self.moveToStartupState()
@ -340,7 +347,7 @@ method onNodeLogin*[T](self: Module[T], error: string) =
self.prepareAndInitFetchingData() self.prepareAndInitFetchingData()
self.controller.connectToFetchingFromWakuEvents() self.controller.connectToFetchingFromWakuEvents()
self.view.setCurrentStartupState(newProfileFetchingState(currStateObj.flowType(), nil)) self.view.setCurrentStartupState(newProfileFetchingState(currStateObj.flowType(), nil))
self.moveToStartupState() self.delayStartingApp()
let err = self.delegate.userLoggedIn() let err = self.delegate.userLoggedIn()
if err.len > 0: if err.len > 0:
self.logoutAndDisplayError(err) self.logoutAndDisplayError(err)

View File

@ -27,9 +27,7 @@ type AccountDto* = object
type WakuBackedUpProfileDto* = object type WakuBackedUpProfileDto* = object
displayName*: string displayName*: string
displayNameStored*: bool
images*: seq[Image] images*: seq[Image]
imagesStored*: bool
proc isValid*(self: AccountDto): bool = proc isValid*(self: AccountDto): bool =
result = self.name.len > 0 and self.keyUid.len > 0 result = self.name.len > 0 and self.keyUid.len > 0
@ -70,8 +68,6 @@ proc contains*(accounts: seq[AccountDto], keyUid: string): bool =
proc toWakuBackedUpProfileDto*(jsonObj: JsonNode): WakuBackedUpProfileDto = proc toWakuBackedUpProfileDto*(jsonObj: JsonNode): WakuBackedUpProfileDto =
result = WakuBackedUpProfileDto() result = WakuBackedUpProfileDto()
discard jsonObj.getProp("displayName", result.displayName) discard jsonObj.getProp("displayName", result.displayName)
discard jsonObj.getProp("displayNameStored", result.displayNameStored)
discard jsonObj.getProp("imagesStored", result.imagesStored)
var imagesObj: JsonNode var imagesObj: JsonNode
if(jsonObj.getProp("images", imagesObj) and imagesObj.kind == JArray): if(jsonObj.getProp("images", imagesObj) and imagesObj.kind == JArray):

View File

@ -93,10 +93,8 @@ QtObject:
proc connectToFetchingFromWakuEvents*(self: Service) = proc connectToFetchingFromWakuEvents*(self: Service) =
self.events.on(SignalType.WakuBackedUpProfile.event) do(e: Args): self.events.on(SignalType.WakuBackedUpProfile.event) do(e: Args):
var receivedData = WakuBackedUpProfileSignal(e) var receivedData = WakuBackedUpProfileSignal(e)
if receivedData.backedUpProfile.displayNameStored: self.loggedInAccount.name = receivedData.backedUpProfile.displayName
self.loggedInAccount.name = receivedData.backedUpProfile.displayName self.loggedInAccount.images = receivedData.backedUpProfile.images
if receivedData.backedUpProfile.imagesStored:
self.loggedInAccount.images = receivedData.backedUpProfile.images
proc init*(self: Service) = proc init*(self: Service) =
try: try:

View File

@ -39,17 +39,4 @@ const lookupContactTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
"uuid": arg.uuid, "uuid": arg.uuid,
"reason": arg.reason "reason": arg.reason
} }
arg.finish(output) arg.finish(output)
#################################################
# Async timer
#################################################
type
TimerTaskArg = ref object of QObjectTaskArg
timeoutInMilliseconds: int
const timerTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[TimerTaskArg](argEncoded)
sleep(arg.timeoutInMilliseconds)
arg.finish("done")

View File

@ -1,52 +1,87 @@
import os, json, chronicles import NimQml, os, json, chronicles
import ../../../backend/general as status_general import ../../../backend/general as status_general
import ../../../app/core/eventemitter
import ../../../app/core/tasks/[qt, threadpool]
import ../../../constants as app_constants import ../../../constants as app_constants
import ../accounts/dto/accounts import ../accounts/dto/accounts
const TimerIntervalInMilliseconds = 1000 # 1 second
const SIGNAL_GENERAL_TIMEOUT* = "timeoutSignal"
logScope: logScope:
topics = "general-app-service" topics = "general-app-service"
type include ../../common/async_tasks
Service* = ref object of RootObj
proc delete*(self: Service) = QtObject:
discard type Service* = ref object of QObject
events: EventEmitter
threadpool: ThreadPool
timeoutInMilliseconds: int
proc newService*(): Service = proc delete*(self: Service) =
result = Service() self.QObject.delete
proc init*(self: Service) = proc newService*(events: EventEmitter, threadpool: ThreadPool): Service =
if not existsDir(app_constants.ROOTKEYSTOREDIR): new(result, delete)
createDir(app_constants.ROOTKEYSTOREDIR) result.QObject.setup
result.events = events
result.threadpool = threadpool
proc startMessenger*(self: Service) = proc init*(self: Service) =
discard status_general.startMessenger() if not existsDir(app_constants.ROOTKEYSTOREDIR):
createDir(app_constants.ROOTKEYSTOREDIR)
proc logout*(self: Service) = proc startMessenger*(self: Service) =
discard status_general.logout() discard status_general.startMessenger()
proc getPasswordStrengthScore*(self: Service, password, userName: string): int = proc logout*(self: Service) =
try: discard status_general.logout()
let response = status_general.getPasswordStrengthScore(password, @[userName])
if(response.result.contains("error")):
let errMsg = response.result["error"].getStr()
error "error: ", methodName="getPasswordStrengthScore", errDesription = errMsg
return
return response.result["score"].getInt() proc getPasswordStrengthScore*(self: Service, password, userName: string): int =
except Exception as e: try:
error "error: ", methodName="getPasswordStrengthScore", errName = e.name, errDesription = e.msg let response = status_general.getPasswordStrengthScore(password, @[userName])
if(response.result.contains("error")):
let errMsg = response.result["error"].getStr()
error "error: ", methodName="getPasswordStrengthScore", errDesription = errMsg
return
proc generateImages*(self: Service, image: string, aX: int, aY: int, bX: int, bY: int): seq[Image] = return response.result["score"].getInt()
try: except Exception as e:
let response = status_general.generateImages(image, aX, aY, bX, bY) error "error: ", methodName="getPasswordStrengthScore", errName = e.name, errDesription = e.msg
if(response.result.kind != JArray):
error "error: ", procName="generateImages", errDesription = "response is not an array"
return
for img in response.result: proc generateImages*(self: Service, image: string, aX: int, aY: int, bX: int, bY: int): seq[Image] =
result.add(toImage(img)) try:
except Exception as e: let response = status_general.generateImages(image, aX, aY, bX, bY)
error "error: ", procName="generateImages", errName = e.name, errDesription = e.msg if(response.result.kind != JArray):
error "error: ", procName="generateImages", errDesription = "response is not an array"
return
for img in response.result:
result.add(toImage(img))
except Exception as e:
error "error: ", procName="generateImages", errName = e.name, errDesription = e.msg
proc runTimer(self: Service) =
let arg = TimerTaskArg(
tptr: cast[ByteAddress](timerTask),
vptr: cast[ByteAddress](self.vptr),
slot: "onTimeout",
timeoutInMilliseconds: TimerIntervalInMilliseconds
)
self.threadpool.start(arg)
proc runTimer*(self: Service, timeoutInMilliseconds: int) =
## Runs timer only once. Each 1000ms we check for timeout in order to have non blocking app closing.
self.timeoutInMilliseconds = timeoutInMilliseconds
self.runTimer()
proc onTimeout(self: Service, response: string) {.slot.} =
self.timeoutInMilliseconds = self.timeoutInMilliseconds - TimerIntervalInMilliseconds
if self.timeoutInMilliseconds <= 0:
self.events.emit(SIGNAL_GENERAL_TIMEOUT, Args())
else:
self.runTimer()

View File

@ -46,7 +46,7 @@ logScope:
include ../../common/json_utils include ../../common/json_utils
include ../../common/mnemonics include ../../common/mnemonics
include internal include internal
include async_tasks include ../../common/async_tasks
type type
KeycardArgs* = ref object of Args KeycardArgs* = ref object of Args
@ -63,16 +63,13 @@ QtObject:
setPayloadForCurrentFlow: JsonNode setPayloadForCurrentFlow: JsonNode
doLogging: bool doLogging: bool
proc setup(self: Service) =
self.QObject.setup
proc delete*(self: Service) = proc delete*(self: Service) =
self.closingApp = true self.closingApp = true
self.QObject.delete self.QObject.delete
proc newService*(events: EventEmitter, threadpool: ThreadPool): Service = proc newService*(events: EventEmitter, threadpool: ThreadPool): Service =
new(result) new(result, delete)
result.setup() result.QObject.setup
result.events = events result.events = events
result.threadpool = threadpool result.threadpool = threadpool
result.closingApp = false result.closingApp = false

View File

@ -90,19 +90,6 @@ const fetchDerivedAddressDetailsTask*: Task = proc(argEncoded: string) {.gcsafe,
data["error"] = %* err data["error"] = %* err
arg.finish(data) arg.finish(data)
#################################################
# Async timer
#################################################
type
TimerTaskArg = ref object of QObjectTaskArg
timeoutInMilliseconds: int
const timerTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[TimerTaskArg](argEncoded)
sleep(arg.timeoutInMilliseconds)
arg.finish("")
################################################# #################################################
# Async building token # Async building token
################################################# #################################################