feat: Pass login account data in account event
The "accountsReady" event now passes the account information for the account that was logged in, which helps pass the correct account info to Profile and is available for other modules that may need it. This will become particularly useful once the login functionality is implemented.
This commit is contained in:
parent
68b48a7082
commit
a1109ca52b
|
@ -24,4 +24,4 @@ proc init*(self: OnboardingController) =
|
|||
let accounts = self.model.generateAddresses()
|
||||
|
||||
for account in accounts:
|
||||
self.view.addAddressToList(account.username, account.identicon, account.key)
|
||||
self.view.addAddressToList(account.name, account.photoPath, account.address)
|
||||
|
|
|
@ -3,6 +3,7 @@ import json
|
|||
import "../../status/core" as status
|
||||
import ../signals/types
|
||||
import profileView
|
||||
import "../../status/types" as status_types
|
||||
|
||||
type ProfileController* = ref object of SignalSubscriber
|
||||
view*: ProfileView
|
||||
|
@ -17,8 +18,6 @@ proc delete*(self: ProfileController) =
|
|||
delete self.view
|
||||
delete self.variant
|
||||
|
||||
proc init*(self: ProfileController, accounts: string) =
|
||||
var chatAccount = parseJSON(accounts)[1]
|
||||
|
||||
self.view.setUsername(chatAccount["name"].str)
|
||||
self.view.setIdenticon(chatAccount["photo-path"].str)
|
||||
proc init*(self: ProfileController, account: Account) =
|
||||
self.view.setUsername(account.name)
|
||||
self.view.setIdenticon(account.photoPath)
|
||||
|
|
|
@ -3,19 +3,7 @@ import eventemitter
|
|||
import ../status/libstatus
|
||||
import ../status/accounts as status_accounts
|
||||
import ../status/utils
|
||||
import ../status/utils
|
||||
|
||||
type
|
||||
GeneratedAccount* = object
|
||||
publicKey*: string
|
||||
address*: string
|
||||
id*: string
|
||||
keyUid*: string
|
||||
mnemonic*: string
|
||||
derived*: JsonNode
|
||||
username*: string
|
||||
key*: string
|
||||
identicon*: string
|
||||
import ../status/types
|
||||
|
||||
type
|
||||
AccountModel* = ref object
|
||||
|
@ -36,18 +24,10 @@ proc delete*(self: AccountModel) =
|
|||
proc generateAddresses*(self: AccountModel): seq[GeneratedAccount] =
|
||||
let accounts = status_accounts.generateAddresses().parseJson
|
||||
for account in accounts:
|
||||
var generatedAccount = GeneratedAccount()
|
||||
var generatedAccount = account.toGeneratedAccount
|
||||
|
||||
generatedAccount.publicKey = account["publicKey"].str
|
||||
generatedAccount.address = account["address"].str
|
||||
generatedAccount.id = account["id"].str
|
||||
generatedAccount.keyUid = account["keyUid"].str
|
||||
generatedAccount.mnemonic = account["mnemonic"].str
|
||||
generatedAccount.derived = account["derived"]
|
||||
|
||||
generatedAccount.username = status_accounts.generateAlias(account["publicKey"].str)
|
||||
generatedAccount.identicon = status_accounts.generateIdenticon(account["publicKey"].str)
|
||||
generatedAccount.key = account["address"].str
|
||||
generatedAccount.name = status_accounts.generateAlias(account["publicKey"].str)
|
||||
generatedAccount.photoPath = status_accounts.generateIdenticon(account["publicKey"].str)
|
||||
|
||||
self.generatedAddresses.add(generatedAccount)
|
||||
self.generatedAddresses
|
||||
|
@ -56,10 +36,10 @@ proc generateAddresses*(self: AccountModel): seq[GeneratedAccount] =
|
|||
proc generateRandomAccountAndLogin*(self: AccountModel) =
|
||||
let generatedAccounts = status_accounts.generateAddresses().parseJson
|
||||
self.subaccounts = status_accounts.setupAccount(generatedAccounts[0], "qwerty").parseJson
|
||||
self.events.emit("accountsReady", Args())
|
||||
self.events.emit("accountsReady", AccountArgs(account: self.subaccounts[1].toAccount))
|
||||
|
||||
proc storeAccountAndLogin*(self: AccountModel, selectedAccountIndex: int, password: string): string =
|
||||
let account: GeneratedAccount = self.generatedAddresses[selectedAccountIndex]
|
||||
result = status_accounts.setupAccount(%account, password)
|
||||
let generatedAccount: GeneratedAccount = self.generatedAddresses[selectedAccountIndex]
|
||||
result = status_accounts.setupAccount(%generatedAccount, password)
|
||||
self.subaccounts = result.parseJson
|
||||
self.events.emit("accountsReady", Args())
|
||||
self.events.emit("accountsReady", AccountArgs(account: generatedAccount.toAccount))
|
||||
|
|
|
@ -24,8 +24,7 @@ logScope:
|
|||
topics = "main"
|
||||
|
||||
proc mainProc() =
|
||||
status_accounts.initNodeAccounts()
|
||||
|
||||
let nodeAccounts = parseJson(status_accounts.initNodeAccounts()).toNodeAccounts # to be used for login
|
||||
let app = newQApplication()
|
||||
let engine = newQQmlApplicationEngine()
|
||||
let signalController = signals.newController(app)
|
||||
|
@ -59,9 +58,10 @@ proc mainProc() =
|
|||
|
||||
var accountsModel = newAccountModel()
|
||||
accountsModel.events.on("accountsReady") do(a: Args):
|
||||
var args = AccountArgs(a)
|
||||
status_chat.startMessenger()
|
||||
wallet.init()
|
||||
profile.init($accountsModel.subaccounts) # TODO: use correct account
|
||||
profile.init(args.account) # TODO: use correct account
|
||||
|
||||
var onboarding = onboarding.newController(accountsModel)
|
||||
onboarding.init()
|
||||
|
|
|
@ -39,7 +39,7 @@ proc ensureDir(dirname: string) =
|
|||
# removeDir(dirname)
|
||||
createDir(dirname)
|
||||
|
||||
proc initNodeAccounts*() =
|
||||
proc initNodeAccounts*(): string =
|
||||
const datadir = "./data/"
|
||||
const keystoredir = "./data/keystore/"
|
||||
const nobackupdir = "./noBackup/"
|
||||
|
@ -49,7 +49,7 @@ proc initNodeAccounts*() =
|
|||
ensureDir(nobackupdir)
|
||||
|
||||
discard $libstatus.initKeystore(keystoredir);
|
||||
discard $libstatus.openAccounts(datadir);
|
||||
result = $libstatus.openAccounts(datadir);
|
||||
|
||||
proc saveAccountAndLogin*(multiAccounts: JsonNode, alias: string, identicon: string, accountData: string, password: string, configJSON: string, settingsJSON: string): JsonNode =
|
||||
let hashedPassword = "0x" & $keccak_256.digest(password)
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import json
|
||||
import eventemitter
|
||||
|
||||
type SignalCallback* = proc(eventMessage: cstring): void {.cdecl.}
|
||||
|
||||
type SignalType* {.pure.} = enum
|
||||
|
@ -19,3 +22,55 @@ type
|
|||
GoString* = object
|
||||
str*: cstring
|
||||
length*: cint
|
||||
|
||||
type
|
||||
Account* = object of RootObj
|
||||
name*: string
|
||||
keyUid*: string
|
||||
photoPath*: string
|
||||
|
||||
type
|
||||
NodeAccount* = ref object of Account
|
||||
timestamp*: int
|
||||
keycardPairing*: string
|
||||
|
||||
type
|
||||
GeneratedAccount* = ref object of Account
|
||||
publicKey*: string
|
||||
address*: string
|
||||
id*: string
|
||||
mnemonic*: string
|
||||
derived*: JsonNode
|
||||
|
||||
proc toNodeAccount*(nodeAccount: JsonNode): NodeAccount =
|
||||
result = NodeAccount(
|
||||
name: nodeAccount["name"].getStr,
|
||||
timestamp: nodeAccount["timestamp"].getInt,
|
||||
photoPath: nodeAccount["photo-path"].getStr,
|
||||
keycardPairing: nodeAccount["keycard-pairing"].getStr,
|
||||
keyUid: nodeAccount["key-uid"].getStr)
|
||||
|
||||
proc toNodeAccounts*(nodeAccounts: JsonNode): seq[NodeAccount] =
|
||||
result = newSeq[NodeAccount]()
|
||||
for v in nodeAccounts:
|
||||
result.add v.toNodeAccount
|
||||
|
||||
proc toGeneratedAccount*(generatedAccount: JsonNode): GeneratedAccount =
|
||||
generatedAccount["name"] = %*""
|
||||
generatedAccount["photoPath"] = %*""
|
||||
result = generatedAccount.to(GeneratedAccount)
|
||||
|
||||
proc toAccount*(generatedAccount: JsonNode): Account =
|
||||
result = Account(
|
||||
name: generatedAccount["name"].getStr,
|
||||
keyUid: generatedAccount{"key-uid"}.getStr,
|
||||
photoPath: generatedAccount["photo-path"].getStr)
|
||||
|
||||
proc toAccount*(generatedAccount: GeneratedAccount): Account =
|
||||
result = Account(
|
||||
name: generatedAccount.name,
|
||||
keyUid: generatedAccount.keyUid,
|
||||
photoPath: generatedAccount.photoPath)
|
||||
|
||||
type AccountArgs* = ref object of Args
|
||||
account*: Account
|
|
@ -194,7 +194,7 @@ SwipeView {
|
|||
id: storeAccountAndLoginError
|
||||
title: "Error storing account and logging in"
|
||||
text: "An error occurred while storing your account and logging in: "
|
||||
// icon: StandardIcon.Error
|
||||
icon: StandardIcon.Warning
|
||||
standardButtons: StandardButton.Ok
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue