2023-10-03 15:43:35 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtWebView 1.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Utils 0.1 as SQUtils
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
implicitWidth: Math.min(mainLayout.implicitWidth, 400)
|
|
|
|
implicitHeight: Math.min(mainLayout.implicitHeight, 700)
|
|
|
|
|
|
|
|
required property color backgroundColor
|
|
|
|
|
2023-11-06 19:05:18 +00:00
|
|
|
property bool sdkReady: state === d.sdkReadyState
|
|
|
|
|
2023-10-27 16:18:24 +00:00
|
|
|
// wallet_connect.Controller \see wallet_section/wallet_connect/controller.nim
|
|
|
|
required property var controller
|
2023-10-03 15:43:35 +00:00
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
id: mainLayout
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
text: qsTr("Debugging UX until design is ready")
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusInput {
|
|
|
|
id: pairLinkInput
|
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
placeholderText: "Insert pair link"
|
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
text: "Pair"
|
|
|
|
onClicked: {
|
|
|
|
statusText.text = "Pairing..."
|
2023-11-06 19:05:18 +00:00
|
|
|
d.sdkView.pair(pairLinkInput.text)
|
2023-10-03 15:43:35 +00:00
|
|
|
}
|
2023-11-06 19:05:18 +00:00
|
|
|
enabled: pairLinkInput.text.length > 0 && d.sdkView.sdkReady
|
2023-10-03 15:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
text: "Auth"
|
|
|
|
onClicked: {
|
|
|
|
statusText.text = "Authenticating..."
|
2023-11-06 19:05:18 +00:00
|
|
|
d.sdkView.auth()
|
2023-10-03 15:43:35 +00:00
|
|
|
}
|
2023-11-06 19:05:18 +00:00
|
|
|
enabled: false && pairLinkInput.text.length > 0 && d.sdkView.sdkReady
|
2023-10-03 15:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
text: "Accept"
|
|
|
|
onClicked: {
|
2023-11-06 19:05:18 +00:00
|
|
|
d.sdkView.approvePairSession(d.sessionProposal, d.supportedNamespaces)
|
2023-10-03 15:43:35 +00:00
|
|
|
}
|
2023-10-27 16:18:24 +00:00
|
|
|
visible: root.state === d.waitingPairState
|
2023-10-03 15:43:35 +00:00
|
|
|
}
|
|
|
|
StatusButton {
|
|
|
|
text: "Reject"
|
|
|
|
onClicked: {
|
2023-11-06 19:05:18 +00:00
|
|
|
d.sdkView.rejectPairSession(d.sessionProposal.id)
|
2023-10-03 15:43:35 +00:00
|
|
|
}
|
2023-10-27 16:18:24 +00:00
|
|
|
visible: root.state === d.waitingPairState
|
2023-10-03 15:43:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-27 16:18:24 +00:00
|
|
|
ColumnLayout {
|
2023-10-03 15:43:35 +00:00
|
|
|
StatusBaseText {
|
|
|
|
id: statusText
|
|
|
|
text: "-"
|
|
|
|
}
|
2023-11-06 19:05:18 +00:00
|
|
|
StatusBaseText {
|
|
|
|
text: "Pairings"
|
|
|
|
visible: d.sdkView.pairingsModel.count > 0
|
|
|
|
}
|
|
|
|
StatusListView {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: contentHeight
|
|
|
|
Layout.maximumHeight: 200
|
|
|
|
|
|
|
|
model: d.sdkView.pairingsModel
|
|
|
|
|
|
|
|
delegate: StatusBaseText {
|
|
|
|
text: `${SQUtils.Utils.elideText(topic, 6, 6)} - ${new Date(expiry * 1000).toLocaleString()}`
|
|
|
|
color: active ? "green" : "orange"
|
|
|
|
}
|
|
|
|
}
|
2023-10-27 16:18:24 +00:00
|
|
|
Flickable {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: 200
|
|
|
|
Layout.maximumHeight: 400
|
|
|
|
|
|
|
|
contentWidth: detailsText.width
|
|
|
|
contentHeight: detailsText.height
|
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
id: detailsText
|
|
|
|
text: ""
|
|
|
|
visible: text.length > 0
|
|
|
|
|
|
|
|
color: "#FF00FF"
|
|
|
|
}
|
|
|
|
|
|
|
|
ScrollBar.vertical: ScrollBar {}
|
|
|
|
|
|
|
|
clip: true
|
|
|
|
}
|
2023-11-06 19:05:18 +00:00
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
StatusButton {
|
|
|
|
text: "Accept"
|
|
|
|
onClicked: {
|
|
|
|
root.controller.sessionRequest(JSON.stringify(d.sessionRequest), passwordInput.text)
|
|
|
|
}
|
|
|
|
visible: root.state === d.waitingUserResponseToSessionRequest
|
|
|
|
}
|
|
|
|
StatusButton {
|
|
|
|
text: "Reject"
|
|
|
|
onClicked: {
|
|
|
|
d.sdkView.rejectSessionRequest(d.sessionRequest.topic, d.sessionRequest.id, false)
|
|
|
|
}
|
|
|
|
visible: root.state === d.waitingUserResponseToSessionRequest
|
|
|
|
}
|
|
|
|
StatusInput {
|
|
|
|
id: passwordInput
|
|
|
|
|
|
|
|
text: "1234567890"
|
|
|
|
placeholderText: "Insert account password"
|
|
|
|
visible: root.state === d.waitingUserResponseToSessionRequest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ColumnLayout { /* spacer */ }
|
2023-10-03 15:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: DEBUG JS Loading in DMG
|
|
|
|
// RowLayout {
|
|
|
|
// TextField {
|
|
|
|
// id: urlInput
|
|
|
|
|
|
|
|
// Layout.fillWidth: true
|
|
|
|
|
|
|
|
// placeholderText: "Insert URL here"
|
|
|
|
// }
|
|
|
|
// Button {
|
|
|
|
// text: "Set URL"
|
|
|
|
// onClicked: {
|
2023-11-06 19:05:18 +00:00
|
|
|
// d.sdkView.url = urlInput.text
|
2023-10-03 15:43:35 +00:00
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Button {
|
|
|
|
// text: "Set HTML"
|
|
|
|
// onClicked: {
|
2023-11-06 19:05:18 +00:00
|
|
|
// d.sdkView.loadHtml(htmlContent.text, "http://status.im")
|
2023-10-03 15:43:35 +00:00
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// StatusInput {
|
|
|
|
// id: htmlContent
|
|
|
|
|
|
|
|
// Layout.fillWidth: true
|
|
|
|
// Layout.minimumHeight: 200
|
|
|
|
// Layout.maximumHeight: 300
|
|
|
|
|
|
|
|
// text: `<!DOCTYPE html><html><head><title>TODO: Test</title>\n<!--<script src="http://127.0.0.1:8080/bundle.js" defer></script>-->\n<script type='text/javascript'>\n console.log("@dd loaded dummy script!")\n</script>\n</head><body style='background-color: ${root.backgroundColor.toString()};'></body></html>`
|
|
|
|
|
|
|
|
// multiline: true
|
|
|
|
// minimumHeight: Layout.minimumHeight
|
|
|
|
// maximumHeight: Layout.maximumHeight
|
|
|
|
|
|
|
|
// }
|
|
|
|
// END DEBUGGING
|
|
|
|
|
|
|
|
// Separator
|
|
|
|
ColumnLayout {}
|
|
|
|
|
2023-11-06 19:05:18 +00:00
|
|
|
// TODO: use it in tests to load a dummy SDK
|
|
|
|
Loader {
|
|
|
|
id: sdkViewLoader
|
2023-10-03 15:43:35 +00:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
// Note that a too smaller height might cause the webview to generate rendering errors
|
|
|
|
Layout.preferredHeight: 10
|
|
|
|
|
2023-11-06 19:05:18 +00:00
|
|
|
sourceComponent: SdkViewComponent {}
|
|
|
|
}
|
|
|
|
}
|
2023-10-27 16:18:24 +00:00
|
|
|
|
2023-11-06 19:05:18 +00:00
|
|
|
component SdkViewComponent: WalletConnectSDK {
|
|
|
|
projectId: controller.projectId
|
|
|
|
|
|
|
|
onSdkInit: function(success, info) {
|
|
|
|
d.setDetailsText(info)
|
|
|
|
if (success) {
|
|
|
|
d.setStatusText("Ready to pair or auth")
|
|
|
|
root.state = d.sdkReadyState
|
|
|
|
} else {
|
|
|
|
d.setStatusText("SDK Error", "red")
|
|
|
|
root.state = ""
|
2023-10-27 16:18:24 +00:00
|
|
|
}
|
2023-11-06 19:05:18 +00:00
|
|
|
}
|
2023-10-27 16:18:24 +00:00
|
|
|
|
2023-11-06 19:05:18 +00:00
|
|
|
onPairSessionProposal: function(success, sessionProposal) {
|
|
|
|
d.setDetailsText(sessionProposal)
|
|
|
|
if (success) {
|
|
|
|
d.setStatusText("Pair ID: " + sessionProposal.id + "; Topic: " + sessionProposal.params.pairingTopic)
|
|
|
|
root.controller.pairSessionProposal(JSON.stringify(sessionProposal))
|
|
|
|
// Expecting signal onProposeUserPair from controller
|
|
|
|
} else {
|
|
|
|
d.setStatusText("Pairing error", "red")
|
2023-10-27 16:18:24 +00:00
|
|
|
}
|
2023-11-06 19:05:18 +00:00
|
|
|
}
|
2023-10-27 16:18:24 +00:00
|
|
|
|
2023-11-06 19:05:18 +00:00
|
|
|
onPairAcceptedResult: function(success, result) {
|
|
|
|
d.setDetailsText(result)
|
|
|
|
if (success) {
|
|
|
|
d.setStatusText("Pairing OK")
|
|
|
|
root.state = d.pairedState
|
|
|
|
} else {
|
|
|
|
d.setStatusText("Pairing error", "red")
|
2023-10-27 16:18:24 +00:00
|
|
|
root.state = d.sdkReadyState
|
|
|
|
}
|
2023-11-06 19:05:18 +00:00
|
|
|
}
|
2023-10-27 16:18:24 +00:00
|
|
|
|
2023-11-06 19:05:18 +00:00
|
|
|
onPairRejectedResult: function(success, result) {
|
|
|
|
d.setDetailsText(result)
|
|
|
|
root.state = d.sdkReadyState
|
|
|
|
if (success) {
|
|
|
|
d.setStatusText("Pairing rejected")
|
|
|
|
} else {
|
|
|
|
d.setStatusText("Rejecting pairing error", "red")
|
2023-10-03 15:43:35 +00:00
|
|
|
}
|
2023-11-06 19:05:18 +00:00
|
|
|
}
|
2023-10-27 16:18:24 +00:00
|
|
|
|
2023-11-06 19:05:18 +00:00
|
|
|
onSessionRequestUserAnswerResult: function(accept, error) {
|
|
|
|
if (error) {
|
|
|
|
d.setStatusText(`Session Request ${accept ? "Accept" : "Reject"} error`, "red")
|
|
|
|
return
|
2023-10-27 16:18:24 +00:00
|
|
|
}
|
2023-11-06 19:05:18 +00:00
|
|
|
root.state = d.pairedState
|
|
|
|
if (accept) {
|
|
|
|
d.setStatusText(`Session Request accepted`)
|
|
|
|
} else {
|
|
|
|
d.setStatusText(`Session Request rejected`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onSessionRequestEvent: function(sessionRequest) {
|
|
|
|
d.setStatusText("Approve session request")
|
|
|
|
d.setDetailsText(JSON.stringify(sessionRequest, null, 2))
|
|
|
|
d.sessionRequest = sessionRequest
|
|
|
|
root.state = d.waitingUserResponseToSessionRequest
|
2023-10-27 16:18:24 +00:00
|
|
|
}
|
2023-11-06 19:05:18 +00:00
|
|
|
|
2023-11-16 15:15:37 +00:00
|
|
|
onPairSessionProposalExpired: {
|
2023-11-06 19:05:18 +00:00
|
|
|
d.setStatusText(`Timeout waiting for response. Reusing URI?`, "red")
|
|
|
|
}
|
|
|
|
|
|
|
|
onStatusChanged: function(message) {
|
|
|
|
statusText.text = message
|
|
|
|
}
|
2023-10-27 16:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
property var sessionProposal: null
|
|
|
|
property var supportedNamespaces: null
|
|
|
|
|
2023-11-06 19:05:18 +00:00
|
|
|
property var sessionRequest: null
|
|
|
|
property var signedData: null
|
|
|
|
|
2023-10-27 16:18:24 +00:00
|
|
|
readonly property string sdkReadyState: "sdk_ready"
|
|
|
|
readonly property string waitingPairState: "waiting_pairing"
|
2023-11-06 19:05:18 +00:00
|
|
|
readonly property string waitingUserResponseToSessionRequest: "waiting_user_response_to_session_request"
|
2023-10-27 16:18:24 +00:00
|
|
|
readonly property string pairedState: "paired"
|
|
|
|
|
2023-11-06 19:05:18 +00:00
|
|
|
property var sdkView: sdkViewLoader.item
|
|
|
|
|
2023-10-27 16:18:24 +00:00
|
|
|
function setStatusText(message, textColor) {
|
|
|
|
statusText.text = message
|
|
|
|
if (textColor === undefined) {
|
|
|
|
textColor = "green"
|
|
|
|
}
|
|
|
|
statusText.color = textColor
|
|
|
|
}
|
|
|
|
function setDetailsText(message) {
|
|
|
|
if (message === undefined) {
|
|
|
|
message = "undefined"
|
|
|
|
} else if (typeof message !== "string") {
|
|
|
|
message = JSON.stringify(message, null, 2)
|
|
|
|
}
|
|
|
|
detailsText.text = message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: root.controller
|
2023-11-06 19:05:18 +00:00
|
|
|
|
2023-10-27 16:18:24 +00:00
|
|
|
function onProposeUserPair(sessionProposalJson, supportedNamespacesJson) {
|
|
|
|
d.setStatusText("Waiting user accept")
|
|
|
|
|
|
|
|
d.sessionProposal = JSON.parse(sessionProposalJson)
|
|
|
|
d.supportedNamespaces = JSON.parse(supportedNamespacesJson)
|
|
|
|
|
|
|
|
d.setDetailsText(JSON.stringify(d.supportedNamespaces, null, 2))
|
|
|
|
|
|
|
|
root.state = d.waitingPairState
|
2023-10-03 15:43:35 +00:00
|
|
|
}
|
2023-11-06 19:05:18 +00:00
|
|
|
|
|
|
|
function onRespondSessionRequest(sessionRequestJson, signedJson, error) {
|
|
|
|
console.log("@dd respondSessionRequest", sessionRequestJson, signedJson, error)
|
|
|
|
if (error) {
|
|
|
|
d.setStatusText("Session Request error", "red")
|
|
|
|
d.sdkView.rejectSessionRequest(d.sessionRequest.topic, d.sessionRequest.id, true)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
d.sessionRequest = JSON.parse(sessionRequestJson)
|
|
|
|
d.signedData = JSON.parse(signedJson)
|
|
|
|
|
|
|
|
d.sdkView.acceptSessionRequest(d.sessionRequest.topic, d.sessionRequest.id, d.signedData)
|
|
|
|
|
|
|
|
d.setStatusText("Session Request accepted")
|
|
|
|
d.setDetailsText(d.signedData)
|
|
|
|
}
|
|
|
|
}
|
2023-10-03 15:43:35 +00:00
|
|
|
}
|