2020-08-03 20:46:37 +00:00
|
|
|
|
import QtQuick 2.14
|
|
|
|
|
import QtQuick.Layouts 1.3
|
|
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
|
import "../../../../../imports"
|
|
|
|
|
import "../../../../../shared"
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: searchENS
|
2020-08-04 22:22:51 +00:00
|
|
|
|
|
|
|
|
|
property var onClick: function(){}
|
|
|
|
|
|
2020-08-03 20:46:37 +00:00
|
|
|
|
property string validationMessage: ""
|
|
|
|
|
property bool valid: false
|
|
|
|
|
property bool isStatus: true
|
2020-08-04 22:22:51 +00:00
|
|
|
|
property string ensStatus: ""
|
2020-08-03 20:46:37 +00:00
|
|
|
|
|
|
|
|
|
property var validateENS: Backpressure.debounce(searchENS, 500, function (ensName, isStatus){
|
|
|
|
|
profileModel.ens.validate(ensName, isStatus)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function validate() {
|
|
|
|
|
validationMessage = "";
|
|
|
|
|
valid = false;
|
2020-08-04 22:22:51 +00:00
|
|
|
|
ensStatus = "";
|
2020-08-03 20:46:37 +00:00
|
|
|
|
if (ensUsername.text.length < 4) {
|
|
|
|
|
validationMessage = qsTr("At least 4 characters. Latin letters, numbers, and lowercase only.");
|
|
|
|
|
} else if(isStatus && !ensUsername.text.match(/^[a-z0-9]+$/)){
|
|
|
|
|
validationMessage = qsTr("Letters and numbers only.");
|
|
|
|
|
} else if(!isStatus && !ensUsername.text.endsWith(".eth")){
|
|
|
|
|
validationMessage = qsTr("Type the entire username including the custom domain like username.domain.eth")
|
|
|
|
|
}
|
|
|
|
|
return validationMessage === "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onKeyReleased(){
|
|
|
|
|
if (!validate()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Qt.callLater(validateENS, ensUsername.text, isStatus)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
|
id: sectionTitle
|
|
|
|
|
text: qsTr("Your username")
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
anchors.leftMargin: 24
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.topMargin: 24
|
|
|
|
|
font.weight: Font.Bold
|
|
|
|
|
font.pixelSize: 20
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: circleAt
|
|
|
|
|
anchors.top: sectionTitle.bottom
|
|
|
|
|
anchors.topMargin: 24
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
width: 60
|
|
|
|
|
height: 60
|
|
|
|
|
radius: 120
|
|
|
|
|
color: Style.current.blue
|
|
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
|
text: "@"
|
|
|
|
|
opacity: 0.7
|
|
|
|
|
font.weight: Font.Bold
|
|
|
|
|
font.pixelSize: 18
|
|
|
|
|
color: Style.current.white
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Input {
|
|
|
|
|
id: ensUsername
|
|
|
|
|
placeholderText: !isStatus ? "vitalik94.domain.eth" : "vitalik94"
|
|
|
|
|
anchors.top: circleAt.bottom
|
|
|
|
|
anchors.topMargin: 24
|
|
|
|
|
anchors.right: btnContinue.left
|
|
|
|
|
anchors.rightMargin: 24
|
|
|
|
|
Keys.onReleased: {
|
|
|
|
|
onKeyReleased();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
|
target: profileModel.ens
|
|
|
|
|
onEnsWasResolved: {
|
2020-08-04 22:22:51 +00:00
|
|
|
|
valid = false;
|
|
|
|
|
ensStatus = ensResult;
|
2020-08-03 20:46:37 +00:00
|
|
|
|
switch(ensResult){
|
|
|
|
|
case "available":
|
|
|
|
|
valid = true;
|
|
|
|
|
validationMessage = qsTr("✓ Username available!");
|
|
|
|
|
break;
|
|
|
|
|
case "owned":
|
2020-08-04 22:22:51 +00:00
|
|
|
|
console.log("TODO: - Continuing will connect this username with your chat key.");
|
2020-08-03 20:46:37 +00:00
|
|
|
|
case "taken":
|
|
|
|
|
validationMessage = !isStatus ?
|
|
|
|
|
qsTr("Username doesn’t belong to you :(")
|
|
|
|
|
:
|
|
|
|
|
qsTr("Username already taken :(");
|
|
|
|
|
break;
|
2020-08-04 22:22:51 +00:00
|
|
|
|
case "already-connected":
|
|
|
|
|
validationMessage = qsTr("Username is already connected with your chat key and can be used inside Status.");
|
|
|
|
|
break;
|
2020-08-03 20:46:37 +00:00
|
|
|
|
case "connected":
|
2020-08-04 22:22:51 +00:00
|
|
|
|
valid = true;
|
|
|
|
|
validationMessage = qsTr("This user name is owned by you and connected with your chat key. Continue to set `Show my ENS username in chats`.");
|
2020-08-03 20:46:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case "connected-different-key":
|
2020-08-04 22:22:51 +00:00
|
|
|
|
valid = true;
|
|
|
|
|
validationMessage = qsTr("Continuing will require a transaction to connect the username with your current chat key.");
|
|
|
|
|
break;
|
2020-08-03 20:46:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Button {
|
|
|
|
|
id: btnContinue
|
|
|
|
|
width: 44
|
|
|
|
|
height: 44
|
|
|
|
|
anchors.top: circleAt.bottom
|
|
|
|
|
anchors.topMargin: 24
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
SVGImage {
|
|
|
|
|
source: !valid ? "../../../../img/arrow-button-inactive.svg" : "../../../../img/arrow-btn-active.svg"
|
|
|
|
|
width: 50
|
|
|
|
|
height: 50
|
|
|
|
|
}
|
|
|
|
|
background: Rectangle {
|
|
|
|
|
color: "transparent"
|
|
|
|
|
}
|
|
|
|
|
MouseArea {
|
|
|
|
|
id: btnMAnewChat
|
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
onClicked : {
|
|
|
|
|
if(!valid) return;
|
2020-08-04 22:22:51 +00:00
|
|
|
|
|
|
|
|
|
if(ensStatus === "connected"){
|
|
|
|
|
profileModel.ens.connect(ensUsername.text);
|
|
|
|
|
onClick(ensStatus, ensUsername.text);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ensStatus === "available"){
|
|
|
|
|
onClick(ensStatus, ensUsername.text);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-03 20:46:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: ensTypeRect
|
|
|
|
|
anchors.top: ensUsername.bottom
|
|
|
|
|
anchors.topMargin: 24
|
|
|
|
|
border.width: 1
|
|
|
|
|
border.color: Style.current.border
|
|
|
|
|
radius: 50
|
|
|
|
|
height: 20
|
|
|
|
|
width: 350
|
|
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
|
text: !isStatus ?
|
|
|
|
|
qsTr("Custom domain")
|
|
|
|
|
:
|
|
|
|
|
".stateofus.eth"
|
|
|
|
|
font.weight: Font.Bold
|
|
|
|
|
font.pixelSize: 12
|
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
|
text: !isStatus ?
|
|
|
|
|
qsTr("I want a stateofus.eth domain")
|
|
|
|
|
:
|
|
|
|
|
qsTr("I own a name on another domain")
|
|
|
|
|
font.pixelSize: 12
|
|
|
|
|
color: Style.current.blue
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
onClicked : {
|
|
|
|
|
isStatus = !isStatus;
|
|
|
|
|
if(validate())
|
|
|
|
|
validateENS(ensUsername.text, isStatus)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
|
id: validationResult
|
|
|
|
|
text: validationMessage
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
anchors.top: ensTypeRect.bottom
|
|
|
|
|
anchors.topMargin: 24
|
|
|
|
|
}
|
|
|
|
|
}
|