From bab04fac6f9bff1f3f1d2f5bcacdae9574c4b9de Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 21 May 2020 16:15:44 -0400 Subject: [PATCH] refactor account setup --- src/models/accounts.nim | 15 +-------------- src/status/accounts.nim | 38 ++++++++++++++------------------------ 2 files changed, 15 insertions(+), 38 deletions(-) diff --git a/src/models/accounts.nim b/src/models/accounts.nim index b63e4e368c..0bc9ded4a3 100644 --- a/src/models/accounts.nim +++ b/src/models/accounts.nim @@ -62,18 +62,5 @@ proc generateRandomAccountAndLogin*(self: AccountModel) = proc storeAccountAndLogin*(self: AccountModel, selectedAccountIndex: int, password: string): string = let account: GeneratedAccount = self.generatedAddresses[selectedAccountIndex] - - let multiAccounts = status_accounts.generateMultiAccounts(%account, password) - - let whisperPubKey = account.derived[constants.PATH_WHISPER]["publicKey"].getStr - let alias = $libstatus.generateAlias(whisperPubKey.toGoString) - let identicon = $libstatus.identicon(whisperPubKey.toGoString) - - let accountData = status_accounts.getAccountData(%account, alias, identicon) - var nodeConfig = constants.NODE_CONFIG - var settingsJSON = status_accounts.getAccountSettings(%account, alias, identicon, multiAccounts, constants.DEFAULT_NETWORKS) - - discard saveAccountAndLogin(multiAccounts, alias, identicon, $accountData, password, $nodeConfig, $settingsJSON) - + result = status_accounts.setupAccount(%account, password) self.events.emit("accountsReady", Args()) - "" diff --git a/src/status/accounts.nim b/src/status/accounts.nim index e453a9aef1..7e6841baad 100644 --- a/src/status/accounts.nim +++ b/src/status/accounts.nim @@ -31,15 +31,6 @@ proc generateAddresses*(): string = proc generateAlias*(publicKey: string): string = result = $libstatus.generateAlias(publicKey.toGoString) -# const datadir = "./data/" -# const keystoredir = "./data/keystore/" -# const nobackupdir = "./noBackup/" - -proc recreateDir(dirname: string) = - if existsDir(dirname): - removeDir(dirname) - createDir(dirname) - proc ensureDir(dirname: string) = if not existsDir(dirname): # removeDir(dirname) @@ -130,22 +121,21 @@ proc getAccountSettings*(account: JsonNode, alias: string, identicon: string, mu "installation-id": $genUUID() } +proc setupAccount*(account: JsonNode, password: string): string = + let multiAccounts = generateMultiAccounts(account, password) + + let whisperPubKey = account["derived"][constants.PATH_WHISPER]["publicKey"].getStr + let alias = $libstatus.generateAlias(whisperPubKey.toGoString) + let identicon = $libstatus.identicon(whisperPubKey.toGoString) + + let accountData = getAccountData(account, alias, identicon) + var settingsJSON = getAccountSettings(account, alias, identicon, multiAccounts, constants.DEFAULT_NETWORKS) + + $saveAccountAndLogin(multiAccounts, alias, identicon, $accountData, password, $constants.NODE_CONFIG, $settingsJSON) + proc setupRandomTestAccount*(): string = let generatedAddresses = generateAddresses().parseJson - - let account0 = generatedAddresses[0] + let account = generatedAddresses[0] let password = "qwerty" - let multiAccounts = generateMultiAccounts(account0, password) - # let alias = $libstatus.generateAlias(whisperPubKey.toGoString) - # let identicon = $libstatus.identicon(whisperPubKey.toGoString) - var alias = "Delectable Overjoyed Nauplius" - var identicon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAmElEQVR4nOzX4QmAIBBA4Yp2aY52aox2ao6mqf+SoajwON73M0J4HBy6TEEYQmMIjSE0htCECVlbDziv+/n6fuzb3OP/UmEmYgiNITRNm+LPqO2UE2YihtAYQlN818ptoZzau1btOakwEzGExhCa5hdi7d2p1zZLhZmIITSG0PhCpDGExhANEmYihtAYQmMIjSE0bwAAAP//kHQdRIWYzToAAAAASUVORK5CYII=" - let accountData = getAccountData(account0, alias, identicon) - - var settingsJSON = getAccountSettings(account0, alias, identicon, multiAccounts, constants.DEFAULT_NETWORKS) - - let configJSON = constants.NODE_CONFIG - - var subaccountdata = saveAccountAndLogin(multiAccounts, alias, identicon, $accountData, password, $configJSON, $settingsJSON) - $subaccountData + setupAccount(account, password)