2020-08-03 20:46:37 +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
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2021-10-06 09:16:39 +00:00
|
|
|
import "../../../../shared"
|
|
|
|
import "../../../../shared/status"
|
2020-08-03 20:46:37 +00:00
|
|
|
|
|
|
|
Item {
|
2021-10-06 09:16:39 +00:00
|
|
|
id: root
|
|
|
|
|
|
|
|
property var store
|
2020-08-04 22:22:51 +00:00
|
|
|
|
2020-08-07 16:27:41 +00:00
|
|
|
signal continueClicked(string output, string username)
|
2020-08-27 20:18:14 +00:00
|
|
|
signal usernameUpdated(username: string);
|
|
|
|
|
2020-08-04 22:22:51 +00:00
|
|
|
|
2020-08-03 20:46:37 +00:00
|
|
|
property string validationMessage: ""
|
|
|
|
property bool valid: false
|
|
|
|
property bool isStatus: true
|
2020-08-05 19:50:55 +00:00
|
|
|
property bool loading: false
|
2020-08-04 22:22:51 +00:00
|
|
|
property string ensStatus: ""
|
2020-08-03 20:46:37 +00:00
|
|
|
|
2021-10-06 09:16:39 +00:00
|
|
|
property var validateENS: Backpressure.debounce(root, 500, function (ensName, isStatus){
|
|
|
|
store.validateEns(ensName, isStatus)
|
2020-08-03 20:46:37 +00:00
|
|
|
});
|
|
|
|
|
2020-08-05 19:50:55 +00:00
|
|
|
function validate(ensUsername) {
|
2020-08-03 20:46:37 +00:00
|
|
|
validationMessage = "";
|
|
|
|
valid = false;
|
2020-08-04 22:22:51 +00:00
|
|
|
ensStatus = "";
|
2020-08-05 19:50:55 +00:00
|
|
|
if (ensUsername.length < 4) {
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "At least 4 characters. Latin letters, numbers, and lowercase only."
|
|
|
|
validationMessage = qsTrId("ens-username-hints");
|
2020-08-05 19:50:55 +00:00
|
|
|
} else if(isStatus && !ensUsername.match(/^[a-z0-9]+$/)){
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Letters and numbers only."
|
|
|
|
validationMessage = qsTrId("ens-username-invalid");
|
2020-08-05 19:50:55 +00:00
|
|
|
} else if(!isStatus && !ensUsername.endsWith(".eth")){
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Type the entire username including the custom domain like username.domain.eth"
|
|
|
|
validationMessage = qsTrId("ens-custom-username-hints")
|
2020-08-03 20:46:37 +00:00
|
|
|
}
|
|
|
|
return validationMessage === "";
|
|
|
|
}
|
|
|
|
|
2020-08-05 19:50:55 +00:00
|
|
|
function onKeyReleased(ensUsername){
|
|
|
|
if (!validate(ensUsername)) {
|
2020-08-03 20:46:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-05 19:50:55 +00:00
|
|
|
loading = true;
|
|
|
|
Qt.callLater(validateENS, ensUsername, isStatus)
|
2020-08-03 20:46:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-09 22:23:52 +00:00
|
|
|
Component {
|
|
|
|
id: transactionDialogComponent
|
|
|
|
StatusETHTransactionModal {
|
2021-07-19 21:57:57 +00:00
|
|
|
onOpened: {
|
2021-10-06 09:16:39 +00:00
|
|
|
root.store.getGasPrice()
|
2021-07-19 21:57:57 +00:00
|
|
|
}
|
2021-08-09 22:23:52 +00:00
|
|
|
title: qsTr("Connect username with your pubkey")
|
2020-11-03 10:29:56 +00:00
|
|
|
onClosed: {
|
2021-08-09 22:23:52 +00:00
|
|
|
destroy()
|
|
|
|
}
|
|
|
|
estimateGasFunction: function(selectedAccount) {
|
|
|
|
if (ensUsername.text === "" || !selectedAccount) return 80000;
|
2021-10-06 09:16:39 +00:00
|
|
|
return root.store.setPubKeyGasEstimate(ensUsername.text + (isStatus ? ".stateofus.eth" : "" ), selectedAccount.address)
|
2020-11-03 10:29:56 +00:00
|
|
|
}
|
2021-08-09 22:23:52 +00:00
|
|
|
onSendTransaction: function(selectedAddress, gasLimit, gasPrice, password) {
|
2021-10-06 09:16:39 +00:00
|
|
|
return root.store.setPubKey(ensUsername.text + (isStatus ? ".stateofus.eth" : "" ),
|
2021-08-09 22:23:52 +00:00
|
|
|
selectedAddress,
|
|
|
|
gasLimit,
|
|
|
|
gasPrice,
|
|
|
|
password)
|
|
|
|
}
|
|
|
|
onSuccess: function(){
|
|
|
|
usernameUpdated(ensUsername.text);
|
|
|
|
}
|
|
|
|
|
|
|
|
width: 475
|
|
|
|
height: 500
|
2020-11-03 10:29:56 +00:00
|
|
|
}
|
2020-08-27 20:18:14 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 16:34:52 +00:00
|
|
|
Item {
|
|
|
|
id: ensContainer
|
2020-08-03 20:46:37 +00:00
|
|
|
anchors.top: parent.top
|
2021-04-08 15:44:58 +00:00
|
|
|
width: profileContainer.profileContentWidth
|
2020-08-03 20:46:37 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
2021-03-23 16:34:52 +00:00
|
|
|
Rectangle {
|
|
|
|
id: circleAt
|
2021-03-25 02:17:33 +00:00
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: Style.current.bigPadding*2
|
2021-03-23 16:34:52 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
width: 60
|
|
|
|
height: 60
|
|
|
|
radius: 120
|
2021-10-06 09:16:39 +00:00
|
|
|
color: Theme.palette.primaryColor1
|
2021-03-23 16:34:52 +00:00
|
|
|
|
|
|
|
SVGImage {
|
|
|
|
id: imgIcon
|
|
|
|
visible: ensStatus === Constants.ens_taken
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2021-09-28 15:04:06 +00:00
|
|
|
source: Style.svg("block-icon-white")
|
2021-03-23 16:34:52 +00:00
|
|
|
width: 20
|
|
|
|
height: 20
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
}
|
|
|
|
|
2021-10-06 09:16:39 +00:00
|
|
|
StatusBaseText {
|
2021-03-23 16:34:52 +00:00
|
|
|
visible: ensStatus !== Constants.ens_taken
|
|
|
|
text: {
|
|
|
|
if((ensStatus === Constants.ens_available ||
|
|
|
|
ensStatus === Constants.ens_connected ||
|
|
|
|
ensStatus === Constants.ens_connected_dkey)) {
|
|
|
|
return "✓"
|
|
|
|
} else {
|
|
|
|
return "@"
|
|
|
|
}
|
2020-08-05 19:50:55 +00:00
|
|
|
}
|
2021-03-23 16:34:52 +00:00
|
|
|
opacity: 0.7
|
|
|
|
font.weight: Font.Bold
|
|
|
|
font.pixelSize: 18
|
2021-10-06 09:16:39 +00:00
|
|
|
color: Theme.palette.indirectColor1
|
2021-03-23 16:34:52 +00:00
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2020-08-05 19:50:55 +00:00
|
|
|
}
|
2020-08-03 20:46:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-23 16:34:52 +00:00
|
|
|
Input {
|
|
|
|
id: ensUsername
|
|
|
|
placeholderText: !isStatus ? "vitalik94.domain.eth" : "vitalik94"
|
|
|
|
anchors.top: circleAt.bottom
|
|
|
|
anchors.topMargin: Style.current.bigPadding
|
|
|
|
anchors.right: btnContinue.left
|
|
|
|
anchors.rightMargin: Style.current.bigPadding
|
|
|
|
Keys.onReleased: {
|
|
|
|
onKeyReleased(ensUsername.text);
|
|
|
|
}
|
2020-08-03 20:46:37 +00:00
|
|
|
|
2021-03-23 16:34:52 +00:00
|
|
|
Connections {
|
2021-10-06 09:16:39 +00:00
|
|
|
target: root.store.ens
|
2021-03-23 16:34:52 +00:00
|
|
|
onEnsWasResolved: {
|
|
|
|
if(!validate(ensUsername.text)) return;
|
|
|
|
valid = false;
|
|
|
|
loading = false;
|
|
|
|
ensStatus = ensResult;
|
|
|
|
switch(ensResult){
|
2021-03-25 02:17:33 +00:00
|
|
|
case "available":
|
|
|
|
case "owned":
|
|
|
|
case "connected":
|
|
|
|
case "connected-different-key":
|
2021-03-23 16:34:52 +00:00
|
|
|
valid = true;
|
|
|
|
validationMessage = Constants.ensState[ensResult]
|
|
|
|
break;
|
2021-03-25 02:17:33 +00:00
|
|
|
case "taken":
|
|
|
|
validationMessage = Constants.ensState[!isStatus ? 'taken-custom' : 'taken']
|
2021-03-23 16:34:52 +00:00
|
|
|
break;
|
2021-03-25 02:17:33 +00:00
|
|
|
case "already-connected":
|
2021-03-23 16:34:52 +00:00
|
|
|
validationMessage = Constants.ensState[ensResult]
|
|
|
|
break;
|
|
|
|
}
|
2020-08-03 20:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 09:16:39 +00:00
|
|
|
// TODO: replace with StatusQ component
|
2021-03-23 16:34:52 +00:00
|
|
|
StatusRoundButton {
|
|
|
|
id: btnContinue
|
|
|
|
width: 44
|
|
|
|
height: 44
|
|
|
|
anchors.top: circleAt.bottom
|
|
|
|
anchors.topMargin: Style.current.bigPadding
|
|
|
|
anchors.right: parent.right
|
|
|
|
size: "medium"
|
|
|
|
type: "secondary"
|
|
|
|
icon.name: "arrow-right"
|
|
|
|
icon.width: 18
|
|
|
|
icon.height: 14
|
|
|
|
visible: valid
|
|
|
|
onClicked: {
|
2020-08-03 20:46:37 +00:00
|
|
|
if(!valid) return;
|
2020-08-04 22:22:51 +00:00
|
|
|
|
2021-03-23 16:34:52 +00:00
|
|
|
if(ensStatus === Constants.ens_connected){
|
2021-10-06 09:16:39 +00:00
|
|
|
root.store.ensConnectOwnedUsername(ensUsername.text, isStatus);
|
2020-08-07 16:27:41 +00:00
|
|
|
continueClicked(ensStatus, ensUsername.text)
|
2020-08-04 22:22:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-23 16:34:52 +00:00
|
|
|
if(ensStatus === Constants.ens_available){
|
2020-08-07 16:27:41 +00:00
|
|
|
continueClicked(ensStatus, ensUsername.text);
|
2020-08-04 22:22:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-27 20:18:14 +00:00
|
|
|
|
2021-03-23 16:34:52 +00:00
|
|
|
if(ensStatus === Constants.ens_connected_dkey || ensStatus === Constants.ens_owned){
|
2021-08-09 22:23:52 +00:00
|
|
|
openPopup(transactionDialogComponent)
|
2020-08-27 20:18:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-08-03 20:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-23 16:34:52 +00:00
|
|
|
Rectangle {
|
|
|
|
id: ensTypeRect
|
|
|
|
anchors.top: ensUsername.bottom
|
|
|
|
anchors.topMargin: Style.current.bigPadding
|
|
|
|
border.width: 1
|
|
|
|
border.color: Style.current.border
|
|
|
|
color: Style.current.background
|
|
|
|
radius: 50
|
|
|
|
height: 30
|
|
|
|
width: 350
|
2020-08-03 20:46:37 +00:00
|
|
|
|
2021-03-23 16:34:52 +00:00
|
|
|
Item {
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: Style.current.halfPadding
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
height: 20
|
2020-08-03 20:46:37 +00:00
|
|
|
|
2021-10-06 09:16:39 +00:00
|
|
|
StatusBaseText {
|
2021-03-23 16:34:52 +00:00
|
|
|
text: !isStatus ?
|
|
|
|
//% "Custom domain"
|
|
|
|
qsTrId("ens-custom-domain")
|
|
|
|
:
|
|
|
|
".stateofus.eth"
|
|
|
|
font.weight: Font.Bold
|
|
|
|
font.pixelSize: 12
|
|
|
|
anchors.leftMargin: Style.current.padding
|
2021-10-06 09:16:39 +00:00
|
|
|
color: Theme.palette.directColor1
|
2021-03-23 16:34:52 +00:00
|
|
|
}
|
2020-08-03 20:46:37 +00:00
|
|
|
|
2021-10-06 09:16:39 +00:00
|
|
|
StatusBaseText {
|
2021-03-23 16:34:52 +00:00
|
|
|
text: !isStatus ?
|
|
|
|
//% "I want a stateofus.eth domain"
|
|
|
|
qsTrId("ens-want-domain")
|
|
|
|
:
|
|
|
|
//% "I own a name on another domain"
|
|
|
|
qsTrId("ens-want-custom-domain")
|
|
|
|
font.pixelSize: 12
|
2021-10-06 09:16:39 +00:00
|
|
|
color: Theme.palette.primaryColor1
|
2021-03-23 16:34:52 +00:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.padding
|
2020-08-03 20:46:37 +00:00
|
|
|
|
2021-03-23 16:34:52 +00:00
|
|
|
MouseArea {
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked : {
|
|
|
|
isStatus = !isStatus;
|
|
|
|
let ensUser = ensUsername.text;
|
|
|
|
if(validate(ensUser))
|
|
|
|
validateENS(ensUser, isStatus)
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 20:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-06 09:16:39 +00:00
|
|
|
StatusBaseText {
|
2021-03-23 16:34:52 +00:00
|
|
|
id: validationResult
|
|
|
|
text: validationMessage
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
2021-04-08 15:44:58 +00:00
|
|
|
width: parent.width
|
2021-03-23 16:34:52 +00:00
|
|
|
anchors.top: ensTypeRect.bottom
|
2021-04-08 15:44:58 +00:00
|
|
|
wrapMode: Text.WordWrap
|
2021-03-23 16:34:52 +00:00
|
|
|
anchors.topMargin: Style.current.bigPadding
|
|
|
|
}
|
2020-08-03 20:46:37 +00:00
|
|
|
}
|
2020-09-14 12:12:47 +00:00
|
|
|
}
|
2021-10-06 09:16:39 +00:00
|
|
|
|