Skip to content
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

Merged
merged 7 commits into from
Oct 30, 2017

Conversation

Samyoul
Copy link
Contributor

@Samyoul Samyoul commented Oct 24, 2017

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


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"];
Copy link
Contributor Author

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's all good :)

@409H 409H changed the title Issue/139 Issue #139 - Convert ENS Address To Link functionality Oct 24, 2017
@409H
Copy link
Owner

409H commented Oct 24, 2017

Awesome - testing now!

image

@409H 409H self-requested a review October 24, 2017 20:12
@Samyoul
Copy link
Contributor Author

Samyoul commented Oct 24, 2017

Ah, I've just spotted that this will fail with a few of the block explorers. I need to handle that.

Copy link
Owner

@409H 409H left a 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.

https://regex101.com/r/feqr8J/1

@409H
Copy link
Owner

409H commented Oct 24, 2017

@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

@Samyoul
Copy link
Contributor Author

Samyoul commented Oct 25, 2017

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.
@Samyoul
Copy link
Contributor Author

Samyoul commented Oct 25, 2017

Working on checking for supported block explorers, on failure give warning.

@409H 409H changed the title Issue #139 - Convert ENS Address To Link functionality WIP: Issue #139 - Convert ENS Address To Link functionality Oct 25, 2017
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
@Samyoul
Copy link
Contributor Author

Samyoul commented Oct 27, 2017

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 :

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 after temporary slot is removed.

Added docblocks

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);
Copy link
Contributor Author

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)

Copy link
Owner

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>
Copy link
Contributor Author

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Owner

@409H 409H Oct 30, 2017

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?

Copy link
Contributor Author

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.

Copy link
Owner

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.

@Samyoul
Copy link
Contributor Author

Samyoul commented Oct 27, 2017

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.

myetherwallet com 3

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]);
    }
}

@Samyoul
Copy link
Contributor Author

Samyoul commented Oct 28, 2017

Bug is resolved. Ready for testing.

@409H
Copy link
Owner

409H commented Oct 29, 2017

@Samyoul Looks all good here! Awesome work. Please can you adjust the version value to 1.9 in manifest.json ?

@409H 409H changed the title WIP: Issue #139 - Convert ENS Address To Link functionality Issue #139 - Convert ENS Address To Link functionality Oct 29, 2017
@Samyoul
Copy link
Contributor Author

Samyoul commented Oct 29, 2017

@409H No problem. Done.

@409H
Copy link
Owner

409H commented Oct 30, 2017

@Samyoul I will merge and package to the Chrome store tonight! 🎉

Thanks for all your work towards this issue!

@Samyoul
Copy link
Contributor Author

Samyoul commented Oct 30, 2017

"Small" change made 😆

@409H 409H merged commit 611b7e4 into 409H:master Oct 30, 2017
@Samyoul Samyoul deleted the issue/139 branch November 7, 2017 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants