diff --git a/frontend/src/main.js b/frontend/src/main.js
index 07cde29..c353295 100644
--- a/frontend/src/main.js
+++ b/frontend/src/main.js
@@ -1,34 +1,6 @@
import axios from 'axios'
-document.querySelector('#faucetForm').addEventListener('submit', (event) => {
- event.preventDefault()
- const form = document.querySelector('#faucetForm')
- const amount = form.dataset.amount
- const explorerURL = form.dataset.explorerUrl
- const account = document.querySelector('#recipientAddress').value
- const resultEl = document.querySelector('#result')
- showResult(resultEl)
- document.querySelector('#result').innerHTML = `
-
-
Adding ${amount} to:
- ${account}
-
-
`
- axios.post('/account/' + account)
- .then(function (response) {
- resultEl.innerHTML = `Added ${amount}!
-
Transaction: ${response.data.tx_hash}
-
Account: ${account}
-
Balance: ${(response.data.balance / 1000000000000000000)} AE
`
- })
- .catch(function (error) {
- resultEl.innerHTML = `Something went wrong. ¯\\_(ツ)_/¯
- ${error.response.data.message}
- Please try again later.`
- console.log(error)
- })
-})
-const showResult = function (resultEl) {
+function showResult(resultEl) {
const className = 'hidden'
if (resultEl.classList) {
resultEl.classList.remove('hidden', 'lg:hidden')
@@ -36,3 +8,51 @@ const showResult = function (resultEl) {
resultEl.className = resultEl.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ')
}
}
+
+function passQueryAccountAddressToInput(inputEl) {
+ const urlParams = new URLSearchParams(window.location.search)
+ const address = urlParams.get('address')
+ if (address) {
+ inputEl.value = address
+ }
+}
+
+
+document.addEventListener('DOMContentLoaded', () => {
+ const form = document.querySelector('#faucetForm')
+ const recipientEl = document.querySelector('#recipientAddress')
+ const resultEl = document.querySelector('#result')
+
+ passQueryAccountAddressToInput(recipientEl)
+
+ form.addEventListener('submit', (event) => {
+ event.preventDefault()
+
+ const account = recipientEl.value
+ const amount = form.dataset.amount
+ const explorerURL = form.dataset.explorerUrl
+
+ showResult(resultEl)
+
+ resultEl.innerHTML = `
+
+
Adding ${amount} AE to:
+ ${account}
+
+
`
+
+ axios.post('/account/' + account)
+ .then(function (response) {
+ resultEl.innerHTML = `Added ${amount}!
+
Transaction: ${response.data.tx_hash}
+
Account: ${account}
+
Balance: ${(response.data.balance / 1000000000000000000)} AE
`
+ })
+ .catch(function (error) {
+ resultEl.innerHTML = `Something went wrong. ¯\\_(ツ)_/¯
+ ${error.response.data.message}
+ Please try again later.`
+ console.log(error)
+ })
+ })
+});