From c53b2cc78aef685c1b4f497f662a83527ef8d393 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Thu, 6 Aug 2020 14:19:26 -0400 Subject: [PATCH] feat: select preferred ENS username --- src/app/profile/views/ens_manager.nim | 19 ++- ui/app/AppLayouts/Profile/ProfileLayout.qml | 2 +- .../Profile/Sections/Ens/ENSPopup.qml | 123 ++++++++++++++++++ .../AppLayouts/Profile/Sections/Ens/List.qml | 51 +++++--- .../Profile/Sections/MyProfileContainer.qml | 8 +- ui/shared/TextWithLabel.qml | 2 +- 6 files changed, 177 insertions(+), 28 deletions(-) create mode 100644 ui/app/AppLayouts/Profile/Sections/Ens/ENSPopup.qml diff --git a/src/app/profile/views/ens_manager.nim b/src/app/profile/views/ens_manager.nim index f776937da2..e40fcba1b6 100644 --- a/src/app/profile/views/ens_manager.nim +++ b/src/app/profile/views/ens_manager.nim @@ -70,6 +70,20 @@ QtObject: self.usernames.add(username) self.endInsertRows() + proc getPreferredUsername(self: EnsManager): string {.slot.} = + result = status_settings.getSetting[string](Setting.PreferredUsername, "") + + proc preferredUsernameChanged(self: EnsManager) {.signal.} + + proc setPreferredUsername(self: EnsManager, newENS: string) {.slot.} = + discard status_settings.saveSetting(Setting.PreferredUsername, newENS) + self.preferredUsernameChanged() + + QtProperty[string] preferredUsername: + read = getPreferredUsername + notify = preferredUsernameChanged + write = setPreferredUsername + proc connect(self: EnsManager, username: string, isStatus: bool) {.slot.} = var ensUsername = username if isStatus: @@ -78,12 +92,9 @@ QtObject: usernames.add ensUsername discard status_settings.saveSetting(Setting.Usernames, %*usernames) if usernames.len == 1: - discard status_settings.saveSetting(Setting.PreferredUsername, ensUsername) + self.setPreferredUsername(ensUsername) self.add ensUsername - proc preferredUsername(self: EnsManager): string {.slot.} = - result = status_settings.getSetting[string](Setting.PreferredUsername, "") - method rowCount(self: EnsManager, index: QModelIndex = nil): int = return self.usernames.len diff --git a/ui/app/AppLayouts/Profile/ProfileLayout.qml b/ui/app/AppLayouts/Profile/ProfileLayout.qml index 8283a540bb..ef19395663 100644 --- a/ui/app/AppLayouts/Profile/ProfileLayout.qml +++ b/ui/app/AppLayouts/Profile/ProfileLayout.qml @@ -41,9 +41,9 @@ SplitView { // Would be better if we could make them match automatically MyProfileContainer { username: profileModel.profile.username + ensName: profileModel.ens.preferredUsername identicon: profileModel.profile.identicon pubkey: profileModel.profile.pubKey - address: profileModel.profile.address } onCurrentIndexChanged: { diff --git a/ui/app/AppLayouts/Profile/Sections/Ens/ENSPopup.qml b/ui/app/AppLayouts/Profile/Sections/Ens/ENSPopup.qml new file mode 100644 index 0000000000..c90eabb885 --- /dev/null +++ b/ui/app/AppLayouts/Profile/Sections/Ens/ENSPopup.qml @@ -0,0 +1,123 @@ +import QtQuick 2.12 +import QtQuick.Controls 2.3 +import QtQuick.Layouts 1.3 +import QtQml.Models 2.3 +import "../../../../../imports" +import "../../../../../shared" + +ModalPopup { + id: popup + + title: qsTr("Primary username") + + property string newUsername: "" + + onOpened: { + for(var i in ensNames.contentItem.children){ + ensNames.contentItem.children[i].checked = ensNames.contentItem.children[i].text === profileModel.ens.preferredUsername + } + } + + StyledText { + id: lbl1 + text: qsTr("Your messages are displayed to others with this username:") + font.pixelSize: 15 + } + + StyledText { + id: lbl2 + anchors.top: lbl1.bottom + anchors.topMargin: Style.current.padding + text: profileModel.ens.preferredUsername + font.pixelSize: 17 + font.weight: Font.Bold + } + + ScrollView { + anchors.fill: parent + anchors.top: lbl2.bottom + anchors.topMargin: 70 + Layout.fillWidth: true + Layout.fillHeight: true + + ScrollBar.horizontal.policy: ScrollBar.AlwaysOff + ScrollBar.vertical.policy: ensNames.contentHeight > ensNames.height ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff + + ListView { + anchors.fill: parent + model: profileModel.ens + spacing: 0 + clip: true + id: ensNames + delegate: RadioDelegate { + id: radioDelegate + text: username + checked: profileModel.ens.preferredUsername === username + MouseArea { + anchors.fill: parent + onClicked: { + parent.checked = true + newUsername = username; + } + } + } + } + } + + onNewUsernameChanged: { + btnSelectPreferred.state = newUsername === profileModel.ens.preferredUsername ? "inactive" : "active" + } + + footer: Item { + anchors.top: parent.bottom + anchors.right: parent.right + anchors.bottom: popup.bottom + anchors.left: parent.left + + Button { + id: btnSelectPreferred + width: 44 + height: 44 + anchors.bottom: parent.bottom + anchors.right: parent.right + state: "inactive" + states: [ + State { + name: "inactive" + PropertyChanges { + target: btnContinue + source: "../../../../img/arrow-right-btn-inactive.svg" + } + }, + State { + name: "active" + PropertyChanges { + target: btnContinue + source: "../../../../img/arrow-right-btn-active.svg" + } + } + ] + + SVGImage { + id: btnContinue + width: 50 + height: 50 + } + background: Rectangle { + color: "transparent" + } + MouseArea { + cursorShape: btnSelectPreferred.state === "active" ? Qt.PointingHandCursor : Qt.ArrowCursor + anchors.fill: parent + onClicked : { + if(btnSelectPreferred.state === "active"){ + profileModel.ens.preferredUsername = newUsername; + newUsername = ""; + popup.close(); + } + } + } + } + } +} + diff --git a/ui/app/AppLayouts/Profile/Sections/Ens/List.qml b/ui/app/AppLayouts/Profile/Sections/Ens/List.qml index 1c523ba55e..19087e5608 100644 --- a/ui/app/AppLayouts/Profile/Sections/Ens/List.qml +++ b/ui/app/AppLayouts/Profile/Sections/Ens/List.qml @@ -90,6 +90,10 @@ Item { } } + ENSPopup { + id: ensPopup + } + StyledText { id: sectionTitle //% "ENS usernames" @@ -187,30 +191,41 @@ Item { font.pixelSize: 16 } - StyledText { - id: usernameLabel - visible: chatSettingsLabel.visible - text: qsTr("Primary Username") + Item { + width: childrenRect.width + height: childrenRect.height + + id: preferredUsername anchors.left: parent.left anchors.top: chatSettingsLabel.bottom anchors.topMargin: 24 - font.pixelSize: 14 - font.weight: Font.Bold - } - StyledText { - id: usernameLabel2 - visible: chatSettingsLabel.visible - text: profileModel.ens.preferredUsername() - anchors.left: usernameLabel.right - anchors.leftMargin: Style.current.padding - anchors.top: chatSettingsLabel.bottom - anchors.topMargin: 24 - font.pixelSize: 14 + StyledText { + id: usernameLabel + visible: chatSettingsLabel.visible + text: qsTr("Primary Username") + font.pixelSize: 14 + font.weight: Font.Bold + } + + StyledText { + id: usernameLabel2 + visible: chatSettingsLabel.visible + text: profileModel.ens.preferredUsername + anchors.left: usernameLabel.right + anchors.leftMargin: Style.current.padding + font.pixelSize: 14 + } + + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + onClicked: ensPopup.open() + } } Item { - anchors.top: profileModel.ens.rowCount() == 1 ? separator.bottom : usernameLabel.bottom + anchors.top: profileModel.ens.rowCount() == 1 ? separator.bottom : preferredUsername.bottom anchors.topMargin: Style.current.padding * 2 UserImage { @@ -223,7 +238,7 @@ Item { UsernameLabel { id: chatName - text: profileModel.ens.preferredUsername() + text: profileModel.ens.preferredUsername anchors.leftMargin: 20 anchors.top: parent.top anchors.topMargin: 0 diff --git a/ui/app/AppLayouts/Profile/Sections/MyProfileContainer.qml b/ui/app/AppLayouts/Profile/Sections/MyProfileContainer.qml index c745df0a83..2fd2a92f4f 100644 --- a/ui/app/AppLayouts/Profile/Sections/MyProfileContainer.qml +++ b/ui/app/AppLayouts/Profile/Sections/MyProfileContainer.qml @@ -8,7 +8,7 @@ Item { property string username: "Jotaro Kujo" property string identicon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAAhklEQVR4nOzWwQ1AQBgFYUQvelKHMtShJ9VwFyvrsExe5jvKXiYv+WPoQhhCYwiNITSG0MSEjLUPt3097r7P09L/8f4qZhFDaAyhqboIT76+TiUxixhCYwhN9b/WW6Xr1ErMIobQGEJjCI0hNIbQGEJjCI0haiRmEUNoDKExhMYQmjMAAP//B2kXcP2uDV8AAAAASUVORK5CYII=" property string pubkey: "0x04d8c07dd137bd1b73a6f51df148b4f77ddaa11209d36e43d8344c0a7d6db1cad6085f27cfb75dd3ae21d86ceffebe4cf8a35b9ce8d26baa19dc264efe6d8f221b" - property string address: "0x13Ed66d9Ffcd4dC1fB86B9414b8c60677E5Ae1cE" + property string ensName: "joestar.eth" id: profileHeaderContent height: parent.height @@ -48,7 +48,7 @@ Item { StyledText { id: profileName - text: username + text: ensName !== "" ? ensName : username anchors.left: profileImg.right anchors.leftMargin: 8 anchors.top: profileImg.top @@ -58,12 +58,12 @@ Item { StyledText { id: pubkeyText - text: address + text: ensName !== "" ? username : pubkey anchors.bottom: profileImg.bottom anchors.left: profileName.left font.family: Style.current.fontHexRegular.name elide: Text.ElideMiddle - width: 140 + width: 200 font.pixelSize: 15 color: Style.current.darkGrey } diff --git a/ui/shared/TextWithLabel.qml b/ui/shared/TextWithLabel.qml index 3e4d057f23..fa7bfa397b 100644 --- a/ui/shared/TextWithLabel.qml +++ b/ui/shared/TextWithLabel.qml @@ -8,6 +8,7 @@ Item { property string label: "My Label" property string fontFamily: Style.current.fontRegular.name property string textToCopy: "" + property alias value: textItem id: infoText height: this.childrenRect.height @@ -25,7 +26,6 @@ Item { id: textItem text: infoText.text font.family: fontFamily - selectByMouse: true readOnly: true anchors.top: inputLabel.bottom anchors.topMargin: 7