This is an automated email from the ASF dual-hosted git repository.
toulmean pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git
The following commit(s) were added to refs/heads/master by this push:
new 38902fa add bootstrap css to wallet, make it look nicer, display
better errors
new 2ce67fc Merge pull request #193 from atoulme/wallet_ui
38902fa is described below
commit 38902fae1f13279f149289a1ac1db2048de621ec
Author: Antoine Toulme <[email protected]>
AuthorDate: Fri Jan 15 00:24:12 2021 -0800
add bootstrap css to wallet, make it look nicer, display better errors
---
eth-faucet/build.gradle | 2 +
.../org/apache/tuweni/faucet/FaucetApplication.kt | 6 +++
.../tuweni/faucet/controller/FaucetController.kt | 42 ++++++++++----------
.../tuweni/faucet/controller/FaucetRequest.kt | 2 +-
eth-faucet/src/main/resources/application.yml | 4 +-
eth-faucet/src/main/resources/templates/index.html | 46 ++++++++++++++--------
6 files changed, 63 insertions(+), 39 deletions(-)
diff --git a/eth-faucet/build.gradle b/eth-faucet/build.gradle
index 495cb9b..9915915 100644
--- a/eth-faucet/build.gradle
+++ b/eth-faucet/build.gradle
@@ -43,6 +43,8 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
+ implementation 'org.webjars:bootstrap'
+ implementation 'org.webjars:webjars-locator'
implementation project(':wallet')
implementation project(':bytes')
implementation project(':eth')
diff --git
a/eth-faucet/src/main/kotlin/org/apache/tuweni/faucet/FaucetApplication.kt
b/eth-faucet/src/main/kotlin/org/apache/tuweni/faucet/FaucetApplication.kt
index bcdf72d..350fcc7 100644
--- a/eth-faucet/src/main/kotlin/org/apache/tuweni/faucet/FaucetApplication.kt
+++ b/eth-faucet/src/main/kotlin/org/apache/tuweni/faucet/FaucetApplication.kt
@@ -120,6 +120,12 @@ class HtmlConfig() {
@Value("\${html.request_message}")
var requestMessage: String? = null
+ @Value("\${html.address_help}")
+ var addressHelp: String? = null
+
+ @Value("\${html.submit_button}")
+ var submitBtn: String? = null
+
@Value("\${faucet.maxETH}")
var maxETH: Long? = null
}
diff --git
a/eth-faucet/src/main/kotlin/org/apache/tuweni/faucet/controller/FaucetController.kt
b/eth-faucet/src/main/kotlin/org/apache/tuweni/faucet/controller/FaucetController.kt
index ff533ef..c1cb56a 100644
---
a/eth-faucet/src/main/kotlin/org/apache/tuweni/faucet/controller/FaucetController.kt
+++
b/eth-faucet/src/main/kotlin/org/apache/tuweni/faucet/controller/FaucetController.kt
@@ -33,24 +33,19 @@ import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.ModelAttribute
import org.springframework.web.bind.annotation.PostMapping
+import java.net.ConnectException
import javax.annotation.PostConstruct
val logger = LoggerFactory.getLogger("faucet")
@Controller
-class FaucetController {
-
- @Autowired
- val vertx: Vertx? = null
+class FaucetController(@Autowired val vertx: Vertx, @Autowired val wallet:
Wallet) {
var jsonrpcClient: JSONRPCClient? = null
@Value("\${faucet.chainId}")
var chainId: Int? = null
- @Autowired
- var wallet: Wallet? = null
-
@Value("\${faucet.gasPrice}")
var gasPrice: Long? = null
@@ -68,12 +63,12 @@ class FaucetController {
@PostConstruct
fun createClient() {
- jsonrpcClient = JSONRPCClient(vertx!!, rpcPort!!, rpcHost!!)
+ jsonrpcClient = JSONRPCClient(vertx, rpcPort!!, rpcHost!!)
}
@GetMapping("/")
fun index(model: Model): String {
- model.addAttribute("faucetRequest", FaucetRequest("", ""))
+ model.addAttribute("faucetRequest", FaucetRequest("", null, ""))
return "index"
}
@@ -85,6 +80,7 @@ class FaucetController {
addr = Address.fromHexString(request.addr ?: "")
} catch (e: IllegalArgumentException) {
request.message = e.message ?: "Invalid address"
+ request.alertClass = "alert-danger"
return "index"
}
try {
@@ -94,31 +90,37 @@ class FaucetController {
val lessThanMax = Wei.fromEth(maxETH!!).compareTo(balance) == 1
if (!lessThanMax) {
request.message = "Balance is more than this faucet gives."
+ request.alertClass = "alert-primary"
return@runBlocking "index"
}
val missing = Wei.fromEth(maxETH!!).subtract(balance)
- val nonce =
jsonrpcClient!!.getTransactionCount_latest(wallet!!.address())
+ val nonce =
jsonrpcClient!!.getTransactionCount_latest(wallet.address())
// Otherwise, send money with the faucet account.
logger.info("Sending $missing to $addr")
- val tx =
- wallet!!.sign(
- nonce,
- Wei.valueOf(gasPrice!!),
- Gas.valueOf(gas!!),
- addr,
- missing,
- Bytes.EMPTY,
- chainId!!
- )
+ val tx = wallet.sign(
+ nonce,
+ Wei.valueOf(gasPrice!!),
+ Gas.valueOf(gas!!),
+ addr,
+ missing,
+ Bytes.EMPTY,
+ chainId!!
+ )
logger.info("Transaction ready to send")
val txHash = jsonrpcClient!!.sendRawTransaction(tx)
logger.info("Transaction sent to client with hash $txHash")
request.message = "Transaction hash: $txHash"
+ request.alertClass = "alert-success"
return@runBlocking "index"
}
} catch (e: ClientRequestException) {
request.message = e.message
+ request.alertClass = "alert-danger"
+ return "index"
+ } catch (e: ConnectException) {
+ request.message = "Could not connect to a client. Try again later."
+ request.alertClass = "alert-danger"
return "index"
}
}
diff --git
a/eth-faucet/src/main/kotlin/org/apache/tuweni/faucet/controller/FaucetRequest.kt
b/eth-faucet/src/main/kotlin/org/apache/tuweni/faucet/controller/FaucetRequest.kt
index 094d53c..7e8c1a2 100644
---
a/eth-faucet/src/main/kotlin/org/apache/tuweni/faucet/controller/FaucetRequest.kt
+++
b/eth-faucet/src/main/kotlin/org/apache/tuweni/faucet/controller/FaucetRequest.kt
@@ -16,4 +16,4 @@
*/
package org.apache.tuweni.faucet.controller
-class FaucetRequest(var addr: String?, var message: String?)
+class FaucetRequest(var addr: String?, var message: String?, var alertClass:
String?)
diff --git a/eth-faucet/src/main/resources/application.yml
b/eth-faucet/src/main/resources/application.yml
index 6e18518..a4bd3c3 100644
--- a/eth-faucet/src/main/resources/application.yml
+++ b/eth-faucet/src/main/resources/application.yml
@@ -21,10 +21,12 @@ spring:
registration:
github:
clientId: 140f55b6cc1b06164bec
- clientSecret: f1d6b479b741021cbc6d518bcb10ecd34b6d4505
+ clientSecret: 8ffa8000b83d8b103bc4633fe308dc0b95fbd5e3
html:
title: Faucet
request_message: Welcome to our faucet. You can ask for up to 100 ETH on
this faucet.
+ address_help: Enter your Ethereum public address.
+ submit_button: Send 💵
auth:
org: apache
diff --git a/eth-faucet/src/main/resources/templates/index.html
b/eth-faucet/src/main/resources/templates/index.html
index 53af428..2684589 100644
--- a/eth-faucet/src/main/resources/templates/index.html
+++ b/eth-faucet/src/main/resources/templates/index.html
@@ -19,25 +19,37 @@ limitations under the License.
<head>
<title th:text="${@htmlConfig.title}"></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <link rel="stylesheet" th:href="@{/webjars/bootstrap/css/bootstrap.min.css}
"/>
</head>
<body>
-<h1 th:text="${@htmlConfig.title}"></h1>
-<h3 th:text="${@htmlConfig.requestMessage}"></h3>
+<div class="container">
+ <div class="jumbotron">
+ <h1 class="display-4" th:text="${@htmlConfig.title}"></h1>
+ <p class="lead" th:text="${@htmlConfig.requestMessage}"></p>
+ <hr class="my-4">
+ <p>Faucet information</p>
+ <ul>
+ <li>Address: <span th:text="${@wallet.address}"></span></li>
+ <li>ETH delivery max: <span th:text="${@htmlConfig.maxETH}"></span></li>
+ </ul>
+ <form action="#" th:action="@{/}" th:object="${faucetRequest}"
method="post">
+ <div class="alert" th:classappend="*{alertClass}" role="alert"
th:text="*{message}">
+ </div>
+ <h4 class=""></h4>
+ <input
+ type="hidden"
+ th:name="${_csrf.parameterName}"
+ th:value="${_csrf.token}"/>
+ <div class="form-group">
+ <input class="form-control" id="address"
aria-describedby="addressHelp" type="text" th:field="*{addr}"/>
+ <small id="addressHelp" class="form-text text-muted"
th:text="${@htmlConfig.addressHelp}"></small>
+ </div>
+ <button class="btn btn-primary" type="submit"
th:text="${@htmlConfig.submitBtn}"></button>
+ </form>
+ </div>
-<form action="#" th:action="@{/}" th:object="${faucetRequest}" method="post">
- <h4 th:text="*{message}"></h4>
- <input
- type="hidden"
- th:name="${_csrf.parameterName}"
- th:value="${_csrf.token}" />
- <p>Address: <input type="text" th:field="*{addr}"/></p>
- <p><input type="submit" value="Submit"/> <input type="reset"
value="Reset"/></p>
-</form>
-
-<p>Faucet information</p>
-<ul>
- <li>Address: <span th:text="${@wallet.address}"></span></li>
- <li>ETH delivery max: <span th:text="${@htmlConfig.maxETH}"></span></li>
-</ul>
+ <script th:src="@{/webjars/jquery/jquery.min.js}"></script>
+ <script th:src="@{/webjars/bootstrap/js/bootstrap.min.js}"></script>
+</div>
</body>
</html>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]