refactor/extract saveAccountAndLogin method
This commit is contained in:
parent
f5a1c8a065
commit
6c03369ca2
|
@ -38,10 +38,7 @@ proc delete*(self: AccountModel) =
|
||||||
|
|
||||||
proc generateAddresses*(self: AccountModel): seq[GeneratedAccount] =
|
proc generateAddresses*(self: AccountModel): seq[GeneratedAccount] =
|
||||||
let accounts = parseJson(status_accounts.generateAddresses())
|
let accounts = parseJson(status_accounts.generateAddresses())
|
||||||
|
|
||||||
echo "----- generating accounts"
|
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
echo account
|
|
||||||
var generatedAccount = GeneratedAccount()
|
var generatedAccount = GeneratedAccount()
|
||||||
|
|
||||||
generatedAccount.publicKey = account["publicKey"].str
|
generatedAccount.publicKey = account["publicKey"].str
|
||||||
|
@ -56,7 +53,6 @@ proc generateAddresses*(self: AccountModel): seq[GeneratedAccount] =
|
||||||
generatedAccount.key = account["address"].str
|
generatedAccount.key = account["address"].str
|
||||||
|
|
||||||
self.generatedAddresses.add(generatedAccount)
|
self.generatedAddresses.add(generatedAccount)
|
||||||
|
|
||||||
self.generatedAddresses
|
self.generatedAddresses
|
||||||
|
|
||||||
# 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
|
||||||
|
@ -112,30 +108,7 @@ proc storeAccountAndLogin*(self: AccountModel, selectedAccountIndex: int, passwo
|
||||||
"installation-id": $genUUID()
|
"installation-id": $genUUID()
|
||||||
}
|
}
|
||||||
|
|
||||||
let subaccountData = %* [
|
discard saveAccountAndLogin(multiAccounts, alias, identicon, $accountData, password, $nodeConfig, $settingsJSON)
|
||||||
{
|
|
||||||
"public-key": multiAccounts[constants.PATH_DEFAULT_WALLET]["publicKey"],
|
|
||||||
"address": multiAccounts[constants.PATH_DEFAULT_WALLET]["address"],
|
|
||||||
"color": "#4360df",
|
|
||||||
"wallet": true,
|
|
||||||
"path": constants.PATH_DEFAULT_WALLET,
|
|
||||||
"name": "Status account"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"public-key": multiAccounts[constants.PATH_WHISPER]["publicKey"],
|
|
||||||
"address": multiAccounts[constants.PATH_WHISPER]["address"],
|
|
||||||
"name": alias,
|
|
||||||
"photo-path": identicon,
|
|
||||||
"path": constants.PATH_WHISPER,
|
|
||||||
"chat": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
result = $libstatus.saveAccountAndLogin($accountData, password, $settingsJSON,
|
|
||||||
$nodeConfig, $subaccountData)
|
|
||||||
|
|
||||||
let saveResult = result.parseJson
|
|
||||||
|
|
||||||
if saveResult["error"].getStr == "":
|
|
||||||
self.events.emit("accountsReady", Args())
|
self.events.emit("accountsReady", Args())
|
||||||
echo "Account saved succesfully"
|
""
|
||||||
|
|
|
@ -2,6 +2,7 @@ import libstatus
|
||||||
import core
|
import core
|
||||||
import json
|
import json
|
||||||
import utils
|
import utils
|
||||||
|
import accounts/constants
|
||||||
import os
|
import os
|
||||||
|
|
||||||
proc queryAccounts*(): string =
|
proc queryAccounts*(): string =
|
||||||
|
@ -56,6 +57,33 @@ proc initNodeAccounts*() =
|
||||||
# 2
|
# 2
|
||||||
discard $libstatus.openAccounts(datadir);
|
discard $libstatus.openAccounts(datadir);
|
||||||
|
|
||||||
|
proc saveAccountAndLogin*(multiAccounts: JsonNode, alias: string, identicon: string, accountData: string, password: string, configJSON: string, settingsJSON: string): JsonNode =
|
||||||
|
let subaccountData = %* [
|
||||||
|
{
|
||||||
|
"public-key": multiAccounts[constants.PATH_DEFAULT_WALLET]["publicKey"],
|
||||||
|
"address": multiAccounts[constants.PATH_DEFAULT_WALLET]["address"],
|
||||||
|
"color": "#4360df",
|
||||||
|
"wallet": true,
|
||||||
|
"path": constants.PATH_DEFAULT_WALLET,
|
||||||
|
"name": "Status account"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"public-key": multiAccounts[constants.PATH_WHISPER]["publicKey"],
|
||||||
|
"address": multiAccounts[constants.PATH_WHISPER]["address"],
|
||||||
|
"name": alias,
|
||||||
|
"photo-path": identicon,
|
||||||
|
"path": constants.PATH_WHISPER,
|
||||||
|
"chat": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
var savedResult = $libstatus.saveAccountAndLogin(accountData, password, settingsJSON, configJSON, $subaccountData)
|
||||||
|
let parsedSavedResult = savedResult.parseJson
|
||||||
|
|
||||||
|
if parsedSavedResult["error"].getStr == "":
|
||||||
|
echo "Account saved succesfully"
|
||||||
|
subaccountData
|
||||||
|
|
||||||
proc setupRandomTestAccount*(): string =
|
proc setupRandomTestAccount*(): string =
|
||||||
var result: string
|
var result: string
|
||||||
# 3
|
# 3
|
||||||
|
@ -287,30 +315,9 @@ proc setupRandomTestAccount*(): string =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let subaccountData = %* [
|
var alias = "Delectable Overjoyed Nauplius"
|
||||||
{
|
var identicon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAmElEQVR4nOzX4QmAIBBA4Yp2aY52aox2ao6mqf+SoajwON73M0J4HBy6TEEYQmMIjSE0htCECVlbDziv+/n6fuzb3OP/UmEmYgiNITRNm+LPqO2UE2YihtAYQlN818ptoZzau1btOakwEzGExhCa5hdi7d2p1zZLhZmIITSG0PhCpDGExhANEmYihtAYQmMIjSE0bwAAAP//kHQdRIWYzToAAAAASUVORK5CYII="
|
||||||
"public-key": multiAccounts["m/44'/60'/0'/0/0"]["publicKey"],
|
|
||||||
"address": multiAccounts["m/44'/60'/0'/0/0"]["address"],
|
|
||||||
"color": "#4360df",
|
|
||||||
"wallet": true,
|
|
||||||
"path": "m/44'/60'/0'/0/0",
|
|
||||||
"name": "Status account"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"public-key": multiAccounts["m/43'/60'/1581'/0'/0"]["publicKey"],
|
|
||||||
"address": multiAccounts["m/43'/60'/1581'/0'/0"]["address"],
|
|
||||||
"name": "Delectable Overjoyed Nauplius",
|
|
||||||
"photo-path": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAmElEQVR4nOzX4QmAIBBA4Yp2aY52aox2ao6mqf+SoajwON73M0J4HBy6TEEYQmMIjSE0htCECVlbDziv+/n6fuzb3OP/UmEmYgiNITRNm+LPqO2UE2YihtAYQlN818ptoZzau1btOakwEzGExhCa5hdi7d2p1zZLhZmIITSG0PhCpDGExhANEmYihtAYQmMIjSE0bwAAAP//kHQdRIWYzToAAAAASUVORK5CYII=",
|
|
||||||
"path": "m/43'/60'/1581'/0'/0",
|
|
||||||
"chat": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
var savedResult = $libstatus.saveAccountAndLogin($accountData, password, $settingsJSON,
|
var subaccountdata = saveAccountAndLogin(multiAccounts, alias, identicon, $accountData, password, $configJSON, $settingsJSON)
|
||||||
$configJSON, $subaccountData)
|
|
||||||
let parsedSavedResult = savedResult.parseJson
|
|
||||||
|
|
||||||
if parsedSavedResult["error"].getStr == "":
|
|
||||||
echo "Account saved succesfully"
|
|
||||||
$subaccountData
|
$subaccountData
|
||||||
|
|
||||||
|
|
|
@ -253,7 +253,7 @@ SwipeView {
|
||||||
|
|
||||||
const storeResponse = onboardingModel.storeAccountAndLogin(selectedAccountIndex, txtPassword.text)
|
const storeResponse = onboardingModel.storeAccountAndLogin(selectedAccountIndex, txtPassword.text)
|
||||||
|
|
||||||
const response = JSON.parse(storeResponse);
|
// const response = JSON.parse(storeResponse);
|
||||||
// if (response.error) {
|
// if (response.error) {
|
||||||
// storeAccountAndLoginError.text += response.error;
|
// storeAccountAndLoginError.text += response.error;
|
||||||
// return storeAccountAndLoginError.open();
|
// return storeAccountAndLoginError.open();
|
||||||
|
|
Loading…
Reference in New Issue