From e65449b8de57cf91530535db0940691cd58e65bc Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 21 May 2020 15:54:25 -0400 Subject: [PATCH] refactor/extract getAccountData method --- src/models/accounts.nim | 10 ++-------- src/status/accounts.nim | 22 ++++++++++------------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/models/accounts.nim b/src/models/accounts.nim index 00ea9ca1e2..3c13371d40 100644 --- a/src/models/accounts.nim +++ b/src/models/accounts.nim @@ -69,15 +69,9 @@ proc storeAccountAndLogin*(self: AccountModel, selectedAccountIndex: int, passwo let whisperPubKey = account.derived[constants.PATH_WHISPER]["publicKey"].getStr let alias = $libstatus.generateAlias(whisperPubKey.toGoString) let identicon = $libstatus.identicon(whisperPubKey.toGoString) - let accountData = %* { - "name": alias, - "address": account.address, - "photo-path": identicon, - "key-uid": account.keyUid, - "keycard-pairing": nil - } - var nodeConfig = constants.NODE_CONFIG + 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) diff --git a/src/status/accounts.nim b/src/status/accounts.nim index 70536a368f..b54d6c62b8 100644 --- a/src/status/accounts.nim +++ b/src/status/accounts.nim @@ -92,6 +92,15 @@ proc generateMultiAccounts*(account: JsonNode, password: string): JsonNode = var response = $libstatus.multiAccountStoreDerivedAccounts($multiAccount); result = response.parseJson +proc getAccountData*(account: JsonNode, alias: string, identicon: string): JsonNode = + result = %* { + "name": alias, + "address": account["address"].getStr, + "photo-path": identicon, + "key-uid": account["keyUid"].getStr, + "keycard-pairing": nil + } + proc getAccountSettings*(account: JsonNode, alias: string, identicon: string, multiAccounts: JsonNode, defaultNetworks: JsonNode): JsonNode = result = %* { "key-uid": account["keyUid"].getStr, @@ -119,27 +128,17 @@ proc getAccountSettings*(account: JsonNode, alias: string, identicon: string, mu } proc setupRandomTestAccount*(): string = - var result: string - let generatedAddresses = generateAddresses().parseJson let account0 = generatedAddresses[0] let password = "0x2cd9bf92c5e20b1b410f5ace94d963a96e89156fbe65b70365e8596b37f1f165" #qwertyh let multiAccounts = generateMultiAccounts(account0, password) - # 5 - let accountData = %* { - "name": "Delectable Overjoyed Nauplius", - "address": account0["address"].getStr, - "photo-path": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAmElEQVR4nOzX4QmAIBBA4Yp2aY52aox2ao6mqf+SoajwON73M0J4HBy6TEEYQmMIjSE0htCECVlbDziv+/n6fuzb3OP/UmEmYgiNITRNm+LPqO2UE2YihtAYQlN818ptoZzau1btOakwEzGExhCa5hdi7d2p1zZLhZmIITSG0PhCpDGExhANEmYihtAYQmMIjSE0bwAAAP//kHQdRIWYzToAAAAASUVORK5CYII=", - "key-uid": account0["keyUid"].getStr, - "keycard-pairing": nil - } - # 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) @@ -147,4 +146,3 @@ proc setupRandomTestAccount*(): string = var subaccountdata = saveAccountAndLogin(multiAccounts, alias, identicon, $accountData, password, $configJSON, $settingsJSON) $subaccountData -