2024-05-16 17:57:37 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
import StatusQ.Core.Utils 0.1
|
|
|
|
|
2024-07-23 14:26:55 +00:00
|
|
|
import AppLayouts.Wallet.services.dapps 1.0
|
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
import shared.stores 1.0
|
|
|
|
|
2024-05-16 17:57:37 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
QObject {
|
2024-05-16 17:57:37 +00:00
|
|
|
id: root
|
|
|
|
|
2024-05-31 09:34:59 +00:00
|
|
|
required property WalletConnectSDKBase sdk
|
2024-05-21 10:42:50 +00:00
|
|
|
required property DAppsStore store
|
2024-07-23 14:26:55 +00:00
|
|
|
required property var supportedAccountsModel
|
2024-05-16 17:57:37 +00:00
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
readonly property alias dappsModel: d.dappsModel
|
2024-05-16 17:57:37 +00:00
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
function updateDapps() {
|
|
|
|
d.updateDappsModel()
|
2024-05-16 17:57:37 +00:00
|
|
|
}
|
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
QObject {
|
2024-05-16 17:57:37 +00:00
|
|
|
id: d
|
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
property ListModel dappsModel: ListModel {
|
|
|
|
id: dapps
|
2024-05-16 17:57:37 +00:00
|
|
|
}
|
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
property var dappsListReceivedFn: null
|
|
|
|
property var getActiveSessionsFn: null
|
|
|
|
function updateDappsModel()
|
2024-05-16 17:57:37 +00:00
|
|
|
{
|
2024-05-21 10:42:50 +00:00
|
|
|
dappsListReceivedFn = (dappsJson) => {
|
|
|
|
dapps.clear();
|
|
|
|
|
|
|
|
let dappsList = JSON.parse(dappsJson);
|
|
|
|
for (let i = 0; i < dappsList.length; i++) {
|
|
|
|
dapps.append(dappsList[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
root.store.dappsListReceived.connect(dappsListReceivedFn);
|
|
|
|
|
|
|
|
// triggers a potential fast response from store.dappsListReceived
|
|
|
|
if (!store.getDapps()) {
|
|
|
|
console.warn("Failed retrieving dapps from persistence")
|
|
|
|
root.store.dappsListReceived.disconnect(dappsListReceivedFn);
|
|
|
|
}
|
2024-05-16 17:57:37 +00:00
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
getActiveSessionsFn = () => {
|
2024-07-23 14:26:55 +00:00
|
|
|
sdk.getActiveSessions((allSessions) => {
|
2024-05-21 10:42:50 +00:00
|
|
|
root.store.dappsListReceived.disconnect(dappsListReceivedFn);
|
2024-05-16 17:57:37 +00:00
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
let tmpMap = {}
|
2024-06-27 14:15:17 +00:00
|
|
|
var topics = []
|
2024-07-29 14:39:56 +00:00
|
|
|
const sessions = DAppsHelpers.filterActiveSessionsForKnownAccounts(allSessions, root.supportedAccountsModel)
|
|
|
|
for (const key in sessions) {
|
|
|
|
const dapp = sessions[key].peer.metadata
|
2024-06-19 15:17:49 +00:00
|
|
|
if (!!dapp.icons && dapp.icons.length > 0) {
|
2024-05-21 10:42:50 +00:00
|
|
|
dapp.iconUrl = dapp.icons[0]
|
2024-06-19 15:17:49 +00:00
|
|
|
} else {
|
|
|
|
dapp.iconUrl = ""
|
2024-05-21 10:42:50 +00:00
|
|
|
}
|
|
|
|
tmpMap[dapp.url] = dapp;
|
2024-06-27 14:15:17 +00:00
|
|
|
topics.push(key)
|
2024-05-21 10:42:50 +00:00
|
|
|
}
|
2024-07-23 14:26:55 +00:00
|
|
|
// TODO #15075: on SDK dApps refresh update the model that has data source from persistence instead of using reset
|
2024-06-19 15:17:49 +00:00
|
|
|
dapps.clear();
|
2024-05-21 10:42:50 +00:00
|
|
|
// Iterate tmpMap and fill dapps
|
2024-07-29 14:39:56 +00:00
|
|
|
for (const key in tmpMap) {
|
2024-05-21 10:42:50 +00:00
|
|
|
dapps.append(tmpMap[key]);
|
2024-05-16 17:57:37 +00:00
|
|
|
}
|
2024-06-27 14:15:17 +00:00
|
|
|
|
|
|
|
root.store.updateWalletConnectSessions(JSON.stringify(topics))
|
2024-05-16 17:57:37 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
if (root.sdk.sdkReady) {
|
|
|
|
getActiveSessionsFn()
|
|
|
|
} else {
|
|
|
|
let conn = root.sdk.sdkReadyChanged.connect(() => {
|
|
|
|
if (root.sdk.sdkReady) {
|
|
|
|
getActiveSessionsFn()
|
|
|
|
}
|
|
|
|
});
|
2024-05-16 17:57:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-29 14:39:56 +00:00
|
|
|
}
|