2020-08-06 07:25:53 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
import QtGraphicalEffects 1.13
|
|
|
|
import "../imports"
|
2020-09-09 11:04:01 +00:00
|
|
|
import "../shared"
|
2020-08-06 07:25:53 +00:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
property string validationError: "Error"
|
2020-09-14 12:12:47 +00:00
|
|
|
//% "ENS Username not found"
|
|
|
|
property string ensAsyncValidationError: qsTrId("ens-username-not-found")
|
2020-08-06 07:25:53 +00:00
|
|
|
property alias label: inpAddress.label
|
|
|
|
property string selectedAddress
|
2020-08-20 04:45:29 +00:00
|
|
|
property var isValid: false
|
2020-09-09 11:04:01 +00:00
|
|
|
property bool isPending: false
|
2020-08-06 07:25:53 +00:00
|
|
|
|
|
|
|
height: inpAddress.height
|
|
|
|
|
2020-08-20 04:45:29 +00:00
|
|
|
function resetInternal() {
|
|
|
|
selectedAddress = ""
|
|
|
|
inpAddress.resetInternal()
|
|
|
|
metrics.text = ""
|
|
|
|
isValid = false
|
|
|
|
}
|
|
|
|
|
2020-08-06 07:25:53 +00:00
|
|
|
function validate(inputValue) {
|
|
|
|
if (!inputValue) inputValue = selectedAddress
|
|
|
|
let isValid =
|
2020-09-09 11:04:01 +00:00
|
|
|
(inputValue && inputValue.startsWith("0x") && Utils.isValidAddress(inputValue) || Utils.isValidEns(inputValue))
|
2020-08-06 07:25:53 +00:00
|
|
|
inpAddress.validationError = isValid ? "" : validationError
|
2020-08-20 04:45:29 +00:00
|
|
|
root.isValid = isValid
|
2020-08-06 07:25:53 +00:00
|
|
|
return isValid
|
|
|
|
}
|
|
|
|
|
2020-09-09 11:04:01 +00:00
|
|
|
property var validateAsync: Backpressure.debounce(inpAddress, 300, function (inputValue) {
|
|
|
|
root.isPending = true
|
|
|
|
var name = inputValue.startsWith("@") ? inputValue.substring(1) : inputValue
|
|
|
|
walletModel.resolveENS(name)
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: walletModel
|
|
|
|
onEnsWasResolved: {
|
|
|
|
root.isPending = false
|
|
|
|
if (resolvedPubKey === ""){
|
|
|
|
inpAddress.validationError = root.ensAsyncValidationError
|
|
|
|
root.isValid = false
|
|
|
|
} else {
|
|
|
|
root.isValid = true
|
|
|
|
root.selectedAddress = resolvedPubKey
|
|
|
|
inpAddress.validationError = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-06 07:25:53 +00:00
|
|
|
Input {
|
|
|
|
id: inpAddress
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "eg. 0x1234 or ENS"
|
|
|
|
placeholderText: qsTrId("eg--0x1234-or-ens")
|
2020-08-06 07:25:53 +00:00
|
|
|
customHeight: 56
|
|
|
|
validationErrorAlignment: TextEdit.AlignRight
|
|
|
|
validationErrorTopMargin: 8
|
|
|
|
textField.onFocusChanged: {
|
|
|
|
let isValid = true
|
|
|
|
if (text !== "") {
|
|
|
|
isValid = root.validate(metrics.text)
|
|
|
|
}
|
|
|
|
if (!isValid) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if (textField.focus) {
|
|
|
|
text = metrics.text
|
2020-08-12 03:40:25 +00:00
|
|
|
} else if (Utils.isValidAddress(metrics.text)) {
|
2020-08-06 07:25:53 +00:00
|
|
|
text = metrics.elidedText
|
|
|
|
}
|
|
|
|
}
|
|
|
|
textField.rightPadding: 73
|
|
|
|
onTextEdited: {
|
|
|
|
metrics.text = text
|
|
|
|
const isValid = root.validate(inputValue)
|
|
|
|
if (isValid) {
|
2020-09-09 11:04:01 +00:00
|
|
|
if (Utils.isValidAddress(inputValue)) {
|
2020-08-06 07:25:53 +00:00
|
|
|
root.selectedAddress = inputValue
|
2020-09-09 11:04:01 +00:00
|
|
|
} else {
|
|
|
|
Qt.callLater(root.validateAsync, inputValue)
|
|
|
|
}
|
2020-08-06 07:25:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
TextMetrics {
|
|
|
|
id: metrics
|
|
|
|
elideWidth: 97
|
|
|
|
elide: Text.ElideMiddle
|
|
|
|
}
|
|
|
|
TertiaryButton {
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 8
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: 14
|
2020-08-26 15:52:26 +00:00
|
|
|
//% "Paste"
|
|
|
|
label: qsTrId("paste")
|
2020-08-06 07:25:53 +00:00
|
|
|
onClicked: {
|
|
|
|
if (inpAddress.textField.canPaste) {
|
|
|
|
inpAddress.textField.paste()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-09 11:04:01 +00:00
|
|
|
|
|
|
|
Loader {
|
|
|
|
sourceComponent: loadingIndicator
|
|
|
|
anchors.top: inpAddress.bottom
|
|
|
|
anchors.right: inpAddress.right
|
|
|
|
anchors.topMargin: Style.current.halfPadding
|
|
|
|
active: root.isPending
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: loadingIndicator
|
|
|
|
LoadingImage {
|
|
|
|
width: 12
|
|
|
|
height: 12
|
|
|
|
}
|
|
|
|
}
|
2020-08-06 07:25:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
|
|
|
D{i:0;autoSize:true;height:480;width:640}
|
|
|
|
}
|
|
|
|
##^##*/
|