Skip to content

Commit

Permalink
feat: configure frontend token symbol via command-line argument
Browse files Browse the repository at this point in the history
  • Loading branch information
iczc committed Sep 13, 2023
1 parent be15a21 commit 20f049d
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 20 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ Then run the faucet application without the wallet command-line flags:

The following are the available command-line flags(excluding above wallet flags):

| Flag | Description | Default Value |
|-----------------|--------------------------------------------------|----------------|
| -httpport | Listener port to serve HTTP connection | 8080 |
| -proxycount | Count of reverse proxies in front of the server | 0 |
| -queuecap | Maximum transactions waiting to be sent | 100 |
| -faucet.amount | Number of Ethers to transfer per user request | 1 |
| -faucet.minutes | Number of minutes to wait between funding rounds | 1440 |
| -faucet.name | Network name to display on the frontend | testnet |
| Flag | Description | Default Value |
|-----------------|--------------------------------------------------|---------------|
| -httpport | Listener port to serve HTTP connection | 8080 |
| -proxycount | Count of reverse proxies in front of the server | 0 |
| -queuecap | Maximum transactions waiting to be sent | 100 |
| -faucet.amount | Number of Ethers to transfer per user request | 1 |
| -faucet.minutes | Number of minutes to wait between funding rounds | 1440 |
| -faucet.name | Network name to display on the frontend | testnet |
| -faucet.symbol | Token symbol to display on the frontend | ETH |

### Docker deployment

Expand Down
3 changes: 2 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
payoutFlag = flag.Int("faucet.amount", 1, "Number of Ethers to transfer per user request")
intervalFlag = flag.Int("faucet.minutes", 1440, "Number of minutes to wait between funding rounds")
netnameFlag = flag.String("faucet.name", "testnet", "Network name to display on the frontend")
symbolFlag = flag.String("faucet.symbol", "ETH", "Token symbol to display on the frontend")

keyJSONFlag = flag.String("wallet.keyjson", os.Getenv("KEYSTORE"), "Keystore file to fund user requests with")
keyPassFlag = flag.String("wallet.keypass", "password.txt", "Passphrase text file to decrypt keystore")
Expand Down Expand Up @@ -57,7 +58,7 @@ func Execute() {
if err != nil {
panic(fmt.Errorf("cannot connect to web3 provider: %w", err))
}
config := server.NewConfig(*netnameFlag, *httpPortFlag, *intervalFlag, *payoutFlag, *proxyCntFlag, *queueCapFlag)
config := server.NewConfig(*netnameFlag, *symbolFlag, *httpPortFlag, *intervalFlag, *payoutFlag, *proxyCntFlag, *queueCapFlag)
go server.NewServer(txBuilder, config).Run()

c := make(chan os.Signal, 1)
Expand Down
4 changes: 3 additions & 1 deletion internal/server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package server

type Config struct {
network string
symbol string
httpPort int
interval int
payout int
proxyCount int
queueCap int
}

func NewConfig(network string, httpPort, interval, payout, proxyCount, queueCap int) *Config {
func NewConfig(network, symbol string, httpPort, interval, payout, proxyCount, queueCap int) *Config {
return &Config{
network: network,
symbol: symbol,
httpPort: httpPort,
interval: interval,
payout: payout,
Expand Down
1 change: 1 addition & 0 deletions internal/server/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type infoResponse struct {
Account string `json:"account"`
Network string `json:"network"`
Payout string `json:"payout"`
Symbol string `json:"symbol"`
}

type malformedRequest struct {
Expand Down
1 change: 1 addition & 0 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func (s *Server) handleInfo() http.HandlerFunc {
renderJSON(w, infoResponse{
Account: s.Sender().String(),
Network: s.cfg.network,
Symbol: s.cfg.symbol,
Payout: strconv.Itoa(s.cfg.payout),
}, http.StatusOK)
}
Expand Down
4 changes: 2 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"prettier": "prettier --write 'src/**/*.{css,html,js,svelte}'"
"prettier": "prettier --write --plugin prettier-plugin-svelte 'src/**/*.{css,html,js,svelte}'"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^2.4.5",
"prettier": "^3.0.0",
"prettier-plugin-svelte": "^2.9.0",
"prettier-plugin-svelte": "^3.0.0",
"svelte": "^4.1.2",
"vite": "^4.4.9"
},
Expand Down
13 changes: 9 additions & 4 deletions web/src/Faucet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
account: '0x0000000000000000000000000000000000000000',
network: 'testnet',
payout: 1,
symbol: 'ETH',
};
$: document.title = `ETH ${capitalize(faucetInfo.network)} Faucet`;
$: document.title = `${faucetInfo.symbol} ${capitalize(
faucetInfo.network,
)} Faucet`;
onMount(async () => {
const res = await fetch('/api/info');
Expand Down Expand Up @@ -80,7 +83,7 @@
<span class="icon">
<i class="fa fa-bath" />
</span>
<span><b>ETH Faucet</b></span>
<span><b>{faucetInfo.symbol} Faucet</b></span>
</a>
</div>
<div id="navbarMenu" class="navbar-menu">
Expand All @@ -106,7 +109,8 @@
<div class="container has-text-centered">
<div class="column is-6 is-offset-3">
<h1 class="title">
Receive {faucetInfo.payout} ETH per request
Receive {faucetInfo.payout}
{faucetInfo.symbol} per request
</h1>
<h2 class="subtitle">
Serving from {faucetInfo.account}
Expand Down Expand Up @@ -139,7 +143,8 @@

<style>
.hero.is-info {
background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)),
background:
linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)),
url('/background.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
Expand Down
8 changes: 4 additions & 4 deletions web/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -632,10 +632,10 @@ postcss@^8.4.27:
picocolors "^1.0.0"
source-map-js "^1.0.2"

prettier-plugin-svelte@^2.9.0:
version "2.10.1"
resolved "https://registry.yarnpkg.com/prettier-plugin-svelte/-/prettier-plugin-svelte-2.10.1.tgz#e1abbe5689e8a926c60b8bc42e61233556ca90d1"
integrity sha512-Wlq7Z5v2ueCubWo0TZzKc9XHcm7TDxqcuzRuGd0gcENfzfT4JZ9yDlCbEgxWgiPmLHkBjfOtpAWkcT28MCDpUQ==
prettier-plugin-svelte@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/prettier-plugin-svelte/-/prettier-plugin-svelte-3.0.3.tgz#a823295167f27dc71a4462ee6cb3da9f3f5ca2ea"
integrity sha512-dLhieh4obJEK1hnZ6koxF+tMUrZbV5YGvRpf2+OADyanjya5j0z1Llo8iGwiHmFWZVG/hLEw/AJD5chXd9r3XA==

prettier@^3.0.0:
version "3.0.3"
Expand Down

0 comments on commit 20f049d

Please sign in to comment.