adjust coingecko option

This commit is contained in:
aglkm
2024-06-01 17:38:13 +03:00
parent 99fdb00f18
commit 8f5d015f6a
4 changed files with 30 additions and 20 deletions

View File

@@ -35,8 +35,6 @@ pub struct Dashboard {
// mempool // mempool
pub txns: String, pub txns: String,
pub stem: String, pub stem: String,
// coingecko api
pub cg_api: String,
} }
impl Dashboard { impl Dashboard {
@@ -66,7 +64,6 @@ impl Dashboard {
breakeven_cost: String::new(), breakeven_cost: String::new(),
txns: String::new(), txns: String::new(),
stem: String::new(), stem: String::new(),
cg_api: String::new(),
} }
} }
} }

View File

@@ -19,6 +19,7 @@ use crate::data::Dashboard;
use crate::data::Block; use crate::data::Block;
use crate::data::Transactions; use crate::data::Transactions;
use crate::data::Kernel; use crate::data::Kernel;
use crate::requests::CONFIG;
// Rendering main (Dashboard) page. // Rendering main (Dashboard) page.
@@ -30,7 +31,7 @@ fn index(dashboard: &State<Arc<Mutex<Dashboard>>>) -> Template {
route: "index", route: "index",
node_ver: &data.node_ver, node_ver: &data.node_ver,
proto_ver: &data.proto_ver, proto_ver: &data.proto_ver,
cg_api: &data.cg_api, cg_api: CONFIG.coingecko_api.clone(),
}) })
} }
@@ -40,6 +41,7 @@ fn index(dashboard: &State<Arc<Mutex<Dashboard>>>) -> Template {
fn block_list() -> Template { fn block_list() -> Template {
Template::render("block_list", context! { Template::render("block_list", context! {
route: "block_list", route: "block_list",
cg_api: CONFIG.coingecko_api.clone(),
}) })
} }
@@ -61,10 +63,12 @@ async fn block_list_by_height(input_height: &str) -> Template {
if index >= height { if index >= height {
Template::render("block_list", context! { Template::render("block_list", context! {
route: "block_list", route: "block_list",
cg_api: CONFIG.coingecko_api.clone(),
}) })
} else { } else {
Template::render("block_list", context! { Template::render("block_list", context! {
route: "block_list_by_height", route: "block_list_by_height",
cg_api: CONFIG.coingecko_api.clone(),
index, index,
blocks, blocks,
height, height,
@@ -73,6 +77,7 @@ async fn block_list_by_height(input_height: &str) -> Template {
} else { } else {
Template::render("block_list", context! { Template::render("block_list", context! {
route: "block_list", route: "block_list",
cg_api: CONFIG.coingecko_api.clone(),
}) })
} }
} }
@@ -89,6 +94,7 @@ async fn block_details_by_height(height: &str) -> Template {
if block.height.is_empty() == false { if block.height.is_empty() == false {
return Template::render("block_details", context! { return Template::render("block_details", context! {
route: "block_details", route: "block_details",
cg_api: CONFIG.coingecko_api.clone(),
block, block,
}); });
} }
@@ -96,6 +102,7 @@ async fn block_details_by_height(height: &str) -> Template {
Template::render("error", context! { Template::render("error", context! {
route: "error", route: "error",
cg_api: CONFIG.coingecko_api.clone(),
}) })
} }
@@ -115,6 +122,7 @@ async fn block_header_by_hash(hash: &str) -> Either<Template, Redirect> {
return Either::Left(Template::render("error", context! { return Either::Left(Template::render("error", context! {
route: "error", route: "error",
cg_api: CONFIG.coingecko_api.clone(),
})) }))
} }
@@ -129,12 +137,14 @@ async fn kernel(excess: &str) -> Template {
if kernel.excess.is_empty() == false { if kernel.excess.is_empty() == false {
return Template::render("kernel", context! { return Template::render("kernel", context! {
route: "kernel", route: "kernel",
cg_api: CONFIG.coingecko_api.clone(),
kernel, kernel,
}) })
} }
return Template::render("error", context! { 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<Template, Redirect> {
// Unwrap Option and forward to Search page if no parameters // Unwrap Option and forward to Search page if no parameters
let input = match input { let input = match input {
Some(value) => value, 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 // Check for valid chars
@@ -169,6 +182,7 @@ fn search(input: Option<&str>) -> Either<Template, Redirect> {
Either::Left(Template::render("error", context! { Either::Left(Template::render("error", context! {
route: "error", route: "error",
cg_api: CONFIG.coingecko_api.clone(),
})) }))
} }

View File

@@ -21,7 +21,7 @@ use crate::Kernel;
// Static explorer config structure // Static explorer config structure
lazy_static! { lazy_static! {
static ref CONFIG: ExplorerConfig = { pub static ref CONFIG: ExplorerConfig = {
let mut cfg = ExplorerConfig::new(); let mut cfg = ExplorerConfig::new();
let settings = Config::builder().add_source(config::File::with_name("Explorer")) let settings = Config::builder().add_source(config::File::with_name("Explorer"))
.build().unwrap(); .build().unwrap();
@@ -94,9 +94,6 @@ pub async fn get_status(dashboard: Arc<Mutex<Dashboard>>) -> Result<(), anyhow::
data.proto_ver = resp["result"]["Ok"]["protocol_version"].to_string(); data.proto_ver = resp["result"]["Ok"]["protocol_version"].to_string();
} }
// Also set cg_api value
data.cg_api = CONFIG.coingecko_api.clone();
Ok(()) Ok(())
} }

View File

@@ -215,15 +215,17 @@
<span style="color:grey"><i class="bi bi-github me-1"></i>v.0.1.5</span> <span style="color:grey"><i class="bi bi-github me-1"></i>v.0.1.5</span>
</a> </a>
<a class="text-decoration-none" href="/search"> <a class="text-decoration-none" href="/search">
<span style="color:grey"><i class="bi bi-search me-1"></i>search</span> <span style="color:grey"><i class="bi bi-search me-1"></i>Search</span>
</a> </a>
</div> </div>
</div> </div>
{% if cg_api == "on" %}
<div class="row"> <div class="row">
<div class="col d-flex justify-content-center" style="color:grey"> <div class="col d-flex justify-content-center" style="color:grey">
Powered by CoinGecko Powered by CoinGecko
</div> </div>
</div> </div>
{% endif %}
</div> </div>
</div> </div>
<br> <br>