mirror of
https://github.com/oceanprotocol/faucet.git
synced 2024-11-22 01:36:57 +01:00
+ error handling
This commit is contained in:
parent
c6e11b3b17
commit
bc7c87bf89
@ -124,14 +124,6 @@
|
||||
margin-top: 5%;
|
||||
}
|
||||
|
||||
.success {
|
||||
color: "green";
|
||||
}
|
||||
|
||||
.error {
|
||||
color: "red";
|
||||
}
|
||||
|
||||
.balance {
|
||||
text-align: end;
|
||||
margin-top: 10px;
|
||||
@ -147,6 +139,7 @@
|
||||
border-color: #f0267e;
|
||||
}
|
||||
|
||||
.btn-primary:visited,
|
||||
.btn-primary:active {
|
||||
background-color: #7b1173;
|
||||
box-shadow: 0 5px #666;
|
||||
|
@ -48,16 +48,16 @@
|
||||
<button type="submit" class="btn btn-primary skip-dark" id="createBtn">Get 10 OCEAN</button>
|
||||
<h6 class="balance">Faucet Balance - <%= balance %> OCEAN</h6>
|
||||
</div>
|
||||
<% if(message && success) { %>
|
||||
<div class="notify text-center">
|
||||
<h5 class="success"><%= message %></h5>
|
||||
<% if(message) { %>
|
||||
<% if(status) { %>
|
||||
<h5 class="text-success"><%= message %></h5>
|
||||
<a target="_blank" href="https://rinkeby.etherscan.io/tx/<%= txHash %>"><%= txHash%></a>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<div class="notify text-center">
|
||||
<h5 class="error"><%= message %></h5>
|
||||
</div>
|
||||
<h5 class="text-danger"><%= message %></h5>
|
||||
<% } %>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
|
@ -24,11 +24,12 @@ app.use(bodyParser.urlencoded({ extended: false }));
|
||||
|
||||
app.get("/", async (req, res) => {
|
||||
let balance = await getBalance();
|
||||
res.render("index.ejs", { message: null, success: false, balance });
|
||||
res.render("index.ejs", { message: null, status: false, balance });
|
||||
});
|
||||
|
||||
app.get("/send", async (req, res) => {
|
||||
try {
|
||||
let balance = await getBalance();
|
||||
let ipAddress =
|
||||
req.headers["x-forwarded-for"] || req.connection.remoteAddress;
|
||||
console.log(`ip address - `, ipAddress);
|
||||
@ -38,7 +39,9 @@ app.get("/send", async (req, res) => {
|
||||
const from = process.env.FROM;
|
||||
const to = query.address;
|
||||
const value = web3.utils.toWei(process.env.TOKEN_AMOUNT, "ether");
|
||||
//check if its valid ETH address
|
||||
|
||||
if (web3.utils.isAddress(to)) {
|
||||
//check if this user is in cool down period
|
||||
await find(
|
||||
{
|
||||
@ -47,10 +50,9 @@ app.get("/send", async (req, res) => {
|
||||
async records => {
|
||||
console.log(records[0]);
|
||||
if (records[0] && !isAllowed(records[0].lastUpdatedOn)) {
|
||||
let balance = await getBalance();
|
||||
res.render("index.ejs", {
|
||||
message: "You have to wait 24 hours between faucet requests",
|
||||
success: false,
|
||||
status: false,
|
||||
balance
|
||||
});
|
||||
} else {
|
||||
@ -68,11 +70,10 @@ app.get("/send", async (req, res) => {
|
||||
.send({ from }, async function(error, txHash) {
|
||||
if (!error) {
|
||||
console.log("txHash - ", txHash);
|
||||
let balance = await getBalance();
|
||||
res.render("index.ejs", {
|
||||
message: `Great!! test OCEANs are on the way !!`,
|
||||
txHash,
|
||||
success: true,
|
||||
status: true,
|
||||
balance
|
||||
});
|
||||
} else {
|
||||
@ -82,6 +83,14 @@ app.get("/send", async (req, res) => {
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
//handle incorrect address response
|
||||
res.render("index.ejs", {
|
||||
message: `Please enter valid Ethereum Wallet Address`,
|
||||
status: false,
|
||||
balance
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user