fix: replace URL in address bar by ens

This commit is contained in:
Richard Ramos 2020-09-30 14:59:36 -04:00 committed by Iuri Matias
parent e8183f3a9f
commit e512768dc0
4 changed files with 30 additions and 7 deletions

View File

@ -177,12 +177,14 @@ QtObject:
let contentHash = contenthash(ens)
if contentHash == "": # ENS does not have a content hash
return url_replaceHostAndAddPath(url, IPFS_SCHEME, url_host(url), "")
return url_replaceHostAndAddPath(url, url_host(url), IPFS_SCHEME)
let decodedContentHash = contentHash.decodeContentHash()
let base32Hash = base32.encode(base58.decode(decodedContentHash).toString()).toLowerAscii().replace("=", "")
result = url_replaceHostAndAddPath(url, IPFS_SCHEME, base32Hash & IPFS_GATEWAY)
result = url_replaceHostAndAddPath(url, base32Hash & IPFS_GATEWAY, IPFS_SCHEME)
proc replaceHostByENS*(self: Web3ProviderView, url: string, ens: string): string {.slot.} =
result = url_replaceHostAndAddPath(url, ens)
proc getHost*(self: Web3ProviderView, url: string): string {.slot.} =
result = url_host(url)

View File

@ -25,11 +25,15 @@ Item {
Layout.fillHeight: true
Layout.fillWidth: true
property var urlENSDictionary: ({})
function determineRealURL(text){
var url = utilsModel.urlFromUserInput(text);
var host = web3Provider.getHost(url);
if(host.endsWith(".eth")){
url = web3Provider.ensResourceURL(host, url);
var ensResource = web3Provider.ensResourceURL(host, url);
urlENSDictionary[web3Provider.getHost(ensResource)] = host;
url = ensResource;
}
return url;
}
@ -37,7 +41,7 @@ Item {
property Component accessDialogComponent: ModalPopup {
id: accessDialog
property var request: {"hostname": "", "title": "", "permission": ""}
property var request: ({"hostname": "", "title": "", "permission": ""})
function postMessage(isAllowed){
request.isAllowed = isAllowed;
@ -126,6 +130,12 @@ Item {
function postMessage(data){
var request = JSON.parse(data)
var ensAddr = urlENSDictionary[request.hostname];
if(ensAddr){
request.hostname = ensAddr;
}
if(request.type === Constants.api_request){
if(!web3Provider.hasPermission(request.hostname, request.permission)){
var dialog = accessDialogComponent.createObject(browserWindow);
@ -363,6 +373,17 @@ Item {
onClicked: currentWebView && currentWebView.loading ? currentWebView.stop() : currentWebView.reload()
}
Connections {
target: currentWebView
onUrlChanged: {
var ensAddr = urlENSDictionary[web3Provider.getHost(currentWebView.url)];
if(ensAddr){ // replace host by ensAddr
addressBar.text = web3Provider.replaceHostByENS(currentWebView.url, ensAddr);
}
}
}
StyledTextField {
id: addressBar
Layout.fillWidth: true
@ -382,7 +403,7 @@ Item {
source: currentWebView && currentWebView.icon ? currentWebView.icon : ""
}
focus: true
text: currentWebView && currentWebView.url
text: ""
Keys.onPressed: {
// TODO: disable browsing local files? file://
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return){

2
vendor/DOtherSide vendored

@ -1 +1 @@
Subproject commit 8a1478aab71e6c8840f19e0bf112393edfb7eeae
Subproject commit dfacb9b7143b37dad9ab96d6f112df8ecb5ce536

2
vendor/nimqml vendored

@ -1 +1 @@
Subproject commit 2a1cc508b1cee4f80a310495998fc70288d8ed59
Subproject commit c44d1ee030d3b02e518984a68d87b6f3ef119dc9