From 8f5d015f6a2fa607fe7cb038d09be3d516687f53 Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Sat, 1 Jun 2024 17:38:13 +0300 Subject: [PATCH] adjust coingecko option --- src/data.rs | 3 --- src/main.rs | 38 ++++++++++++++++++++++++++------------ src/requests.rs | 5 +---- templates/base.html.tera | 4 +++- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/data.rs b/src/data.rs index bae2440..a9e8139 100644 --- a/src/data.rs +++ b/src/data.rs @@ -35,8 +35,6 @@ pub struct Dashboard { // mempool pub txns: String, pub stem: String, - // coingecko api - pub cg_api: String, } impl Dashboard { @@ -66,7 +64,6 @@ impl Dashboard { breakeven_cost: String::new(), txns: String::new(), stem: String::new(), - cg_api: String::new(), } } } diff --git a/src/main.rs b/src/main.rs index 5e74b06..80dde39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ use crate::data::Dashboard; use crate::data::Block; use crate::data::Transactions; use crate::data::Kernel; +use crate::requests::CONFIG; // Rendering main (Dashboard) page. @@ -30,7 +31,7 @@ fn index(dashboard: &State>>) -> Template { route: "index", node_ver: &data.node_ver, proto_ver: &data.proto_ver, - cg_api: &data.cg_api, + cg_api: CONFIG.coingecko_api.clone(), }) } @@ -39,7 +40,8 @@ fn index(dashboard: &State>>) -> Template { #[get("/block_list")] fn block_list() -> Template { Template::render("block_list", context! { - route: "block_list", + route: "block_list", + cg_api: CONFIG.coingecko_api.clone(), }) } @@ -60,11 +62,13 @@ async fn block_list_by_height(input_height: &str) -> Template { if index >= height { Template::render("block_list", context! { - route: "block_list", + route: "block_list", + cg_api: CONFIG.coingecko_api.clone(), }) } else { Template::render("block_list", context! { - route: "block_list_by_height", + route: "block_list_by_height", + cg_api: CONFIG.coingecko_api.clone(), index, blocks, height, @@ -72,7 +76,8 @@ async fn block_list_by_height(input_height: &str) -> Template { } } else { Template::render("block_list", context! { - route: "block_list", + route: "block_list", + cg_api: CONFIG.coingecko_api.clone(), }) } } @@ -88,14 +93,16 @@ async fn block_details_by_height(height: &str) -> Template { if block.height.is_empty() == false { return Template::render("block_details", context! { - route: "block_details", + route: "block_details", + cg_api: CONFIG.coingecko_api.clone(), block, }); } } Template::render("error", context! { - route: "error", + route: "error", + cg_api: CONFIG.coingecko_api.clone(), }) } @@ -114,7 +121,8 @@ async fn block_header_by_hash(hash: &str) -> Either { } return Either::Left(Template::render("error", context! { - route: "error", + route: "error", + cg_api: CONFIG.coingecko_api.clone(), })) } @@ -128,13 +136,15 @@ async fn kernel(excess: &str) -> Template { if kernel.excess.is_empty() == false { return Template::render("kernel", context! { - route: "kernel", + route: "kernel", + cg_api: CONFIG.coingecko_api.clone(), kernel, }) } return Template::render("error", context! { - route: "error", + route: "error", + cg_api: CONFIG.coingecko_api.clone(), }) } @@ -147,7 +157,10 @@ fn search(input: Option<&str>) -> Either { // Unwrap Option and forward to Search page if no parameters let input = match input { Some(value) => value, - None => return Either::Left(Template::render("search", context! { route: "search", })), + None => return Either::Left(Template::render("search", context! { + route: "search", + cg_api: CONFIG.coingecko_api.clone(), + })), }; // Check for valid chars @@ -168,7 +181,8 @@ fn search(input: Option<&str>) -> Either { } Either::Left(Template::render("error", context! { - route: "error", + route: "error", + cg_api: CONFIG.coingecko_api.clone(), })) } diff --git a/src/requests.rs b/src/requests.rs index b6f62dd..30e10f6 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -21,7 +21,7 @@ use crate::Kernel; // Static explorer config structure lazy_static! { - static ref CONFIG: ExplorerConfig = { + pub static ref CONFIG: ExplorerConfig = { let mut cfg = ExplorerConfig::new(); let settings = Config::builder().add_source(config::File::with_name("Explorer")) .build().unwrap(); @@ -94,9 +94,6 @@ pub async fn get_status(dashboard: Arc>) -> Result<(), anyhow:: data.proto_ver = resp["result"]["Ok"]["protocol_version"].to_string(); } - // Also set cg_api value - data.cg_api = CONFIG.coingecko_api.clone(); - Ok(()) } diff --git a/templates/base.html.tera b/templates/base.html.tera index 584869d..e4da64b 100644 --- a/templates/base.html.tera +++ b/templates/base.html.tera @@ -215,15 +215,17 @@ v.0.1.5 - search + Search + {% if cg_api == "on" %}
Powered by CoinGecko
+ {% endif %}