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

Fix notlogged #6467

Merged
merged 7 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions app/assets/v2/js/pages/bounty_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,40 +560,40 @@ var showWarningMessage = function(txid) {
};

// refresh page if metamask changes
waitforWeb3(function() {
setInterval(function() {
if (document.web3Changed) {
return;
}
reloadCbAddress();

if (typeof document.lastWeb3Network == 'undefined') {
document.lastWeb3Network = document.web3network;
return;
}

if (typeof document.lastCoinbase == 'undefined') {

web3.eth.getCoinbase(function(error, coinbase) {
if (error) {
console.log('web3.eth.coinbase could not be loaded');
document.lastCoinbase = null;
return;
}
document.lastCoinbase = coinbase;
});
return;
}

if (web3 && (document.lastCoinbase != cb_address) ||
(document.lastWeb3Network != document.web3network)) {
_alert(gettext('Detected a web3 change. Refreshing the page. '), 'info');
document.location.reload();
document.web3Changed = true;
}

}, 500);
});
// waitforWeb3(function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we want to save this for later?

// setInterval(function() {
// if (document.web3Changed) {
// return;
// }
// reloadCbAddress();

// if (typeof document.lastWeb3Network == 'undefined') {
// document.lastWeb3Network = document.web3network;
// return;
// }

// if (typeof document.lastCoinbase == 'undefined') {

// web3.eth.getCoinbase(function(error, coinbase) {
// if (error) {
// console.log('web3.eth.coinbase could not be loaded');
// document.lastCoinbase = null;
// return;
// }
// document.lastCoinbase = coinbase;
// });
// return;
// }

// if (web3 && (document.lastCoinbase != cb_address) ||
// (document.lastWeb3Network != document.web3network)) {
// _alert(gettext('Detected a web3 change. Refreshing the page. '), 'info');
// document.location.reload();
// document.web3Changed = true;
// }

// }, 500);
// });

var wait_for_tx_to_mine_and_then_ping_server = function() {
console.log('checking for updates');
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/fulfill_bounty/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ window.onload = function() {
const fetchFromWeb3Wallet = () => {
web3.eth.getAccounts(function(_, accounts) {
$('#payoutAddress').val(accounts[0]);
$('#payoutAddress').attr('disabled', true);
$('#payoutAddress').attr('readonly', true);
});
}
4 changes: 2 additions & 2 deletions app/assets/v2/js/pages/kudos_send.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ function sendKudos(email, github_url, from_name, username, amountInEth, comments
if ($('.redemptions select').length) {
num_redemptions = $('.redemptions select').val();
}

web3.eth.getCoinbase(function(_, account) {
var formbody = {
username: username,
Expand Down Expand Up @@ -647,7 +647,7 @@ function sendKudos(email, github_url, from_name, username, amountInEth, comments
// web3.currentProvider.publicConfigStore.on('update', function(e) {
var error;

if (window.ethereum.publicConfigStore) {
if (window.ethereum && window.ethereum.publicConfigStore) {
window.ethereum.publicConfigStore.on('update', checkNetwork);
}
function checkNetwork(e) {
Expand Down
102 changes: 48 additions & 54 deletions app/assets/v2/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ var reloadCbAddress = function() {
return;
}
web3.eth.getCoinbase(function(error, result) {
// console.log(error, result)
if (!error) {
cb_address = result;
} else {
Expand All @@ -91,6 +92,53 @@ var reloadCbAddress = function() {

reloadCbAddress();


const Web3Modal = window.Web3Modal.default;

window.Web3Modal.providers.push({
id: 'injected',
name: 'QRcode',
logo: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='512' height='512' fill='none'%3E%3Cpath fill='url(%23paint0_radial)' fill-rule='evenodd' d='M256 0c141.385 0 256 114.615 256 256S397.385 512 256 512 0 397.385 0 256 114.615 0 256 0z' clip-rule='evenodd'/%3E%3Cpath fill='%23fff' d='M165 243v-78h78v78h-78zm16.25-61.75v45.5h45.5v-45.5h-45.5zM269 165h78v78h-78v-78zm61.75 61.75v-45.5h-45.5v45.5h45.5zM165 347v-78h78v78h-78zm16.25-61.75v45.5h45.5v-45.5h-45.5zm13 13h19.5v19.5h-19.5v-19.5zm0-104h19.5v19.5h-19.5v-19.5zm123.5 19.5h-19.5v-19.5h19.5v19.5zM334 269h13v52h-52v-13h-13v39h-13v-78h39v13h26v-13zm0 65h13v13h-13v-13zm-26 0h13v13h-13v-13z'/%3E%3Cdefs%3E%3CradialGradient id='paint0_radial' cx='0' cy='0' r='1' gradientTransform='translate(9.283 256) scale(502.717)' gradientUnits='userSpaceOnUse'%3E%3Cstop stop-color='%237C89FF'/%3E%3Cstop offset='1' stop-color='%231E34FF'/%3E%3C/radialGradient%3E%3C/defs%3E%3C/svg%3E",
type: 'injected',
check: 'isQRcode',
styled: {
noShadow: true
}
});

// Determine if we're on prod or not
const isProd = document.location.href.startsWith('https://gitcoin.co');
const formaticKey = isProd ? document.contxt['fortmatic_live_key'] : document.contxt['fortmatic_test_key'];
const providerOptions = {
authereum: {
'package': Authereum
},
fortmatic: {
'package': Fortmatic,
options: {
key: formaticKey
}
}
};
const network = isProd ? 'mainnet' : 'rinkeby';

const web3Modal = new Web3Modal({
network,
cacheProvider: true,
providerOptions
});

// const provider = await web3Modal.connect();
function qrcodeConnect() {
localStorage['WEB3_CONNECT_CACHED_PROVIDER'] = '"injected"';
web3Modal.toggleModal();
}

web3Modal.providers.push({name: 'QRcode', onClick: qrcodeConnect});
web3Modal.connect().then(function(provider) {
window.web3 = new Web3(provider);
});

var update_metamask_conf_time_and_cost_estimate = function() {
var confTime = 'unknown';
var ethAmount = 'unknown';
Expand Down Expand Up @@ -1077,60 +1125,6 @@ var actions_page_warn_if_not_on_same_network = function() {

attach_change_element_type();

Web3Modal.providers.push({
id: 'injected',
name: 'QRcode',
logo: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='512' height='512' fill='none'%3E%3Cpath fill='url(%23paint0_radial)' fill-rule='evenodd' d='M256 0c141.385 0 256 114.615 256 256S397.385 512 256 512 0 397.385 0 256 114.615 0 256 0z' clip-rule='evenodd'/%3E%3Cpath fill='%23fff' d='M165 243v-78h78v78h-78zm16.25-61.75v45.5h45.5v-45.5h-45.5zM269 165h78v78h-78v-78zm61.75 61.75v-45.5h-45.5v45.5h45.5zM165 347v-78h78v78h-78zm16.25-61.75v45.5h45.5v-45.5h-45.5zm13 13h19.5v19.5h-19.5v-19.5zm0-104h19.5v19.5h-19.5v-19.5zm123.5 19.5h-19.5v-19.5h19.5v19.5zM334 269h13v52h-52v-13h-13v39h-13v-78h39v13h26v-13zm0 65h13v13h-13v-13zm-26 0h13v13h-13v-13z'/%3E%3Cdefs%3E%3CradialGradient id='paint0_radial' cx='0' cy='0' r='1' gradientTransform='translate(9.283 256) scale(502.717)' gradientUnits='userSpaceOnUse'%3E%3Cstop stop-color='%237C89FF'/%3E%3Cstop offset='1' stop-color='%231E34FF'/%3E%3C/radialGradient%3E%3C/defs%3E%3C/svg%3E",
type: 'injected',
check: 'isQRcode',
styled: {
noShadow: true
}
});


$(document).ready(function() {
// Don't prompt user if they are not logged in
if (!document.contxt.github_handle) {
return;
}
// const Web3Modal = window.Web3Modal.default;
const Web3Modal = window.Web3Modal.default;
// Determine if we're on prod or not
const isProd = document.location.href.startsWith('https://gitcoin.co');
const formaticKey = isProd ? document.contxt['fortmatic_live_key'] : document.contxt['fortmatic_test_key'];
const providerOptions = {
authereum: {
'package': Authereum
},
fortmatic: {
'package': Fortmatic,
options: {
key: formaticKey
}
}
};
const network = isProd ? 'mainnet' : 'rinkeby';

window.web3Modal = new Web3Modal({
network,
cacheProvider: true,
providerOptions
});

// const provider = await web3Modal.connect();
function qrcodeConnect() {
localStorage['WEB3_CONNECT_CACHED_PROVIDER'] = '"injected"';
web3Modal.toggleModal();
}

window.web3Modal.providers.push({name: 'QRcode', onClick: qrcodeConnect});
web3Modal.connect().then(function(provider) {
window.web3 = new Web3(provider);
});

});

var setUsdAmount = function() {
const amount = $('input[name=amount]').val();
const denomination = $('#token option:selected').text();
Expand Down
8 changes: 3 additions & 5 deletions app/retail/templates/shared/footer_scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
document.contxt = {{ json_context|safe }};
</script>
<script src="{% url 'javascript-catalog' %}"></script>
{% if not ignore_inject_web3 %}
{% include 'shared/shared_scripts.html' %}
{% endif %}
<script src="{% static "v2/js/lib/jquery.js" %}"></script>
{% if env == 'prod' %}
<script src="{% static 'v2/js/lib/vue.js' %}"></script>
Expand Down Expand Up @@ -73,11 +76,6 @@
{% endif %}
<script src="{% static "cookielaw/js/cl.js" %}"></script>

{% if not ignore_inject_web3 %}
{% include 'shared/shared_scripts.html' %}
{% endif %}


<script>
var host = ("{{ ipfs_config.host }}" == "ipfs" ? "localhost" : "{{ ipfs_config.host }}");
var ipfsConfig = {
Expand Down
6 changes: 3 additions & 3 deletions app/retail/templates/shared/footer_scripts_lite.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
document.contxt = {{ json_context|safe }};
</script>
<script src="{% url 'javascript-catalog' %}"></script>
{% if not ignore_inject_web3 %}
{% include 'shared/shared_scripts.html' %}
{% endif %}
<script src="{% static "v2/js/lib/jquery.js" %}"></script>
{% if env == 'prod' %}
<script src="{% static 'v2/js/lib/vue.js' %}"></script>
Expand Down Expand Up @@ -60,9 +63,6 @@

<script src="{% static "cookielaw/js/cl.js" %}"></script>
<script defer src="{% static "v2/js/work_with_gitcoin.js" %}"></script>
{% if not ignore_inject_web3 %}
{% include 'shared/shared_scripts.html' %}
{% endif %}

<script>
var host = ("{{ ipfs_config.host }}" == "ipfs" ? "localhost" : "{{ ipfs_config.host }}");
Expand Down
2 changes: 1 addition & 1 deletion app/retail/templates/shared/shared_scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{% endcomment %}
{% load static %}

<script src="{% static "v2/js/lib/web3.0.20.6.min.js" %}"></script>
<script src="{% static "v2/js/lib/web3.0.20.7.min.js" %}"></script>
<script>
var web3 = window.web3 ? new Web3(window.web3.currentProvider) : new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/v3/{{INFURA_V3_PROJECT_ID}}"));
</script>