Skip to content

Commit

Permalink
fix(@desktop/onboarding): onboarding flows for I already use Status
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
saledjenic committed Jan 4, 2023
1 parent 19ba018 commit 6b6aaf3
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/app/boot/app_controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
result.globalUtilsVariant = newQVariant(singletonInstance.utils)

# 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.keycardService = keycard_service.newService(statusFoundation.events, statusFoundation.threadpool)
result.nodeConfigurationService = node_configuration_service.newService(statusFoundation.fleetConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ proc fromEvent*(T: type WakuFetchingBackupProgressSignal, event: JsonNode): Waku
result = WakuFetchingBackupProgressSignal()
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:
let entity = event["event"]["fetchingBackedUpDataProgress"][key]
var details = WakuFetchingBackupProgress()
Expand Down
6 changes: 6 additions & 0 deletions src/app/modules/startup/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ proc connectToFetchingFromWakuEvents*(self: Controller) =
self.delegate.onFetchingFromWakuMessageReceived(k, v.totalNumber, v.dataNumber)
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) =
self.disconnectKeychain()
for id in self.connectionIds:
Expand Down
9 changes: 8 additions & 1 deletion src/app/modules/startup/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ proc prepareAndInitFetchingData[T](self: Module[T]) =
FetchingFromWakuSettings]
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) =
self.delegate.logout()
self.moveToStartupState()
Expand All @@ -340,7 +347,7 @@ method onNodeLogin*[T](self: Module[T], error: string) =
self.prepareAndInitFetchingData()
self.controller.connectToFetchingFromWakuEvents()
self.view.setCurrentStartupState(newProfileFetchingState(currStateObj.flowType(), nil))
self.moveToStartupState()
self.delayStartingApp()
let err = self.delegate.userLoggedIn()
if err.len > 0:
self.logoutAndDisplayError(err)
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions src/app_service/service/accounts/dto/accounts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ type AccountDto* = object

type WakuBackedUpProfileDto* = object
displayName*: string
displayNameStored*: bool
images*: seq[Image]
imagesStored*: bool

proc isValid*(self: AccountDto): bool =
result = self.name.len > 0 and self.keyUid.len > 0
Expand Down Expand Up @@ -70,8 +68,6 @@ proc contains*(accounts: seq[AccountDto], keyUid: string): bool =
proc toWakuBackedUpProfileDto*(jsonObj: JsonNode): WakuBackedUpProfileDto =
result = WakuBackedUpProfileDto()
discard jsonObj.getProp("displayName", result.displayName)
discard jsonObj.getProp("displayNameStored", result.displayNameStored)
discard jsonObj.getProp("imagesStored", result.imagesStored)

var imagesObj: JsonNode
if(jsonObj.getProp("images", imagesObj) and imagesObj.kind == JArray):
Expand Down
6 changes: 2 additions & 4 deletions src/app_service/service/accounts/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ QtObject:
proc connectToFetchingFromWakuEvents*(self: Service) =
self.events.on(SignalType.WakuBackedUpProfile.event) do(e: Args):
var receivedData = WakuBackedUpProfileSignal(e)
if receivedData.backedUpProfile.displayNameStored:
self.loggedInAccount.name = receivedData.backedUpProfile.displayName
if receivedData.backedUpProfile.imagesStored:
self.loggedInAccount.images = receivedData.backedUpProfile.images
self.loggedInAccount.name = receivedData.backedUpProfile.displayName
self.loggedInAccount.images = receivedData.backedUpProfile.images

proc init*(self: Service) =
try:
Expand Down
15 changes: 1 addition & 14 deletions src/app_service/service/contacts/async_tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,4 @@ const lookupContactTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
"uuid": arg.uuid,
"reason": arg.reason
}
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")
arg.finish(output)
103 changes: 69 additions & 34 deletions src/app_service/service/general/service.nim
Original file line number Diff line number Diff line change
@@ -1,52 +1,87 @@
import os, json, chronicles
import NimQml, os, json, chronicles

import ../../../backend/general as status_general
import ../../../app/core/eventemitter
import ../../../app/core/tasks/[qt, threadpool]
import ../../../constants as app_constants

import ../accounts/dto/accounts

const TimerIntervalInMilliseconds = 1000 # 1 second

const SIGNAL_GENERAL_TIMEOUT* = "timeoutSignal"

logScope:
topics = "general-app-service"

type
Service* = ref object of RootObj
include ../../common/async_tasks

QtObject:
type Service* = ref object of QObject
events: EventEmitter
threadpool: ThreadPool
timeoutInMilliseconds: int

proc delete*(self: Service) =
self.QObject.delete

proc newService*(events: EventEmitter, threadpool: ThreadPool): Service =
new(result, delete)
result.QObject.setup
result.events = events
result.threadpool = threadpool

proc init*(self: Service) =
if not existsDir(app_constants.ROOTKEYSTOREDIR):
createDir(app_constants.ROOTKEYSTOREDIR)

proc delete*(self: Service) =
discard
proc startMessenger*(self: Service) =
discard status_general.startMessenger()

proc newService*(): Service =
result = Service()
proc logout*(self: Service) =
discard status_general.logout()

proc init*(self: Service) =
if not existsDir(app_constants.ROOTKEYSTOREDIR):
createDir(app_constants.ROOTKEYSTOREDIR)
proc getPasswordStrengthScore*(self: Service, password, userName: string): int =
try:
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 startMessenger*(self: Service) =
discard status_general.startMessenger()
return response.result["score"].getInt()
except Exception as e:
error "error: ", methodName="getPasswordStrengthScore", errName = e.name, errDesription = e.msg

proc logout*(self: Service) =
discard status_general.logout()
proc generateImages*(self: Service, image: string, aX: int, aY: int, bX: int, bY: int): seq[Image] =
try:
let response = status_general.generateImages(image, aX, aY, bX, bY)
if(response.result.kind != JArray):
error "error: ", procName="generateImages", errDesription = "response is not an array"
return

proc getPasswordStrengthScore*(self: Service, password, userName: string): int =
try:
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
for img in response.result:
result.add(toImage(img))
except Exception as e:
error "error: ", procName="generateImages", errName = e.name, errDesription = e.msg

return response.result["score"].getInt()
except Exception as e:
error "error: ", methodName="getPasswordStrengthScore", 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 generateImages*(self: Service, image: string, aX: int, aY: int, bX: int, bY: int): seq[Image] =
try:
let response = status_general.generateImages(image, aX, aY, bX, bY)
if(response.result.kind != JArray):
error "error: ", procName="generateImages", errDesription = "response is not an array"
return
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()

for img in response.result:
result.add(toImage(img))
except Exception as e:
error "error: ", procName="generateImages", errName = e.name, errDesription = e.msg
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()
9 changes: 3 additions & 6 deletions src/app_service/service/keycard/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ logScope:
include ../../common/json_utils
include ../../common/mnemonics
include internal
include async_tasks
include ../../common/async_tasks

type
KeycardArgs* = ref object of Args
Expand All @@ -63,16 +63,13 @@ QtObject:
setPayloadForCurrentFlow: JsonNode
doLogging: bool

proc setup(self: Service) =
self.QObject.setup

proc delete*(self: Service) =
self.closingApp = true
self.QObject.delete

proc newService*(events: EventEmitter, threadpool: ThreadPool): Service =
new(result)
result.setup()
new(result, delete)
result.QObject.setup
result.events = events
result.threadpool = threadpool
result.closingApp = false
Expand Down
13 changes: 0 additions & 13 deletions src/app_service/service/wallet_account/async_tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,6 @@ const fetchDerivedAddressDetailsTask*: Task = proc(argEncoded: string) {.gcsafe,
data["error"] = %* err
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
#################################################
Expand Down

0 comments on commit 6b6aaf3

Please sign in to comment.