Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add eslint to explorer #3648

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions applications/tari_explorer/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"plugins": ["prettier", "@babel"],
"env": {
"browser": true,
"commonjs": true,
"node": true,
"es2021": true
},
"parser": "@babel/eslint-parser", // Tell ESLint that you want to use the @babel/eslint-parser.
"parserOptions": {
"ecmaVersion": 2021,
"sourceType": "module",
"allowImportExportEverywhere": false,
"ecmaFeatures": {
"globalReturn": false
},
"requireConfigFile": false
},
"rules": {
"no-undef": "error",
"no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
],
"prettier/prettier": [
"error",
{
"doubleQuote": true,
"endOfLine": "auto"
}
]
}
}
4 changes: 4 additions & 0 deletions applications/tari_explorer/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"endOfLine": "auto",
"semi": false
}
5 changes: 4 additions & 1 deletion applications/tari_explorer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
## No client-side JavaScript block explorer

### Dependencies

- `npm i`

### Development (nodemon reload)

- `npm run dev`

### Start server
- `npm start`

- `npm start`
102 changes: 51 additions & 51 deletions applications/tari_explorer/app.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
const createError = require("http-errors");
const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const logger = require("morgan");
const asciichart = require("asciichart");
const createError = require("http-errors")
const express = require("express")
const path = require("path")
const cookieParser = require("cookie-parser")
const logger = require("morgan")
const asciichart = require("asciichart")

var indexRouter = require("./routes/index");
var blocksRouter = require("./routes/blocks");
var mempoolRouter = require("./routes/mempool");
var indexRouter = require("./routes/index")
var blocksRouter = require("./routes/blocks")
var mempoolRouter = require("./routes/mempool")

var hbs = require("hbs");
var hbs = require("hbs")
hbs.registerHelper("hex", function (buffer) {
return buffer ? Buffer.from(buffer).toString("hex") : "";
});
return buffer ? Buffer.from(buffer).toString("hex") : ""
})
hbs.registerHelper("json", function (obj) {
return Buffer.from(JSON.stringify(obj)).toString("base64");
});
return Buffer.from(JSON.stringify(obj)).toString("base64")
})

hbs.registerHelper("timestamp", function (timestamp) {
var dateObj = new Date(timestamp.seconds * 1000);
const day = dateObj.getUTCDate();
const month = dateObj.getUTCMonth() + 1;
const year = dateObj.getUTCFullYear();
const hours = dateObj.getUTCHours();
const minutes = dateObj.getUTCMinutes();
const seconds = dateObj.getSeconds();
var dateObj = new Date(timestamp.seconds * 1000)
const day = dateObj.getUTCDate()
const month = dateObj.getUTCMonth() + 1
const year = dateObj.getUTCFullYear()
const hours = dateObj.getUTCHours()
const minutes = dateObj.getUTCMinutes()
const seconds = dateObj.getSeconds()

return (
year.toString() +
Expand All @@ -38,57 +38,57 @@ hbs.registerHelper("timestamp", function (timestamp) {
minutes.toString().padStart(2, "0") +
":" +
seconds.toString().padStart(2, "0")
);
});
)
})

hbs.registerHelper("percentbar", function (a, b) {
var percent = (a / (a + b)) * 100;
var barWidth = percent / 10;
var bar = "**********".slice(0, barWidth);
var space = "...........".slice(0, 10 - barWidth);
return bar + space + " " + parseInt(percent) + "% ";
});
var percent = (a / (a + b)) * 100
var barWidth = percent / 10
var bar = "**********".slice(0, barWidth)
var space = "...........".slice(0, 10 - barWidth)
return bar + space + " " + parseInt(percent) + "% "
})

hbs.registerHelper("chart", function (data, height) {
return asciichart.plot(data, {
height: height,
});
});
})
})

var app = express();
var app = express()

// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "hbs");
app.set("views", path.join(__dirname, "views"))
app.set("view engine", "hbs")

app.use(logger("dev"));
app.use(express.json());
app.use(logger("dev"))
app.use(express.json())
app.use(
express.urlencoded({
extended: false,
})
);
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public")));
)
app.use(cookieParser())
app.use(express.static(path.join(__dirname, "public")))

app.use("/", indexRouter);
app.use("/blocks", blocksRouter);
app.use("/mempool", mempoolRouter);
app.use("/", indexRouter)
app.use("/blocks", blocksRouter)
app.use("/mempool", mempoolRouter)

// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404));
});
next(createError(404))
})

// error handler
app.use(function (err, req, res, next) {
app.use(function (err, req, res) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};
res.locals.message = err.message
res.locals.error = req.app.get("env") === "development" ? err : {}

// render the error page
res.status(err.status || 500);
res.render("error");
});
res.status(err.status || 500)
res.render("error")
})

module.exports = app;
module.exports = app
7 changes: 3 additions & 4 deletions applications/tari_explorer/baseNodeClient.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
var {Client} = require("base-node-grpc-client");
var { Client } = require("base-node-grpc-client")

function createClient() {
return Client.connect("localhost:18142");
return Client.connect("localhost:18142")
}

module.exports = {
createClient
createClient,
}

Loading