diff --git a/Cargo.lock b/Cargo.lock index 88d9d5f..eaa258b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -831,6 +831,7 @@ dependencies = [ "serde", "serde_json", "shellexpand", + "tera_thousands", ] [[package]] @@ -2273,6 +2274,16 @@ dependencies = [ "unic-segment", ] +[[package]] +name = "tera_thousands" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1087c29fa0b4b12ccd41617704e3f89237616185ce11359b433af67fd04ff332" +dependencies = [ + "tera", + "thousands", +] + [[package]] name = "thiserror" version = "1.0.63" @@ -2293,6 +2304,12 @@ dependencies = [ "syn", ] +[[package]] +name = "thousands" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" + [[package]] name = "thread_local" version = "1.1.8" diff --git a/Cargo.toml b/Cargo.toml index 8258f2b..a6a86f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,20 +6,21 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rocket = {version = "0.5.0", features = ["json"]} -serde = {version = "1.0.198", features = ["derive"]} -serde_json = "1.0.111" -num-format = "0.4.4" -fs_extra = "1.3.0" -humantime = "2.1.0" -chrono = "0.4.37" -futures = "0.3.30" -config = "0.14.0" -lazy_static = "1.4.0" -shellexpand = "3.1.0" -either = "1.11.0" -anyhow = "1.0.86" -env_logger = "0.11.3" +rocket = {version = "0.5.0", features = ["json"]} +serde = {version = "1.0.198", features = ["derive"]} +serde_json = "1.0.111" +num-format = "0.4.4" +fs_extra = "1.3.0" +humantime = "2.1.0" +chrono = "0.4.37" +futures = "0.3.30" +config = "0.14.0" +lazy_static = "1.4.0" +shellexpand = "3.1.0" +either = "1.11.0" +anyhow = "1.0.86" +env_logger = "0.11.3" +tera_thousands = "0.1.0" [dependencies.reqwest] version = "0.11.23" diff --git a/src/main.rs b/src/main.rs index 8a5627c..629e701 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use rocket::serde::json::json; use std::sync::{Arc, Mutex}; use std::time::Duration; use serde_json::Value; +use tera_thousands::separate_with_commas; use crate::data::{Block, Dashboard, Kernel, Output, Statistics, Transactions, OUTPUT_SIZE, KERNEL_SIZE}; use crate::requests::CONFIG; @@ -131,7 +132,7 @@ async fn kernel(excess: &str) -> Template { }) } - return Template::render("error", context! { + Template::render("error", context! { route: "error", }) } @@ -151,7 +152,7 @@ async fn output(commit: &str) -> Template { }) } - return Template::render("error", context! { + Template::render("error", context! { route: "error", }) } @@ -232,6 +233,38 @@ fn stats(statistics: &State>>) -> Template { } +// Rendering Grinflation page. +#[get("/emission")] +fn emission(dashboard: &State>>) -> Template { + let data = dashboard.lock().unwrap(); + + let mut usd = 0.0; + let mut btc = 0.0; + + if data.price_usd.is_empty() == false && data.price_btc.is_empty() == false { + usd = data.price_usd.parse::().unwrap(); + btc = data.price_btc.parse::().unwrap(); + } + + Template::render("emission", context! { + route: "emission", + cg_api: CONFIG.coingecko_api.clone(), + usd_minute: format!("{:.2}", usd * 60.0), + usd_hour: ((usd * 3600.0) as u64).to_formatted_string(&Locale::en), + usd_day: ((usd * 86400.0) as u64).to_formatted_string(&Locale::en), + usd_week: ((usd * 604800.0) as u64).to_formatted_string(&Locale::en), + usd_month: ((usd * 2592000.0) as u64).to_formatted_string(&Locale::en), + usd_year: ((usd * 31557600.0) as u64).to_formatted_string(&Locale::en), + btc_minute: format!("{:.8}", btc * 60.0), + btc_hour: format!("{:.8}", btc * 3600.0), + btc_day: format!("{:.8}", btc * 86400.0), + btc_week: format!("{:.8}", btc * 604800.0), + btc_month: format!("{:.8}", btc * 2592000.0), + btc_year: format!("{:.8}", btc * 31557600.0), + }) +} + + // Owner API. // Whitelisted methods: get_connected_peers, get_peers, get_status. #[post("/v2/owner", data="")] @@ -777,9 +810,10 @@ async fn main() { block_size, block_weight, block_details_by_height, block_header_by_hash, soft_supply, production_cost, reward_ratio, breakeven_cost, last_block_age, block_list_by_height, block_list_index, search, kernel, - output, api_owner, api_foreign, stats, unspent_outputs, kernels]) + output, api_owner, api_foreign, stats, unspent_outputs, kernels, + emission]) .mount("/static", FileServer::from("static")) - .attach(Template::fairing()) + .attach(Template::custom(|engines| {engines.tera.register_filter("separate_with_commas", separate_with_commas)})) .launch() .await; } diff --git a/static/styles/style.css b/static/styles/style.css index e4c0286..2822624 100644 --- a/static/styles/style.css +++ b/static/styles/style.css @@ -6,6 +6,10 @@ color: #FF7518 !important; } +.green-text { + color: #5cb85c !important; +} + .card-background { background-color: #FBFBFB !important; } diff --git a/templates/base.html.tera b/templates/base.html.tera index f3a61bc..c52c112 100644 --- a/templates/base.html.tera +++ b/templates/base.html.tera @@ -47,6 +47,9 @@ + {% elif route == "block_list" or route == "block_list_by_height" %} + {% elif route == "stats" %} + + {% elif route == "emission" %} + + + + {% else %} + {% endif %} @@ -190,12 +215,6 @@
-
- -
-
Grinexplorer diff --git a/templates/emission.html.tera b/templates/emission.html.tera new file mode 100644 index 0000000..1f19554 --- /dev/null +++ b/templates/emission.html.tera @@ -0,0 +1,127 @@ +{% extends "base" %} + +{% block content %} + +{% if cg_api == "enabled" %} + + +
+
+
Inflation Rate
+
%
+
+
Price
+

+
Supply
+
/span>
+
+
Market Cap
+
+
+
+ +
+ +
+
+ +
+
+

Grin was started with as fair of a launch as possible for what's under our control. We did this for good reason: we believe in Grin's mission to enable private money for everyone and open access to it.

+
+ +
+ +
+
+ + + +
+
+
Emission 1 GRIN/SEC
+
+
+ 1 Minute ツ 60
+ $ {{ usd_minute }} + {{ btc_minute }} +
+
+
+ 1 Hour ツ 3,600
+ $ {{ usd_hour }} + ₿ {{ btc_hour }} +
+
+
+ 1 Day ツ 86,400
+ $ {{ usd_day }} + ₿ {{ btc_day }} +
+
+
+ 1 Week ツ 604,800
+ $ {{ usd_week }} + ₿ {{ btc_week }} +
+
+
+ 1 Month ツ 2,592,000
+ $ {{ usd_month }} + ₿ {{ btc_month }} +
+
+
+ 1 Year ツ 31,557,600
+ $ {{ usd_year }} + ₿ {{ btc_year }} +
+
+
+ +
+ +
+
+ +
+
+

I don't measure grin's success by its marketcap, but by its elegance, simplicity, scalability and long term survival.

+
+ +
+ +
+
+ +{% endif %} + + + +
+
+
Inflation Rate by Year
+
+
+ 2019 ツ 0 +
+ {% for i in range(end=100) %} +
+
+ {{ 2019 + i + 1 }} ツ {{ ((i + 1) * 31557600) | separate_with_commas }} + + {{ (31557600 / ((i + 1) * 31557600)) * 100 | round(method="ceil", precision=2)}} % + +
+ {% endfor %} +
+
+ +
+ +{% endblock %} +