2020-08-06 19:45:57 +00:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Layouts 1.3
|
|
|
|
import QtQuick.Controls 2.14
|
2021-09-28 15:04:06 +00:00
|
|
|
|
2021-10-06 09:16:39 +00:00
|
|
|
import StatusQ.Core 0.1
|
2021-11-01 09:42:00 +00:00
|
|
|
import StatusQ.Core.Theme 0.1
|
2021-10-21 15:07:13 +00:00
|
|
|
import StatusQ.Controls 0.1 as StatusQControls
|
2021-10-06 09:16:39 +00:00
|
|
|
import StatusQ.Components 0.1
|
|
|
|
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared.status 1.0
|
2022-10-17 10:17:25 +00:00
|
|
|
import shared.popups 1.0
|
2020-08-06 19:45:57 +00:00
|
|
|
|
|
|
|
Item {
|
2021-10-06 09:16:39 +00:00
|
|
|
id: root
|
2022-01-17 08:56:44 +00:00
|
|
|
property var ensUsernamesStore
|
2022-01-04 12:06:05 +00:00
|
|
|
property var contactsStore
|
2020-08-06 19:45:57 +00:00
|
|
|
property string username: ""
|
2023-01-11 16:10:13 +00:00
|
|
|
property string chainId: ""
|
2020-08-06 19:45:57 +00:00
|
|
|
property string walletAddress: "-"
|
|
|
|
property string key: "-"
|
|
|
|
|
2020-08-07 16:27:41 +00:00
|
|
|
signal backBtnClicked();
|
2023-01-11 16:10:13 +00:00
|
|
|
signal usernameReleased()
|
2020-08-07 16:27:41 +00:00
|
|
|
|
2022-12-06 21:12:09 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
2023-02-13 12:49:28 +00:00
|
|
|
property double expirationTimestamp: 0
|
2022-12-06 21:12:09 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 09:16:39 +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
|
2021-11-01 09:42:00 +00:00
|
|
|
color: Theme.palette.directColor1
|
2020-08-06 19:45:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: loadingImageComponent
|
2021-04-26 10:25:01 +00:00
|
|
|
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 {
|
2022-01-17 08:56:44 +00:00
|
|
|
target: root.ensUsernamesStore.ensUsernamesModule
|
2023-01-18 09:25:36 +00:00
|
|
|
function onDetailsObtained(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))
|
2022-01-17 08:56:44 +00:00
|
|
|
return;
|
|
|
|
walletAddressLbl.subTitle = address;
|
|
|
|
keyLbl.subTitle = pubkey.substring(0, 20) + "..." + pubkey.substring(pubkey.length - 20);
|
|
|
|
walletAddressLbl.visible = true;
|
|
|
|
keyLbl.visible = true;
|
|
|
|
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
|
|
|
}
|
2023-01-18 09:25:36 +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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 09:16:39 +00:00
|
|
|
StatusDescriptionListItem {
|
2020-08-06 19:45:57 +00:00
|
|
|
id: walletAddressLbl
|
2021-10-06 09:16:39 +00:00
|
|
|
title: qsTr("Wallet address")
|
2020-08-06 19:45:57 +00:00
|
|
|
visible: false
|
|
|
|
anchors.top: sectionTitle.bottom
|
|
|
|
anchors.topMargin: 24
|
2022-08-11 11:55:08 +00:00
|
|
|
asset.name: "copy"
|
2021-10-06 09:16:39 +00:00
|
|
|
tooltip.text: qsTr("Copied to clipboard!")
|
|
|
|
iconButton.onClicked: {
|
2022-01-17 08:56:44 +00:00
|
|
|
root.ensUsernamesStore.copyToClipboard(subTitle)
|
2021-10-06 09:16:39 +00:00
|
|
|
tooltip.visible = !tooltip.visible
|
|
|
|
}
|
2020-08-06 19:45:57 +00:00
|
|
|
}
|
2021-10-06 09:16:39 +00:00
|
|
|
StatusDescriptionListItem {
|
2020-08-06 19:45:57 +00:00
|
|
|
id: keyLbl
|
2021-10-06 09:16:39 +00:00
|
|
|
title: qsTr("Key")
|
2020-08-06 19:45:57 +00:00
|
|
|
visible: false
|
|
|
|
anchors.top: walletAddressLbl.bottom
|
|
|
|
anchors.topMargin: 24
|
2022-08-11 11:55:08 +00:00
|
|
|
asset.name: "copy"
|
2021-10-06 09:16:39 +00:00
|
|
|
tooltip.text: qsTr("Copied to clipboard!")
|
|
|
|
iconButton.onClicked: {
|
2022-01-17 08:56:44 +00:00
|
|
|
root.ensUsernamesStore.copyToClipboard(subTitle)
|
2021-10-06 09:16:39 +00:00
|
|
|
tooltip.visible = !tooltip.visible
|
|
|
|
}
|
2020-08-06 19:45:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-09 22:23:52 +00:00
|
|
|
Component {
|
|
|
|
id: transactionDialogComponent
|
2022-10-17 10:17:25 +00:00
|
|
|
SendModal {
|
|
|
|
id: releaseEnsModal
|
|
|
|
modalHeader: qsTr("Release your username")
|
|
|
|
interactive: false
|
|
|
|
sendType: Constants.SendType.ENSRelease
|
|
|
|
preSelectedRecipient: root.ensUsernamesStore.getEnsRegisteredAddress()
|
|
|
|
preDefinedAmountToSend: LocaleUtils.numberToLocaleString(0)
|
2023-04-07 10:34:01 +00:00
|
|
|
preSelectedAsset: store.getAsset(releaseEnsModal.store.currentAccount.assets, "ETH")
|
2022-10-17 10:17:25 +00:00
|
|
|
sendTransaction: function() {
|
|
|
|
if(bestRoutes.length === 1) {
|
|
|
|
let path = bestRoutes[0]
|
|
|
|
let eip1559Enabled = path.gasFees.eip1559Enabled
|
2022-11-30 12:59:21 +00:00
|
|
|
let maxFeePerGas = path.gasFees.maxFeePerGasM
|
2022-10-17 10:17:25 +00:00
|
|
|
root.ensUsernamesStore.authenticateAndReleaseEns(
|
2023-01-11 16:10:13 +00:00
|
|
|
root.chainId,
|
2022-10-17 10:17:25 +00:00
|
|
|
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
|
|
|
}
|
2022-10-17 10:17:25 +00:00
|
|
|
Connections {
|
|
|
|
target: root.ensUsernamesStore.ensUsernamesModule
|
2023-01-18 09:25:36 +00:00
|
|
|
function onTransactionWasSent(txResult: string) {
|
2022-10-17 10:17:25 +00:00
|
|
|
try {
|
|
|
|
let response = JSON.parse(txResult)
|
|
|
|
if (!response.success) {
|
2022-11-30 18:57:00 +00:00
|
|
|
if (response.result.includes(Constants.walletSection.cancelledMessage)) {
|
2022-10-17 10:17:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
releaseEnsModal.sendingError.text = response.result
|
|
|
|
return releaseEnsModal.sendingError.open()
|
|
|
|
}
|
2022-12-08 15:56:02 +00:00
|
|
|
for(var i=0; i<releaseEnsModal.bestRoutes.length; i++) {
|
2023-01-11 16:10:13 +00:00
|
|
|
usernameReleased()
|
2022-12-08 15:56:02 +00:00
|
|
|
let url = "%1/%2".arg(releaseEnsModal.store.getEtherscanLink(releaseEnsModal.bestRoutes[i].fromNetwork.chainId)).arg(response.result)
|
|
|
|
Global.displayToastMessage(qsTr("Transaction pending..."),
|
|
|
|
qsTr("View on etherscan"),
|
|
|
|
"",
|
|
|
|
true,
|
|
|
|
Constants.ephemeralNotificationType.normal,
|
|
|
|
url)
|
|
|
|
}
|
2022-10-17 10:17:25 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error('Error parsing the response', e)
|
|
|
|
}
|
|
|
|
releaseEnsModal.close()
|
|
|
|
}
|
2021-08-09 22:23:52 +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: {
|
|
|
|
Global.openPopup(transactionDialogComponent)
|
|
|
|
}
|
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: {
|
2023-01-12 22:39:46 +00:00
|
|
|
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)
|
|
|
|
}
|
2021-08-09 22:23:52 +00:00
|
|
|
color: Style.current.darkGrey
|
|
|
|
}
|
|
|
|
|
2021-10-21 15:07:13 +00:00
|
|
|
StatusQControls.StatusButton {
|
2020-08-06 19:45:57 +00:00
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.bottomMargin: Style.current.padding
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2022-04-04 11:26:30 +00:00
|
|
|
text: qsTr("Back")
|
2020-08-07 16:27:41 +00:00
|
|
|
onClicked: backBtnClicked()
|
2020-08-06 19:45:57 +00:00
|
|
|
}
|
2020-09-14 12:12:47 +00:00
|
|
|
}
|