From eb1a5177998d58b922c14951cd2772a85d683bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Est=C3=A1cio?= Date: Fri, 22 Dec 2023 20:21:01 -0300 Subject: [PATCH 1/6] feat: add redirect param --- static/index.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/static/index.html b/static/index.html index f76ec24..5647fd5 100644 --- a/static/index.html +++ b/static/index.html @@ -235,6 +235,7 @@

Test Ether sent to the wallet

let blockExplorer = "https://fuellabs.github.io/block-explorer-v2"; let query = params = new URLSearchParams(document.location.search); let address = query.get('address'); + let redirectUrl = decodeURIComponent(query.get('redirectUrl') || ''); if (address) { let $address = document.getElementById('address'); @@ -297,6 +298,9 @@

Test Ether sent to the wallet

).href = `${blockExplorer}/address/${address}?providerUrl=${encodeURIComponent( providerUrl )}`; + if (redirectUrl) { + location.href = redirectUrl; + } } else { document.getElementById("response-failure").innerText = data.error; hideWaiting(); From 19bb2971c0955ca7672b7205b488a3a9d3def21c Mon Sep 17 00:00:00 2001 From: luizstacio Date: Mon, 8 Jan 2024 13:11:25 -0300 Subject: [PATCH 2/6] feat: change from redirect url param to use document referrer --- README.md | 38 +++++++++++++++++++++++++------------- static/index.html | 8 ++++---- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 734503e..5f1ed3a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -Faucet App -=== +# Faucet App + [![build](https://github.com/FuelLabs/faucet/actions/workflows/ci.yml/badge.svg)](https://github.com/FuelLabs/faucet/actions/workflows/ci.yml) [![discord](https://img.shields.io/badge/chat%20on-discord-orange?&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/xfpK4Pe) @@ -7,20 +7,21 @@ A simple faucet app for dispensing tokens on a fuel network. It uses Google capt without requiring any social media based identification. ## Configuration + The faucet makes use of environment variables for configuration. -| Environment Variable | Description | -|----------------------|-------------------------------------------------------------------------| -| RUST_LOG | EnvFilter configuration for adjusting logging granularity. | -| HUMAN_LOGGING | If false, logs will be output as machine readable JSON. | -| CAPTCHA_SECRET | The secret key used for enabling Google captcha authentication. | -| CAPTCHA_KEY | The website key used for enabling Google captcha authentication. | -| WALLET_SECRET_KEY | A hex formatted string of the wallet private key that owns some tokens. | -| FUEL_NODE_URL | The GraphQL endpoint for connecting to fuel-core. | +| Environment Variable | Description | +| -------------------- | ----------------------------------------------------------------------------------------------- | +| RUST_LOG | EnvFilter configuration for adjusting logging granularity. | +| HUMAN_LOGGING | If false, logs will be output as machine readable JSON. | +| CAPTCHA_SECRET | The secret key used for enabling Google captcha authentication. | +| CAPTCHA_KEY | The website key used for enabling Google captcha authentication. | +| WALLET_SECRET_KEY | A hex formatted string of the wallet private key that owns some tokens. | +| FUEL_NODE_URL | The GraphQL endpoint for connecting to fuel-core. | | PUBLIC_FUEL_NODE_URL | The public GraphQL endpoint for connecting to fuel-core. Ex.: https://node.fuel.network/graphql | -| SERVICE_PORT | The port the service will listen for http connections on. | -| DISPENSE_AMOUNT | Dispense amount on each faucet | -| MIN_GAS_PRICE | The minimum gas price to use in each transfer | +| SERVICE_PORT | The port the service will listen for http connections on. | +| DISPENSE_AMOUNT | Dispense amount on each faucet | +| MIN_GAS_PRICE | The minimum gas price to use in each transfer | ## Build and Run @@ -29,3 +30,14 @@ To run locally, assuming environment variables have already been set: ```sh cargo run ``` + +## Query Params + +When integrating the faucet you can use the following query params: + +| Name | Type | Description | +| -------- | ------- | ------------------------------------------------------------------------------------------ | +| address | Address | Auto-fill the address field using the provided value | +| redirect | Boolean | If true once the faucet is complete, the user will be redirected back to the referrer page | + +Ex.: `http://localhost:3000/?address=fuel134ddh9pfsspar086htdldwxq2jsr3yvqtj5w456kkrz3s653la5q347kmc&redirect=true` diff --git a/static/index.html b/static/index.html index 5647fd5..1d510bb 100644 --- a/static/index.html +++ b/static/index.html @@ -233,9 +233,9 @@

Test Ether sent to the wallet

const faucetApp = (function () { let providerUrl = "{{ public_node_url }}"; let blockExplorer = "https://fuellabs.github.io/block-explorer-v2"; - let query = params = new URLSearchParams(document.location.search); + let query = new URLSearchParams(document.location.search); let address = query.get('address'); - let redirectUrl = decodeURIComponent(query.get('redirectUrl') || ''); + let shouldRedirect = query.get('redirect') === 'true'; if (address) { let $address = document.getElementById('address'); @@ -298,8 +298,8 @@

Test Ether sent to the wallet

).href = `${blockExplorer}/address/${address}?providerUrl=${encodeURIComponent( providerUrl )}`; - if (redirectUrl) { - location.href = redirectUrl; + if (shouldRedirect && document.referrer) { + location.href = document.referrer; } } else { document.getElementById("response-failure").innerText = data.error; From 0c1108c65b7377e2983e458188e40fd43f7b9656 Mon Sep 17 00:00:00 2001 From: luizstacio Date: Mon, 15 Jul 2024 17:33:01 -0300 Subject: [PATCH 3/6] chore: change docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3b3c87..0f0f619 100644 --- a/README.md +++ b/README.md @@ -40,4 +40,4 @@ When integrating the faucet you can use the following query params to enhance th | address | Address | Auto-fill the address field using the provided value | | redirectUrl | String | If provided with a valid url, once the faucet is complete, the user will be redirected back to the url with tx_id as a query param | -Ex.: `http://192.168.3.240:3003/?address=fuel134ddh9pfsspar086htdldwxq2jsr3yvqtj5w456kkrz3s653la5q347kmc&redirectUrl=http://localhost:4000` +Ex.: `http://localhost:3000/?address=fuel134ddh9pfsspar086htdldwxq2jsr3yvqtj5w456kkrz3s653la5q347kmc&redirectUrl=http://localhost:4000` From 01add847efa6ba995fb608b22ce9faf40525aecf Mon Sep 17 00:00:00 2001 From: luizstacio Date: Mon, 15 Jul 2024 17:39:47 -0300 Subject: [PATCH 4/6] chore: remove unsed var --- static/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/index.html b/static/index.html index 658d134..f444fba 100644 --- a/static/index.html +++ b/static/index.html @@ -292,7 +292,7 @@

Test Ether sent to the wallet

return !!document.getElementsByClassName("captcha-container")[0]; } - function showWaiting(text) { + function showWaiting() { if (hasCaptcha()) { document.getElementsByClassName("captcha-container")[0].classList.add("hidden"); } From e16ec6780ca34b178eb5649c4cc07a23a1f161c0 Mon Sep 17 00:00:00 2001 From: Matt Auer Date: Tue, 30 Jul 2024 21:26:09 -0500 Subject: [PATCH 5/6] chore: remove deprecated import --- tests/dispense.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/dispense.rs b/tests/dispense.rs index 03ddb0e..58bf2dd 100644 --- a/tests/dispense.rs +++ b/tests/dispense.rs @@ -24,7 +24,6 @@ use serde_json::json; use std::net::SocketAddr; use std::sync::{Arc, Mutex}; use std::time::Duration; -use std::usize; #[derive(Debug, Clone)] struct MockClock { From d5b3cbc5a27bd58c74ef5278e57173cd04d5f306 Mon Sep 17 00:00:00 2001 From: luizstacio Date: Wed, 31 Jul 2024 00:19:44 -0300 Subject: [PATCH 6/6] feat: add autoclose param --- README.md | 7 ++++++- static/index.html | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f0f619..a297284 100644 --- a/README.md +++ b/README.md @@ -39,5 +39,10 @@ When integrating the faucet you can use the following query params to enhance th | ----------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------- | | address | Address | Auto-fill the address field using the provided value | | redirectUrl | String | If provided with a valid url, once the faucet is complete, the user will be redirected back to the url with tx_id as a query param | +| autoClose | String | If provided empty or true will close automatically the window after the transaction is finished | -Ex.: `http://localhost:3000/?address=fuel134ddh9pfsspar086htdldwxq2jsr3yvqtj5w456kkrz3s653la5q347kmc&redirectUrl=http://localhost:4000` +### Example - Redirect +- `http://localhost:3000/?address=fuel134ddh9pfsspar086htdldwxq2jsr3yvqtj5w456kkrz3s653la5q347kmc&redirectUrl=http://localhost:4000` + +### Example - Auto Close +- `http://localhost:3000/?address=fuel134ddh9pfsspar086htdldwxq2jsr3yvqtj5w456kkrz3s653la5q347kmc&autoClose` diff --git a/static/index.html b/static/index.html index f444fba..8447edd 100644 --- a/static/index.html +++ b/static/index.html @@ -268,7 +268,9 @@

Test Ether sent to the wallet

let query = params = new URLSearchParams(document.location.search); let address = query.get('address'); let redirectUrl = query.get('redirectUrl'); + let autoClose = query.get('autoClose'); let buttonSubmit = form.querySelector("input[type=submit]"); + let shouldAutoClose = (autoClose === "" || autoClose === "true"); if (address) { let $address = document.getElementById('address'); @@ -342,6 +344,10 @@

Test Ether sent to the wallet

document.getElementById("form").hidden = true; document.getElementById("response").style.display = "block"; link.href = `${blockExplorer}/tx/${tx_id}`; + + if (shouldAutoClose) { + window.close(); + } if (redirectUrl) { try {