improve js and onboarding flow

main
lza_menace 3 years ago
parent 4ccd68abec
commit 2c2782797a

@ -6,3 +6,35 @@ async function getSignedData(publicAddress, jsonData) {
console.log(signedData);
return signedData
}
async function confirmAvalanche(){
try {
await ethereum.request({
method: 'wallet_switchEthereumChain',
params: [{ chainId: '0xA86A' }],
});
} catch (switchError) {
// This error code indicates that the chain has not been added to MetaMask.
if (switchError.code === 4902) {
try {
await ethereum.request({
method: 'wallet_addEthereumChain',
params: [{
chainId: '0xA86A',
chainName: 'Avalanche',
nativeCurrency: {
name: 'Avalanche',
symbol: 'AVAX',
decimals: 18,
},
rpcUrls: ['https://api.avax.network/ext/bc/C/rpc'],
blockExplorerUrls: ['https://snowtrace.io'],
}],
});
} catch (addError) {
// handle "add" error
}
}
// handle other "switch" errors
}
}

@ -1,5 +1,5 @@
window.addEventListener('DOMContentLoaded', () => {
onboardMetaMask()
onboardMetaMask();
})
async function onboardMetaMask(){
@ -25,6 +25,7 @@ async function onboardMetaMask(){
onboardButton.classList.add('is-loading');
onboardButton.disabled = true;
let userExists;
await confirmAvalanche();
const allAccounts = await window.ethereum.request({
method: 'eth_requestAccounts',
});

@ -11,7 +11,7 @@
<a class="button is-secondary" href="{{ url_for('user.show', handle=current_user.handle) }}" up-follow=".container" up-preload>Profile</a>
<a class="button is-danger" href="{{ url_for('meta.disconnect') }}">Disconnect</a>
{% if current_user.is_moderator() %}
<a class="button is-warning" href="{{ url_for('meme.mod') }}">Mod</a>
<a class="button is-warning" href="{{ url_for('meme.mod') }}" up-preload up-follow=".container">Mod</a>
{% endif %}
<a class="button is-primary" href="{{ url_for('meme.publish') }}">New Meme</a>
{% else %}

@ -1,10 +1,10 @@
<script src="/static/js/main.js"></script>
<script src="/static/js/vendor/noty-3.2.0.js"></script>
{% if not current_user.is_authenticated %}
<!-- <script src="/static/js/vendor/web3-1.3.6.min.js"></script> -->
<script src="/static/js/vendor/metamask-onboarding-1.0.1.bundle.js"></script>
<script src="/static/js/metamask.js"></script>
{% endif %}
<script src="/static/js/vendor/noty-3.2.0.js"></script>
<script src="/static/js/main.js"></script>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}

Loading…
Cancel
Save