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

migrate to web3modal #6454

Merged
merged 1 commit into from
Apr 17, 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 .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ app/assets/v2/js/lib/highlight.js
app/assets/v2/js/lib/tooltip.js
app/assets/v2/js/lib/tweenlite.js
app/assets/v2/js/lib/web3.0.20.7.js
app/assets/v2/js/lib/web3connect.js
app/assets/v2/js/lib/web3modal.min.js
app/assets/v2/js/abi.js

app/assets/onepager/js/confetti.js
Expand Down
54 changes: 0 additions & 54 deletions app/assets/v2/js/lib/web3connect.js

This file was deleted.

54 changes: 54 additions & 0 deletions app/assets/v2/js/lib/web3modal.min.js

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions app/assets/v2/js/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,8 @@ const randomElement = array => {
};

$('#change-wallet').click(function(_) {
web3connect.clearCachedProvider();
web3connect.connect().then(function(provider) {
web3Modal.clearCachedProvider();
web3Modal.connect().then(function(provider) {
window.web3 = new Web3(provider);
});
});
Expand Down Expand Up @@ -725,11 +725,11 @@ var currentNetwork = function(network, no_ui_updates) {
$('#navbar-network-banner').removeClass('network-banner--warning');
$('#navbar-network-banner').addClass('hidden');

if (web3connect.cachedProvider === 'authereum') {
if (web3Modal.cachedProvider === 'authereum') {
$('#current-network').text('Main Ethereum Network (Authereum)');
$('#go-to-wallet').removeClass('hidden');
$('#go-to-wallet').attr('href', 'https://authereum.com/account');
} else if (web3connect.cachedProvider === 'fortmatic') {
} else if (web3Modal.cachedProvider === 'fortmatic') {
$('#current-network').text('Main Ethereum Network (Fortmatic)');
$('#go-to-wallet').removeClass('hidden');
$('#go-to-wallet').attr('href', 'https://app.zerion.io/' + cb_address + '/overview');
Expand All @@ -743,7 +743,7 @@ var currentNetwork = function(network, no_ui_updates) {
'<a href="https://metamask.io/?utm_source=gitcoin.co&utm_medium=referral" target="_blank" rel="noopener noreferrer">Metamask</a>';
$('#current-network').text(gettext('Metamask Not Enabled'));
$('#navbar-network-banner').html(info);
} else if (network == 'locked' && web3connect.cachedProvider === 'injected') {
} else if (network == 'locked' && web3Modal.cachedProvider === 'injected') {
if (is_metamask_approved || !is_metamask_unlocked) {
info = gettext('Web3 locked. Please unlock ') +
'<a href="https://metamask.io/?utm_source=gitcoin.co&utm_medium=referral" target="_blank" rel="noopener noreferrer">Metamask</a>';
Expand Down Expand Up @@ -778,11 +778,11 @@ var currentNetwork = function(network, no_ui_updates) {
$('#navbar-network-banner').removeClass('network-banner--warning');
$('#navbar-network-banner').addClass('hidden');

if (web3connect.cachedProvider === 'authereum') {
if (web3Modal.cachedProvider === 'authereum') {
$('#current-network').text('Rinkeby Network (Authereum)');
$('#go-to-wallet').removeClass('hidden');
$('#go-to-wallet').attr('href', 'https://rinkeby.authereum.com/account');
} else if (web3connect.cachedProvider === 'fortmatic') {
} else if (web3Modal.cachedProvider === 'fortmatic') {
$('#current-network').text('Rinkeby Network (Fortmatic)');
$('#go-to-wallet').removeClass('hidden');
$('#go-to-wallet').attr('href', 'https://rinkeby.etherscan.io/address/' + cb_address);
Expand All @@ -796,7 +796,7 @@ var currentNetwork = function(network, no_ui_updates) {
'<a href="https://metamask.io/?utm_source=gitcoin.co&utm_medium=referral" target="_blank" rel="noopener noreferrer">Metamask</a>';
$('#current-network').text(gettext('Metamask Not Enabled'));
$('#navbar-network-banner').html(info);
} else if (network == 'locked' && web3connect.cachedProvider === 'injected') {
} else if (network == 'locked' && web3Modal.cachedProvider === 'injected') {
if (is_metamask_approved || !is_metamask_unlocked) {
info = gettext('Web3 locked. Please unlock ') +
'<a href="https://metamask.io/?utm_source=gitcoin.co&utm_medium=referral" target="_blank" rel="noopener noreferrer">Metamask</a>';
Expand Down Expand Up @@ -1018,7 +1018,7 @@ var listen_for_web3_changes = async function(no_ui_updates) {
}
}

if (web3connect.cachedProvider === 'injected' && window.ethereum && !document.has_checked_for_ethereum_enable) {
if (web3Modal.cachedProvider === 'injected' && window.ethereum && !document.has_checked_for_ethereum_enable) {
if (window.ethereum._metamask) {
document.has_checked_for_ethereum_enable = true;
is_metamask_approved = await window.ethereum._metamask.isApproved();
Expand Down Expand Up @@ -1069,7 +1069,7 @@ var actions_page_warn_if_not_on_same_network = function() {

attach_change_element_type();

Web3Connect.default.providers.push({
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",
Expand All @@ -1086,7 +1086,8 @@ $(document).ready(function() {
if (!document.contxt.github_handle) {
return;
}
const Web3Connect = window.Web3Connect.default;
// 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'];
Expand All @@ -1103,19 +1104,20 @@ $(document).ready(function() {
};
const network = isProd ? 'mainnet' : 'rinkeby';

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

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

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

Expand Down Expand Up @@ -1554,7 +1556,7 @@ const caseInsensitiveCompare = (val1, val2) => {
*/
const indicateMetamaskPopup = (closePopup) => {
// Don't show popup if user is not using Metamask
if (web3connect.cachedProvider !== 'injected') {
if (web3Modal.cachedProvider !== 'injected') {
return;
}

Expand Down
3 changes: 3 additions & 0 deletions app/retail/templates/shared/footer_scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
$.fn.bootstrapModal = bootstrapModal;

</script>
<script src="{% static "v2/js/lib/web3modal.min.js" %}"></script>
<script src="{% static "v2/js/lib/authereum.js" %}"></script>
<script src="{% static "v2/js/lib/fortmatic.js" %}"></script>

<script src="{% static "v2/js/lib/jquery.cookie.js" %}"></script>
{% if not slim %}
Expand Down
4 changes: 4 additions & 0 deletions app/retail/templates/shared/footer_scripts_lite.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
const bootstrapTooltip = $.fn.tooltip.noConflict()
$.fn.bootstrapTooltip = bootstrapTooltip;
</script>
<script src="{% static "v2/js/lib/web3modal.min.js" %}"></script>
<script src="{% static "v2/js/lib/authereum.js" %}"></script>
<script src="{% static "v2/js/lib/fortmatic.js" %}"></script>

<script src="{% static "v2/js/lib/jquery.cookie.js" %}"></script>
<script src="{% static "v2/js/lib/jquery.select2.min.js" %}"></script>
<script src="{% static "v2/js/lib/moment.min.js" %}"></script>
Expand Down
3 changes: 0 additions & 3 deletions app/retail/templates/shared/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@
{% if meta_title %}<meta name="title" content="{{meta_title}}" />{% endif %}
{% if meta_description %}<meta name="description" content="{{meta_description}}" />{% endif %}
<script async src="{% static "v2/js/metamask-approval.js" %}"></script>
<script src="{% static "v2/js/lib/web3connect.js" %}"></script>
<script src="{% static "v2/js/lib/authereum.js" %}"></script>
<script src="{% static "v2/js/lib/fortmatic.js" %}"></script>

{% if env == 'prod' %}
<!-- Hotjar Tracking Code for gitcoin.co -->
Expand Down