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

210 lines
7.7 KiB
QML
Raw Normal View History

2020-08-06 19:45:57 +00:00
import QtQuick 2.14
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.14
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
2020-08-06 19:45:57 +00:00
Item {
id: root
property var ensUsernamesStore
property var contactsStore
2020-08-06 19:45:57 +00:00
property string username: ""
property string walletAddress: "-"
property string key: "-"
2021-08-09 22:23:52 +00:00
property var expiration: 0
2020-08-06 19:45:57 +00:00
2020-08-07 16:27:41 +00:00
signal backBtnClicked();
2021-08-09 22:23:52 +00:00
signal usernameReleased(username: string);
2020-08-07 16:27:41 +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: Style.current.padding
anchors.top: parent.top
anchors.topMargin: Style.currentPadding
}
Connections {
target: root.ensUsernamesStore.ensUsernamesModule
2020-08-06 19:45:57 +00:00
onDetailsObtained: {
2022-07-18 08:34:11 +00:00
if(username != (isStatus ? ensName + ".stateofus.eth" : ensName))
return;
walletAddressLbl.subTitle = address;
keyLbl.subTitle = pubkey.substring(0, 20) + "..." + pubkey.substring(pubkey.length - 20);
walletAddressLbl.visible = true;
keyLbl.visible = true;
releaseBtn.visible = isStatus
releaseBtn.enabled = (Date.now() / 1000) > expirationTime && expirationTime > 0 &&
root.ensUsernamesStore.preferredUsername != username
2022-07-18 08:34:11 +00:00
releaseBtn.enabled = true
expiration = new Date(expirationTime * 1000).getTime()
2020-08-06 19:45:57 +00:00
}
onLoading: {
loadingImg.active = isLoading
if(!isLoading) return;
walletAddressLbl.visible = false;
keyLbl.visible = false;
2021-08-09 22:23:52 +00:00
releaseBtn.visible = false;
expiration = 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: {
root.ensUsernamesStore.copyToClipboard(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: {
root.ensUsernamesStore.copyToClipboard(subTitle)
tooltip.visible = !tooltip.visible
}
2020-08-06 19:45:57 +00:00
}
2021-08-09 22:23:52 +00:00
Component {
id: transactionDialogComponent
SendModal {
id: releaseEnsModal
modalHeader: qsTr("Release your username")
interactive: false
sendType: Constants.SendType.ENSRelease
preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress()
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(0)
preSelectedAsset: {
let assetsList = releaseEnsModal.store.currentAccount.assets
for(var i=0; i< assetsList.count;i++) {
if("ETH" === assetsList.rowData(i, "symbol"))
return {
name: assetsList.rowData(i, "name"),
symbol: assetsList.rowData(i, "symbol"),
totalBalance: assetsList.rowData(i, "totalBalance"),
totalCurrencyBalance: assetsList.rowData(i, "totalCurrencyBalance"),
balances: assetsList.rowData(i, "balances"),
decimals: assetsList.rowData(i, "decimals")
}
}
return {}
2021-08-09 22:23:52 +00:00
}
sendTransaction: function() {
if(bestRoutes.length === 1) {
let path = bestRoutes[0]
let eip1559Enabled = path.gasFees.eip1559Enabled
let maxFeePerGas = (selectedPriority === 0) ? path.gasFees.maxFeePerGasL:
(selectedPriority === 1) ? path.gasFees.maxFeePerGasM:
path.gasFees.maxFeePerGasH
root.ensUsernamesStore.authenticateAndReleaseEns(
root.username,
selectedAccount.address,
path.gasAmount,
eip1559Enabled ? "" : path.gasFees.gasPrice,
eip1559Enabled ? path.gasFees.maxPriorityFeePerGas : "",
eip1559Enabled ? maxFeePerGas: path.gasFees.gasPrice,
eip1559Enabled,
)
}
2021-08-09 22:23:52 +00:00
}
Connections {
target: root.ensUsernamesStore.ensUsernamesModule
onTransactionWasSent: {
try {
let response = JSON.parse(txResult)
if (!response.success) {
if (Utils.isInvalidPasswordMessage(response.result)) {
releaseEnsModal.setSendTxError()
return
}
releaseEnsModal.sendingError.text = response.result
return releaseEnsModal.sendingError.open()
}
usernameReleased(username);
let url = `${releaseEnsModal.store.getEtherscanLink()}/${response.result}`;
Global.displayToastMessage(qsTr("Transaction pending..."),
qsTr("View on etherscan"),
"",
true,
Constants.ephemeralNotificationType.normal,
url)
} catch (e) {
console.error('Error parsing the response', e)
}
releaseEnsModal.close()
}
2021-08-09 22:23:52 +00:00
}
}
}
StatusQControls.StatusButton {
2021-08-09 22:23:52 +00:00
id: releaseBtn
visible: false
enabled: false
anchors.top: keyLbl.bottom
anchors.topMargin: 24
anchors.left: parent.left
anchors.leftMargin: 24
text: qsTr("Release username")
2021-08-09 22:23:52 +00:00
onClicked: {
Global.openPopup(transactionDialogComponent)
2021-08-09 22:23:52 +00:00
}
}
Text {
visible: releaseBtn.visible && !releaseBtn.enabled
anchors.top: releaseBtn.bottom
anchors.topMargin: 2
anchors.left: parent.left
anchors.leftMargin: 24
text: qsTr("Username locked. You won't be able to release it until %1").arg(Utils.formatShortDateStr(new Date(expiration).toDateString()))
2021-08-09 22:23:52 +00:00
color: Style.current.darkGrey
}
StatusQControls.StatusButton {
2020-08-06 19:45:57 +00:00
anchors.bottom: parent.bottom
anchors.bottomMargin: Style.current.padding
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
}
}