Files
pay/desktop/NewAccountImportAccount.qml
T

169 lines
6.3 KiB
QML
Raw Permalink Normal View History

2021-11-30 13:51:01 +01:00
/*
* This file is part of the Flowee project
* Copyright (C) 2021 Tom Zander <tom@flowee.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.11
import QtQuick.Controls 2.11
import QtQuick.Layouts 1.11
import "widgets" as Flowee
import Flowee.org.pay 1.0
GridLayout {
id: importAccount
columns: 3
2021-10-25 19:42:13 +02:00
rowSpacing: 10
2021-11-02 19:29:14 +01:00
property var typedData: Pay.identifyString(secrets.text)
property bool finished: typedData === Bitcoin.PrivateKey || typedData === Bitcoin.CorrectMnemonic;
property bool isMnemonic: typedData === Bitcoin.CorrectMnemonic || typedData === Bitcoin.PartialMnemonic || typedData === Bitcoin.PartialMnemonicWithTypo;
property bool isPrivateKey: typedData === Bitcoin.PrivateKey
Label {
2021-11-09 21:34:40 +01:00
text: qsTr("Please enter the secrets of the wallet to import. This can be a seed-phrase or a private key.")
Layout.columnSpan: 3
2021-10-25 19:42:13 +02:00
wrapMode: Text.Wrap
}
Label {
2021-11-09 21:34:40 +01:00
text: qsTr("Secret", "The seed-phrase or private key") + ":"
Layout.alignment: Qt.AlignBaseline
}
2021-11-02 19:38:36 +01:00
Flowee.MultilineTextField {
id: secrets
Layout.fillWidth: true
onTextChanged: if (!importAccount.isMnemonic) { text = text.trim(); }
nextFocusTarget: accountName
2021-11-09 21:34:40 +01:00
placeholderText: qsTr("Example: %1", "placeholder text").arg("L5bxhjPeQqVFgCLALiFaJYpptdX6Nf6R9TuKgHaAikcNwg32Q4aL")
}
Label {
id: feedback
text: importAccount.finished ? "✔" : " "
2021-11-02 19:29:14 +01:00
color: Bitcoin.useDarkSkin ? "#37be2d" : "green"
font.pixelSize: 24
Layout.alignment: Qt.AlignTop
}
Label {
2021-11-09 21:34:40 +01:00
text: qsTr("Name") + ":"
Layout.alignment: Qt.AlignBaseline
}
2021-11-02 19:38:36 +01:00
Flowee.TextField {
id: accountName
onAccepted: if (startImport.enabled) startImport.clicked()
Layout.columnSpan: 2
}
RowLayout {
Layout.fillWidth: true
Layout.columnSpan: 3
Label {
id: detectedType
2021-10-31 13:46:47 +01:00
color: typedData === Pay.PartialMnemonicWithTypo ? "red" : feedback.color
text: {
var typedData = importAccount.typedData
2021-11-02 19:29:14 +01:00
if (typedData === Bitcoin.PrivateKey)
return qsTr("Private key", "description of type") // TODO print address to go with it
2021-11-02 19:29:14 +01:00
if (typedData === Bitcoin.CorrectMnemonic)
2021-11-09 21:34:40 +01:00
return qsTr("BIP 39 seed-phrase", "description of type")
2021-11-02 19:29:14 +01:00
if (typedData === Bitcoin.PartialMnemonicWithTypo)
2021-10-31 13:46:47 +01:00
return qsTr("Unrecognized word", "Word from the seed-phrases lexicon")
2021-11-02 19:29:14 +01:00
if (typedData === Bitcoin.MissingLexicon)
2021-10-31 13:46:47 +01:00
return "Installation error; no lexicon found"; // intentionally not translated, end-users should not see this
return ""
}
}
Item { width: 1; height: 1; Layout.fillWidth: true } // spacer
Flowee.Button {
id: startImport
2021-10-25 19:42:13 +02:00
enabled: importAccount.finished
text: qsTr("Import wallet")
onClicked: {
var sh = parseInt("0" + startHeight.text, 10);
if (sh === 0) // the genesis was block 1, zero doesn't exist
sh = 1;
if (importAccount.isMnemonic)
2021-11-02 19:29:14 +01:00
var options = Pay.createImportedHDWallet(secrets.text, passwordField.text, derivationPath.text, accountName.text, sh);
else
2021-11-02 19:29:14 +01:00
options = Pay.createImportedWallet(secrets.text, accountName.text, sh)
2021-10-25 19:42:13 +02:00
options.forceSingleAddress = singleAddress.checked;
var accounts = portfolio.accounts;
for (var i = 0; i < accounts.length; ++i) {
var a = accounts[i];
2021-10-25 19:42:13 +02:00
if (a.name === options.name) {
portfolio.current = a;
break;
}
}
root.visible = false;
}
}
}
2021-11-02 19:38:36 +01:00
Flowee.GroupBox {
title: qsTr("Advanced Options")
2021-10-30 15:23:43 +02:00
collapsed: true
Layout.columnSpan: 3
Layout.fillWidth: true
2021-10-25 19:42:13 +02:00
columns: 2
/*
2021-11-02 19:35:38 +01:00
Flowee.CheckBox {
2021-10-25 19:42:13 +02:00
id: schnorr
text: qsTr("Default to signing using ECDSA");
tooltipText: qsTr("When enabled, newer style Schnorr signatures are not set as default for this wallet.")
Layout.columnSpan: 2
} */
2021-11-02 19:35:38 +01:00
Flowee.CheckBox {
2021-10-25 19:42:13 +02:00
id: singleAddress
text: qsTr("Force Single Address");
2021-10-28 17:40:10 +02:00
tooltipText: qsTr("When enabled, no extra addresses will be auto-generated in this wallet.\nChange will come back to the imported key.")
checked: true
visible: importAccount.isPrivateKey
2021-10-25 19:42:13 +02:00
Layout.columnSpan: 2
}
Label {
2021-11-09 21:34:40 +01:00
text: qsTr("Alternate phrase") + ":"
2021-10-28 17:40:10 +02:00
visible: !importAccount.isPrivateKey
2021-10-25 19:42:13 +02:00
}
2021-11-02 19:38:36 +01:00
Flowee.TextField {
2021-10-28 17:40:10 +02:00
// according to the BIP39 spec this is the 'password', but from a UX
// perspective that is confusing and no actual wallet uses it
2021-10-25 19:42:13 +02:00
id: passwordField
2021-10-28 17:40:10 +02:00
visible: !importAccount.isPrivateKey
2021-10-25 19:42:13 +02:00
Layout.fillWidth: true
}
Label {
2021-11-09 21:34:40 +01:00
text: qsTr("Start Height") + ":"
2021-10-25 19:42:13 +02:00
}
2021-11-02 19:38:36 +01:00
Flowee.TextField {
2021-10-25 19:42:13 +02:00
id: startHeight
Layout.fillWidth: true
validator: IntValidator{bottom: 0; top: 999999}
}
Label {
2021-11-09 21:34:40 +01:00
text: qsTr("Derivation") + ":"
2021-10-28 17:40:10 +02:00
visible: !importAccount.isPrivateKey
2021-10-25 19:42:13 +02:00
}
2021-11-02 19:38:36 +01:00
Flowee.TextField {
2021-10-25 19:42:13 +02:00
id: derivationPath
2022-08-18 16:57:28 +02:00
text: "m/44'/0'/0'" // What most BCH wallets are created with
2021-10-28 17:40:10 +02:00
visible: !importAccount.isPrivateKey
2021-11-02 19:29:14 +01:00
color: Pay.checkDerivation(text) ? palette.text : "red"
}
}
}