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
|
|
|
|
|
|
|
|
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-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
|
|
|
// TODO DEV: check if still holds true
|
|
|
|
// Reasons to postpone `getDapps` call:
|
|
|
|
// - the first recent made session will always have `active` prop set to false
|
2024-05-16 17:57:37 +00:00
|
|
|
// - expiration date won't be the correct one, but one used in session proposal
|
2024-05-21 10:42:50 +00:00
|
|
|
// - the list of dapps will display successfully made pairing as inactive
|
|
|
|
getActiveSessionsFn = () => {
|
|
|
|
sdk.getActiveSessions((sessions) => {
|
|
|
|
root.store.dappsListReceived.disconnect(dappsListReceivedFn);
|
2024-05-16 17:57:37 +00:00
|
|
|
|
2024-05-21 10:42:50 +00:00
|
|
|
let tmpMap = {}
|
|
|
|
for (let key in sessions) {
|
|
|
|
let 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-19 15:17:49 +00:00
|
|
|
// TODO #14755: on SDK dApps refresh update the model that has data source from persistence instead of using reset
|
|
|
|
dapps.clear();
|
2024-05-21 10:42:50 +00:00
|
|
|
// Iterate tmpMap and fill dapps
|
|
|
|
for (let key in tmpMap) {
|
|
|
|
dapps.append(tmpMap[key]);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|