2023-03-22 15:48:44 +00:00
|
|
|
import QtQuick 2.14
|
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import "../stores"
|
2023-08-04 12:41:57 +00:00
|
|
|
import "../../common"
|
2023-03-22 15:48:44 +00:00
|
|
|
|
|
|
|
Column {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property AddAccountStore store
|
|
|
|
|
|
|
|
function reset() {
|
|
|
|
addressInput.reset()
|
|
|
|
}
|
|
|
|
|
2024-07-30 13:01:16 +00:00
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
property bool incorrectChecksum: false
|
2024-08-20 12:29:56 +00:00
|
|
|
property string uuid
|
|
|
|
property string resolvedEnsAddress
|
2024-07-30 13:01:16 +00:00
|
|
|
|
|
|
|
function checkIfAddressChecksumIsValid(address) {
|
|
|
|
d.incorrectChecksum = !root.store.isChecksumValidForAddress(address)
|
|
|
|
}
|
2024-08-20 12:29:56 +00:00
|
|
|
|
|
|
|
function validateEnsAsync(value) {
|
|
|
|
var name = value.startsWith("@") ? value.substring(1) : value
|
|
|
|
d.uuid = Utils.uuid()
|
|
|
|
root.store.validateEnsAsync(name, d.uuid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: root.store
|
|
|
|
function onResolvedENS(resolvedPubKey: string, resolvedAddress: string, uuid: string) {
|
|
|
|
if (uuid !== d.uuid) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
d.resolvedEnsAddress = resolvedAddress
|
|
|
|
addressInput.validate()
|
|
|
|
root.store.changeWatchOnlyAccountAddressPostponed(resolvedAddress)
|
|
|
|
}
|
2024-07-30 13:01:16 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 15:48:44 +00:00
|
|
|
StatusInput {
|
|
|
|
id: addressInput
|
2023-04-13 10:27:56 +00:00
|
|
|
objectName: "AddAccountPopup-WatchOnlyAddress"
|
2023-03-22 15:48:44 +00:00
|
|
|
width: parent.width
|
|
|
|
maximumHeight: Constants.addAccountPopup.itemHeight
|
|
|
|
minimumHeight: Constants.addAccountPopup.itemHeight
|
|
|
|
label: qsTr("Ethereum address or ENS name")
|
2023-05-02 14:19:55 +00:00
|
|
|
placeholderText: qsTr("Type or paste ETH address")
|
2023-03-22 15:48:44 +00:00
|
|
|
input.multiline: true
|
2024-07-30 13:01:16 +00:00
|
|
|
input.rightComponent: Row {
|
|
|
|
spacing: 8
|
|
|
|
|
|
|
|
StatusIconWithTooltip {
|
|
|
|
visible: d.incorrectChecksum
|
|
|
|
icon: "warning"
|
|
|
|
width: 20
|
|
|
|
height: 20
|
|
|
|
color: Theme.palette.warningColor1
|
|
|
|
tooltipText: qsTr("Checksum of the entered address is incorrect")
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
borderColor: Theme.palette.primaryColor1
|
|
|
|
size: StatusBaseButton.Size.Tiny
|
|
|
|
text: qsTr("Paste")
|
|
|
|
onClicked: {
|
|
|
|
addressInput.text = ""
|
|
|
|
addressInput.input.edit.paste()
|
|
|
|
}
|
2023-03-22 15:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
validators: [
|
2024-08-20 12:29:56 +00:00
|
|
|
StatusValidator {
|
|
|
|
name: "address-or-ens"
|
|
|
|
validate: (value) => {
|
|
|
|
return Utils.isValidAddress(value) ||
|
|
|
|
Utils.isValidEns(value) &&
|
|
|
|
!!d.resolvedEnsAddress
|
|
|
|
}
|
2023-03-22 15:48:44 +00:00
|
|
|
errorMessage: qsTr("Please enter a valid Ethereum address or ENS name")
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
onTextChanged: {
|
2024-07-30 13:01:16 +00:00
|
|
|
d.incorrectChecksum = false
|
2024-08-20 12:29:56 +00:00
|
|
|
const trimmedText = text.trim()
|
|
|
|
if (Utils.isValidEns(trimmedText)) {
|
|
|
|
d.resolvedEnsAddress = ""
|
|
|
|
d.validateEnsAsync(trimmedText)
|
|
|
|
return
|
|
|
|
} else if (Utils.isValidAddress(trimmedText)) {
|
2024-07-30 13:01:16 +00:00
|
|
|
root.store.changeWatchOnlyAccountAddressPostponed(trimmedText)
|
|
|
|
d.checkIfAddressChecksumIsValid(trimmedText)
|
2023-03-22 15:48:44 +00:00
|
|
|
return
|
|
|
|
}
|
2024-08-20 12:29:56 +00:00
|
|
|
|
2023-03-22 15:48:44 +00:00
|
|
|
root.store.cleanWatchOnlyAccountAddress()
|
|
|
|
}
|
|
|
|
|
|
|
|
onKeyPressed: {
|
2023-08-04 12:41:57 +00:00
|
|
|
root.store.submitPopup(event)
|
2023-03-22 15:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddressDetails {
|
|
|
|
width: parent.width
|
|
|
|
addressDetailsItem: root.store.watchOnlyAccAddress
|
|
|
|
defaultMessage: qsTr("You will need to import your seed phrase or use your Keycard to transact with this account")
|
|
|
|
defaultMessageCondition: addressInput.text === "" || !addressInput.valid
|
|
|
|
}
|
|
|
|
}
|