diff --git a/app/assets/onepager/js/web3alert.js b/app/assets/onepager/js/web3alert.js index 6c8db47281e..ec9009e7ca2 100644 --- a/app/assets/onepager/js/web3alert.js +++ b/app/assets/onepager/js/web3alert.js @@ -29,6 +29,8 @@ var metaMaskWarning = function() { _alert({ message: gettext('You must install Metamask to use this tool.') }, 'info'); } return true; + } else if (is_metamask_unlocked && !is_metamask_approved) { + _alert({ message: gettext('Please connect to Metamask.') }, 'info'); } else if (web3.eth.accounts.length == 0) { _alert({ message: gettext('Please unlock Metamask.') }, 'info'); return true; diff --git a/app/assets/v2/css/buttons.css b/app/assets/v2/css/buttons.css index 07b0e5ce9c5..7743323242e 100644 --- a/app/assets/v2/css/buttons.css +++ b/app/assets/v2/css/buttons.css @@ -187,3 +187,10 @@ button:focus { .btn > svg:first-child { margin-right: .5rem; } + +#metamask_connect { + background: none; + color: white; + border: 2px solid white; + border-radius: 10px; +} diff --git a/app/assets/v2/js/metamask-approval.js b/app/assets/v2/js/metamask-approval.js new file mode 100644 index 00000000000..80b74ac90bb --- /dev/null +++ b/app/assets/v2/js/metamask-approval.js @@ -0,0 +1,45 @@ +async function metamaskApproval() { + if (window.ethereum) { + window.web3 = new Web3(ethereum); + is_metamask_approved = await window.ethereum._metamask.isApproved(); + is_metamask_unlocked = await window.ethereum._metamask.isUnlocked(); + + try { + if (is_metamask_unlocked && is_metamask_approved) { + await ethereum.enable(); + } + } catch (error) { + _alert('Permission to connect to metamask rejected. Allow gitcoin to connect to metamask.', 'warning'); + } + } + ask_metamask_connection(); +} + +window.addEventListener('load', metamaskApproval); + +async function approve_metamask() { + try { + await ethereum.enable(); + is_metamask_approved = true; + } catch (error) { + _alert('Permission to connect to metamask rejected. Allow gitcoin to connect to metamask.', 'warning'); + } +} + +function ask_metamask_connection() { + var page_url = $(location).attr('pathname'); + + shown_on = [ '/tip/send/2', '/kudos/send', '/ens' ]; + var len = page_url.length - 1; + + if (page_url.lastIndexOf('/') === len) { + page_url = page_url.substring(0, len); + } + if ($.inArray(page_url, shown_on) != -1 && !is_metamask_approved) { + _alert('Metamask not connected. ', 'error'); + $('#metamask_connect').css('background', 'none'); + $('#metamask_connect').css('color', 'white'); + $('#metamask_connect').css('border', '2px solid white'); + $('#metamask_connect').css('border-radius', '10px'); + } +} diff --git a/app/assets/v2/js/shared.js b/app/assets/v2/js/shared.js index ad6bb829547..8316d705d29 100644 --- a/app/assets/v2/js/shared.js +++ b/app/assets/v2/js/shared.js @@ -635,10 +635,17 @@ var currentNetwork = function(network) { $('#current-network').text(gettext('Metamask Not Enabled')); $('#navbar-network-banner').html(info); } else if (network == 'locked') { - info = gettext('Web3 locked. Please unlock ') + - 'Metamask'; - $('#current-network').text(gettext('Metamask Locked')); - $('#navbar-network-banner').html(info); + if (is_metamask_approved || !is_metamask_unlocked) { + info = gettext('Web3 locked. Please unlock ') + + 'Metamask'; + $('#current-network').text(gettext('Metamask Locked')); + $('#navbar-network-banner').html(info); + } else { + info = gettext('Metamask not connected. ') + + ''; + $('#current-network').text(gettext('Metamask Not Connected')); + $('#navbar-network-banner').html(info); + } } else { info = gettext('Connect to Mainnet via Metamask'); $('#current-network').text(gettext('Unsupported Network')); @@ -669,10 +676,17 @@ var currentNetwork = function(network) { $('#current-network').text(gettext('Metamask Not Enabled')); $('#navbar-network-banner').html(info); } else if (network == 'locked') { - info = gettext('Web3 locked. Please unlock ') + - 'Metamask'; - $('#current-network').text(gettext('Metamask Locked')); - $('#navbar-network-banner').html(info); + if (is_metamask_approved || !is_metamask_unlocked) { + info = gettext('Web3 locked. Please unlock ') + + 'Metamask'; + $('#current-network').text(gettext('Metamask Locked')); + $('#navbar-network-banner').html(info); + } else { + info = gettext('Metamask not connected. ') + + ''; + $('#current-network').text(gettext('Metamask Not Connected')); + $('#navbar-network-banner').html(info); + } } else { info = gettext('Connect to Rinkeby / Custom RPC via Metamask'); $('#current-network').text(gettext('Unsupported Network')); @@ -708,14 +722,26 @@ var trigger_primary_form_web3_hooks = function() { $('#primary_form').addClass('hidden'); $('.submit_bounty .newsletter').addClass('hidden'); $('#unlock_metamask_error').css('display', 'none'); + $('#connect_metamask_error').css('display', 'none'); $('#no_issue_error').css('display', 'none'); mixpanel_track_once('No Metamask Error', params); + } else if (is_metamask_unlocked && !is_metamask_approved) { + $('#connect_metamask_error').css('display', 'block'); + $('#unlock_metamask_error').css('display', 'none'); + $('#zero_balance_error').css('display', 'none'); + $('#no_metamask_error').css('display', 'none'); + $('#robot_error').removeClass('hidden'); + $('#primary_form').addClass('hidden'); + $('.submit_bounty .newsletter').addClass('hidden'); + $('#no_issue_error').css('display', 'none'); + mixpanel_track_once('Unlock Metamask Error', params); } else if (!web3.eth.coinbase) { $('#unlock_metamask_error').css('display', 'block'); $('#zero_balance_error').css('display', 'none'); $('#no_metamask_error').css('display', 'none'); $('#robot_error').removeClass('hidden'); $('#primary_form').addClass('hidden'); + $('#connect_metamask_error').css('display', 'none'); $('.submit_bounty .newsletter').addClass('hidden'); $('#no_issue_error').css('display', 'none'); mixpanel_track_once('Unlock Metamask Error', params); @@ -725,6 +751,7 @@ var trigger_primary_form_web3_hooks = function() { $('#primary_form').addClass('hidden'); $('.submit_bounty .newsletter').addClass('hidden'); $('#unlock_metamask_error').css('display', 'none'); + $('#connect_metamask_error').css('display', 'none'); $('#no_metamask_error').css('display', 'none'); $('#no_issue_error').css('display', 'none'); mixpanel_track_once('Zero Balance Metamask Error', params); @@ -732,6 +759,7 @@ var trigger_primary_form_web3_hooks = function() { $('#zero_balance_error').css('display', 'none'); $('#unlock_metamask_error').css('display', 'none'); $('#no_metamask_error').css('display', 'none'); + $('#connect_metamask_error').css('display', 'none'); $('#no_issue_error').css('display', 'block'); $('#robot_error').addClass('hidden'); $('#primary_form').removeClass('hidden'); @@ -755,14 +783,23 @@ var trigger_faucet_form_web3_hooks = function() { $('#faucet_form').addClass('hidden'); mixpanel_track_once('No Metamask Error', params); return; + } else if (is_metamask_unlocked && !is_metamask_approved) { + $('#no_metamask_error').css('display', 'none'); + $('#unlock_metamask_error').css('display', 'none'); + $('#connect_metamask_error').css('display', 'block'); + $('#over_balance_error').css('display', 'none'); + $('#faucet_form').addClass('hidden'); } else if (!web3.eth.coinbase) { $('#no_metamask_error').css('display', 'none'); $('#unlock_metamask_error').css('display', 'block'); + $('#connect_metamask_error').css('display', 'none'); + $('#over_balance_error').css('display', 'none'); $('#faucet_form').addClass('hidden'); return; } else if (balance >= faucet_amount) { $('#no_metamask_error').css('display', 'none'); $('#unlock_metamask_error').css('display', 'none'); + $('#connect_metamask_error').css('display', 'none'); $('#over_balance_error').css('display', 'block'); $('#faucet_form').addClass('hidden'); mixpanel_track_once('Faucet Available Funds Metamask Error', params); @@ -770,6 +807,7 @@ var trigger_faucet_form_web3_hooks = function() { $('#over_balance_error').css('display', 'none'); $('#no_metamask_error').css('display', 'none'); $('#unlock_metamask_error').css('display', 'none'); + $('#connect_metamask_error').css('display', 'none'); $('#faucet_form').removeClass('hidden'); } } @@ -780,6 +818,11 @@ var trigger_faucet_form_web3_hooks = function() { mixpanel_track_once('No Metamask Error', params); return; } + if (is_metamask_unlocked && !is_metamask_approved) { + $('#unlock_metamask_error').css('display', 'none'); + $('#connect_metamask_error').css('display', 'block'); + $('#faucet_form').addClass('hidden'); + } if (!web3.eth.coinbase) { $('#unlock_metamask_error').css('display', 'block'); $('#faucet_form').addClass('hidden'); @@ -816,7 +859,7 @@ function getNetwork(id) { } // figure out what version of web3 this is, whether we're logged in, etc.. -var listen_for_web3_changes = function() { +var listen_for_web3_changes = async function() { if (!document.listen_for_web3_iterations) { document.listen_for_web3_iterations = 1; @@ -831,6 +874,7 @@ var listen_for_web3_changes = function() { currentNetwork('locked'); trigger_form_hooks(); } else { + is_metamask_unlocked = true; web3.eth.getBalance(web3.eth.coinbase, function(errors, result) { if (typeof result != 'undefined') { document.balance = result.toNumber(); @@ -848,6 +892,13 @@ var listen_for_web3_changes = function() { } }); } + if (window.ethereum) { + is_metamask_approved = await window.ethereum._metamask.isApproved(); + is_metamask_unlocked = await window.ethereum._metamask.isUnlocked(); + if (is_metamask_approved && is_metamask_unlocked) { + await ethereum.enable(); + } + } }; var actions_page_warn_if_not_on_same_network = function() { diff --git a/app/dashboard/templates/bounty/fulfill.html b/app/dashboard/templates/bounty/fulfill.html index 7948802b0ba..5a95bd4bfcb 100644 --- a/app/dashboard/templates/bounty/fulfill.html +++ b/app/dashboard/templates/bounty/fulfill.html @@ -35,6 +35,7 @@ {% include 'shared/no_metamask_error.html' %} {% include 'shared/zero_balance_error.html' %} {% include 'shared/unlock_metamask.html' %} + {% include 'shared/connect_metamask.html' %}
diff --git a/app/dashboard/templates/bounty/increase.html b/app/dashboard/templates/bounty/increase.html index 545e9b68352..06cc90cd5a0 100644 --- a/app/dashboard/templates/bounty/increase.html +++ b/app/dashboard/templates/bounty/increase.html @@ -37,6 +37,7 @@ {% include 'shared/no_metamask_error.html' %} {% include 'shared/zero_balance_error.html' %} {% include 'shared/unlock_metamask.html' %} + {% include 'shared/connect_metamask.html' %}
{% include 'shared/success_container.html' %} diff --git a/app/dashboard/templates/bounty/kill.html b/app/dashboard/templates/bounty/kill.html index ae12ab5e482..48a7598de8d 100644 --- a/app/dashboard/templates/bounty/kill.html +++ b/app/dashboard/templates/bounty/kill.html @@ -35,6 +35,7 @@ {% include 'shared/no_metamask_error.html' %} {% include 'shared/zero_balance_error.html' %} {% include 'shared/unlock_metamask.html' %} + {% include 'shared/connect_metamask.html' %}
diff --git a/app/dashboard/templates/bounty/new.html b/app/dashboard/templates/bounty/new.html index d7049929a3d..189847f87c0 100644 --- a/app/dashboard/templates/bounty/new.html +++ b/app/dashboard/templates/bounty/new.html @@ -39,6 +39,7 @@ {% include 'shared/no_metamask_error.html' %} {% include 'shared/zero_balance_error.html' %} {% include 'shared/unlock_metamask.html' %} + {% include 'shared/connect_metamask.html' %}
diff --git a/app/dashboard/templates/bulk_payout_bounty.html b/app/dashboard/templates/bulk_payout_bounty.html index 02ed11a138f..7b88e755de1 100644 --- a/app/dashboard/templates/bulk_payout_bounty.html +++ b/app/dashboard/templates/bulk_payout_bounty.html @@ -38,6 +38,7 @@ {% include 'shared/no_metamask_error.html' %} {% include 'shared/zero_balance_error.html' %} {% include 'shared/unlock_metamask.html' %} + {% include 'shared/connect_metamask.html' %}
diff --git a/app/dashboard/templates/ens/base.html b/app/dashboard/templates/ens/base.html index fcfad0a0c33..ffd5892c5cc 100644 --- a/app/dashboard/templates/ens/base.html +++ b/app/dashboard/templates/ens/base.html @@ -20,6 +20,7 @@ + diff --git a/app/dashboard/templates/onepager/base.html b/app/dashboard/templates/onepager/base.html index 9237a213244..d7a5f6e2430 100644 --- a/app/dashboard/templates/onepager/base.html +++ b/app/dashboard/templates/onepager/base.html @@ -139,5 +139,6 @@ root: "{{ ipfs_config.root }}" }; + diff --git a/app/dashboard/templates/payout_bounty.html b/app/dashboard/templates/payout_bounty.html index 0ee0c0c20cf..ab289e2c53b 100644 --- a/app/dashboard/templates/payout_bounty.html +++ b/app/dashboard/templates/payout_bounty.html @@ -35,6 +35,7 @@ {% include 'shared/no_metamask_error.html' %} {% include 'shared/zero_balance_error.html' %} {% include 'shared/unlock_metamask.html' %} + {% include 'shared/connect_metamask.html' %}
{% include 'shared/success_container.html' %} diff --git a/app/dashboard/templates/process_bounty.html b/app/dashboard/templates/process_bounty.html index c9b0a1b1878..0617e75ede0 100644 --- a/app/dashboard/templates/process_bounty.html +++ b/app/dashboard/templates/process_bounty.html @@ -49,6 +49,7 @@ {% include 'shared/no_metamask_error.html' %} {% include 'shared/zero_balance_error.html' %} {% include 'shared/unlock_metamask.html' %} + {% include 'shared/connect_metamask.html' %}
diff --git a/app/dashboard/templates/shared/connect_metamask.html b/app/dashboard/templates/shared/connect_metamask.html new file mode 100644 index 00000000000..04c3cd0a4ac --- /dev/null +++ b/app/dashboard/templates/shared/connect_metamask.html @@ -0,0 +1,34 @@ +{% comment %} + Copyright (C) 2018 Gitcoin Core + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +{% endcomment %} +{% load i18n static %} + diff --git a/app/dashboard/templates/social_contribution.html b/app/dashboard/templates/social_contribution.html index 98c9dded434..adc07e5db59 100644 --- a/app/dashboard/templates/social_contribution.html +++ b/app/dashboard/templates/social_contribution.html @@ -36,6 +36,7 @@ {% include 'shared/no_metamask_error.html' %} {% include 'shared/zero_balance_error.html' %} {% include 'shared/unlock_metamask.html' %} + {% include 'shared/connect_metamask.html' %}
diff --git a/app/faucet/templates/faucet_form.html b/app/faucet/templates/faucet_form.html index a477701e021..0ad324a384e 100644 --- a/app/faucet/templates/faucet_form.html +++ b/app/faucet/templates/faucet_form.html @@ -32,9 +32,10 @@
- {% include 'shared/faucet_no_metamask_error.html' %} + {% include 'shared/no_metamask_error.html' %} + {% include 'shared/unlock_metamask.html' %} + {% include 'shared/connect_metamask.html' %} {% include 'shared/faucet_over_balance_error.html' %} - {% include 'shared/faucet_unlock_metamask.html' %}

{% trans "Faucet Request" %} {% trans "Alpha" %}

diff --git a/app/faucet/templates/shared/faucet_over_balance_error.html b/app/faucet/templates/shared/faucet_over_balance_error.html index 5313ef609c4..8036fc6420a 100644 --- a/app/faucet/templates/shared/faucet_over_balance_error.html +++ b/app/faucet/templates/shared/faucet_over_balance_error.html @@ -1,29 +1,41 @@ {% comment %} - Copyright (C) 2018 Gitcoin Core + Copyright (C) 2018 Gitcoin Core - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . {% endcomment %} {% load i18n static %} - +