feat(Onboarding): validate mnemonic when importing seed phrase
Closes #395
This commit is contained in:
parent
9041eb59e7
commit
89da127468
|
@ -2,7 +2,7 @@ import NimQml, Tables, json, nimcrypto, strformat, json_serialization, strutils
|
||||||
import ../../status/libstatus/types as status_types
|
import ../../status/libstatus/types as status_types
|
||||||
import ../../signals/types
|
import ../../signals/types
|
||||||
import ../../status/accounts as AccountModel
|
import ../../status/accounts as AccountModel
|
||||||
import ../../status/status
|
import ../../status/[status, wallet]
|
||||||
import views/account_info
|
import views/account_info
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -90,6 +90,9 @@ QtObject:
|
||||||
except StatusGoException as e:
|
except StatusGoException as e:
|
||||||
result = StatusGoError(error: e.msg).toJson
|
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.} =
|
proc storeDerivedAndLogin(self: OnboardingView, password: string): string {.slot.} =
|
||||||
try:
|
try:
|
||||||
result = self.status.accounts.storeDerivedAndLogin(self.currentAccount.account, password).toJson
|
result = self.status.accounts.storeDerivedAndLogin(self.currentAccount.account, password).toJson
|
||||||
|
|
|
@ -35,3 +35,5 @@ proc identicon*(p0: GoString): cstring {.importc: "Identicon".}
|
||||||
proc login*(acctData: cstring, password: cstring): cstring {.importc: "Login".}
|
proc login*(acctData: cstring, password: cstring): cstring {.importc: "Login".}
|
||||||
|
|
||||||
proc logout*(): cstring {.importc: "Logout".}
|
proc logout*(): cstring {.importc: "Logout".}
|
||||||
|
|
||||||
|
proc validateMnemonic*(mnemonic: cstring): cstring {.importc: "ValidateMnemonic".}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import json, httpclient, json, strformat, stint, strutils, sequtils, chronicles
|
import json, httpclient, json, strformat, stint, strutils, sequtils, chronicles
|
||||||
import core, types
|
import libstatus, core, types
|
||||||
import ../wallet/account
|
import ../wallet/account
|
||||||
|
|
||||||
proc getWalletAccounts*(): seq[WalletAccount] =
|
proc getWalletAccounts*(): seq[WalletAccount] =
|
||||||
|
@ -77,3 +77,6 @@ proc hex2Eth*(input: string): string =
|
||||||
|
|
||||||
var (eth, remainder) = divmod(value, one_eth)
|
var (eth, remainder) = divmod(value, one_eth)
|
||||||
fmt"{eth}.{remainder}"
|
fmt"{eth}.{remainder}"
|
||||||
|
|
||||||
|
proc validateMnemonic*(mnemonic: string): string =
|
||||||
|
result = $libstatus.validateMnemonic(mnemonic)
|
||||||
|
|
|
@ -154,3 +154,7 @@ proc toggleAsset*(self: WalletModel, symbol: string, enable: bool, address: stri
|
||||||
|
|
||||||
proc getTransfersByAddress*(self: WalletModel, address: string): seq[Transaction] =
|
proc getTransfersByAddress*(self: WalletModel, address: string): seq[Transaction] =
|
||||||
result = status_wallet.getTransfersByAddress(address)
|
result = status_wallet.getTransfersByAddress(address)
|
||||||
|
|
||||||
|
proc validateMnemonic*(self: WalletModel, mnemonic: string): string =
|
||||||
|
result = status_wallet.validateMnemonic(mnemonic).parseJSON()["error"].getStr
|
||||||
|
|
||||||
|
|
|
@ -68,9 +68,7 @@ ModalPopup {
|
||||||
if (mnemonicTextField.text === "") {
|
if (mnemonicTextField.text === "") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
onConfirmSeedClick(mnemonicTextField.text)
|
onConfirmSeedClick(mnemonicTextField.text)
|
||||||
popup.close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,17 @@ Item {
|
||||||
property bool wentNext: false
|
property bool wentNext: false
|
||||||
id: enterSeedPhraseModal
|
id: enterSeedPhraseModal
|
||||||
onConfirmSeedClick: function (mnemonic) {
|
onConfirmSeedClick: function (mnemonic) {
|
||||||
|
let error = onboardingModel.validateMnemonic(mnemonic)
|
||||||
|
if (error != "") {
|
||||||
|
invalidSeedPhraseModal.error = error
|
||||||
|
invalidSeedPhraseModal.open()
|
||||||
|
} else {
|
||||||
wentNext = true
|
wentNext = true
|
||||||
|
enterSeedPhraseModal.close()
|
||||||
onboardingModel.importMnemonic(mnemonic)
|
onboardingModel.importMnemonic(mnemonic)
|
||||||
createPasswordModal.open()
|
createPasswordModal.open()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
onClosed: function () {
|
onClosed: function () {
|
||||||
if (!wentNext) {
|
if (!wentNext) {
|
||||||
existingKeyView.onClosed()
|
existingKeyView.onClosed()
|
||||||
|
@ -31,6 +38,10 @@ Item {
|
||||||
existingKeyView.onClosed()
|
existingKeyView.onClosed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InvalidSeedPhraseModal {
|
||||||
|
id: invalidSeedPhraseModal
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*##^##
|
/*##^##
|
||||||
|
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,3 +8,4 @@ Slide 1.0 Slide.qml
|
||||||
EnterSeedPhraseModal 1.0 EnterSeedPhraseModal.qml
|
EnterSeedPhraseModal 1.0 EnterSeedPhraseModal.qml
|
||||||
CreatePasswordModal 1.0 CreatePasswordModal.qml
|
CreatePasswordModal 1.0 CreatePasswordModal.qml
|
||||||
GenKeyModal 1.0 GenKeyModal.qml
|
GenKeyModal 1.0 GenKeyModal.qml
|
||||||
|
InvalidSeedPhraseModal 1.0 InvalidSeedPhraseModal.qml
|
||||||
|
|
Loading…
Reference in New Issue