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

[WIP] Added support for EIP-1102 #2548

Merged
merged 19 commits into from
Nov 10, 2018
Merged

[WIP] Added support for EIP-1102 #2548

merged 19 commits into from
Nov 10, 2018

Conversation

usmanmuhd
Copy link
Contributor

@usmanmuhd usmanmuhd commented Oct 27, 2018

Fixes #1964

app/assets/v2/js/metamask-approval.js Outdated Show resolved Hide resolved
app/assets/v2/js/metamask-approval.js Outdated Show resolved Hide resolved
@usmanmuhd
Copy link
Contributor Author

@owocki Can we get to know from the metamask team,

  1. If there is a way to know without actually authorizing if the present website has been authorized?

@codecov
Copy link

codecov bot commented Oct 27, 2018

Codecov Report

Merging #2548 into master will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2548      +/-   ##
=========================================
- Coverage   28.65%   28.6%   -0.05%     
=========================================
  Files         163     163              
  Lines       13097   13097              
  Branches     1753    1753              
=========================================
- Hits         3753    3747       -6     
- Misses       9244    9250       +6     
  Partials      100     100
Impacted Files Coverage Δ
app/dashboard/embed.py 28.16% <0%> (-3.45%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f1651c...def45fa. Read the comment docs.

@thelostone-mc
Copy link
Member

thelostone-mc commented Oct 28, 2018

Not sure if it makes more sense

  • to keep a disabled / keep a enabled list / let the check on every page
    aka add it to footer_scripts.js something like this :
window.addEventListener('load', async () => {
  if(window.ethereum) {
    window.web3 = new Web3(ethereum);
    try {
      await ethereum.enable();
    } catch (errow) {
      console.log("alert: user disabled transaction");
    }
  } else if (window.web3) {
    window.web3 = new Web3(web3.currentProvider);
  } else {
    console.log("alert: use dapp browser")
  }
});

cc @owocki

@usmanmuhd

If there is a way to know without actually authorizing if the present website has been authorized?

I think the code above would take care ethereum.enable does that check internally

x

@thelostone-mc thelostone-mc added upgrade frontend This needs frontend expertise. labels Oct 28, 2018
@usmanmuhd
Copy link
Contributor Author

@thelostone-mc ethereum.enable takes a bit of time to return after approval. Some times in the bounty page it does not recognise a user as the owner. Thus I added it to header.
I wanted to know if there is way without authorising because currently it makes the user almost unable to use gitcoin without pressing the enable option. That way I can make a user continue using gitcoin without bugging him to accept the authorisation.

@mbeacom
Copy link
Contributor

mbeacom commented Nov 1, 2018

Relevant: https://github.com/portis-project/cryptoauth
I spoke with the guys from Portis the other day and they discussed the above repo a bit. Seems to make sense 🤔

@thelostone-mc @SaptakS @owocki What does everything think of this repo?

@owocki
Copy link
Contributor

owocki commented Nov 2, 2018

If there is a way to know without actually authorizing if the present website has been authorized?

i donno, you could ask around or log an issue on their github issue board

@owocki
Copy link
Contributor

owocki commented Nov 2, 2018

If there is a way to know without actually authorizing if the present website has been authorized?

i could probably manage/create a list in localstorage

@@ -63,6 +63,9 @@
<title>{% if title %}{{title}}{% else %}{% trans "Grow Open Source" %}{% endif %} | Gitcoin</title>
{% include 'shared/favicon.html' %}
Copy link
Contributor

Choose a reason for hiding this comment

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

from the metamask blog post about preparing your dapp for EIP 1102

Previously, dapps would access the MetaMask provider by using window.web3.currentProvider. While this will still work, the new, standard way to access the Ethereum provider in a Web browser is to use window.ethereum.

I dont see any updates for this in this repo...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I completely missed this. Will make the updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@owocki where is web3.currentProvider used and for what purpose?

Copy link
Contributor

Choose a reason for hiding this comment

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

Searching 18920 files for "currentProvider"

/Users/kevinowocki/Sites/gitcoin/web/app/assets/ens/index.js:
    4    var method = 'personal_sign';
    5  
    6:   web3.currentProvider.sendAsync({
    7      method,
    8      params,

/Users/kevinowocki/Sites/gitcoin/web/app/assets/onepager/js/web3alert.js:
   25  };
   26  var metaMaskWarning = function() {
   27:   if (typeof web3 == 'undefined' || !web3.currentProvider || !web3.currentProvider.isMetaMask) {
   28      if (typeof document.suppressweb3alert != 'undefined') {
   29        _alert({ message: gettext('You must install <a href=https://metamask.io/>Metamask</a> to use this tool.') }, 'info');

/Users/kevinowocki/Sites/gitcoin/web/app/assets/v2/js/truncate-hash.js:
   70  new metamaskAddress();
   71  
   72: web3.currentProvider.publicConfigStore.on('update', function(e) {
   73    new metamaskAddress();
   74  });

/Users/kevinowocki/Sites/gitcoin/web/app/assets/v2/js/pages/kudos_send.js:
  561  }
  562  
  563: // web3.currentProvider.publicConfigStore.on('update', function(e) {
  564  var error;
  565  
  ...
  572    var network = e ? e.networkVersion : web3.version.network;
  573  
  574:   console.log(web3.currentProvider);
  575    if (network === '4' || network === '1') {
  576      console.log(network);

/Users/kevinowocki/Sites/gitcoin/web/app/assets/v2/js/pages/wallet_estimate.js:
    1  window.addEventListener('load', function() {
    2:   if (web3.currentProvider.isTrust) {
    3      $('#trust_label').show();
    4    } else {


You can find the answer by grepping the codebase. I dont know more about the 'why' than you do.

Copy link
Contributor Author

@usmanmuhd usmanmuhd Nov 8, 2018

Choose a reason for hiding this comment

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

@owocki From my discussions with @PumpkingWok, It is most probably updated only in the below case:

if (window.ethereum) {
    window.web3 = new Web3(window.ethereum) // updated case
    try {
      await window.ethereum.enable()
    } catch (error) {
      console.error(error)
      console.error(`Refresh the page to approve/reject again`)
      window.web3 = null
    }
  } else if(window.web3) { // for legacy dapp browsers
    window.web3 = new Web3(window.web3.currentProvider)
  }

This is also the only example given in the blog post as well.

app/assets/v2/js/metamask-approval.js Show resolved Hide resolved
@usmanmuhd
Copy link
Contributor Author

If there is a way to know without actually authorizing if the present website has been authorized?

i could probably manage/create a list in localstorage

Ah I was thinking of doing the same.
But then it might lead to cases where the local storage says that gitcoin has been authenticated but the user clears the privacy data. It will anyway lead to only 1 time nagging.

@owocki
Copy link
Contributor

owocki commented Nov 3, 2018

But then it might lead to cases where the local storage says that gitcoin has been authenticated but the user clears the privacy data. It will anyway lead to only 1 time nagging.

yes i agree. we'll have to figure out a way to manage that... or move it into a v2 ticket

@usmanmuhd
Copy link
Contributor Author

Metamask has provided a way to check if a user has approved in metamask. It had a bug in the older build. Updating to latest build seems to solve it. I will get this done by tomorrow.

@pinkiebell
Copy link
Contributor

Can we put this into the existing web3 listener?
Also, right now we don't have to source our own web3.js because metamask still injects it.
In the future we want to do something like var web3 = web3 || new Web3() in shared.js and setting the metmask provider if available.

For now we can do simply:

diff --git a/app/assets/v2/js/shared.js b/app/assets/v2/js/shared.js
index ad6bb8295..9a011e906 100644
--- a/app/assets/v2/js/shared.js
+++ b/app/assets/v2/js/shared.js
@@ -830,6 +830,18 @@ var listen_for_web3_changes = function() {
   } else if (typeof web3 == 'undefined' || typeof web3.eth == 'undefined' || typeof web3.eth.coinbase == 'undefined' || !web3.eth.coinbase) {
     currentNetwork('locked');
     trigger_form_hooks();
+
+    if (window.ethereum) {
+      window.ethereum.enable().then(
+        function() {
+          //approved
+        }
+      ).catch(
+        function() {
+          //rejected
+        }
+      );
+    }
   } else {
     web3.eth.getBalance(web3.eth.coinbase, function(errors, result) {
       if (typeof result != 'undefined') {

@usmanmuhd
Copy link
Contributor Author

@pinkiebell I am not entirely sure that we should do it that way.
The current method will make it better for the next update to web3js 1.0

@usmanmuhd
Copy link
Contributor Author

I think this is good to test now.
cc: @thelostone-mc

screencast-from-wednesday-07-november-2018-03_34_04-ist

@thelostone-mc
Copy link
Member

@usmanmuhd DM-ed you a few changes ! Could you get that done too ?
Apart from that this looks good from my side

@owocki
Copy link
Contributor

owocki commented Nov 8, 2018

QA notes:

  1. i should not have to refresh the page after i give metamask perms -- the curernt site notices you've unlocked and shows the right elements without a refresh
  2. faucet page doesnt prompt me to connect to metamask, still asks to unlock
  3. same with tip page / kudos page, contribute page and /explorer, and i presume, all the other pages that check for metamask

@usmanmuhd
Copy link
Contributor Author

@thelostone-mc How do I handle the metamask connection request on kudos, tips and ens?
I was planning on showing an alert with a button.

@usmanmuhd
Copy link
Contributor Author

usmanmuhd commented Nov 8, 2018

@owocki @thelostone-mc I guess this is good to go (except for web3.currentProvider)!

@owocki
Copy link
Contributor

owocki commented Nov 9, 2018

How do I handle the metamask connection request on kudos, tips and ens?

you can just use the same styles as exists on bounties, no?

i think we need to handle this before shipping

@owocki
Copy link
Contributor

owocki commented Nov 9, 2018

testing now

@usmanmuhd
Copy link
Contributor Author

@owocki I handled it using _alert. If that is not proper I will change it.

@owocki
Copy link
Contributor

owocki commented Nov 10, 2018

this is awesome! just tested and it seems really good.. merging now, will deploy monday

@owocki owocki merged commit def45fa into gitcoinco:master Nov 10, 2018
@usmanmuhd
Copy link
Contributor Author

usmanmuhd commented Nov 10, 2018

Thanks, waiting to use it!

@thelostone-mc
Copy link
Member

Thanks man for updating the faucet banners ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend This needs frontend expertise.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants