-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #139 - Convert ENS Address To Link functionality #140
Conversation
js/DomManipulator.js
Outdated
|
||
var arrWhitelistedTags = new Array("code", "span", "p", "td", "li", "em", "i", "b", "strong", "small"); | ||
var strRegex = /(^|\s|:|-)((?:0x)[0-9a-fA-F]{40})(?:\s|$)/gi; | ||
var arrWhitelistedTags = ["code", "span", "p", "td", "li", "em", "i", "b", "strong", "small"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also refactored the array instantiation, let me know if this is a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's all good :)
Ah, I've just spotted that this will fail with a few of the block explorers. I need to handle that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may have to modify the regex a little more... I'm doing some tests here - feel free to add some more and experiment.
@Samyoul can you hop on to MEW slack channel or join me over at https://tlk.io/b383fb if you're still working on this tonight |
We settled on https://regex101.com/r/feqr8J/7 (\s|^|\.|\"|\'|\>)([a-z0-9][a-z0-9-\.]+[a-z0-9](?:.eth))(\s|$|\.|\"|\'|\<) With the following substitution string: $1<a title="See this address on the blockchain explorer" href="https://etherscan.io/address/$2" class="ext-etheraddresslookup-link">$2</a>$3 This handles standard domain structure. |
Additionally refactored the constructor so that search and replace settings are handled by a single method. Moved replace pattern into an abstracted pattern variable to allow for multiple patterns to be used. TODO: Check for explorers supporting ENS, on fail notify user.
Working on checking for supported block explorers, on failure give warning. |
Quite a lot of refactor work was done on this commit, and I should have just commited each part separately. But I wanted to fix the bug I found because it was messing up my testing. Bug Fix : basically stopped regex being applied to anything that wasn't a textNode, otherwise we would have attribute overwrites and other kinds of mess. In order for this to work I've created a tempory "slot" element that holds new elements, after regex is applied they are moved into the parent node. Added docblocks
I've committed the functionality that completes this issue. However I'm sorry that so much refactor work was push in a single commit. Notes from my commit :
|
init() | ||
{ | ||
let objBrowser = chrome ? chrome : browser; | ||
//Get the highlight option for the user | ||
objBrowser.runtime.sendMessage({func: "highlight_option"}, function(objResponse) { | ||
if(objResponse && objResponse.hasOwnProperty("resp")) { | ||
this.blHighlight = (objResponse.resp == 1 ? true : false); | ||
this.blHighlight = (objResponse.resp == 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed this because it is basically the thing:
(objResponse.resp == 1 ? true : false)
== (objResponse.resp == 1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, nice spot! 👍
options.html
Outdated
<option value="https://ethplorer.io/address">Ethplorer.io</option> | ||
<option value="http://ethergraphs.com/dashboard">Ethergraphs.com</option> | ||
</select> | ||
<div> | ||
<p>* ENS address compatible.</p> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made this amendment to allow the user to know which explorers will allow them the ability view ENS addresses. We can in future add new functionality to lookup the underlying Ethereum address then link to this on the user's chosen explorer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this text smaller please?
Just a small UI change, put it in <small></small>
tags. (I have selective OCD 😕)
Or do you have an idea on how to present notes/not-main-labels on the UI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make this smaller for now, we can discuss ideas later, though UI isn't really my strong suit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Once v1.9 is up, we can arrange a more in-depth discussion on it for later this week when both our schedules are free.
I've spotted a bug with this, I need to take a look at it: In some cases the new .eth address is moved to the end of the element. Likely related to : https://github.com/409H/EtherAddressLookup/pull/140/files#diff-082dfc69c6b55d30d3aef681bb1b3fe8R232 tidyUpSlots()
{
var slots = document.querySelectorAll("slot.ext-etheraddresslookup-temporary");
for(var i=0; i < slots.length; i++){
while(slots[i].childNodes.length > 0){
slots[i].parentNode.appendChild(slots[i].firstChild); // <-- Problem here.
}
slots[i].parentNode.removeChild(slots[i]);
}
} |
Bug is resolved. Ready for testing. |
@Samyoul Looks all good here! Awesome work. Please can you adjust the |
@409H No problem. Done. |
@Samyoul I will merge and package to the Chrome store tonight! 🎉 Thanks for all your work towards this issue! |
"Small" change made 😆 |
Resolves #139
I've refactored the regex portions of the application so that we only instantiate the RegEx once and abstracted away the conversion logic into a more generic function