2022-03-28 08:19:57 +00:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
import StatusQ.Components 0.1
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
import "../stores"
|
2022-03-31 11:46:25 +00:00
|
|
|
import "../panels"
|
2022-03-28 08:19:57 +00:00
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
id: advancedSection
|
|
|
|
|
2022-03-31 11:46:25 +00:00
|
|
|
property int addAccountType: SelectGeneratedAccount.AddAccountType.GenerateNew
|
|
|
|
property string derivedFromAddress: ""
|
|
|
|
property string mnemonicText: ""
|
|
|
|
property alias privateKey: importPrivateKeyPanel.text
|
|
|
|
property string path: ""
|
|
|
|
property string pathSubFix: ""
|
|
|
|
property string completePath: path + "/" + pathSubFix
|
2022-04-11 08:02:36 +00:00
|
|
|
property alias watchAddress: addressInput.text
|
2022-03-31 11:46:25 +00:00
|
|
|
property bool isValid: addAccountType === SelectGeneratedAccount.AddAccountType.ImportSeedPhrase ? importSeedPhrasePanel.isValid :
|
|
|
|
addAccountType === SelectGeneratedAccount.AddAccountType.ImportPrivateKey ? (importPrivateKeyPanel.text !== "" && importPrivateKeyPanel.valid) :
|
|
|
|
addAccountType === SelectGeneratedAccount.AddAccountType.WatchOnly ? (addressInput.text !== "" && addressInput.valid) : true
|
2022-03-28 08:19:57 +00:00
|
|
|
|
2022-03-31 11:46:25 +00:00
|
|
|
signal calculateDerivedPath()
|
2022-05-05 18:54:45 +00:00
|
|
|
signal enterPressed()
|
2022-03-28 08:19:57 +00:00
|
|
|
|
|
|
|
function reset() {
|
2022-03-31 11:46:25 +00:00
|
|
|
//reset selectGeneratedAccount
|
|
|
|
selectGeneratedAccount.resetMe()
|
|
|
|
|
|
|
|
// reset privateKey
|
|
|
|
importPrivateKeyPanel.resetMe()
|
|
|
|
|
|
|
|
// reset importSeedPhrasePanel
|
|
|
|
importSeedPhrasePanel.reset()
|
|
|
|
|
|
|
|
// reset derivation path
|
|
|
|
derivationPathsPanel.reset()
|
|
|
|
|
|
|
|
// reset derviedAccountsList
|
|
|
|
derivedAddressesPanel.reset()
|
|
|
|
|
|
|
|
// reset watch only address input
|
2022-04-11 08:02:36 +00:00
|
|
|
addressInput.text = ""
|
|
|
|
addressInput.reset()
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function validate() {
|
2022-03-31 11:46:25 +00:00
|
|
|
if(addAccountType === SelectGeneratedAccount.AddAccountType.ImportSeedPhrase) {
|
|
|
|
// validate mnemonic
|
|
|
|
return importSeedPhrasePanel.validate()
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
2022-03-31 11:46:25 +00:00
|
|
|
else if(addAccountType === SelectGeneratedAccount.AddAccountType.ImportPrivateKey) {
|
|
|
|
// validate privateKey
|
|
|
|
return importPrivateKeyPanel.validateMe()
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
2022-03-31 11:46:25 +00:00
|
|
|
else if(addAccountType === SelectGeneratedAccount.AddAccountType.WatchOnly) {
|
2022-04-11 08:02:36 +00:00
|
|
|
return addressInput.valid
|
|
|
|
}
|
|
|
|
|
2022-03-28 08:19:57 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-03-31 11:46:25 +00:00
|
|
|
onPathChanged: {
|
|
|
|
if(addAccountType === SelectGeneratedAccount.AddAccountType.ImportSeedPhrase) {
|
|
|
|
if(importSeedPhrasePanel.isValid) {
|
|
|
|
calculateDerivedPath()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
calculateDerivedPath()
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-31 11:46:25 +00:00
|
|
|
onDerivedFromAddressChanged: {
|
|
|
|
// reset derviedAccountsList
|
|
|
|
derivedAddressesPanel.reset()
|
|
|
|
|
|
|
|
if(addAccountType === SelectGeneratedAccount.AddAccountType.ImportSeedPhrase) {
|
|
|
|
if(importSeedPhrasePanel.isValid) {
|
|
|
|
calculateDerivedPath()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
calculateDerivedPath()
|
|
|
|
}
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spacing: Style.current.padding
|
|
|
|
|
2022-03-31 11:46:25 +00:00
|
|
|
SelectGeneratedAccount {
|
|
|
|
id: selectGeneratedAccount
|
2022-03-28 08:19:57 +00:00
|
|
|
Layout.margins: Style.current.padding
|
2022-03-31 11:46:25 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
advancedSection.addAccountType = Qt.binding(function() {return addAccountType})
|
|
|
|
advancedSection.derivedFromAddress = Qt.binding(function() {return derivedFromAddress})
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-31 11:46:25 +00:00
|
|
|
ImportPrivateKeyPanel {
|
|
|
|
id: importPrivateKeyPanel
|
|
|
|
visible: advancedSection.addAccountType === SelectGeneratedAccount.AddAccountType.ImportPrivateKey && advancedSection.visible
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
|
|
|
|
2022-03-31 11:46:25 +00:00
|
|
|
ImportSeedPhrasePanel {
|
|
|
|
id: importSeedPhrasePanel
|
2022-03-28 08:19:57 +00:00
|
|
|
Layout.preferredWidth: parent.width
|
2022-03-31 11:46:25 +00:00
|
|
|
Layout.preferredHeight: visible ? importSeedPhrasePanel.preferredHeight: 0
|
2022-03-28 08:19:57 +00:00
|
|
|
Layout.leftMargin: Style.current.padding
|
|
|
|
Layout.rightMargin: Style.current.padding
|
2022-03-31 11:46:25 +00:00
|
|
|
visible: advancedSection.addAccountType === SelectGeneratedAccount.AddAccountType.ImportSeedPhrase && advancedSection.visible
|
|
|
|
onMnemonicStringChanged: {
|
|
|
|
advancedSection.mnemonicText = mnemonicString
|
|
|
|
if(isValid) {
|
|
|
|
calculateDerivedPath()
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-05 18:54:45 +00:00
|
|
|
onEnterPressed: advancedSection.enterPressed()
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
|
|
|
|
2022-04-11 08:02:36 +00:00
|
|
|
StatusInput {
|
|
|
|
id: addressInput
|
2022-03-31 11:46:25 +00:00
|
|
|
visible: advancedSection.addAccountType === SelectGeneratedAccount.AddAccountType.WatchOnly && advancedSection.visible
|
2022-04-11 08:02:36 +00:00
|
|
|
//% "Enter address..."
|
|
|
|
input.placeholderText: qsTrId("enter-address...")
|
|
|
|
//% "Account address"
|
|
|
|
label: qsTrId("wallet-key-title")
|
|
|
|
validators: [
|
|
|
|
StatusAddressValidator {
|
|
|
|
//% "This needs to be a valid address (starting with 0x)"
|
|
|
|
errorMessage: qsTrId("this-needs-to-be-a-valid-address-(starting-with-0x)")
|
|
|
|
},
|
|
|
|
StatusMinLengthValidator {
|
|
|
|
//% "You need to enter an address"
|
|
|
|
errorMessage: qsTrId("you-need-to-enter-an-address")
|
|
|
|
minLength: 1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-03-28 08:19:57 +00:00
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
Layout.margins: Style.current.padding
|
|
|
|
Layout.preferredWidth: parent.width
|
|
|
|
spacing: Style.current.bigPadding
|
2022-03-31 11:46:25 +00:00
|
|
|
visible: advancedSection.addAccountType !== SelectGeneratedAccount.AddAccountType.ImportPrivateKey &&
|
|
|
|
advancedSection.addAccountType !== SelectGeneratedAccount.AddAccountType.WatchOnly
|
|
|
|
DerivationPathsPanel {
|
|
|
|
id: derivationPathsPanel
|
2022-03-28 08:19:57 +00:00
|
|
|
Layout.preferredWidth: 213
|
2022-03-31 11:46:25 +00:00
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
Component.onCompleted: advancedSection.path = Qt.binding(function() { return derivationPathsPanel.path})
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
2022-03-31 11:46:25 +00:00
|
|
|
DerivedAddressesPanel {
|
|
|
|
id: derivedAddressesPanel
|
2022-03-28 08:19:57 +00:00
|
|
|
Layout.preferredWidth: 213
|
2022-03-31 11:46:25 +00:00
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
Component.onCompleted: advancedSection.pathSubFix = Qt.binding(function() { return derivedAddressesPanel.pathSubFix})
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|