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

refactor: fixup listen_for_web3_changes #6355

Merged
merged 2 commits into from
Apr 2, 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
2 changes: 1 addition & 1 deletion app/assets/onepager/js/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function sendTip(email, github_url, from_name, username, amount, comments_public
return;
}
// setup
var fromAccount = web3.eth.accounts[0];
var fromAccount = web3.eth.accounts[0] ? web3.eth.accounts[0] : document.web3_address;

if (typeof fromAccount == 'undefined') {
_alert({ message: gettext('You must unlock & enable Gitcoin via your web3 wallet to continue.') }, 'warning');
Expand Down
3 changes: 3 additions & 0 deletions app/assets/v2/js/activity.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint no-useless-concat: 0 */ // --> OFF
window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 5000);
Copy link
Contributor

Choose a reason for hiding this comment

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

note that this wont populate the web3 info for 5000ms after pageload. listen_for_web3_changes() should probably be called immediately upon load unless we re hoping that people dont interact with web3 for 5s.

});

$(document).ready(function() {

Expand Down
7 changes: 6 additions & 1 deletion app/assets/v2/js/grants/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ $(document).ready(function() {
currentNetwork(getNetwork(network));
});

web3.eth.getAccounts((error, accounts) => {
if (accounts && accounts[0]) {
document.web3_address = accounts[0];
}
});
} else {
currentNetwork('locked');
}
Expand All @@ -208,6 +213,6 @@ $(document).ready(function() {
});
};

setInterval(listen_web3_1_changes, 1000);
setInterval(listen_web3_1_changes, 5000);

});
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/bounty_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint no-loop-func: "warn" */

window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
setInterval(listen_for_web3_changes, 5000);
});

const _truthy = function(val) {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/bulk_payout.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
setInterval(listen_for_web3_changes, 5000);
});

const rateUser = (elem) => {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/cancel_bounty/ETH.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
setInterval(listen_for_web3_changes, 5000);
});

const ethCancelBounty = data => {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/faucet_form.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
setInterval(listen_for_web3_changes, 5000);
});

$('document').ready(function() {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/fulfill_bounty/ETH.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
setInterval(listen_for_web3_changes, 5000);
});

const ethFulfillBounty = data => {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/increase_bounty.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-lonely-if */
window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
setInterval(listen_for_web3_changes, 5000);
});

load_tokens();
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/process_bounty.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */

window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
setInterval(listen_for_web3_changes, 5000);
});

window.onload = function() {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/refund_request.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
setInterval(listen_for_web3_changes, 5000);
});

$(document).ready(function() {
Expand Down
9 changes: 0 additions & 9 deletions app/assets/v2/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,15 +1028,6 @@ var actions_page_warn_if_not_on_same_network = function() {

attach_change_element_type();

window.addEventListener('load', function() {
const listen = function() {
listen_for_web3_changes(true);
};

listen();
setInterval(listen, 5000);
});

var setUsdAmount = function() {
const amount = $('input[name=amount]').val();
const denomination = $('#token option:selected').text();
Expand Down
4 changes: 4 additions & 0 deletions app/dashboard/templates/onepager/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
protocol: "{{ ipfs_config.protocol }}",
root: "{{ ipfs_config.root }}"
};

window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 5000);
});
</script>
<script src="{% static "v2/js/metamask-approval.js" %}"></script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion app/retail/templates/pricing/subscribe.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ <h2 class="price">
<script>

window.addEventListener('load', function() {
setInterval(listen_for_web3_changes, 1000);
setInterval(listen_for_web3_changes, 5000);
});

$(document).ready(function() {
Expand Down