2022-03-10 17:01:17 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
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
|
|
|
|
|
|
|
|
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-04-17 11:36:40 +00:00
|
|
|
header.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) {
|
2022-08-11 11:55:08 +00:00
|
|
|
popup.contentItem.accountNameInput.input.asset.emoji = emojiText
|
2022-03-10 17:01:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contentItem: Column {
|
|
|
|
property alias accountNameInput: accountNameInput
|
|
|
|
|
|
|
|
width: popup.width
|
|
|
|
spacing: marginBetweenInputs
|
|
|
|
topPadding: Style.current.padding
|
|
|
|
|
|
|
|
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
|
|
|
|
input.asset.color: popup.account.color
|
|
|
|
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()
|
|
|
|
popup.emojiPopup.x = popup.x + accountNameInput.x + Style.current.padding
|
|
|
|
popup.emojiPopup.y = popup.y + contentItem.y + accountNameInput.y + accountNameInput.height + Style.current.halfPadding
|
|
|
|
}
|
|
|
|
validators: [
|
|
|
|
StatusMinLengthValidator {
|
2022-04-04 11:26:30 +00:00
|
|
|
errorMessage: qsTr("You need to enter an account name")
|
2022-03-10 17:01:17 +00:00
|
|
|
minLength: 1
|
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
|
|
|
}
|
|
|
|
]
|
2022-03-24 14:56:43 +00:00
|
|
|
charLimit: 40
|
2022-03-10 17:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusColorSelectorGrid {
|
|
|
|
id: accountColorInput
|
|
|
|
anchors.top: selectedColor.bottom
|
|
|
|
anchors.topMargin: 10
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2022-12-16 09:37:08 +00:00
|
|
|
model: Constants.preDefinedWalletAccountColors
|
2022-03-10 17:01:17 +00:00
|
|
|
titleText: qsTr("color").toUpperCase()
|
2023-04-17 11:36:40 +00:00
|
|
|
selectedColor: popup.account.color
|
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")
|
|
|
|
|
2022-03-24 14:56:43 +00:00
|
|
|
enabled: accountNameInput.text !== "" && accountNameInput.valid
|
2023-04-17 11:36:40 +00:00
|
|
|
&& (accountNameInput.text !== popup.account.name
|
|
|
|
|| (accountColorInput.selectedColorIndex >= 0 && accountColorInput.selectedColor !== popup.account.color))
|
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-04-17 11:36:40 +00:00
|
|
|
const error = walletStore.updateAccount(popup.account.address, accountNameInput.text, 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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|