diff --git a/suchwowx/static/js/metamask.js b/suchwowx/static/js/metamask.js deleted file mode 100644 index 901bcc1..0000000 --- a/suchwowx/static/js/metamask.js +++ /dev/null @@ -1,92 +0,0 @@ -window.addEventListener('DOMContentLoaded', () => { - onboardMetaMask(); -}) - -async function getSignedData(publicAddress, jsonData) { - const signedData = await window.ethereum.request({ - method: 'eth_signTypedData_v3', - params: [publicAddress, JSON.stringify(jsonData)] - }); - console.log(signedData); - return signedData -} - -async function onboardMetaMask(){ - const onboarding = new MetaMaskOnboarding(); - const onboardButton = document.getElementById('metamaskConnect'); - let accounts; - let nonce = 0; - - const connectButton = async () => { - if (!MetaMaskOnboarding.isMetaMaskInstalled()) { - onboardButton.onclick = () => { - onboardButton.classList.add('is-loading'); - onboardButton.disabled = true; - onboarding.startOnboarding(); - }; - } else if (accounts && accounts.length > 0) { - onboardButton.classList.remove('is-loading'); - onboardButton.disabled = false; - onboarding.stopOnboarding(); - } else { - onboardButton.onclick = async () => { - try { - onboardButton.classList.add('is-loading'); - onboardButton.disabled = true; - let userExists; - await addAvalancheNetwork(); - const allAccounts = await window.ethereum.request({ - method: 'eth_requestAccounts', - }); - await fetch('/api/v1/user_exists?public_address=' + allAccounts[0]) - .then((resp) => resp.json()) - .then(function(data) { - if (!data['success']) { - console.log('error checking user_exists!') - return - } - console.log(data); - nonce = data['nonce']; - }) - - const msg = 'Authentication request from SuchWowX app! Verifying message with nonce ' + nonce - const signedData = await window.ethereum.request({ - method: 'personal_sign', - params: [msg, allAccounts[0]] - }); - console.log(`Signing data with msg "${msg}", address "${allAccounts[0]}", signed data: ${signedData}`) - - await fetch('/api/v1/authenticate/metamask', { - method: 'POST', - headers: { - 'Content-Type': 'application/json;charset=utf-8' - }, - body: JSON.stringify({ - 'signed_data': signedData, - 'public_address': allAccounts[0], - 'nonce': nonce, - 'message': msg, - }) - }) - .then((resp) => resp.json()) - .then(function(data) { - console.log(data); - if (data['success']) { - window.location.href = '/'; - } - }) - } catch(e) { - console.log(e); - onboardButton.classList.remove('is-loading'); - } - } - } - }; - - connectButton(); - if (MetaMaskOnboarding.isMetaMaskInstalled()) { - window.ethereum.on('accountsChanged', (newAccounts) => { - window.location.href = '/disconnect'; - }); - } -}; diff --git a/suchwowx/templates/includes/scripts.html b/suchwowx/templates/includes/scripts.html index 2d1cdd7..420ece5 100644 --- a/suchwowx/templates/includes/scripts.html +++ b/suchwowx/templates/includes/scripts.html @@ -1,12 +1,8 @@ + {% include 'includes/web3.html' %} -{% if not current_user.is_authenticated %} - - -{% endif %} - {% with messages = get_flashed_messages(with_categories=true) %} {% if messages %}