fix: double "login" event being emitted by login / onboarding

This commit is contained in:
Richard Ramos 2020-06-29 15:49:34 -04:00 committed by Iuri Matias
parent 6874c7eb55
commit 6d6f67476b
6 changed files with 51 additions and 0 deletions

View File

@ -34,6 +34,7 @@ proc handleNodeStopped(self: LoginController, data: Signal) =
self.view.onLoggedOut() self.view.onLoggedOut()
proc handleNodeLogin(self: LoginController, data: Signal) = proc handleNodeLogin(self: LoginController, data: Signal) =
if not self.view.isCurrentFlow: return
let response = NodeSignal(data) let response = NodeSignal(data)
if self.view.currentAccount.account != nil: if self.view.currentAccount.account != nil:
self.view.setLastLoginResponse(response.event) self.view.setLastLoginResponse(response.event)

View File

@ -18,6 +18,7 @@ QtObject:
status: Status status: Status
accounts: seq[NodeAccount] accounts: seq[NodeAccount]
currentAccount*: AccountInfoView currentAccount*: AccountInfoView
isCurrentFlow*: bool
proc setup(self: LoginView) = proc setup(self: LoginView) =
self.QAbstractListModel.setup self.QAbstractListModel.setup
@ -32,6 +33,7 @@ QtObject:
result.accounts = @[] result.accounts = @[]
result.currentAccount = newAccountInfoView() result.currentAccount = newAccountInfoView()
result.status = status result.status = status
result.isCurrentFlow = false
result.setup result.setup
proc getCurrentAccount*(self: LoginView): QVariant {.slot.} = proc getCurrentAccount*(self: LoginView): QVariant {.slot.} =
@ -101,3 +103,20 @@ QtObject:
self.loginResponseChanged(loginResponse.error) self.loginResponseChanged(loginResponse.error)
proc onLoggedOut*(self: LoginView) {.signal.} proc onLoggedOut*(self: LoginView) {.signal.}
proc isCurrentFlow*(self: LoginView): bool {.slot.} =
result = self.isCurrentFlow
proc currentFlowChanged*(self: LoginView, v: bool) {.signal.}
proc setCurrentFlow*(self: LoginView, v: bool) {.slot.} =
if self.isCurrentFlow == v: return
self.isCurrentFlow = v
self.currentFlowChanged(v)
proc `isCurrentFlow=`*(self: LoginView, v: bool) = self.setCurrentFlow(v)
QtProperty[bool] isCurrentFlow:
read = isCurrentFlow
write = setCurrentFlow
notify = currentFlowChanged

View File

@ -30,6 +30,7 @@ proc reset*(self: OnboardingController) =
self.view.removeAccounts() self.view.removeAccounts()
proc handleNodeLogin(self: OnboardingController, data: Signal) = proc handleNodeLogin(self: OnboardingController, data: Signal) =
if not self.view.isCurrentFlow: return
let response = NodeSignal(data) let response = NodeSignal(data)
if self.view.currentAccount.account != nil: if self.view.currentAccount.account != nil:
self.view.setLastLoginResponse(response.event) self.view.setLastLoginResponse(response.event)

View File

@ -16,6 +16,7 @@ QtObject:
accounts*: seq[GeneratedAccount] accounts*: seq[GeneratedAccount]
currentAccount*: AccountInfoView currentAccount*: AccountInfoView
status*: Status status*: Status
isCurrentFlow*: bool
proc setup(self: OnboardingView) = proc setup(self: OnboardingView) =
self.QAbstractListModel.setup self.QAbstractListModel.setup
@ -30,6 +31,7 @@ QtObject:
result.accounts = @[] result.accounts = @[]
result.currentAccount = newAccountInfoView() result.currentAccount = newAccountInfoView()
result.status = status result.status = status
result.isCurrentFlow = false
result.setup result.setup
proc addAccountToList*(self: OnboardingView, account: GeneratedAccount) = proc addAccountToList*(self: OnboardingView, account: GeneratedAccount) =
@ -106,3 +108,20 @@ QtObject:
proc setLastLoginResponse*(self: OnboardingView, loginResponse: StatusGoError) = proc setLastLoginResponse*(self: OnboardingView, loginResponse: StatusGoError) =
self.loginResponseChanged(loginResponse.error) self.loginResponseChanged(loginResponse.error)
proc isCurrentFlow*(self: OnboardingView): bool {.slot.} =
result = self.isCurrentFlow
proc currentFlowChanged*(self: OnboardingView, v: bool) {.signal.}
proc setCurrentFlow*(self: OnboardingView, v: bool) {.slot.} =
if self.isCurrentFlow == v: return
self.isCurrentFlow = v
self.currentFlowChanged(v)
proc `isCurrentFlow=`*(self: OnboardingView, v: bool) = self.setCurrentFlow(v)
QtProperty[bool] isCurrentFlow:
read = isCurrentFlow
write = setCurrentFlow
notify = currentFlowChanged

View File

@ -155,6 +155,8 @@ ModalPopup {
} }
// TODO this doesn't seem to work because the function freezes the view // TODO this doesn't seem to work because the function freezes the view
loading = true loading = true
loginModel.isCurrentFlow = false;
onboardingModel.isCurrentFlow = true;
const result = onboardingModel.storeDerivedAndLogin(repeatPasswordField.text); const result = onboardingModel.storeDerivedAndLogin(repeatPasswordField.text);
const error = JSON.parse(result).error const error = JSON.parse(result).error
if (error) { if (error) {

View File

@ -15,6 +15,11 @@ Item {
id: loginView id: loginView
anchors.fill: parent anchors.fill: parent
function setCurrentFlow(isLogin) {
loginModel.isCurrentFlow = isLogin;
onboardingModel.isCurrentFlow = !isLogin;
}
Component.onCompleted: { Component.onCompleted: {
txtPassword.forceActiveFocus(Qt.MouseFocusReason) txtPassword.forceActiveFocus(Qt.MouseFocusReason)
} }
@ -46,6 +51,7 @@ Item {
ConfirmAddExistingKeyModal { ConfirmAddExistingKeyModal {
id: confirmAddExstingKeyModal id: confirmAddExstingKeyModal
onOpenModalClick: function () { onOpenModalClick: function () {
setCurrentFlow(false);
onExistingKeyClicked() onExistingKeyClicked()
} }
} }
@ -56,6 +62,7 @@ Item {
loginModel.setCurrentAccount(index) loginModel.setCurrentAccount(index)
} }
onOpenModalClick: function () { onOpenModalClick: function () {
setCurrentFlow(true);
confirmAddExstingKeyModal.open() confirmAddExstingKeyModal.open()
} }
} }
@ -143,6 +150,7 @@ Item {
if (loading) { if (loading) {
return; return;
} }
setCurrentFlow(true);
loading = true loading = true
loginModel.login(txtPassword.textField.text) loginModel.login(txtPassword.textField.text)
} }
@ -222,6 +230,7 @@ Item {
anchors.topMargin: 26 anchors.topMargin: 26
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
onClicked: { onClicked: {
setCurrentFlow(false);
onGenKeyClicked() onGenKeyClicked()
} }