feat(Onboarding): validate mnemonic when importing seed phrase

Closes #395
This commit is contained in:
Pascal Precht 2020-06-25 11:06:31 +02:00 committed by Iuri Matias
parent 9041eb59e7
commit 89da127468
8 changed files with 57 additions and 7 deletions

View File

@ -2,7 +2,7 @@ import NimQml, Tables, json, nimcrypto, strformat, json_serialization, strutils
import ../../status/libstatus/types as status_types
import ../../signals/types
import ../../status/accounts as AccountModel
import ../../status/status
import ../../status/[status, wallet]
import views/account_info
type
@ -90,6 +90,9 @@ QtObject:
except StatusGoException as e:
result = StatusGoError(error: e.msg).toJson
proc validateMnemonic*(self: OnboardingView, mnemonic: string): string {.slot.} =
result = self.status.wallet.validateMnemonic(mnemonic)
proc storeDerivedAndLogin(self: OnboardingView, password: string): string {.slot.} =
try:
result = self.status.accounts.storeDerivedAndLogin(self.currentAccount.account, password).toJson

View File

@ -35,3 +35,5 @@ proc identicon*(p0: GoString): cstring {.importc: "Identicon".}
proc login*(acctData: cstring, password: cstring): cstring {.importc: "Login".}
proc logout*(): cstring {.importc: "Logout".}
proc validateMnemonic*(mnemonic: cstring): cstring {.importc: "ValidateMnemonic".}

View File

@ -1,5 +1,5 @@
import json, httpclient, json, strformat, stint, strutils, sequtils, chronicles
import core, types
import libstatus, core, types
import ../wallet/account
proc getWalletAccounts*(): seq[WalletAccount] =
@ -77,3 +77,6 @@ proc hex2Eth*(input: string): string =
var (eth, remainder) = divmod(value, one_eth)
fmt"{eth}.{remainder}"
proc validateMnemonic*(mnemonic: string): string =
result = $libstatus.validateMnemonic(mnemonic)

View File

@ -154,3 +154,7 @@ proc toggleAsset*(self: WalletModel, symbol: string, enable: bool, address: stri
proc getTransfersByAddress*(self: WalletModel, address: string): seq[Transaction] =
result = status_wallet.getTransfersByAddress(address)
proc validateMnemonic*(self: WalletModel, mnemonic: string): string =
result = status_wallet.validateMnemonic(mnemonic).parseJSON()["error"].getStr

View File

@ -68,9 +68,7 @@ ModalPopup {
if (mnemonicTextField.text === "") {
return
}
onConfirmSeedClick(mnemonicTextField.text)
popup.close()
}
}
}

View File

@ -14,9 +14,16 @@ Item {
property bool wentNext: false
id: enterSeedPhraseModal
onConfirmSeedClick: function (mnemonic) {
wentNext = true
onboardingModel.importMnemonic(mnemonic)
createPasswordModal.open()
let error = onboardingModel.validateMnemonic(mnemonic)
if (error != "") {
invalidSeedPhraseModal.error = error
invalidSeedPhraseModal.open()
} else {
wentNext = true
enterSeedPhraseModal.close()
onboardingModel.importMnemonic(mnemonic)
createPasswordModal.open()
}
}
onClosed: function () {
if (!wentNext) {
@ -31,6 +38,10 @@ Item {
existingKeyView.onClosed()
}
}
InvalidSeedPhraseModal {
id: invalidSeedPhraseModal
}
}
/*##^##

View File

@ -0,0 +1,28 @@
import QtQuick 2.13
import QtQuick.Controls 2.13
import "../imports"
import "../shared"
ModalPopup {
id: popup
title: qsTr("Invalid seed phrase")
height: 200
property string error: "Invalid seed phrase."
StyledText {
text: qsTr(popup.error)
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
font.pixelSize: 15
}
footer: StyledButton {
anchors.right: parent.right
anchors.rightMargin: Theme.smallPadding
label: qsTr("Cancel")
anchors.bottom: parent.bottom
onClicked: {
popup.close()
}
}
}

View File

@ -8,3 +8,4 @@ Slide 1.0 Slide.qml
EnterSeedPhraseModal 1.0 EnterSeedPhraseModal.qml
CreatePasswordModal 1.0 CreatePasswordModal.qml
GenKeyModal 1.0 GenKeyModal.qml
InvalidSeedPhraseModal 1.0 InvalidSeedPhraseModal.qml