pass generated account to profile

This commit is contained in:
Iuri Matias 2020-05-21 16:52:00 -04:00
parent 656e553a32
commit 4c9a370fc3
4 changed files with 26 additions and 19 deletions

View File

@ -16,14 +16,15 @@ type OnboardingController* = ref object of SignalSubscriber
variant*: QVariant variant*: QVariant
model*: AccountModel model*: AccountModel
proc newController*(events: EventEmitter): OnboardingController = proc newController*(events: EventEmitter, model: AccountModel): OnboardingController =
result = OnboardingController() result = OnboardingController()
# TODO: events should be specific to the model itself # TODO: events should be specific to the model itself
result.model = newAccountModel() # result.model = newAccountModel()
result.model = model
result.view = newOnboardingView(result.model) result.view = newOnboardingView(result.model)
result.variant = newQVariant(result.view) result.variant = newQVariant(result.view)
result.model.events.on("accountsReady") do(a: Args): # result.model.events.on("accountsReady") do(a: Args):
events.emit("node:ready", Args()) # events.emit("node:ready", Args())
proc delete*(self: OnboardingController) = proc delete*(self: OnboardingController) =
delete self.view delete self.view

View File

@ -20,5 +20,5 @@ proc delete*(self: ProfileController) =
proc init*(self: ProfileController, accounts: string) = proc init*(self: ProfileController, accounts: string) =
var chatAccount = parseJSON(accounts)[1] var chatAccount = parseJSON(accounts)[1]
self.view.username = chatAccount["name"].str self.view.setUsername(chatAccount["name"].str)
self.view.identicon = chatAccount["photo-path"].str self.view.setIdenticon(chatAccount["photo-path"].str)

View File

@ -22,11 +22,13 @@ type
AccountModel* = ref object AccountModel* = ref object
generatedAddresses*: seq[GeneratedAccount] generatedAddresses*: seq[GeneratedAccount]
events*: EventEmitter events*: EventEmitter
subaccounts*: JsonNode #TODO use correct account, etc..
proc newAccountModel*(): AccountModel = proc newAccountModel*(): AccountModel =
result = AccountModel() result = AccountModel()
result.events = createEventEmitter() result.events = createEventEmitter()
result.generatedAddresses = @[] result.generatedAddresses = @[]
result.subaccounts = %*{}
proc delete*(self: AccountModel) = proc delete*(self: AccountModel) =
# delete self.generatedAddresses # delete self.generatedAddresses
@ -54,10 +56,11 @@ proc generateAddresses*(self: AccountModel): seq[GeneratedAccount] =
# TODO: this is temporary and will be removed once accounts import and creation is working # TODO: this is temporary and will be removed once accounts import and creation is working
proc generateRandomAccountAndLogin*(self: AccountModel) = proc generateRandomAccountAndLogin*(self: AccountModel) =
let generatedAccounts = status_accounts.generateAddresses().parseJson let generatedAccounts = status_accounts.generateAddresses().parseJson
discard status_accounts.setupAccount(generatedAccounts[0], "qwerty") self.subaccounts = status_accounts.setupAccount(generatedAccounts[0], "qwerty").parseJson
self.events.emit("accountsReady", Args()) self.events.emit("accountsReady", Args())
proc storeAccountAndLogin*(self: AccountModel, selectedAccountIndex: int, password: string): string = proc storeAccountAndLogin*(self: AccountModel, selectedAccountIndex: int, password: string): string =
let account: GeneratedAccount = self.generatedAddresses[selectedAccountIndex] let account: GeneratedAccount = self.generatedAddresses[selectedAccountIndex]
result = status_accounts.setupAccount(%account, password) result = status_accounts.setupAccount(%account, password)
self.subaccounts = result.parseJson
self.events.emit("accountsReady", Args()) self.events.emit("accountsReady", Args())

View File

@ -19,6 +19,7 @@ import status/chat as status_chat
import status/types as types import status/types as types
import status/wallet as status_wallet import status/wallet as status_wallet
import status/libstatus import status/libstatus
import models/accounts
import state import state
import status/types import status/types
import eventemitter import eventemitter
@ -56,12 +57,7 @@ proc mainProc() =
# echo "---------" # echo "---------"
# discard status_test.setupNewAccount() # discard status_test.setupNewAccount()
events.on("node:ready") do(a: Args):
status_chat.startMessenger()
var wallet = wallet.newController() var wallet = wallet.newController()
events.on("node:ready") do(a: Args):
wallet.init()
engine.setRootContextProperty("assetsModel", wallet.variant) engine.setRootContextProperty("assetsModel", wallet.variant)
var chat = chat.newController() var chat = chat.newController()
@ -70,17 +66,23 @@ proc mainProc() =
var node = node.newController() var node = node.newController()
node.init() node.init()
engine.setRootContextProperty("nodeModel", node.variant) engine.setRootContextProperty("nodeModel", node.variant)
var onboarding = onboarding.newController(events) var profile = profile.newController()
engine.setRootContextProperty("profileModel", profile.variant)
var accountsModel = newAccountModel()
# accountsModel.events.on("accountsReady") do(a: Args):
# events.on("node:ready") do(a: Args):
accountsModel.events.on("accountsReady") do(a: Args):
status_chat.startMessenger()
wallet.init()
profile.init($accountsModel.subaccounts) # TODO: use correct account
var onboarding = onboarding.newController(events, accountsModel)
onboarding.init() onboarding.init()
engine.setRootContextProperty("onboardingModel", onboarding.variant) engine.setRootContextProperty("onboardingModel", onboarding.variant)
var profile = profile.newController()
# profile.init(accounts) # TODO: use correct account
engine.setRootContextProperty("profileModel", profile.variant)
signalController.init() signalController.init()
signalController.addSubscriber(SignalType.Wallet, wallet) signalController.addSubscriber(SignalType.Wallet, wallet)
signalController.addSubscriber(SignalType.Wallet, node) signalController.addSubscriber(SignalType.Wallet, node)
@ -94,7 +96,8 @@ proc mainProc() =
chat.join(channel.name) chat.join(channel.name)
) )
events.on("node:ready") do(a: Args): # events.on("node:ready12313asdada") do(a: Args):
accountsModel.events.on("accountsReady") do(a: Args):
appState.addChannel("test") appState.addChannel("test")
appState.addChannel("test2") appState.addChannel("test2")