status-desktop/ui/app/AppLayouts/Profile/views/EnsDetailsView.qml

175 lines
5.1 KiB
QML
Raw Normal View History

import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import StatusQ 0.1
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Controls 0.1 as StatusQControls
import StatusQ.Components 0.1
import utils 1.0
import shared.status 1.0
import shared.popups 1.0
import shared.popups.send 1.0
import shared.stores.send 1.0
2020-08-06 19:45:57 +00:00
import AppLayouts.Profile.stores 1.0
2020-08-06 19:45:57 +00:00
Item {
id: root
property EnsUsernamesStore ensUsernamesStore
2020-08-06 19:45:57 +00:00
property string username: ""
property int chainId: -1
2020-08-06 19:45:57 +00:00
signal backBtnClicked()
signal releaseUsernameRequested(string senderAddress)
2020-08-07 16:27:41 +00:00
2022-12-06 21:12:09 +00:00
QtObject {
id: d
property double expirationTimestamp: 0
property string walletAddress: "-"
property string key: "-"
2022-12-06 21:12:09 +00:00
}
StatusBaseText {
2020-08-06 19:45:57 +00:00
id: sectionTitle
text: username
anchors.left: parent.left
anchors.leftMargin: 24
anchors.top: parent.top
anchors.topMargin: 24
font.weight: Font.Bold
font.pixelSize: 20
color: Theme.palette.directColor1
2020-08-06 19:45:57 +00:00
}
Component {
id: loadingImageComponent
StatusLoadingIndicator {}
2020-08-06 19:45:57 +00:00
}
Loader {
id: loadingImg
active: false
sourceComponent: loadingImageComponent
anchors.right: parent.right
anchors.rightMargin: Theme.padding
2020-08-06 19:45:57 +00:00
anchors.top: parent.top
anchors.topMargin: Theme.padding
2020-08-06 19:45:57 +00:00
}
Connections {
target: root.ensUsernamesStore.ensUsernamesModule
function onDetailsObtained(chainId: int, ensName: string, address: string, pubkey: string, isStatus: bool, expirationTime: int) {
2022-07-18 08:34:11 +00:00
if(username != (isStatus ? ensName + ".stateofus.eth" : ensName))
return;
d.walletAddress = address
walletAddressLbl.subTitle = address;
walletAddressLbl.visible = !!address;
d.key = pubkey
keyLbl.subTitle = pubkey.substring(0, 20) + "..." + pubkey.substring(pubkey.length - 20);
keyLbl.visible = !!pubkey;
releaseBtn.visible = isStatus
2022-12-06 21:12:09 +00:00
removeButton.visible = true
releaseBtn.enabled = expirationTime > 0
&& (Date.now() / 1000) > expirationTime
&& root.ensUsernamesStore.preferredUsername !== username
d.expirationTimestamp = expirationTime * 1000
2020-08-06 19:45:57 +00:00
}
function onLoading(isLoading: bool) {
2020-08-06 19:45:57 +00:00
loadingImg.active = isLoading
2022-12-06 21:12:09 +00:00
if (!isLoading)
return;
2020-08-06 19:45:57 +00:00
walletAddressLbl.visible = false;
keyLbl.visible = false;
2021-08-09 22:23:52 +00:00
releaseBtn.visible = false;
2022-12-06 21:12:09 +00:00
removeButton.visible = false;
d.expirationTimestamp = 0;
2020-08-06 19:45:57 +00:00
}
}
StatusDescriptionListItem {
2020-08-06 19:45:57 +00:00
id: walletAddressLbl
title: qsTr("Wallet address")
2020-08-06 19:45:57 +00:00
visible: false
anchors.top: sectionTitle.bottom
anchors.topMargin: 24
asset.name: "copy"
tooltip.text: qsTr("Copied to clipboard!")
iconButton.onClicked: {
ClipboardUtils.setText(subTitle)
tooltip.visible = !tooltip.visible
}
2020-08-06 19:45:57 +00:00
}
StatusDescriptionListItem {
2020-08-06 19:45:57 +00:00
id: keyLbl
title: qsTr("Key")
2020-08-06 19:45:57 +00:00
visible: false
anchors.top: walletAddressLbl.bottom
anchors.topMargin: 24
asset.name: "copy"
tooltip.text: qsTr("Copied to clipboard!")
iconButton.onClicked: {
ClipboardUtils.setText(subTitle)
tooltip.visible = !tooltip.visible
}
2020-08-06 19:45:57 +00:00
}
2022-12-06 21:12:09 +00:00
RowLayout {
id: actionsLayout
2021-08-09 22:23:52 +00:00
anchors.top: keyLbl.bottom
anchors.topMargin: 24
anchors.left: parent.left
anchors.leftMargin: 24
2022-12-06 21:12:09 +00:00
StatusQControls.StatusButton {
id: removeButton
visible: false
type: StatusQControls.StatusBaseButton.Type.Danger
text: qsTr("Remove username")
onClicked: {
2023-01-11 16:10:13 +00:00
root.ensUsernamesStore.removeEnsUsername(root.chainId, root.username)
2022-12-06 21:12:09 +00:00
root.backBtnClicked()
}
}
StatusQControls.StatusButton {
id: releaseBtn
visible: false
enabled: false
text: qsTr("Release username")
onClicked: {
root.releaseUsernameRequested(d.walletAddress)
2022-12-06 21:12:09 +00:00
}
2021-08-09 22:23:52 +00:00
}
}
Text {
visible: releaseBtn.visible && !releaseBtn.enabled
2022-12-06 21:12:09 +00:00
anchors.top: actionsLayout.bottom
2021-08-09 22:23:52 +00:00
anchors.topMargin: 2
anchors.left: parent.left
anchors.leftMargin: 24
2022-12-06 21:12:09 +00:00
text: {
if (d.expirationTimestamp === 0)
return ""
const formattedDate = LocaleUtils.formatDate(d.expirationTimestamp, Locale.ShortFormat)
2022-12-06 21:12:09 +00:00
return qsTr("Username locked. You won't be able to release it until %1").arg(formattedDate)
}
color: Theme.palette.darkGrey
2021-08-09 22:23:52 +00:00
}
StatusQControls.StatusButton {
2020-08-06 19:45:57 +00:00
anchors.bottom: parent.bottom
anchors.bottomMargin: Theme.padding
2020-08-06 19:45:57 +00:00
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Back")
2020-08-07 16:27:41 +00:00
onClicked: backBtnClicked()
2020-08-06 19:45:57 +00:00
}
}