move storeAccount logic out of the view
This commit is contained in:
parent
033cd3bd06
commit
2cf1541115
|
@ -1,16 +1,106 @@
|
|||
import NimQml
|
||||
import json
|
||||
import ../../status/accounts as status_accounts
|
||||
import nimcrypto
|
||||
import ../../status/utils
|
||||
import ../../status/libstatus
|
||||
import ../../models/accounts as Models
|
||||
import ../../constants/constants
|
||||
import ../../status/test as status_test
|
||||
# import "../../status/core" as status
|
||||
import ../signals/types
|
||||
import uuids
|
||||
import eventemitter
|
||||
import view
|
||||
|
||||
proc storeAccountAndLogin(events: EventEmitter, selectedAccount: string, password: string): string =
|
||||
echo "--------------------"
|
||||
echo "--------------------"
|
||||
echo "storeAccountAndLogin"
|
||||
echo "--------------------"
|
||||
echo "--------------------"
|
||||
let account = to(json.parseJson(selectedAccount), Models.GeneratedAccount)
|
||||
let password = "0x" & $keccak_256.digest(password)
|
||||
let multiAccount = %* {
|
||||
"accountID": account.id,
|
||||
"paths": [constants.PATH_WALLET_ROOT, constants.PATH_EIP_1581, constants.PATH_WHISPER,
|
||||
constants.PATH_DEFAULT_WALLET],
|
||||
"password": password
|
||||
}
|
||||
let storeResult = $libstatus.multiAccountStoreDerivedAccounts($multiAccount);
|
||||
let multiAccounts = storeResult.parseJson
|
||||
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 defaultNetworks = constants.DEFAULT_NETWORKS
|
||||
let settingsJSON = %* {
|
||||
"key-uid": account.keyUid,
|
||||
"mnemonic": account.mnemonic,
|
||||
"public-key": multiAccounts[constants.PATH_WHISPER]["publicKey"].getStr,
|
||||
"name": alias,
|
||||
"address": account.address,
|
||||
"eip1581-address": multiAccounts[constants.PATH_EIP_1581]["address"].getStr,
|
||||
"dapps-address": multiAccounts[constants.PATH_DEFAULT_WALLET]["address"].getStr,
|
||||
"wallet-root-address": multiAccounts[constants.PATH_WALLET_ROOT]["address"].getStr,
|
||||
"preview-privacy?": true,
|
||||
"signing-phrase": generateSigningPhrase(3),
|
||||
"log-level": "INFO",
|
||||
"latest-derived-path": 0,
|
||||
"networks/networks": $defaultNetworks,
|
||||
"currency": "usd",
|
||||
"photo-path": identicon,
|
||||
"waku-enabled": true,
|
||||
"wallet/visible-tokens": {
|
||||
"mainnet": ["SNT"]
|
||||
},
|
||||
"appearance": 0,
|
||||
"networks/current-network": "mainnet_rpc",
|
||||
"installation-id": $genUUID()
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
]
|
||||
|
||||
result = $libstatus.saveAccountAndLogin($accountData, password, $settingsJSON,
|
||||
$nodeConfig, $subaccountData)
|
||||
|
||||
let saveResult = result.parseJson
|
||||
|
||||
if saveResult["error"].getStr == "":
|
||||
events.emit("node:ready", Args())
|
||||
echo "Account saved succesfully"
|
||||
|
||||
type OnboardingController* = ref object of SignalSubscriber
|
||||
view*: OnboardingView
|
||||
variant*: QVariant
|
||||
|
||||
proc newController*(events: EventEmitter): OnboardingController =
|
||||
result = OnboardingController()
|
||||
result.view = newOnboardingView(events)
|
||||
result.view = newOnboardingView(events, storeAccountAndLogin)
|
||||
result.variant = newQVariant(result.view)
|
||||
|
||||
proc delete*(self: OnboardingController) =
|
||||
|
|
|
@ -14,6 +14,7 @@ QtObject:
|
|||
type OnboardingView* = ref object of QObject
|
||||
m_generatedAddresses: string
|
||||
events: EventEmitter
|
||||
doStoreAccountAndLogin: proc(events: EventEmitter, selectedAccount: string, password: string): string
|
||||
|
||||
proc setup(self: OnboardingView) =
|
||||
self.QObject.setup
|
||||
|
@ -21,9 +22,10 @@ QtObject:
|
|||
proc delete*(self: OnboardingView) =
|
||||
self.QObject.delete
|
||||
|
||||
proc newOnboardingView*(events: EventEmitter): OnboardingView =
|
||||
proc newOnboardingView*(events: EventEmitter, doStoreAccountAndLogin: proc): OnboardingView =
|
||||
new(result, delete)
|
||||
result.events = events
|
||||
result.doStoreAccountAndLogin = doStoreAccountAndLogin
|
||||
result.setup()
|
||||
|
||||
proc getGeneratedAddresses*(self: OnboardingView): string {.slot.} =
|
||||
|
@ -54,80 +56,7 @@ QtObject:
|
|||
result = $libstatus.identicon(publicKey.toGoString)
|
||||
|
||||
proc storeAccountAndLogin(self: OnboardingView, selectedAccount: string, password: string): string {.slot.} =
|
||||
let account = to(json.parseJson(selectedAccount), Models.GeneratedAccount)
|
||||
let password = "0x" & $keccak_256.digest(password)
|
||||
let multiAccount = %* {
|
||||
"accountID": account.id,
|
||||
"paths": [constants.PATH_WALLET_ROOT, constants.PATH_EIP_1581, constants.PATH_WHISPER,
|
||||
constants.PATH_DEFAULT_WALLET],
|
||||
"password": password
|
||||
}
|
||||
let storeResult = $libstatus.multiAccountStoreDerivedAccounts($multiAccount);
|
||||
let multiAccounts = storeResult.parseJson
|
||||
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 defaultNetworks = constants.DEFAULT_NETWORKS
|
||||
let settingsJSON = %* {
|
||||
"key-uid": account.keyUid,
|
||||
"mnemonic": account.mnemonic,
|
||||
"public-key": multiAccounts[constants.PATH_WHISPER]["publicKey"].getStr,
|
||||
"name": alias,
|
||||
"address": account.address,
|
||||
"eip1581-address": multiAccounts[constants.PATH_EIP_1581]["address"].getStr,
|
||||
"dapps-address": multiAccounts[constants.PATH_DEFAULT_WALLET]["address"].getStr,
|
||||
"wallet-root-address": multiAccounts[constants.PATH_WALLET_ROOT]["address"].getStr,
|
||||
"preview-privacy?": true,
|
||||
"signing-phrase": generateSigningPhrase(3),
|
||||
"log-level": "INFO",
|
||||
"latest-derived-path": 0,
|
||||
"networks/networks": $defaultNetworks,
|
||||
"currency": "usd",
|
||||
"photo-path": identicon,
|
||||
"waku-enabled": true,
|
||||
"wallet/visible-tokens": {
|
||||
"mainnet": ["SNT"]
|
||||
},
|
||||
"appearance": 0,
|
||||
"networks/current-network": "mainnet_rpc",
|
||||
"installation-id": $genUUID()
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
]
|
||||
|
||||
result = $libstatus.saveAccountAndLogin($accountData, password, $settingsJSON,
|
||||
$nodeConfig, $subaccountData)
|
||||
|
||||
let saveResult = result.parseJson
|
||||
|
||||
if saveResult["error"].getStr == "":
|
||||
self.events.emit("node:ready", Args())
|
||||
echo "Account saved succesfully"
|
||||
result = self.doStoreAccountAndLogin(self.events, selectedAccount, password)
|
||||
|
||||
proc generateRandomAccountAndLogin*(self: OnboardingView) {.slot.} =
|
||||
discard status_test.setupNewAccount()
|
||||
|
|
|
@ -79,6 +79,7 @@ proc mainProc() =
|
|||
var onboarding = onboarding.newController(events)
|
||||
# onboarding.init()
|
||||
engine.setRootContextProperty("onboardingLogic", onboarding.variant)
|
||||
engine.setRootContextProperty("onboardingModel", onboarding.variant)
|
||||
|
||||
|
||||
# TODO: figure out a way to prevent this from breaking Qt Creator
|
||||
|
|
|
@ -196,18 +196,17 @@ SwipeView {
|
|||
console.log("confirm clicked " + txtConfirmPassword.text + " : " + txtPassword.text);
|
||||
|
||||
if (txtConfirmPassword.text != txtPassword.text) {
|
||||
passwordsDontMatchError.open();
|
||||
return passwordsDontMatchError.open();
|
||||
}
|
||||
else {
|
||||
const selectedAccount = swipeView.generatedAccounts[wizardStep2.selectedIndex];
|
||||
const storeResponse = onboardingLogic.storeAccountAndLogin(JSON.stringify(selectedAccount), txtPassword.text)
|
||||
const response = JSON.parse(storeResponse);
|
||||
if (response.error) {
|
||||
storeAccountAndLoginError.text += response.error;
|
||||
return storeAccountAndLoginError.open();
|
||||
}
|
||||
swipeView.storeAccountAndLoginResult(response);
|
||||
|
||||
const selectedAccount = swipeView.generatedAccounts[wizardStep2.selectedIndex];
|
||||
const storeResponse = onboardingModel.storeAccountAndLogin(JSON.stringify(selectedAccount), txtPassword.text)
|
||||
const response = JSON.parse(storeResponse);
|
||||
if (response.error) {
|
||||
storeAccountAndLoginError.text += response.error;
|
||||
return storeAccountAndLoginError.open();
|
||||
}
|
||||
swipeView.storeAccountAndLoginResult(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,9 +37,9 @@ RowLayout {
|
|||
anchors.topMargin: 50
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 15
|
||||
label: "Generate random acct and login"
|
||||
label: "Generate random account and login"
|
||||
onClicked: {
|
||||
onboardingLogic.generateRandomAccountAndLogin()
|
||||
onboardingModel.generateRandomAccountAndLogin()
|
||||
app.visible = true
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue