fix(dapps) Wallet Connect url validation

The static url validation state `Pairing.errors.ok` was directly
responsible for the validation action in UX. With current change
the validation is now based on the pairing response. When the
pairing response is received the UX is validated and after half second
UX is moved to the approval process (`ConnectedDAppModal`)

Closes: #15591
This commit is contained in:
Stefan 2024-07-24 18:37:08 +03:00 committed by Stefan Dunca
parent 597d4bac9f
commit f6ae5ceabe
4 changed files with 28 additions and 11 deletions

View File

@ -271,10 +271,12 @@ DappsComboBox {
connectDappLoader.sessionTopic = null
if (pairWCLoader.item) {
pairWCLoader.item.close()
// Allow user to get the uri valid confirmation
pairWCLoader.item.pairingValidated(Pairing.errors.dappReadyForApproval)
connectDappTimer.start()
} else {
connectDappLoader.active = true
}
connectDappLoader.active = true
}
function onApproveSessionResult(session, err) {
@ -296,4 +298,18 @@ DappsComboBox {
sessionRequestLoader.active = true
}
}
// Used between transitioning from PairWCModal to ConnectDAppModal
Timer {
id: connectDappTimer
interval: 500
running: false
repeat: false
onTriggered: {
pairWCLoader.item.close()
connectDappLoader.active = true
}
}
}

View File

@ -63,7 +63,7 @@ QObject {
let info = Helpers.extractInfoFromPairUri(uri)
wcSDK.getActiveSessions((sessions) => {
// Check if the URI is already paired
var validationState = Pairing.errors.ok
var validationState = Pairing.errors.uriOk
for (let key in sessions) {
if (sessions[key].pairingTopic == info.topic) {
validationState = Pairing.errors.alreadyUsed
@ -72,7 +72,7 @@ QObject {
}
// Check if expired
if (validationState == Pairing.errors.ok) {
if (validationState == Pairing.errors.uriOk) {
const now = (new Date().getTime())/1000
if (info.expiry < now) {
validationState = Pairing.errors.expired
@ -159,9 +159,8 @@ QObject {
}
return
}
if (!(approvedNamespaces.eip155.accounts) || approvedNamespaces.eip155.accounts.length === 0
|| (!(approvedNamespaces.eip155.chains) || approvedNamespaces.eip155.chains.length === 0)
) {
const an = approvedNamespaces.eip155
if (!(an.accounts) || an.accounts.length === 0 || (!(an.chains) || an.chains.length === 0)) {
d.reportPairErrorState(Pairing.errors.unsupportedNetwork)
return
}

View File

@ -5,12 +5,13 @@ import QtQml 2.15
QtObject {
readonly property QtObject errors: QtObject {
readonly property int notChecked: 0
readonly property int ok: 1
readonly property int uriOk: 1
readonly property int tooCool: 2
readonly property int invalidUri: 3
readonly property int alreadyUsed: 4
readonly property int expired: 5
readonly property int unsupportedNetwork: 6
readonly property int unknownError: 7
readonly property int dappReadyForApproval: 8
}
}

View File

@ -29,7 +29,7 @@ StatusDialog {
function pairingValidated(validationState) {
uriInput.errorState = validationState
if (validationState === Pairing.errors.ok) {
if (validationState === Pairing.errors.uriOk) {
d.doPair()
}
}
@ -52,6 +52,7 @@ StatusDialog {
id: uriInput
pending: uriInput.errorState === Pairing.errors.notChecked
|| uriInput.errorState === Pairing.errors.uriOk
onTextChanged: {
root.isPairing = false
@ -91,7 +92,7 @@ StatusDialog {
enabled: uriInput.valid
&& !root.isPairing
&& uriInput.text.length > 0
&& uriInput.errorState === Pairing.errors.ok
&& uriInput.errorState === Pairing.errors.uriOk
onClicked: {
d.doPair()