status-desktop/ui/app/AppLayouts/Wallet/AccountSettingsModal.qml
Alexandra Betouni 4ee21ada05 feat(desktop) Added image function in Style
Introduced Style.svg() Style.png() Style.emoji() and
Style.icon() in Style.qml. Those should be used to
set the source in Images instead of using relative
paths. Usage:
Image {
   source: Style.svg("check)
   ....

Also moved all Singletons inside a new "utils"
folder and made it a QML module, to use
import utils 1.0 instead of relative paths

Closes #3678
2021-09-28 15:28:00 -04:00

201 lines
6.3 KiB
QML

import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import QtQuick.Dialogs 1.3
import utils 1.0
import "../../../shared"
import "../../../shared/status"
ModalPopup {
property var currentAccount: walletModel.accountsView.currentAccount
property var changeSelectedAccount
id: popup
// TODO add icon when we have that feature
//% "Status account settings"
title: qsTrId("status-account-settings")
height: 675
property int marginBetweenInputs: 35
property string accountNameValidationError: ""
function validate() {
if (accountNameInput.text === "") {
//% "You need to enter an account name"
accountNameValidationError = qsTrId("you-need-to-enter-an-account-name")
} else {
accountNameValidationError = ""
}
return accountNameValidationError === ""
}
onOpened: {
accountNameInput.forceActiveFocus(Qt.MouseFocusReason)
}
Input {
id: accountNameInput
//% "Enter an account name..."
placeholderText: qsTrId("enter-an-account-name...")
//% "Account name"
label: qsTrId("account-name")
text: currentAccount.name
validationError: popup.accountNameValidationError
}
StatusWalletColorSelect {
id: accountColorInput
selectedColor: currentAccount.iconColor.toUpperCase()
anchors.top: accountNameInput.bottom
anchors.topMargin: marginBetweenInputs
anchors.left: parent.left
anchors.right: parent.right
}
TextWithLabel {
id: typeText
//% "Type"
label: qsTrId("type")
text: {
var result = ""
switch (currentAccount.walletType) {
//% "Watch-only"
case Constants.watchWalletType: result = qsTrId("watch-only"); break;
case Constants.keyWalletType:
//% "Off Status tree"
case Constants.seedWalletType: result = qsTrId("off-status-tree"); break;
//% "On Status tree"
default: result = qsTrId("on-status-tree")
}
return result
}
anchors.top: accountColorInput.bottom
anchors.topMargin: marginBetweenInputs
}
TextWithLabel {
id: addressText
//% "Wallet address"
label: qsTrId("wallet-address")
text: currentAccount.address
fontFamily: Style.current.fontHexRegular.name
anchors.top: typeText.bottom
anchors.topMargin: marginBetweenInputs
}
TextWithLabel {
id: pathText
visible: currentAccount.walletType !== Constants.watchWalletType && currentAccount.walletType !== Constants.keyWalletType
//% "Derivation path"
label: qsTrId("derivation-path")
text: currentAccount.path
anchors.top: addressText.bottom
anchors.topMargin: marginBetweenInputs
}
TextWithLabel {
id: storageText
visible: currentAccount.walletType !== Constants.watchWalletType
//% "Storage"
label: qsTrId("storage")
//% "This device"
text: qsTrId("this-device")
anchors.top: pathText.bottom
anchors.topMargin: marginBetweenInputs
}
footer: Item {
width: parent.width
height: saveBtn.height
StatusButton {
visible: currentAccount.walletType === Constants.watchWalletType
anchors.top: parent.top
anchors.right: saveBtn.left
anchors.rightMargin: Style.current.padding
//% "Delete account"
text: qsTrId("delete-account")
bgColor: "transparent"
showBorder: true
borderColor: Style.current.border
hoveredBorderColor: Style.current.transparent
type: "warn"
MessageDialog {
id: deleteError
title: "Deleting account failed"
icon: StandardIcon.Critical
standardButtons: StandardButton.Ok
}
MessageDialog {
id: confirmationDialog
//% "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")
icon: StandardIcon.Warning
standardButtons: StandardButton.Yes | StandardButton.No
onAccepted: {
const error = walletModel.accountsView.deleteAccount(currentAccount.address);
if (error) {
errorSound.play()
deleteError.text = error
deleteError.open()
return
}
// Change active account to the first
changeSelectedAccount(0)
popup.close();
}
}
onClicked : {
confirmationDialog.open()
}
}
StatusButton {
id: saveBtn
anchors.top: parent.top
anchors.right: parent.right
anchors.rightMargin: Style.current.padding
//% "Save changes"
text: qsTrId("save-changes")
enabled: accountNameInput.text !== ""
MessageDialog {
id: changeError
title: "Changing settings failed"
icon: StandardIcon.Critical
standardButtons: StandardButton.Ok
}
onClicked : {
if (!validate()) {
return
}
const error = walletModel.accountsView.changeAccountSettings(currentAccount.address, accountNameInput.text, accountColorInput.selectedColor);
if (error) {
errorSound.play()
changeError.text = error
changeError.open()
return
}
popup.close();
}
}
}
}
/*##^##
Designer {
D{i:0;formeditorColor:"#ffffff";height:500;width:400}
}
##^##*/