Skip to content

Commit

Permalink
feat: change from redirect url param to use document referrer
Browse files Browse the repository at this point in the history
  • Loading branch information
luizstacio committed Jan 8, 2024
1 parent eb1a517 commit 19bb297
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
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)

A simple faucet app for dispensing tokens on a fuel network. It uses Google captcha for spam resistance
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

Expand All @@ -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`
8 changes: 4 additions & 4 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ <h2 class="response-title">Test Ether sent to the wallet</h2>
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');
Expand Down Expand Up @@ -298,8 +298,8 @@ <h2 class="response-title">Test Ether sent to the wallet</h2>
).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;
Expand Down

0 comments on commit 19bb297

Please sign in to comment.