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
|
|
|
|
|
2023-01-31 12:23:35 +00:00
|
|
|
readonly property alias useFullyCustomPath: fullyCustomPathCheckBox.checked
|
2023-02-01 12:42:45 +00:00
|
|
|
property int addAccountType: Constants.AddAccountType.GenerateNew
|
2022-10-27 09:26:34 +00:00
|
|
|
property string selectedKeyUid: RootStore.defaultSelectedKeyUid
|
|
|
|
property bool selectedKeyUidMigratedToKeycard: RootStore.defaultSelectedKeyUidMigratedToKeycard
|
|
|
|
property string selectedAddress: ""
|
2023-01-31 12:23:35 +00:00
|
|
|
property bool selectedAddressAvailable: false
|
2022-10-27 09:26:34 +00:00
|
|
|
property string enterPasswordIcon: ""
|
2022-03-31 11:46:25 +00:00
|
|
|
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
|
2023-02-01 12:42:45 +00:00
|
|
|
property bool isValid: addAccountType === Constants.AddAccountType.ImportSeedPhrase ? importSeedPhrasePanel.isValid :
|
|
|
|
addAccountType === Constants.AddAccountType.ImportPrivateKey ? (importPrivateKeyPanel.text !== "" && importPrivateKeyPanel.valid) :
|
|
|
|
addAccountType === Constants.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
|
|
|
|
2023-02-24 12:59:14 +00:00
|
|
|
objectName: "advancedAddAccountViewRoot"
|
|
|
|
|
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() {
|
2023-02-01 12:42:45 +00:00
|
|
|
if(addAccountType === Constants.AddAccountType.ImportSeedPhrase) {
|
2022-03-31 11:46:25 +00:00
|
|
|
// validate mnemonic
|
|
|
|
return importSeedPhrasePanel.validate()
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
2023-02-01 12:42:45 +00:00
|
|
|
else if(addAccountType === Constants.AddAccountType.ImportPrivateKey) {
|
2022-03-31 11:46:25 +00:00
|
|
|
// validate privateKey
|
|
|
|
return importPrivateKeyPanel.validateMe()
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
2023-02-01 12:42:45 +00:00
|
|
|
else if(addAccountType === Constants.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: {
|
2023-02-01 12:42:45 +00:00
|
|
|
if(addAccountType === Constants.AddAccountType.ImportSeedPhrase) {
|
2022-03-31 11:46:25 +00:00
|
|
|
if(importSeedPhrasePanel.isValid) {
|
2023-01-31 12:23:35 +00:00
|
|
|
advancedSection.calculateDerivedPath()
|
2022-03-31 11:46:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2023-01-31 12:23:35 +00:00
|
|
|
advancedSection.calculateDerivedPath()
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-31 11:46:25 +00:00
|
|
|
onDerivedFromAddressChanged: {
|
|
|
|
// reset derviedAccountsList
|
|
|
|
derivedAddressesPanel.reset()
|
|
|
|
|
2023-02-01 12:42:45 +00:00
|
|
|
if(addAccountType === Constants.AddAccountType.ImportSeedPhrase) {
|
2022-03-31 11:46:25 +00:00
|
|
|
if(importSeedPhrasePanel.isValid) {
|
2023-01-31 12:23:35 +00:00
|
|
|
advancedSection.calculateDerivedPath()
|
2022-03-31 11:46:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2023-01-31 12:23:35 +00:00
|
|
|
advancedSection.calculateDerivedPath()
|
2022-03-31 11:46:25 +00:00
|
|
|
}
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spacing: Style.current.padding
|
|
|
|
|
2022-03-31 11:46:25 +00:00
|
|
|
SelectGeneratedAccount {
|
|
|
|
id: selectGeneratedAccount
|
2023-02-24 12:59:14 +00:00
|
|
|
objectName: "selectGeneratedAccount"
|
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-10-27 09:26:34 +00:00
|
|
|
advancedSection.selectedKeyUid = Qt.binding(function() {return selectedKeyUid})
|
|
|
|
advancedSection.selectedKeyUidMigratedToKeycard = Qt.binding(function() {return selectedKeyUidMigratedToKeycard})
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-31 11:46:25 +00:00
|
|
|
ImportPrivateKeyPanel {
|
|
|
|
id: importPrivateKeyPanel
|
2023-02-01 12:42:45 +00:00
|
|
|
visible: advancedSection.addAccountType === Constants.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-07-08 09:48:37 +00:00
|
|
|
Layout.preferredHeight: visible ? importSeedPhrasePanel.preferredHeight: 0
|
2022-07-07 15:35:23 +00:00
|
|
|
Layout.leftMargin: (Style.current.halfPadding/4)
|
2023-02-01 12:42:45 +00:00
|
|
|
visible: advancedSection.addAccountType === Constants.AddAccountType.ImportSeedPhrase && advancedSection.visible
|
2022-03-31 11:46:25 +00:00
|
|
|
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
|
2023-02-24 12:59:14 +00:00
|
|
|
input.placeholder.objectName: "advancedAddAccountViewAddressInputPlaceholder"
|
|
|
|
input.objectName: "advancedAddAccountViewAddressInput"
|
2023-02-01 12:42:45 +00:00
|
|
|
visible: advancedSection.addAccountType === Constants.AddAccountType.WatchOnly && advancedSection.visible
|
2022-07-22 10:28:04 +00:00
|
|
|
placeholderText: qsTr("Enter address...")
|
2022-04-04 11:26:30 +00:00
|
|
|
label: qsTr("Account address")
|
2022-04-11 08:02:36 +00:00
|
|
|
validators: [
|
|
|
|
StatusAddressValidator {
|
2022-04-04 11:26:30 +00:00
|
|
|
errorMessage: qsTr("This needs to be a valid address (starting with 0x)")
|
2022-04-11 08:02:36 +00:00
|
|
|
},
|
|
|
|
StatusMinLengthValidator {
|
2022-04-04 11:26:30 +00:00
|
|
|
errorMessage: qsTr("You need to enter an address")
|
2022-04-11 08:02:36 +00:00
|
|
|
minLength: 1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-03-28 08:19:57 +00:00
|
|
|
|
2023-01-31 12:23:35 +00:00
|
|
|
ColumnLayout {
|
2023-02-03 10:28:54 +00:00
|
|
|
Layout.preferredWidth: parent.width
|
2023-01-31 12:23:35 +00:00
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
Layout.preferredWidth: advancedSection.width
|
|
|
|
Layout.rightMargin: 2
|
|
|
|
spacing: Style.current.bigPadding
|
|
|
|
visible: advancedSection.addAccountType !== Constants.AddAccountType.ImportPrivateKey &&
|
|
|
|
advancedSection.addAccountType !== Constants.AddAccountType.WatchOnly
|
|
|
|
|
|
|
|
readonly property int itemWidth: (advancedSection.width - Style.current.bigPadding) * 0.5
|
|
|
|
|
2023-02-24 12:59:14 +00:00
|
|
|
DerivationPathsPanel {
|
2023-01-31 12:23:35 +00:00
|
|
|
id: derivationPathsPanel
|
|
|
|
useFullyCustomPath: fullyCustomPathCheckBox.checked
|
|
|
|
Layout.preferredWidth: parent.itemWidth
|
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
Component.onCompleted: advancedSection.path = Qt.binding(function() { return derivationPathsPanel.path})
|
|
|
|
}
|
|
|
|
DerivedAddressesPanel {
|
|
|
|
id: derivedAddressesPanel
|
|
|
|
Layout.preferredWidth: parent.itemWidth
|
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
|
|
|
|
selectedAccountType: advancedSection.addAccountType
|
|
|
|
selectedKeyUid: advancedSection.selectedKeyUid
|
|
|
|
selectedKeyUidMigratedToKeycard: advancedSection.selectedKeyUidMigratedToKeycard
|
|
|
|
selectedPath: advancedSection.path
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
advancedSection.selectedAddress = Qt.binding(function() { return derivedAddressesPanel.selectedAddress})
|
|
|
|
advancedSection.selectedAddressAvailable = Qt.binding(function() { return derivedAddressesPanel.selectedAddressAvailable})
|
|
|
|
advancedSection.pathSubFix = Qt.binding(function() { return derivedAddressesPanel.pathSubFix})
|
|
|
|
}
|
|
|
|
}
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
2023-01-31 12:23:35 +00:00
|
|
|
|
|
|
|
StatusCheckBox {
|
|
|
|
id: fullyCustomPathCheckBox
|
2023-02-24 12:59:14 +00:00
|
|
|
objectName: "fullyCustomPathCheckBox"
|
|
|
|
visible: advancedSection.addAccountType === Constants.AddAccountType.GenerateNew
|
2023-01-31 12:23:35 +00:00
|
|
|
Layout.preferredWidth: advancedSection.width
|
|
|
|
text: qsTr("I acknowledge that by adding an account out of the default Status derivation path I will not be able to migrate a keypair to a Keycard")
|
|
|
|
onToggled: {
|
|
|
|
advancedSection.reset()
|
2022-10-27 09:26:34 +00:00
|
|
|
}
|
2022-03-28 08:19:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|