This commit is contained in:
Iuri Matias 2020-05-21 12:16:00 -04:00
parent ff25fc818a
commit ce236fbc82
6 changed files with 3 additions and 166 deletions

View File

@ -7,7 +7,6 @@ import ../../status/libstatus
import ../../models/accounts as Models import ../../models/accounts as Models
import ../../constants/constants import ../../constants/constants
import ../../status/test as status_test import ../../status/test as status_test
# import "../../status/core" as status
import ../signals/types import ../signals/types
import uuids import uuids
import eventemitter import eventemitter
@ -22,7 +21,6 @@ proc newController*(events: EventEmitter): 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(events) result.model = newAccountModel(events)
# result.view = newOnboardingView(result.model, storeAccountAndLogin, generateRandomAccountAndLogin)
result.view = newOnboardingView(result.model) result.view = newOnboardingView(result.model)
result.variant = newQVariant(result.view) result.variant = newQVariant(result.view)
@ -31,19 +29,7 @@ proc delete*(self: OnboardingController) =
delete self.variant delete self.variant
proc init*(self: OnboardingController) = proc init*(self: OnboardingController) =
# let addresses = parseJson(status_accounts.generateAddresses())
let accounts = self.model.generateAddresses() let accounts = self.model.generateAddresses()
for account in accounts: for account in accounts:
# self.view.addAddressToList("account.username", "account.identicon", "account.key")
self.view.addAddressToList(account.username, account.identicon, account.key) self.view.addAddressToList(account.username, account.identicon, account.key)
# echo address
# var username = $libstatus.generateAlias(address["publicKey"].str.toGoString)
# var identicon = $libstatus.identicon(address["publicKey"].str.toGoString)
# var generatedAddress = address["address"].str
# self.view.addAddressToList(username, identicon, generatedAddress)
# method onSignal(self: OnboardingController, data: Signal) =
# echo "new signal received"
# var msg = cast[WalletSignal](data)
# self.view.setLastMessage(msg.content)

View File

@ -25,9 +25,6 @@ QtObject:
type OnboardingView* = ref object of QAbstractListModel type OnboardingView* = ref object of QAbstractListModel
addresses*: seq[Address] addresses*: seq[Address]
model: AccountModel model: AccountModel
# m_generatedAddresses: string
# doStoreAccountAndLogin: proc(model: AccountModel, selectedAccount: int, password: string): string
# doGenerateRandomAccountAndLogin: proc(events: EventEmitter)
proc setup(self: OnboardingView) = proc setup(self: OnboardingView) =
self.QAbstractListModel.setup self.QAbstractListModel.setup
@ -38,12 +35,9 @@ QtObject:
address.delete address.delete
self.addresses = @[] self.addresses = @[]
# proc newOnboardingView*(model: AccountModel, doStoreAccountAndLogin: proc, doGenerateRandomAccountAndLogin: proc(events: EventEmitter)): OnboardingView =
proc newOnboardingView*(model: AccountModel): OnboardingView = proc newOnboardingView*(model: AccountModel): OnboardingView =
new(result, delete) new(result, delete)
result.model = model result.model = model
# result.doStoreAccountAndLogin = doStoreAccountAndLogin
# result.doGenerateRandomAccountAndLogin = doGenerateRandomAccountAndLogin
result.addresses = @[] result.addresses = @[]
result.setup result.setup
@ -75,41 +69,7 @@ QtObject:
AddressRoles.Identicon.int:"identicon", AddressRoles.Identicon.int:"identicon",
AddressRoles.Key.int:"key" }.toTable AddressRoles.Key.int:"key" }.toTable
# proc getGeneratedAddresses*(self: OnboardingView): string {.slot.} =
# result = self.m_generatedAddresses
# proc generatedAddressesChanged*(self: OnboardingView,
# generatedAddresses: string) {.signal.}
# proc setGeneratedAddresses*(self: OnboardingView, generatedAddresses: string) {.slot.} =
# if self.m_generatedAddresses == generatedAddresses:
# return
# self.m_generatedAddresses = generatedAddresses
# self.generatedAddressesChanged(generatedAddresses)
# QtProperty[string]generatedAddresses:
# read = getGeneratedAddresses
# write = setGeneratedAddresses
# notify = generatedAddressesChanged
# QML functions
# proc generateAddresses*(self: OnboardingView) {.slot.} =
# self.setGeneratedAddresses(status_accounts.generateAddresses())
# proc generateAlias*(self: OnboardingView, publicKey: string): string {.slot.} =
# result = $libstatus.generateAlias(publicKey.toGoString)
# proc identicon*(self: OnboardingView, publicKey: string): string {.slot.} =
# result = $libstatus.identicon(publicKey.toGoString)
# proc storeAccountAndLogin(self: OnboardingView, selectedAccount: string, password: string): string {.slot.} =
proc storeAccountAndLogin(self: OnboardingView, selectedAccountIndex: int, password: string): string {.slot.} = proc storeAccountAndLogin(self: OnboardingView, selectedAccountIndex: int, password: string): string {.slot.} =
echo "--------------------"
echo "--------------------"
echo selectedAccountIndex
echo "--------------------"
echo "--------------------"
# var selectedAccountIndex = self.addresses
result = self.model.storeAccountAndLogin(selectedAccountIndex, password) result = self.model.storeAccountAndLogin(selectedAccountIndex, password)
# 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

View File

@ -58,12 +58,6 @@ proc generateAddresses*(self: AccountModel): seq[GeneratedAccount] =
generatedAccount.identicon = $libstatus.identicon(account["publicKey"].str.toGoString) generatedAccount.identicon = $libstatus.identicon(account["publicKey"].str.toGoString)
generatedAccount.key = account["address"].str generatedAccount.key = account["address"].str
# var generatedAccount = cast[GeneratedAccount](account.to(GeneratedAccountBase))
# generatedAccount.username = $libstatus.generateAlias(account["publicKey"].str.toGoString)
# generatedAccount.identicon = $libstatus.identicon(account["publicKey"].str.toGoString)
# generatedAccount.key = account["address"].str
self.generatedAddresses.add(generatedAccount) self.generatedAddresses.add(generatedAccount)
self.generatedAddresses self.generatedAddresses

View File

@ -81,14 +81,6 @@ proc mainProc() =
engine.setRootContextProperty("onboardingLogic", onboarding.variant) engine.setRootContextProperty("onboardingLogic", onboarding.variant)
engine.setRootContextProperty("onboardingModel", onboarding.variant) engine.setRootContextProperty("onboardingModel", onboarding.variant)
# TODO: figure out a way to prevent this from breaking Qt Creator
# var initLibStatusQml = proc(): LibStatusQml =
# let libStatus = newLibStatusQml();
# return libStatus;
# discard qmlRegisterSingletonType[LibStatusQml]("im.status.desktop.Status", 1, 0, "Status", initLibStatusQml)
var profile = profile.newController() var profile = profile.newController()
# profile.init(accounts) # TODO: use correct account # profile.init(accounts) # TODO: use correct account
engine.setRootContextProperty("profileModel", profile.variant) engine.setRootContextProperty("profileModel", profile.variant)

View File

@ -12,7 +12,7 @@ SwipeView {
// property string strGeneratedAccounts: onboardingLogic.generatedAddresses // property string strGeneratedAccounts: onboardingLogic.generatedAddresses
// property var generatedAccounts: {} // property var generatedAccounts: {}
// signal storeAccountAndLoginResult(response: var) // signal storeAccountAndLoginResult(response: var)
signal storeAccountAndLoginResult() signal loginDone()
onCurrentItemChanged: { onCurrentItemChanged: {
currentItem.txtPassword.focus = true; currentItem.txtPassword.focus = true;
@ -39,12 +39,6 @@ SwipeView {
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }
// Item {
// Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
// transformOrigin: Item.Center
// anchors.top: parent.top
// anchors.topMargin: 50
Row { Row {
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
@ -134,59 +128,9 @@ SwipeView {
Layout.fillWidth: true Layout.fillWidth: true
anchors.topMargin: 36 anchors.topMargin: 36
anchors.fill: parent anchors.fill: parent
// model: ListModel {
// ListElement {
// username: "Bill Smith"
// key: "0x123"
// }
// ListElement {
// username: "Slushy Welltodo Woodborer"
// key: "0x234"
// }
// }
} }
// Repeater {
// model: generatedAccountsModel
// Rectangle {
// height: 32
// width: 32
// anchors.leftMargin: 20
// anchors.rightMargin: 20
// Row {
// RadioButton {
// checked: index == 0 ? true : false
// ButtonGroup.group: accountGroup
// onClicked: {
// wizardStep2.selectedIndex = index;
// }
// }
// Column {
// Image {
// source: identicon
// }
// }
// Column {
// Text {
// text: alias
// }
// Text {
// text: publicKey
// width: 160
// elide: Text.ElideMiddle
// }
// }
// }
// }
// }
} }
// }
Button { Button {
text: "Select" text: "Select"
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
@ -199,8 +143,6 @@ SwipeView {
} }
} }
} }
} }
@ -214,7 +156,6 @@ SwipeView {
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: 20 anchors.topMargin: 20
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }
Rectangle { Rectangle {
@ -288,15 +229,10 @@ SwipeView {
} }
} }
MessageDialog { MessageDialog {
id: storeAccountAndLoginError id: storeAccountAndLoginError
title: "Error storing account and logging in" title: "Error storing account and logging in"
text: "An error occurred while storing your account and logging in: " text: "An error occurred while storing your account and logging in: "
// icon: StandardIcon.Error // icon: StandardIcon.Error
standardButtons: StandardButton.Ok standardButtons: StandardButton.Ok
} }
@ -317,48 +253,17 @@ SwipeView {
const storeResponse = onboardingModel.storeAccountAndLogin(selectedAccountIndex, txtPassword.text) const storeResponse = onboardingModel.storeAccountAndLogin(selectedAccountIndex, txtPassword.text)
// const storeResponse = onboardingModel.storeAccountAndLogin(JSON.stringify(selectedAccount), txtPassword.text)
// const selectedAccount = swipeView.generatedAccounts[wizardStep2.selectedIndex];
// const storeResponse = onboardingModel.storeAccountAndLogin(JSON.stringify(selectedAccount), 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();
// } // }
console.log("======="); swipeView.loginDone();
console.log(storeResponse);
console.log("=======")
// swipeView.storeAccountAndLoginResult(response);
swipeView.storeAccountAndLoginResult();
} }
} }
} }
// handle the serialised result coming from node and deserialise into JSON
// TODO: maybe we should figure out a clever to avoid this?
// onStrGeneratedAccountsChanged: {
// if (generatedAccounts === null || generatedAccounts === "") {
// return;
// }
// swipeView.generatedAccounts = JSON.parse(strGeneratedAccounts);
// }
// handle deserialised data coming from the node
// onGeneratedAccountsChanged: {
// generatedAccountsModel.clear();
// generatedAccounts.forEach(acc => {
// generatedAccountsModel.append({
// publicKey: acc.publicKey,
// alias: onboardingLogic.generateAlias(acc.publicKey),
// identicon: onboardingLogic.identicon(acc.publicKey)
// });
// });
// }
} }
/*##^## /*##^##
Designer { Designer {
D{i:0;autoSize:true;height:480;width:640} D{i:0;autoSize:true;height:480;width:640}

View File

@ -57,7 +57,7 @@ Page {
DSM.SignalTransition { DSM.SignalTransition {
targetState: appState targetState: appState
signal: genKey.storeAccountAndLoginResult signal: genKey.loginDone
// guard: !response.error // guard: !response.error
} }
} }