2020-06-17 19:18:31 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2020-06-10 18:40:27 +00:00
|
|
|
import QtQuick.Dialogs 1.3
|
2021-09-28 15:04:06 +00:00
|
|
|
|
2021-10-27 11:32:10 +00:00
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2021-10-20 10:21:23 +00:00
|
|
|
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared.panels 1.0
|
|
|
|
import shared.popups 1.0
|
|
|
|
import shared.controls 1.0
|
2020-06-10 20:32:04 +00:00
|
|
|
|
2021-10-27 11:32:10 +00:00
|
|
|
import "../stores"
|
2021-10-20 10:21:23 +00:00
|
|
|
|
2021-10-14 11:07:19 +00:00
|
|
|
// TODO: replace with StatusModal
|
2020-06-10 20:32:04 +00:00
|
|
|
ModalPopup {
|
|
|
|
id: popup
|
2021-10-05 20:50:22 +00:00
|
|
|
|
|
|
|
property var currentAccount: RootStore.currentAccount
|
|
|
|
property var changeSelectedAccount
|
|
|
|
|
2020-06-10 20:32:04 +00:00
|
|
|
// TODO add icon when we have that feature
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Status account settings"
|
|
|
|
title: qsTrId("status-account-settings")
|
2020-07-22 20:40:32 +00:00
|
|
|
height: 675
|
2020-06-10 20:32:04 +00:00
|
|
|
|
|
|
|
property int marginBetweenInputs: 35
|
2020-06-22 18:49:58 +00:00
|
|
|
property string accountNameValidationError: ""
|
|
|
|
|
|
|
|
function validate() {
|
|
|
|
if (accountNameInput.text === "") {
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "You need to enter an account name"
|
|
|
|
accountNameValidationError = qsTrId("you-need-to-enter-an-account-name")
|
2020-06-22 18:49:58 +00:00
|
|
|
} else {
|
|
|
|
accountNameValidationError = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return accountNameValidationError === ""
|
|
|
|
}
|
2020-06-10 20:32:04 +00:00
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
accountNameInput.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
|
|
|
|
|
|
|
Input {
|
|
|
|
id: accountNameInput
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Enter an account name..."
|
|
|
|
placeholderText: qsTrId("enter-an-account-name...")
|
|
|
|
//% "Account name"
|
|
|
|
label: qsTrId("account-name")
|
2020-06-10 15:55:24 +00:00
|
|
|
text: currentAccount.name
|
2020-06-22 18:49:58 +00:00
|
|
|
validationError: popup.accountNameValidationError
|
2020-06-10 20:32:04 +00:00
|
|
|
}
|
|
|
|
|
2021-01-20 16:24:21 +00:00
|
|
|
StatusWalletColorSelect {
|
2020-06-10 20:32:04 +00:00
|
|
|
id: accountColorInput
|
2021-01-20 16:24:21 +00:00
|
|
|
selectedColor: currentAccount.iconColor.toUpperCase()
|
2021-10-27 11:32:10 +00:00
|
|
|
model: Theme.palette.accountColors
|
2020-06-10 20:32:04 +00:00
|
|
|
anchors.top: accountNameInput.bottom
|
|
|
|
anchors.topMargin: marginBetweenInputs
|
2020-07-30 05:18:54 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
2020-06-10 20:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TextWithLabel {
|
|
|
|
id: typeText
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Type"
|
|
|
|
label: qsTrId("type")
|
2020-06-10 15:55:24 +00:00
|
|
|
text: {
|
|
|
|
var result = ""
|
|
|
|
switch (currentAccount.walletType) {
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Watch-only"
|
|
|
|
case Constants.watchWalletType: result = qsTrId("watch-only"); break;
|
2020-06-10 15:55:24 +00:00
|
|
|
case Constants.keyWalletType:
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Off Status tree"
|
|
|
|
case Constants.seedWalletType: result = qsTrId("off-status-tree"); break;
|
|
|
|
//% "On Status tree"
|
|
|
|
default: result = qsTrId("on-status-tree")
|
2020-06-10 15:55:24 +00:00
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
2020-06-10 20:32:04 +00:00
|
|
|
anchors.top: accountColorInput.bottom
|
|
|
|
anchors.topMargin: marginBetweenInputs
|
|
|
|
}
|
|
|
|
|
|
|
|
TextWithLabel {
|
|
|
|
id: addressText
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Wallet address"
|
|
|
|
label: qsTrId("wallet-address")
|
2020-06-10 15:55:24 +00:00
|
|
|
text: currentAccount.address
|
2020-07-02 15:14:31 +00:00
|
|
|
fontFamily: Style.current.fontHexRegular.name
|
2020-06-10 20:32:04 +00:00
|
|
|
anchors.top: typeText.bottom
|
|
|
|
anchors.topMargin: marginBetweenInputs
|
|
|
|
}
|
|
|
|
|
|
|
|
TextWithLabel {
|
|
|
|
id: pathText
|
2020-12-08 15:07:20 +00:00
|
|
|
visible: currentAccount.walletType !== Constants.watchWalletType && currentAccount.walletType !== Constants.keyWalletType
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Derivation path"
|
|
|
|
label: qsTrId("derivation-path")
|
2020-06-10 15:55:24 +00:00
|
|
|
text: currentAccount.path
|
2020-06-10 20:32:04 +00:00
|
|
|
anchors.top: addressText.bottom
|
|
|
|
anchors.topMargin: marginBetweenInputs
|
|
|
|
}
|
|
|
|
|
|
|
|
TextWithLabel {
|
|
|
|
id: storageText
|
2020-06-10 15:55:24 +00:00
|
|
|
visible: currentAccount.walletType !== Constants.watchWalletType
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Storage"
|
|
|
|
label: qsTrId("storage")
|
|
|
|
//% "This device"
|
|
|
|
text: qsTrId("this-device")
|
2020-06-10 20:32:04 +00:00
|
|
|
anchors.top: pathText.bottom
|
|
|
|
anchors.topMargin: marginBetweenInputs
|
|
|
|
}
|
|
|
|
|
|
|
|
footer: Item {
|
2021-01-13 19:15:52 +00:00
|
|
|
width: parent.width
|
|
|
|
height: saveBtn.height
|
|
|
|
|
2021-01-28 11:04:10 +00:00
|
|
|
StatusButton {
|
2020-12-08 15:07:20 +00:00
|
|
|
visible: currentAccount.walletType === Constants.watchWalletType
|
2020-06-10 20:32:04 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.right: saveBtn.left
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.rightMargin: Style.current.padding
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Delete account"
|
2021-01-28 11:04:10 +00:00
|
|
|
text: qsTrId("delete-account")
|
2021-10-20 10:21:23 +00:00
|
|
|
type: StatusBaseButton.Type.Danger
|
2020-06-10 20:32:04 +00:00
|
|
|
|
2020-06-10 20:21:23 +00:00
|
|
|
MessageDialog {
|
|
|
|
id: deleteError
|
|
|
|
title: "Deleting account failed"
|
|
|
|
icon: StandardIcon.Critical
|
|
|
|
standardButtons: StandardButton.Ok
|
2020-06-10 20:28:24 +00:00
|
|
|
|
2020-06-10 20:21:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 20:28:24 +00:00
|
|
|
MessageDialog {
|
|
|
|
id: confirmationDialog
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Are you sure?"
|
|
|
|
title: qsTrId("are-you-sure?")
|
|
|
|
//% "A deleted account cannot be retrieved later. Only press yes if you backed up your key/seed or don't care about this account anymore"
|
|
|
|
text: qsTrId("a-deleted-account-cannot-be-retrieved-later.-only-press-yes-if-you-backed-up-your-key/seed-or-don't-care-about-this-account-anymore")
|
2020-06-10 20:28:24 +00:00
|
|
|
icon: StandardIcon.Warning
|
|
|
|
standardButtons: StandardButton.Yes | StandardButton.No
|
2021-12-06 21:10:54 +00:00
|
|
|
onAccepted: {
|
|
|
|
const error = RootStore.deleteAccount(currentAccount.address)
|
|
|
|
if (error) {
|
|
|
|
Global.playErrorSound();
|
|
|
|
deleteError.text = error
|
|
|
|
deleteError.open()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change active account to the first
|
2020-06-10 20:28:24 +00:00
|
|
|
changeSelectedAccount(0)
|
|
|
|
popup.close();
|
2020-06-10 20:21:23 +00:00
|
|
|
}
|
2020-06-10 20:28:24 +00:00
|
|
|
}
|
2020-06-10 20:21:23 +00:00
|
|
|
|
2020-06-10 20:28:24 +00:00
|
|
|
onClicked : {
|
|
|
|
confirmationDialog.open()
|
2020-06-10 20:32:04 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-28 11:04:10 +00:00
|
|
|
StatusButton {
|
2020-06-10 20:32:04 +00:00
|
|
|
id: saveBtn
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.right: parent.right
|
2020-07-02 15:14:31 +00:00
|
|
|
anchors.rightMargin: Style.current.padding
|
2020-07-06 20:39:55 +00:00
|
|
|
//% "Save changes"
|
2021-01-28 11:04:10 +00:00
|
|
|
text: qsTrId("save-changes")
|
2020-06-10 20:32:04 +00:00
|
|
|
|
2021-01-28 11:04:10 +00:00
|
|
|
enabled: accountNameInput.text !== ""
|
2020-06-10 20:32:04 +00:00
|
|
|
|
2020-06-10 18:40:27 +00:00
|
|
|
MessageDialog {
|
|
|
|
id: changeError
|
2021-12-06 21:10:54 +00:00
|
|
|
title: qsTr("Changing settings failed")
|
2020-06-10 18:40:27 +00:00
|
|
|
icon: StandardIcon.Critical
|
|
|
|
standardButtons: StandardButton.Ok
|
|
|
|
}
|
|
|
|
|
2020-06-10 20:32:04 +00:00
|
|
|
onClicked : {
|
2020-06-22 18:49:58 +00:00
|
|
|
if (!validate()) {
|
|
|
|
return
|
2020-06-10 18:40:27 +00:00
|
|
|
}
|
|
|
|
|
2021-10-21 08:22:05 +00:00
|
|
|
const error = RootStore.updateCurrentAccount(currentAccount.address, accountNameInput.text, accountColorInput.selectedColor);
|
2020-06-10 18:40:27 +00:00
|
|
|
|
|
|
|
if (error) {
|
2021-12-06 21:10:54 +00:00
|
|
|
Global.playErrorSound();
|
2020-06-10 18:40:27 +00:00
|
|
|
changeError.text = error
|
|
|
|
changeError.open()
|
|
|
|
return
|
|
|
|
}
|
2020-06-10 20:32:04 +00:00
|
|
|
popup.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|