diff --git a/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml b/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml new file mode 100644 index 0000000000..6ed3b12dc1 --- /dev/null +++ b/ui/app/AppLayouts/Wallet/services/dapps/DAppsListProvider.qml @@ -0,0 +1,79 @@ +import QtQuick 2.15 + +import utils 1.0 + +QtObject { + id: root + + required property WalletConnectSDK sdk + + readonly property alias pairingsModel: d.pairingsModel + readonly property alias sessionsModel: d.sessionsModel + + function updatePairings() { + d.resetPairingsModel() + } + function updateSessions() { + d.resetSessionsModel() + } + + readonly property QtObject _d: QtObject { + id: d + + property ListModel pairingsModel: ListModel { + id: pairings + } + property ListModel sessionsModel: ListModel { + id: sessions + } + + function resetPairingsModel(entryCallback) + { + pairings.clear(); + + // We have to postpone `getPairings` call, cause otherwise: + // - the last made pairing will always have `active` prop set to false + // - expiration date won't be the correct one, but one used in session proposal + // - the list of pairings will display succesfully made pairing as inactive + Backpressure.debounce(this, 250, () => { + sdk.getPairings((pairList) => { + for (let i = 0; i < pairList.length; i++) { + pairings.append(pairList[i]); + + if (entryCallback) { + entryCallback(pairList[i]) + } + } + }); + })(); + } + + function resetSessionsModel() { + sessions.clear(); + + Backpressure.debounce(this, 250, () => { + sdk.getActiveSessions((sessionList) => { + for (var topic of Object.keys(sessionList)) { + sessions.append(sessionList[topic]); + } + }); + })(); + } + + function getPairingTopicFromPairingUrl(url) + { + if (!url.startsWith("wc:")) + { + return null; + } + + const atIndex = url.indexOf("@"); + if (atIndex < 0) + { + return null; + } + + return url.slice(3, atIndex); + } + } +} \ No newline at end of file diff --git a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectSDK.qml b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectSDK.qml index f1d9913385..2da7e532bb 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectSDK.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectSDK.qml @@ -8,15 +8,11 @@ import QtWebChannel 1.15 import StatusQ.Core.Utils 0.1 as SQUtils import StatusQ.Components 0.1 -import utils 1.0 - Item { id: root required property string projectId readonly property alias sdkReady: d.sdkReady - readonly property alias pairingsModel: d.pairingsModel - readonly property alias sessionsModel: d.sessionsModel readonly property alias webEngineLoader: loader property alias active: loader.active @@ -108,67 +104,7 @@ Item { id: d property bool sdkReady: false - property ListModel pairingsModel: pairings - property ListModel sessionsModel: sessions - property WebEngineView engine: loader.instance - - onSdkReadyChanged: { - if (sdkReady) - { - d.resetPairingsModel() - d.resetSessionsModel() - } - } - - function resetPairingsModel(entryCallback) - { - pairings.clear(); - - // We have to postpone `getPairings` call, cause otherwise: - // - the last made pairing will always have `active` prop set to false - // - expiration date won't be the correct one, but one used in session proposal - // - the list of pairings will display succesfully made pairing as inactive - Backpressure.debounce(this, 250, () => { - wcCalls.getPairings((pairList) => { - for (let i = 0; i < pairList.length; i++) { - pairings.append(pairList[i]); - - if (entryCallback) { - entryCallback(pairList[i]) - } - } - }); - })(); - } - - function resetSessionsModel() { - sessions.clear(); - - Backpressure.debounce(this, 250, () => { - wcCalls.getActiveSessions((sessionList) => { - for (var topic of Object.keys(sessionList)) { - sessions.append(sessionList[topic]); - } - }); - })(); - } - - function getPairingTopicFromPairingUrl(url) - { - if (!url.startsWith("wc:")) - { - return null; - } - - const atIndex = url.indexOf("@"); - if (atIndex < 0) - { - return null; - } - - return url.slice(3, atIndex); - } } QtObject { @@ -445,13 +381,11 @@ Item { function onDisconnectSessionResponse(topic, error) { console.debug(`WC WalletConnectSDK.onDisconnectSessionResponse; topic: ${topic}, error: ${error}`) - d.resetSessionsModel() root.sessionDelete(topic, error) } function onDisconnectPairingResponse(topic, error) { console.debug(`WC WalletConnectSDK.onDisconnectPairingResponse; topic: ${topic}, error: ${error}`) - d.resetPairingsModel() } function onBuildApprovedNamespacesResponse(approvedNamespaces, error) { @@ -461,30 +395,22 @@ Item { function onApproveSessionResponse(session, error) { console.debug(`WC WalletConnectSDK.onApproveSessionResponse; sessionTopic: ${JSON.stringify(session, null, 2)}, error: ${error}`) - d.resetPairingsModel() - d.resetSessionsModel() root.approveSessionResult(session, error) } function onRejectSessionResponse(error) { console.debug(`WC WalletConnectSDK.onRejectSessionResponse; error: ${error}`) root.rejectSessionResult(error) - d.resetPairingsModel() - d.resetSessionsModel() } function onRespondSessionRequestResponse(error) { console.debug(`WC WalletConnectSDK.onRespondSessionRequestResponse; error: ${error}`) root.sessionRequestUserAnswerResult(true, error) - d.resetPairingsModel() - d.resetSessionsModel() } function onRejectSessionRequestResponse(error) { console.debug(`WC WalletConnectSDK.onRejectSessionRequestResponse; error: ${error}`) root.sessionRequestUserAnswerResult(false, error) - d.resetPairingsModel() - d.resetSessionsModel() } function onSessionProposal(details) { @@ -507,8 +433,6 @@ Item { function onSessionDelete(details) { console.debug(`WC WalletConnectSDK.onSessionDelete; details: ${JSON.stringify(details, null, 2)}`) root.sessionDelete(details.topic, "") - d.resetPairingsModel() - d.resetSessionsModel() } function onSessionExpire(details) { @@ -553,14 +477,6 @@ Item { } } - ListModel { - id: pairings - } - - ListModel { - id: sessions - } - WebEngineLoader { id: loader diff --git a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml index 9d80863f53..e6c89ef9bb 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml +++ b/ui/app/AppLayouts/Wallet/services/dapps/WalletConnectService.qml @@ -103,5 +103,9 @@ QtObject { readonly property QtObject _d: QtObject { property var currentSessionProposal: null property var acceptedSessionProposal: null + + readonly property DAppsListProvider dappsProvider: DAppsListProvider { + sdk: root.wcSDK + } } } \ No newline at end of file diff --git a/ui/app/AppLayouts/Wallet/services/dapps/qmldir b/ui/app/AppLayouts/Wallet/services/dapps/qmldir index 6c5a0e3a4a..e99ace38b5 100644 --- a/ui/app/AppLayouts/Wallet/services/dapps/qmldir +++ b/ui/app/AppLayouts/Wallet/services/dapps/qmldir @@ -1,4 +1,5 @@ WalletConnectSDK 1.0 WalletConnectSDK.qml WalletConnectService 1.0 WalletConnectService.qml +DAppsListProvider 1.0 DAppsListProvider.qml Helpers 1.0 helpers.js \ No newline at end of file