2023-11-15 21:26:12 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Popups 0.1
|
|
|
|
|
|
|
|
Popup {
|
|
|
|
id: root
|
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
implicitWidth: 500
|
|
|
|
implicitHeight: Math.min(mainLayout.implicitHeight * 2, 700)
|
2023-11-15 21:26:12 +00:00
|
|
|
|
|
|
|
required property WalletConnectSDK sdk
|
|
|
|
|
|
|
|
parent: Overlay.overlay
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
property bool sdkReady: d.state === d.sdkReadyState
|
|
|
|
|
|
|
|
// wallet_connect.Controller \see wallet_section/wallet_connect/controller.nim
|
|
|
|
required property var controller
|
|
|
|
|
|
|
|
function openWithSessionRequestEvent(sessionRequest) {
|
|
|
|
d.setStatusText("Approve session request")
|
|
|
|
d.setDetailsText(JSON.stringify(sessionRequest, null, 2))
|
|
|
|
d.sessionRequest = sessionRequest
|
|
|
|
d.state = d.waitingUserResponseToSessionRequest
|
|
|
|
root.open()
|
|
|
|
}
|
|
|
|
|
|
|
|
Flickable {
|
|
|
|
id: flickable
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
contentWidth: mainLayout.implicitWidth
|
|
|
|
contentHeight: mainLayout.implicitHeight
|
|
|
|
|
|
|
|
interactive: contentHeight > height || contentWidth > width
|
2023-11-15 21:26:12 +00:00
|
|
|
|
|
|
|
ColumnLayout {
|
2023-11-24 12:51:36 +00:00
|
|
|
id: mainLayout
|
2023-11-15 21:26:12 +00:00
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
StatusBaseText {
|
|
|
|
text: qsTr("Debugging UX until design is ready")
|
|
|
|
}
|
2023-11-15 21:26:12 +00:00
|
|
|
|
2023-12-06 14:01:25 +00:00
|
|
|
StatusSwitch {
|
|
|
|
id: testAuthentication
|
|
|
|
checkable: true
|
|
|
|
text: qsTr("Test Authentication")
|
|
|
|
}
|
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
StatusInput {
|
|
|
|
id: pairLinkInput
|
2023-11-15 21:26:12 +00:00
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
Layout.fillWidth: true
|
2023-11-15 21:26:12 +00:00
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
placeholderText: "Insert pair link"
|
|
|
|
}
|
2023-11-15 21:26:12 +00:00
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
RowLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
StatusButton {
|
2023-12-06 14:01:25 +00:00
|
|
|
text: testAuthentication.checked? "Authentication" : "Pair"
|
2023-11-15 21:26:12 +00:00
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
onClicked: {
|
2023-12-06 14:01:25 +00:00
|
|
|
if (testAuthentication.checked) {
|
|
|
|
d.setStatusText("")
|
|
|
|
d.setDetailsText("")
|
|
|
|
d.state = ""
|
|
|
|
accountsModel.clear()
|
|
|
|
|
|
|
|
statusText.text = "Authenticating..."
|
|
|
|
root.sdk.auth(pairLinkInput.text)
|
|
|
|
return
|
|
|
|
}
|
2023-11-15 21:26:12 +00:00
|
|
|
|
2023-12-06 14:01:25 +00:00
|
|
|
statusText.text = "Pairing..."
|
|
|
|
root.sdk.pair(pairLinkInput.text)
|
2023-11-24 12:51:36 +00:00
|
|
|
}
|
2023-12-06 14:01:25 +00:00
|
|
|
enabled: pairLinkInput.text.length > 0 && root.sdk.sdkReady
|
2023-11-15 21:26:12 +00:00
|
|
|
}
|
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
StatusButton {
|
|
|
|
text: "Accept"
|
|
|
|
onClicked: {
|
2023-12-06 14:01:25 +00:00
|
|
|
root.sdk.approvePairSession(d.observedData, d.supportedNamespaces)
|
2023-11-24 12:51:36 +00:00
|
|
|
}
|
|
|
|
visible: d.state === d.waitingPairState
|
2023-11-15 21:26:12 +00:00
|
|
|
}
|
2023-11-24 12:51:36 +00:00
|
|
|
StatusButton {
|
|
|
|
text: "Reject"
|
|
|
|
onClicked: {
|
2023-12-06 14:01:25 +00:00
|
|
|
root.sdk.rejectPairSession(d.observedData.id)
|
2023-11-24 12:51:36 +00:00
|
|
|
}
|
|
|
|
visible: d.state === d.waitingPairState
|
2023-11-15 21:26:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
ColumnLayout {
|
|
|
|
StatusBaseText {
|
|
|
|
id: statusText
|
|
|
|
text: "-"
|
|
|
|
}
|
|
|
|
StatusBaseText {
|
|
|
|
text: "Pairings"
|
2023-12-06 14:01:25 +00:00
|
|
|
visible: root.sdk.pairingsModel.count > 0
|
2023-11-24 12:51:36 +00:00
|
|
|
}
|
2023-11-15 21:26:12 +00:00
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
Pairings {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.minimumWidth: count > 0 ? 400 : 0
|
|
|
|
Layout.preferredHeight: contentHeight
|
|
|
|
Layout.maximumHeight: 300
|
2023-11-15 21:26:12 +00:00
|
|
|
|
2023-12-06 14:01:25 +00:00
|
|
|
model: root.sdk.pairingsModel
|
2023-11-15 21:26:12 +00:00
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
onDisconnect: function (topic) {
|
2023-12-06 14:01:25 +00:00
|
|
|
root.sdk.disconnectPairing(topic)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ButtonGroup {
|
|
|
|
id: selAccBtnGroup
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectAccount {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.minimumWidth: count > 0 ? 400 : 0
|
|
|
|
Layout.preferredHeight: contentHeight
|
|
|
|
Layout.maximumHeight: 300
|
|
|
|
|
|
|
|
model: accountsModel
|
|
|
|
|
|
|
|
buttonGroup: selAccBtnGroup
|
|
|
|
|
|
|
|
onAccountSelected: {
|
|
|
|
root.sdk.formatAuthMessage(d.observedData.params.cacaoPayload, address)
|
2023-11-24 12:51:36 +00:00
|
|
|
}
|
|
|
|
}
|
2023-11-15 21:26:12 +00:00
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
id: detailsText
|
|
|
|
text: ""
|
|
|
|
visible: text.length > 0
|
|
|
|
|
|
|
|
color: "#FF00FF"
|
|
|
|
}
|
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
RowLayout {
|
|
|
|
StatusButton {
|
|
|
|
text: "Accept"
|
|
|
|
onClicked: {
|
2023-12-06 14:01:25 +00:00
|
|
|
if (testAuthentication.checked) {
|
|
|
|
root.controller.authRequest(d.selectedAddress, d.authMessage, passwordInput.text)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
root.controller.sessionRequest(JSON.stringify(d.sessionRequest), passwordInput.text)
|
|
|
|
}
|
2023-12-06 14:01:25 +00:00
|
|
|
visible: d.state === d.waitingUserResponseToSessionRequest ||
|
|
|
|
d.state === d.waitingUserResponseToAuthRequest
|
2023-11-15 21:26:12 +00:00
|
|
|
}
|
2023-11-24 12:51:36 +00:00
|
|
|
StatusButton {
|
|
|
|
text: "Reject"
|
|
|
|
onClicked: {
|
2023-12-06 14:01:25 +00:00
|
|
|
if (testAuthentication.checked) {
|
|
|
|
root.sdk.authReject(d.observedData.id, d.selectedAddress)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
root.sdk.rejectSessionRequest(d.sessionRequest.topic, d.sessionRequest.id, false)
|
2023-11-24 12:51:36 +00:00
|
|
|
}
|
2023-12-06 14:01:25 +00:00
|
|
|
visible: d.state === d.waitingUserResponseToSessionRequest ||
|
|
|
|
d.state === d.waitingUserResponseToAuthRequest
|
2023-11-15 21:26:12 +00:00
|
|
|
}
|
2023-11-24 12:51:36 +00:00
|
|
|
StatusInput {
|
|
|
|
id: passwordInput
|
2023-11-15 21:26:12 +00:00
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
text: "1234567890"
|
|
|
|
placeholderText: "Insert account password"
|
2023-12-06 14:01:25 +00:00
|
|
|
visible: d.state === d.waitingUserResponseToSessionRequest ||
|
|
|
|
d.state === d.waitingUserResponseToAuthRequest
|
2023-11-24 12:51:36 +00:00
|
|
|
}
|
2023-11-15 21:26:12 +00:00
|
|
|
}
|
2023-11-24 12:51:36 +00:00
|
|
|
|
|
|
|
ColumnLayout { /* spacer */ }
|
2023-11-15 21:26:12 +00:00
|
|
|
}
|
|
|
|
|
2023-11-24 12:51:36 +00:00
|
|
|
// Separator
|
|
|
|
ColumnLayout {}
|
2023-11-15 21:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScrollBar.vertical: ScrollBar {}
|
|
|
|
|
|
|
|
clip: true
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: root.sdk
|
|
|
|
|
|
|
|
function onSdkInit(success, info) {
|
|
|
|
d.setDetailsText(info)
|
|
|
|
if (success) {
|
|
|
|
d.setStatusText("Ready to pair or auth")
|
|
|
|
d.state = d.sdkReadyState
|
|
|
|
} else {
|
|
|
|
d.setStatusText("SDK Error", "red")
|
|
|
|
d.state = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 14:01:25 +00:00
|
|
|
function onPairSessionProposal(sessionProposal) {
|
2023-11-15 21:26:12 +00:00
|
|
|
d.setDetailsText(sessionProposal)
|
2023-12-06 14:01:25 +00:00
|
|
|
d.setStatusText("Pair ID: " + sessionProposal.id + "; Topic: " + sessionProposal.params.pairingTopic)
|
|
|
|
root.controller.pairSessionProposal(JSON.stringify(sessionProposal))
|
2023-11-15 21:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function onPairAcceptedResult(sessionProposal, success, result) {
|
|
|
|
d.setDetailsText(result)
|
|
|
|
if (success) {
|
|
|
|
d.setStatusText("Pairing OK")
|
|
|
|
d.state = d.pairedState
|
|
|
|
root.controller.recordSuccessfulPairing(JSON.stringify(sessionProposal))
|
|
|
|
} else {
|
|
|
|
d.setStatusText("Pairing error", "red")
|
|
|
|
d.state = d.sdkReadyState
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onPairRejectedResult(success, result) {
|
|
|
|
d.setDetailsText(result)
|
|
|
|
d.state = d.sdkReadyState
|
|
|
|
if (success) {
|
|
|
|
d.setStatusText("Pairing rejected")
|
|
|
|
} else {
|
|
|
|
d.setStatusText("Rejecting pairing error", "red")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onSessionRequestUserAnswerResult(accept, error) {
|
|
|
|
if (error) {
|
|
|
|
d.setStatusText(`Session Request ${accept ? "Accept" : "Reject"} error`, "red")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
d.state = d.pairedState
|
|
|
|
if (accept) {
|
|
|
|
d.setStatusText(`Session Request accepted`)
|
|
|
|
} else {
|
|
|
|
d.setStatusText(`Session Request rejected`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onPairSessionProposalExpired() {
|
|
|
|
d.setStatusText(`Timeout waiting for response. Reusing URI?`, "red")
|
|
|
|
}
|
|
|
|
|
|
|
|
function onStatusChanged(message) {
|
|
|
|
statusText.text = message
|
|
|
|
}
|
2023-12-06 14:01:25 +00:00
|
|
|
|
|
|
|
function onAuthRequest(request) {
|
|
|
|
d.observedData = request
|
|
|
|
d.setStatusText("Select the address you want to sign in with:")
|
|
|
|
|
|
|
|
accountsModel.clear()
|
|
|
|
|
|
|
|
let walletAccounts = root.controller.getWalletAccounts()
|
|
|
|
try {
|
|
|
|
let walletAccountsJsonArr = JSON.parse(walletAccounts)
|
|
|
|
|
|
|
|
for (let i = 0; i < walletAccountsJsonArr.length; i++) {
|
|
|
|
let obj = {
|
|
|
|
preferredSharingChainIds: ""
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var key in walletAccountsJsonArr[i]) {
|
|
|
|
obj[key] = walletAccountsJsonArr[i][key]
|
|
|
|
}
|
|
|
|
|
|
|
|
accountsModel.append(obj)
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
console.error("error parsing wallet accounts, error: ", e)
|
|
|
|
d.setStatusText("error parsing walelt accounts", "red")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAuthSignMessage(message, address) {
|
|
|
|
let details = ""
|
|
|
|
if (!!d.observedData.verifyContext.verified.isScam) {
|
|
|
|
details = "This website you`re trying to connect is flagged as malicious by multiple security providers.\nApproving may lead to loss of funds."
|
|
|
|
} else {
|
|
|
|
if (d.observedData.verifyContext.verified.validation === "UNKNOWN")
|
|
|
|
details = "Website is Unverified"
|
|
|
|
else if (d.observedData.verifyContext.verified.validation === "INVALID")
|
|
|
|
details = "Website is Mismatched"
|
|
|
|
else
|
|
|
|
details = "Website is Valid"
|
|
|
|
}
|
|
|
|
|
|
|
|
d.selectedAddress = address
|
|
|
|
d.authMessage = message
|
|
|
|
d.setDetailsText(`${details}\n\n${message}`)
|
|
|
|
d.state = d.waitingUserResponseToAuthRequest
|
|
|
|
}
|
|
|
|
|
|
|
|
function onAuthRequestUserAnswerResult(accept, error) {
|
|
|
|
if (error) {
|
|
|
|
d.setStatusText(`Auth Request ${accept ? "Accept" : "Reject"} error`, "red")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (accept) {
|
|
|
|
d.setStatusText(`Auth Request completed`)
|
|
|
|
} else {
|
|
|
|
d.setStatusText(`Auth Request aborted`)
|
|
|
|
}
|
|
|
|
}
|
2023-11-15 21:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
2023-12-06 14:01:25 +00:00
|
|
|
property string selectedAddress: ""
|
|
|
|
property var observedData: null
|
|
|
|
property var authMessage: null
|
2023-11-15 21:26:12 +00:00
|
|
|
property var supportedNamespaces: null
|
|
|
|
|
|
|
|
property var sessionRequest: null
|
|
|
|
property var signedData: null
|
|
|
|
|
|
|
|
property string state: ""
|
|
|
|
readonly property string sdkReadyState: "sdk_ready"
|
|
|
|
readonly property string waitingPairState: "waiting_pairing"
|
|
|
|
readonly property string waitingUserResponseToSessionRequest: "waiting_user_response_to_session_request"
|
2023-12-06 14:01:25 +00:00
|
|
|
readonly property string waitingUserResponseToAuthRequest: "waiting_user_response_to_auth_request"
|
2023-11-15 21:26:12 +00:00
|
|
|
readonly property string pairedState: "paired"
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 14:01:25 +00:00
|
|
|
ListModel {
|
|
|
|
id: accountsModel
|
|
|
|
}
|
|
|
|
|
2023-11-15 21:26:12 +00:00
|
|
|
Connections {
|
|
|
|
target: root.controller
|
|
|
|
|
|
|
|
function onProposeUserPair(sessionProposalJson, supportedNamespacesJson) {
|
|
|
|
d.setStatusText("Waiting user accept")
|
|
|
|
|
2023-12-06 14:01:25 +00:00
|
|
|
d.observedData = JSON.parse(sessionProposalJson)
|
2023-11-15 21:26:12 +00:00
|
|
|
d.supportedNamespaces = JSON.parse(supportedNamespacesJson)
|
|
|
|
|
|
|
|
d.setDetailsText(JSON.stringify(d.supportedNamespaces, null, 2))
|
|
|
|
|
|
|
|
d.state = d.waitingPairState
|
|
|
|
}
|
|
|
|
|
|
|
|
function onRespondSessionRequest(sessionRequestJson, signedData, error) {
|
|
|
|
console.log("WC respondSessionRequest", sessionRequestJson, " signedData", signedData, " error: ", error)
|
|
|
|
if (error) {
|
|
|
|
d.setStatusText("Session Request error", "red")
|
2023-12-06 14:01:25 +00:00
|
|
|
root.sdk.rejectSessionRequest(d.sessionRequest.topic, d.sessionRequest.id, true)
|
2023-11-15 21:26:12 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
d.sessionRequest = JSON.parse(sessionRequestJson)
|
|
|
|
d.signedData = signedData
|
|
|
|
|
2023-12-06 14:01:25 +00:00
|
|
|
root.sdk.acceptSessionRequest(d.sessionRequest.topic, d.sessionRequest.id, d.signedData)
|
2023-11-15 21:26:12 +00:00
|
|
|
|
|
|
|
d.state = d.pairedState
|
|
|
|
|
|
|
|
d.setStatusText("Session Request accepted")
|
|
|
|
d.setDetailsText(d.signedData)
|
|
|
|
}
|
2023-12-06 14:01:25 +00:00
|
|
|
|
|
|
|
function onRespondAuthRequest(signature, error) {
|
|
|
|
console.log("WC signature", signature, " error: ", error)
|
|
|
|
if (error) {
|
|
|
|
d.setStatusText("Session Request error", "red")
|
|
|
|
root.sdk.authReject(d.observedData.id, d.selectedAddress)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
root.sdk.authApprove(d.observedData, d.selectedAddress, signature)
|
|
|
|
}
|
2023-11-15 21:26:12 +00:00
|
|
|
}
|
|
|
|
}
|