2021-10-18 22:14:12 +02:00
|
|
|
import QtQuick 2.11
|
|
|
|
|
import QtQuick.Controls 2.11
|
|
|
|
|
import QtQuick.Layouts 1.11
|
2021-11-02 19:32:13 +01:00
|
|
|
import "widgets" as Flowee
|
2021-10-18 22:14:12 +02:00
|
|
|
import Flowee.org.pay 1.0
|
|
|
|
|
|
|
|
|
|
GridLayout {
|
|
|
|
|
id: importAccount
|
|
|
|
|
columns: 3
|
2021-10-25 19:42:13 +02:00
|
|
|
rowSpacing: 10
|
2021-10-18 22:14:12 +02:00
|
|
|
|
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
|
2021-10-18 22:14:12 +02:00
|
|
|
|
|
|
|
|
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.")
|
2021-10-18 22:14:12 +02:00
|
|
|
Layout.columnSpan: 3
|
2021-10-25 19:42:13 +02:00
|
|
|
wrapMode: Text.Wrap
|
2021-10-18 22:14:12 +02:00
|
|
|
}
|
|
|
|
|
Label {
|
2021-11-09 21:34:40 +01:00
|
|
|
text: qsTr("Secret", "The seed-phrase or private key") + ":"
|
2021-10-18 22:14:12 +02:00
|
|
|
Layout.alignment: Qt.AlignBaseline
|
|
|
|
|
}
|
2021-11-02 19:38:36 +01:00
|
|
|
Flowee.MultilineTextField {
|
2021-10-18 22:14:12 +02:00
|
|
|
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")
|
2021-10-18 22:14:12 +02:00
|
|
|
}
|
|
|
|
|
Label {
|
|
|
|
|
id: feedback
|
|
|
|
|
text: importAccount.finished ? "✔" : " "
|
2021-11-02 19:29:14 +01:00
|
|
|
color: Bitcoin.useDarkSkin ? "#37be2d" : "green"
|
2021-10-18 22:14:12 +02:00
|
|
|
font.pixelSize: 24
|
|
|
|
|
Layout.alignment: Qt.AlignTop
|
|
|
|
|
}
|
|
|
|
|
Label {
|
2021-11-09 21:34:40 +01:00
|
|
|
text: qsTr("Name") + ":"
|
2021-10-18 22:14:12 +02:00
|
|
|
Layout.alignment: Qt.AlignBaseline
|
|
|
|
|
}
|
2021-11-02 19:38:36 +01:00
|
|
|
Flowee.TextField {
|
2021-10-18 22:14:12 +02:00
|
|
|
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
|
2021-10-18 22:14:12 +02:00
|
|
|
text: {
|
|
|
|
|
var typedData = importAccount.typedData
|
2021-11-02 19:29:14 +01:00
|
|
|
if (typedData === Bitcoin.PrivateKey)
|
2021-10-18 22:14:12 +02:00
|
|
|
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
|
2021-10-18 22:14:12 +02:00
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Item { width: 1; height: 1; Layout.fillWidth: true } // spacer
|
2021-11-02 19:32:13 +01:00
|
|
|
Flowee.Button {
|
2021-10-18 22:14:12 +02:00
|
|
|
id: startImport
|
2021-10-25 19:42:13 +02:00
|
|
|
enabled: importAccount.finished
|
2021-10-18 22:14:12 +02:00
|
|
|
|
|
|
|
|
text: qsTr("Import wallet")
|
|
|
|
|
onClicked: {
|
2021-10-21 20:54:34 +02:00
|
|
|
var sh = parseInt("0" + startHeight.text, 10);
|
|
|
|
|
if (sh === 0) // the genesis was block 1, zero doesn't exist
|
|
|
|
|
sh = 1;
|
2021-10-18 22:14:12 +02:00
|
|
|
if (importAccount.isMnemonic)
|
2021-11-02 19:29:14 +01:00
|
|
|
var options = Pay.createImportedHDWallet(secrets.text, passwordField.text, derivationPath.text, accountName.text, sh);
|
2021-10-18 22:14:12 +02:00
|
|
|
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;
|
2021-10-18 22:14:12 +02:00
|
|
|
|
|
|
|
|
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) {
|
2021-10-18 22:14:12 +02:00
|
|
|
portfolio.current = a;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
root.visible = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-02 19:38:36 +01:00
|
|
|
Flowee.GroupBox {
|
2021-10-18 22:14:12 +02:00
|
|
|
title: qsTr("Advanced Options")
|
2021-10-30 15:23:43 +02:00
|
|
|
collapsed: true
|
2021-10-18 22:14:12 +02:00
|
|
|
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
|
|
|
|
|
text: "m/44'/145'/0'" // default for BCH wallets
|
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"
|
2021-10-18 22:14:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|