2024-10-15 19:26:12 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
2022-03-10 17:01:17 +00:00
|
|
|
import QtQuick.Dialogs 1.3
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
2023-10-12 16:20:55 +00:00
|
|
|
import StatusQ.Core.Utils 0.1 as StatusQUtils
|
2022-03-10 17:01:17 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import shared.panels 1.0
|
|
|
|
import shared.controls 1.0
|
|
|
|
|
|
|
|
import "../stores"
|
|
|
|
|
|
|
|
StatusModal {
|
|
|
|
id: popup
|
|
|
|
|
|
|
|
property WalletStore walletStore
|
2023-04-17 11:36:40 +00:00
|
|
|
property var account
|
2022-03-10 17:01:17 +00:00
|
|
|
property var emojiPopup
|
|
|
|
|
2023-05-23 12:46:16 +00:00
|
|
|
headerSettings.title: qsTr("Rename %1").arg(popup.account.name)
|
2022-03-10 17:01:17 +00:00
|
|
|
|
|
|
|
property int marginBetweenInputs: 30
|
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
accountNameInput.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
enabled: popup.opened
|
|
|
|
target: emojiPopup
|
2023-01-18 09:25:36 +00:00
|
|
|
function onEmojiSelected(emojiText: string, atCursor: bool) {
|
2023-10-12 16:20:55 +00:00
|
|
|
let emoji = StatusQUtils.Emoji.deparse(emojiText)
|
|
|
|
popup.contentItem.accountNameInput.input.asset.emoji = emoji
|
2022-03-10 17:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contentItem: Column {
|
|
|
|
property alias accountNameInput: accountNameInput
|
|
|
|
|
|
|
|
width: popup.width
|
|
|
|
spacing: marginBetweenInputs
|
2024-10-15 19:26:12 +00:00
|
|
|
topPadding: Theme.padding
|
2022-03-10 17:01:17 +00:00
|
|
|
|
|
|
|
StatusInput {
|
|
|
|
id: accountNameInput
|
2023-01-03 15:25:45 +00:00
|
|
|
|
2022-08-10 09:23:06 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
input.edit.objectName: "renameAccountNameInput"
|
2022-03-10 17:01:17 +00:00
|
|
|
input.isIconSelectable: true
|
2022-07-22 10:28:04 +00:00
|
|
|
placeholderText: qsTr("Enter an account name...")
|
2023-04-17 11:36:40 +00:00
|
|
|
input.text: popup.account.name
|
|
|
|
input.asset.emoji: popup.account.emoji
|
2023-05-22 15:55:47 +00:00
|
|
|
input.asset.color: Utils.getColorForId(popup.account.colorId)
|
2023-04-17 11:36:40 +00:00
|
|
|
input.asset.name: !popup.account.emoji ? "filled-account": ""
|
2023-01-03 15:25:45 +00:00
|
|
|
|
|
|
|
validationMode: StatusInput.ValidationMode.Always
|
|
|
|
|
2022-03-10 17:01:17 +00:00
|
|
|
onIconClicked: {
|
|
|
|
popup.emojiPopup.open()
|
2024-10-15 19:26:12 +00:00
|
|
|
popup.emojiPopup.x = popup.x + accountNameInput.x + Theme.padding
|
|
|
|
popup.emojiPopup.y = popup.y + contentItem.y + accountNameInput.y + accountNameInput.height + Theme.halfPadding
|
2022-03-10 17:01:17 +00:00
|
|
|
}
|
|
|
|
validators: [
|
|
|
|
StatusMinLengthValidator {
|
2024-02-05 10:04:20 +00:00
|
|
|
errorMessage: qsTr("Account name must be at least %n character(s)", "", Constants.addAccountPopup.keyPairAccountNameMinLength)
|
|
|
|
minLength: Constants.addAccountPopup.keyPairAccountNameMinLength
|
2022-03-24 14:56:43 +00:00
|
|
|
},
|
|
|
|
StatusRegularExpressionValidator {
|
|
|
|
regularExpression: /^[^<>]+$/
|
|
|
|
errorMessage: qsTr("This is not a valid account name")
|
2022-03-10 17:01:17 +00:00
|
|
|
}
|
|
|
|
]
|
2024-02-05 10:04:20 +00:00
|
|
|
charLimit: 20
|
2022-03-10 17:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusColorSelectorGrid {
|
|
|
|
id: accountColorInput
|
|
|
|
anchors.top: selectedColor.bottom
|
|
|
|
anchors.topMargin: 10
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2023-05-22 15:55:47 +00:00
|
|
|
model: Theme.palette.customisationColorsArray
|
2024-10-15 19:26:12 +00:00
|
|
|
titleText: qsTr("COLOUR")
|
2023-05-22 15:55:47 +00:00
|
|
|
selectedColor: Utils.getColorForId(popup.account.colorId)
|
2022-03-10 17:01:17 +00:00
|
|
|
selectedColorIndex: {
|
|
|
|
for (let i = 0; i < model.length; i++) {
|
2023-04-17 11:36:40 +00:00
|
|
|
if(model[i] === popup.account.color)
|
2022-03-10 17:01:17 +00:00
|
|
|
return i
|
|
|
|
}
|
2023-01-03 15:25:45 +00:00
|
|
|
return -1
|
2022-03-10 17:01:17 +00:00
|
|
|
}
|
|
|
|
onSelectedColorChanged: {
|
2023-04-17 11:36:40 +00:00
|
|
|
if(selectedColor !== popup.account.color) {
|
2022-08-11 11:55:08 +00:00
|
|
|
accountNameInput.input.asset.color = selectedColor
|
2022-03-10 17:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
width: parent.width
|
|
|
|
height: 8
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rightButtons: [
|
|
|
|
StatusButton {
|
|
|
|
id: saveBtn
|
2022-08-10 09:23:06 +00:00
|
|
|
objectName: "renameAccountModalSaveBtn"
|
2022-03-10 17:01:17 +00:00
|
|
|
text: qsTr("Change Name")
|
|
|
|
|
2023-10-12 16:20:55 +00:00
|
|
|
enabled: accountNameInput.text !== "" &&
|
|
|
|
accountNameInput.valid &&
|
|
|
|
(accountNameInput.text !== popup.account.name ||
|
|
|
|
accountColorInput.selectedColorIndex >= 0 && accountColorInput.selectedColor !== popup.account.color ||
|
|
|
|
accountNameInput.input.asset.emoji !== popup.account.emoji)
|
2022-03-10 17:01:17 +00:00
|
|
|
|
|
|
|
MessageDialog {
|
|
|
|
id: changeError
|
|
|
|
title: qsTr("Changing settings failed")
|
|
|
|
icon: StandardIcon.Critical
|
|
|
|
standardButtons: StandardButton.Ok
|
|
|
|
}
|
|
|
|
|
2023-01-03 15:25:45 +00:00
|
|
|
onClicked : {
|
2022-03-10 17:01:17 +00:00
|
|
|
if (!accountNameInput.valid) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-22 15:55:47 +00:00
|
|
|
const error = walletStore.updateAccount(popup.account.address, accountNameInput.text, Utils.getIdForColor(accountColorInput.selectedColor), accountNameInput.input.asset.emoji);
|
2022-03-10 17:01:17 +00:00
|
|
|
|
|
|
|
if (error) {
|
|
|
|
Global.playErrorSound();
|
|
|
|
changeError.text = error
|
|
|
|
changeError.open()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
popup.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|