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-10-25 19:37:44 +00:00
|
|
|
import StatusQ.Controls 0.1 as StatusQControls
|
2021-10-06 09:16:39 +00:00
|
|
|
|
2021-09-28 15:04:06 +00:00
|
|
|
import utils 1.0
|
2021-10-27 21:27:49 +00:00
|
|
|
import shared 1.0
|
|
|
|
import shared.panels 1.0
|
|
|
|
import shared.status 1.0
|
|
|
|
import shared.controls 1.0
|
2022-10-17 10:17:25 +00:00
|
|
|
import shared.popups 1.0
|
2020-08-03 20:46:37 +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
|
2021-12-09 13:28:02 +00:00
|
|
|
property int profileContentWidth
|
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){
|
2022-01-17 08:56:44 +00:00
|
|
|
root.ensUsernamesStore.checkEnsUsernameAvailability(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) {
|
2022-04-04 11:26:30 +00:00
|
|
|
validationMessage = qsTr("At least 4 characters. Latin letters, numbers, and lowercase only.");
|
2020-08-05 19:50:55 +00:00
|
|
|
} else if(isStatus && !ensUsername.match(/^[a-z0-9]+$/)){
|
2022-04-04 11:26:30 +00:00
|
|
|
validationMessage = qsTr("Letters and numbers only.");
|
2020-08-05 19:50:55 +00:00
|
|
|
} else if(!isStatus && !ensUsername.endsWith(".eth")){
|
2022-04-04 11:26:30 +00:00
|
|
|
validationMessage = qsTr("Type the entire username including the custom domain like username.domain.eth")
|
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
|
2022-10-17 10:17:25 +00:00
|
|
|
SendModal {
|
|
|
|
id: releaseEnsModal
|
|
|
|
modalHeader: qsTr("Connect username with your pubkey")
|
|
|
|
interactive: false
|
|
|
|
sendType: Constants.SendType.ENSSetPubKey
|
|
|
|
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
|
|
|
}
|
2022-10-17 10:17:25 +00:00
|
|
|
sendTransaction: function() {
|
|
|
|
if(bestRoutes.length === 1) {
|
|
|
|
let path = bestRoutes[0]
|
|
|
|
let eip1559Enabled = path.gasFees.eip1559Enabled
|
|
|
|
root.ensUsernamesStore.authenticateAndSetPubKey(
|
|
|
|
ensUsername.text + (isStatus ? ".stateofus.eth" : "" ),
|
|
|
|
selectedAccount.address,
|
|
|
|
path.gasAmount,
|
|
|
|
eip1559Enabled ? "" : path.gasFees.gasPrice,
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
eip1559Enabled,
|
|
|
|
)
|
|
|
|
}
|
2020-11-03 10:29:56 +00:00
|
|
|
}
|
2022-10-17 10:17:25 +00:00
|
|
|
Connections {
|
|
|
|
target: root.ensUsernamesStore.ensUsernamesModule
|
|
|
|
onTransactionWasSent: {
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
usernameUpdated(ensUsername.text);
|
|
|
|
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
|
|
|
}
|
2020-11-03 10:29:56 +00:00
|
|
|
}
|
2022-10-17 10:17:25 +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-12-09 13:28:02 +00:00
|
|
|
width: 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: {
|
2022-02-09 09:43:23 +00:00
|
|
|
if((ensStatus === Constants.ens_available ||
|
|
|
|
ensStatus === Constants.ens_connected ||
|
2021-03-23 16:34:52 +00:00
|
|
|
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
|
2022-08-09 13:52:17 +00:00
|
|
|
textField.objectName: "ensUsernameInput"
|
2021-03-23 16:34:52 +00:00
|
|
|
placeholderText: !isStatus ? "vitalik94.domain.eth" : "vitalik94"
|
2022-07-25 13:22:09 +00:00
|
|
|
anchors.left: parent.left
|
2021-03-23 16:34:52 +00:00
|
|
|
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 {
|
2022-01-17 08:56:44 +00:00
|
|
|
target: root.ensUsernamesStore.ensUsernamesModule
|
|
|
|
onUsernameAvailabilityChecked: {
|
2021-03-23 16:34:52 +00:00
|
|
|
if(!validate(ensUsername.text)) return;
|
|
|
|
valid = false;
|
|
|
|
loading = false;
|
2022-01-17 08:56:44 +00:00
|
|
|
ensStatus = availabilityStatus;
|
|
|
|
switch(availabilityStatus){
|
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;
|
2022-01-17 08:56:44 +00:00
|
|
|
validationMessage = Constants.ensState[availabilityStatus]
|
2021-03-23 16:34:52 +00:00
|
|
|
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":
|
2022-01-17 08:56:44 +00:00
|
|
|
validationMessage = Constants.ensState[availabilityStatus]
|
2021-03-23 16:34:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-08-03 20:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-25 19:37:44 +00:00
|
|
|
StatusQControls.StatusRoundButton {
|
2021-03-23 16:34:52 +00:00
|
|
|
id: btnContinue
|
2021-10-25 19:37:44 +00:00
|
|
|
width: 40
|
|
|
|
height: 40
|
2021-03-23 16:34:52 +00:00
|
|
|
anchors.top: circleAt.bottom
|
|
|
|
anchors.topMargin: Style.current.bigPadding
|
|
|
|
anchors.right: parent.right
|
2021-10-25 19:37:44 +00:00
|
|
|
type: StatusQControls.StatusRoundButton.Type.Secondary
|
2022-08-09 13:52:17 +00:00
|
|
|
objectName: "ensNextButton"
|
2021-03-23 16:34:52 +00:00
|
|
|
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){
|
2022-01-17 08:56:44 +00:00
|
|
|
root.ensUsernamesStore.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){
|
2022-02-09 16:39:10 +00:00
|
|
|
Global.openPopup(transactionDialogComponent, {ensUsername: ensUsername.text})
|
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 {
|
2022-02-09 09:43:23 +00:00
|
|
|
text: !isStatus ?
|
2022-04-04 11:26:30 +00:00
|
|
|
qsTr("Custom domain")
|
2021-03-23 16:34:52 +00:00
|
|
|
:
|
|
|
|
".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 {
|
2022-02-09 09:43:23 +00:00
|
|
|
text: !isStatus ?
|
2022-04-04 11:26:30 +00:00
|
|
|
qsTr("I want a stateofus.eth domain")
|
2021-03-23 16:34:52 +00:00
|
|
|
:
|
2022-04-04 11:26:30 +00:00
|
|
|
qsTr("I own a name on another domain")
|
2021-03-23 16:34:52 +00:00
|
|
|
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
|
2021-11-01 09:42:00 +00:00
|
|
|
color: Theme.palette.directColor1
|
2021-03-23 16:34:52 +00:00
|
|
|
}
|
2020-08-03 20:46:37 +00:00
|
|
|
}
|
2020-09-14 12:12:47 +00:00
|
|
|
}
|
2021-10-06 09:16:39 +00:00
|
|
|
|