Skip to content

Commit

Permalink
add missing loadings and errors and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jrainville committed Jan 27, 2025
1 parent d8e954f commit 6b598ce
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/app/modules/onboarding/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,5 @@ proc stopKeycardService*(self: Controller) =
proc generateMnemonic*(self: Controller, length: int): string =
return self.keycardServiceV2.generateMnemonic(length)

# TODO make this async
proc exportRecoverKeysFromKeycard*(self: Controller) =
self.keycardServiceV2.asyncExportRecoverKeys()
5 changes: 2 additions & 3 deletions src/app/modules/onboarding/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ method validMnemonic*[T](self: Module[T], mnemonic: string): bool =
self.controller.validMnemonic(mnemonic)

method getMnemonic*[T](self: Module[T]): string =
return self.controller.generateMnemonic(12) # TODO put in a constant
return self.controller.generateMnemonic(SupportedMnemonicLength12)

method validateLocalPairingConnectionString*[T](self: Module[T], connectionString: string): bool =
self.controller.validateLocalPairingConnectionString(connectionString)
Expand Down Expand Up @@ -219,8 +219,7 @@ method onKeycardStateUpdated*[T](self: Module[T], keycardEvent: KeycardEventDto)
self.view.setKeycardEvent(keycardEvent)

method onKeycardSetPinFailure*[T](self: Module[T], error: string) =
# TODO handle error
echo "ERROR ", error
self.view.setPinFailed(error)

method onKeycardAuthorizeFailure*[T](self: Module[T], error: string) =
self.view.authorizationFailed(error)
Expand Down
5 changes: 1 addition & 4 deletions src/app/modules/onboarding/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ QtObject:
### QtSignals ###

proc appLoaded*(self: View) {.signal.}
proc setPinFailed*(self: View, error: string) {.signal.}
proc authorizationFailed*(self: View, error: string) {.signal.}
proc keycardExportKeysFailed*(self: View, error: string) {.signal.}
proc keycardExportKeysSuccess*(self: View) {.signal.}
Expand Down Expand Up @@ -99,9 +100,5 @@ QtObject:
proc exportRecoverKeys(self: View) {.slot.} =
self.delegate.exportRecoverKeys()

# TODO find what does this do
# proc mnemonicWasShown(self: View): string {.slot.} =
# return self.delegate.getMnemonic()

proc finishOnboardingFlow(self: View, flowInt: int, dataJson: string): string {.slot.} =
self.delegate.finishOnboardingFlow(flowInt, dataJson)
3 changes: 1 addition & 2 deletions src/app_service/service/keycardV2/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include async_tasks
logScope:
topics = "keycardV2-service"

const SupportedMnemonicLength12* = 12
const PUKLengthForStatusApp* = 12

const SIGNAL_KEYCARD_STATE_UPDATED* = "keycardStateUpdated"
Expand Down Expand Up @@ -94,7 +95,6 @@ QtObject:
seedPhrase.add(englishWords[ind.getInt])
return seedPhrase

# TODO make async?
proc generateMnemonic*(self: Service, length: int): string =
try:
let response = self.callRPC("GenerateMnemonic", %*{"length": length})
Expand Down Expand Up @@ -172,7 +172,6 @@ QtObject:
self.oldKeyCardService.receiveKeycardSignal(signal)
var jsonSignal = signal.parseJson

# TODO find what are the other types and if we need an enum for them
if jsonSignal["type"].getStr == "status-changed":
let keycardEvent = jsonSignal["event"].toKeycardEventDto()

Expand Down
4 changes: 0 additions & 4 deletions storybook/pages/OnboardingLayoutPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ SplitView {
logs.logEvent("OnboardingStore.mnemonicWasShown()")
}

function removeMnemonic() { // -> void
logs.logEvent("OnboardingStore.removeMnemonic()")
}

function validateLocalPairingConnectionString(connectionString: string) { // -> bool
logs.logEvent("OnboardingStore.validateLocalPairingConnectionString", ["connectionString"], arguments)
return !Number.isNaN(parseInt(connectionString))
Expand Down
1 change: 0 additions & 1 deletion storybook/qmlTests/tests/tst_OnboardingLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ Item {
return mockDriver.seedWords.join(" ")
}
function mnemonicWasShown() {}
function removeMnemonic() {}

readonly property int syncState: Onboarding.SyncState.InProgress // enum Onboarding.SyncState
function validateLocalPairingConnectionString(connectionString: string) {
Expand Down
19 changes: 12 additions & 7 deletions ui/app/AppLayouts/Onboarding2/KeycardCreateProfileFlow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ SQUtils.QObject {
signal keycardFactoryResetRequested
signal loadMnemonicRequested
signal keycardPinCreated(string pin)
signal setPinFailed(string error)
signal seedphraseSubmitted(string seedphrase)

signal keypairAddTryAgainRequested
signal reloadKeycardRequested
signal createProfileWithoutKeycardRequested
signal authorizationRequested

signal mnemonicRemovalRequested()
signal finished(bool withNewSeedphrase)

function init() {
Expand Down Expand Up @@ -158,8 +158,6 @@ SQUtils.QObject {

BackupSeedphraseOutro {
onBackupSeedphraseRemovalConfirmed: {
// TODO is this needed?
// root.mnemonicRemovalRequested()
root.loadMnemonicRequested()
root.stackView.push(addKeypairPage)
}
Expand All @@ -170,13 +168,15 @@ SQUtils.QObject {
id: seedphrasePage

SeedphrasePage {
id: seedphrasePage
title: qsTr("Create profile on empty Keycard using a recovery phrase")

isSeedPhraseValid: root.isSeedPhraseValid
onSeedphraseSubmitted: (seedphrase) => {
root.seedphraseSubmitted(seedphrase)
// TODO add loading here
seedphrasePage.btnLoading = true
root.authorizationRequested()
// The page transition happens in keycardCreatePinPage's Connections
}
}
}
Expand All @@ -185,15 +185,17 @@ SQUtils.QObject {
id: keycardCreatePinPage

KeycardCreatePinPage {
id: createPinPage

onKeycardPinCreated: (pin) => {
createPinPage.loading = true
Backpressure.debounce(root, root.keycardPinInfoPageDelay, () => {
// TODO add loading here
root.keycardPinCreated(pin)
})()
}
Connections {
target: root
onKeycardStateChanged: {
onKeycardStateChanged: function () {
if (root.keycardState === Onboarding.KeycardState.NotEmpty) {
if (d.withNewSeedphrase) {
// Need to authorize before getting a seedphrase
Expand All @@ -209,7 +211,10 @@ SQUtils.QObject {
root.stackView.push(addKeypairPage)
}
}
// TODO add other states and errors
}
onSetPinFailed: function (error) {
createPinPage.loading = false
createPinPage.error = qsTr("Error setting pin: %1").arg(error)
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions ui/app/AppLayouts/Onboarding2/LoginWithKeycardFlow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SQUtils.QObject {
property bool displayKeycardPromoBanner

signal keycardPinCreated(string pin)
signal setPinFailed(string error)
signal seedphraseSubmitted(string seedphrase)
signal reloadKeycardRequested
signal keycardFactoryResetRequested
Expand Down Expand Up @@ -127,12 +128,22 @@ SQUtils.QObject {
id: keycardCreatePinPage

KeycardCreatePinPage {
id: createPinPage

onKeycardPinCreated: (pin) => {
createPinPage.loading = true
Backpressure.debounce(root, root.keycardPinInfoPageDelay, () => {
root.keycardPinCreated(pin)
root.finished()
})()
}
Connections {
target: root
onSetPinFailed: function (error) {
createPinPage.loading = false
createPinPage.error = qsTr("Error setting pin: %1").arg(error)
}
}
}
}
}
9 changes: 5 additions & 4 deletions ui/app/AppLayouts/Onboarding2/OnboardingFlow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ SQUtils.QObject {
signal exportKeysRequested
signal loadMnemonicRequested
signal authorizationRequested
signal setPinFailed(string error)
signal authorizationFailed(string error)
signal keycardExportKeysFailed(string error)
signal keycardExportKeysSuccess

signal mnemonicRemovalRequested()

signal finished(int flow)

onSetPinFailed: function (error) {
keycardCreateProfileFlow.setPinFailed(error)
loginWithKeycardFlow.setPinFailed(error)
}
onAuthorizationFailed: loginWithKeycardFlow.authorizationFailed(error)
onKeycardExportKeysFailed: loginWithKeycardFlow.keycardExportKeysFailed(error)
onKeycardExportKeysSuccess: loginWithKeycardFlow.keycardExportKeysSuccess()
Expand Down Expand Up @@ -198,8 +201,6 @@ SQUtils.QObject {
stackView.replace(page, createProfilePage, StackView.PopTransition)
}

onMnemonicRemovalRequested: root.mnemonicRemovalRequested()

onSeedphraseSubmitted: (seedphrase) => root.seedphraseSubmitted(seedphrase)

onFinished: (withNewSeedphrase) => {
Expand Down
3 changes: 1 addition & 2 deletions ui/app/AppLayouts/Onboarding2/OnboardingLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Page {

readonly property Connections conn: Connections {
target: onboardingStore
onSetPinFailed: onboardingFlow.setPinFailed(error)
onAuthorizationFailed: onboardingFlow.authorizationFailed(error)
onKeycardExportKeysFailed: onboardingFlow.keycardExportKeysFailed(error)
onKeycardExportKeysSuccess: onboardingFlow.keycardExportKeysSuccess()
Expand Down Expand Up @@ -165,7 +166,6 @@ Page {
syncState: root.onboardingStore.syncState
addKeyPairState: root.onboardingStore.addKeyPairState

// TODO fix this, we can only call this when the keycard is connected
getSeedWords: function () {
return root.onboardingStore.getMnemonic().split(" ")
}
Expand All @@ -189,7 +189,6 @@ Page {
onAuthorizationRequested: d.authorize()
onShareUsageDataRequested: (enabled) => root.shareUsageDataRequested(enabled)
onReloadKeycardRequested: root.reloadKeycardRequested()
onMnemonicRemovalRequested: root.onboardingStore.removeMnemonic()

onSyncProceedWithConnectionString: (connectionString) =>
root.onboardingStore.inputConnectionStringForBootstrapping(connectionString)
Expand Down
26 changes: 24 additions & 2 deletions ui/app/AppLayouts/Onboarding2/pages/KeycardCreatePinPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import utils 1.0
KeycardBasePage {
id: root

property bool loading
property string error

signal keycardPinCreated(string pin)

image.source: Theme.png("onboarding/keycard/reading")
Expand Down Expand Up @@ -53,10 +56,16 @@ KeycardBasePage {
StatusBaseText {
id: errorText
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("PINs dont match")
text: qsTr("PINs don't match")
font.pixelSize: Theme.tertiaryTextFontSize
color: Theme.palette.dangerColor1
visible: false
},
StatusLoadingIndicator {
id: loadingIndicator
anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: Theme.halfPadding
visible: root.loading
}
]

Expand All @@ -83,13 +92,26 @@ KeycardBasePage {
image.source: Theme.png("onboarding/keycard/error")
}
},
State {
name: "error"
when: !!root.error
PropertyChanges {
target: errorText
visible: true
text: root.error
}
PropertyChanges {
target: root
image.source: Theme.png("onboarding/keycard/error")
}
},
State {
name: "success"
extend: "repeating"
when: !!d.pin && !!d.pin2 && d.pin === d.pin2
PropertyChanges {
target: root
title: qsTr("Keycard PIN set")
title: qsTr("Setting Keycard PIN")
}
PropertyChanges {
target: pinInput
Expand Down
1 change: 1 addition & 0 deletions ui/app/AppLayouts/Onboarding2/pages/SeedphrasePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ OnboardingPage {
title: qsTr("Create profile using a recovery phrase")
property string subtitle: qsTr("Enter your 12, 18 or 24 word recovery phrase")
property alias btnContinueText: btnContinue.text
property alias btnLoading: btnContinue.loading

property var isSeedPhraseValid: (mnemonic) => { console.error("isSeedPhraseValid IMPLEMENT ME"); return false }

Expand Down
5 changes: 2 additions & 3 deletions ui/app/AppLayouts/Onboarding2/stores/OnboardingStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ QtObject {
id: root

signal appLoaded
signal setPinFailed(string error)
signal authorizationFailed(string error)
signal keycardExportKeysSuccess
signal keycardExportKeysFailed(string error)
Expand All @@ -22,6 +23,7 @@ QtObject {
// d.onboardingModuleInst.accountLoginError.connect(root.accountLoginError)
// d.onboardingModuleInst.obtainingPasswordSuccess.connect(root.obtainingPasswordSuccess)
// d.onboardingModuleInst.obtainingPasswordError.connect(root.obtainingPasswordError)
d.onboardingModuleInst.setPinFailed.connect(root.setPinFailed)
d.onboardingModuleInst.authorizationFailed.connect(root.authorizationFailed)
d.onboardingModuleInst.onKeycardExportKeysSuccess.connect(root.keycardExportKeysSuccess)
d.onboardingModuleInst.keycardExportKeysFailed.connect(root.keycardExportKeysFailed)
Expand Down Expand Up @@ -70,9 +72,6 @@ QtObject {
function getMnemonic() { // -> string
return d.onboardingModuleInst.getMnemonic()
}
function removeMnemonic() { // -> void
d.onboardingModuleInst.removeMnemonic()
}

// sync
readonly property int syncState: d.onboardingModuleInst.syncState // cf. enum Onboarding.SyncState
Expand Down

0 comments on commit 6b598ce

Please sign in to comment.