2021-09-30 09:43:29 +00:00
|
|
|
pragma Singleton
|
|
|
|
|
|
|
|
import QtQuick 2.13
|
|
|
|
|
2022-03-14 12:32:21 +00:00
|
|
|
import utils 1.0
|
|
|
|
|
2021-09-30 09:43:29 +00:00
|
|
|
QtObject {
|
|
|
|
id: root
|
|
|
|
|
2021-10-21 14:46:24 +00:00
|
|
|
property var web3ProviderInst: providerModule
|
2021-09-30 09:43:29 +00:00
|
|
|
property var urlENSDictionary: ({})
|
|
|
|
|
2021-11-15 15:06:25 +00:00
|
|
|
property int networkId: providerModule.networkId
|
2022-03-14 12:32:21 +00:00
|
|
|
property string currentNetwork: providerModule.currentNetwork
|
2021-11-15 15:06:25 +00:00
|
|
|
|
2022-03-04 09:09:58 +00:00
|
|
|
function disconnectAddress(dappName, address){
|
2022-03-14 12:32:21 +00:00
|
|
|
dappPermissionsModule.disconnectAddress(dappName, address)
|
|
|
|
}
|
|
|
|
|
|
|
|
function disconnect(hostname) {
|
|
|
|
dappPermissionsModule.disconnect(hostname)
|
2021-11-18 23:40:49 +00:00
|
|
|
}
|
|
|
|
|
2022-03-04 09:09:58 +00:00
|
|
|
function addPermission(hostname, address, permission){
|
|
|
|
dappPermissionsModule.addPermission(hostname, address, permission)
|
|
|
|
}
|
|
|
|
|
|
|
|
function hasPermission(hostname, address, permission){
|
|
|
|
return dappPermissionsModule.hasPermission(hostname, address, permission)
|
2021-12-16 17:24:26 +00:00
|
|
|
}
|
|
|
|
|
2022-03-14 12:32:21 +00:00
|
|
|
function hasWalletConnected(hostname) {
|
|
|
|
return hasPermission(hostname, WalletStore.dappBrowserAccount.address, "web3")
|
|
|
|
}
|
|
|
|
|
2021-09-30 09:43:29 +00:00
|
|
|
function determineRealURL(text){
|
|
|
|
var url = RootStore.getUrlFromUserInput(text);
|
2021-10-21 14:46:24 +00:00
|
|
|
var host = providerModule.getHost(url);
|
2021-09-30 09:43:29 +00:00
|
|
|
if(host.endsWith(".eth")){
|
2021-10-26 14:36:31 +00:00
|
|
|
var ensResource = providerModule.ensResourceURL(host, url);
|
2021-09-30 09:43:29 +00:00
|
|
|
|
|
|
|
if(/^https\:\/\/swarm\-gateways\.net\/bzz:\/([0-9a-fA-F]{64}|.+\.eth)(\/?)/.test(ensResource)){
|
|
|
|
// TODO: populate urlENSDictionary for prettier url instead of swarm-gateway big URL
|
|
|
|
return ensResource;
|
|
|
|
} else {
|
2021-10-21 14:46:24 +00:00
|
|
|
urlENSDictionary[providerModule.getHost(ensResource)] = host;
|
2021-09-30 09:43:29 +00:00
|
|
|
}
|
|
|
|
url = ensResource;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
function obtainAddress(url) {
|
2021-10-21 14:46:24 +00:00
|
|
|
var ensAddr = urlENSDictionary[providerModule.getHost(url)];
|
|
|
|
return ensAddr ? providerModule.replaceHostByENS( url, ensAddr) : url;
|
2021-09-30 09:43:29 +00:00
|
|
|
}
|
|
|
|
}
|