diff --git a/src/subcommand/server.rs b/src/subcommand/server.rs index b69a8bc07b..c7a099afd5 100644 --- a/src/subcommand/server.rs +++ b/src/subcommand/server.rs @@ -298,6 +298,7 @@ impl Server { } async fn ordinal( + Extension(chain): Extension, Extension(index): Extension>, Path(DeserializeFromStr(ordinal)): Path>, ) -> ServerResult { @@ -313,14 +314,14 @@ impl Server { )) })?, } - .page(), + .page(chain), ) } async fn output( + Extension(chain): Extension, Extension(index): Extension>, Path(outpoint): Path, - Extension(chain): Extension, ) -> ServerResult { let list = index .list(outpoint) @@ -343,11 +344,12 @@ impl Server { chain, output, } - .page(), + .page(chain), ) } async fn range( + Extension(chain): Extension, Path((DeserializeFromStr(start), DeserializeFromStr(end))): Path<( DeserializeFromStr, DeserializeFromStr, @@ -358,7 +360,7 @@ impl Server { Ordering::Greater => Err(ServerError::BadRequest( "range start greater than range end".to_string(), )), - Ordering::Less => Ok(RangeHtml { start, end }.page()), + Ordering::Less => Ok(RangeHtml { start, end }.page(chain)), } } @@ -368,20 +370,24 @@ impl Server { })?)) } - async fn home(Extension(index): Extension>) -> ServerResult { + async fn home( + Extension(chain): Extension, + Extension(index): Extension>, + ) -> ServerResult { Ok( HomeHtml::new( index .blocks(100) .map_err(|err| ServerError::Internal(anyhow!("error getting blocks: {err}")))?, ) - .page(), + .page(chain), ) } async fn block( + Extension(chain): Extension, + Extension(index): Extension>, Path(DeserializeFromStr(query)): Path>, - index: Extension>, ) -> ServerResult { let (block, height) = match query { BlockQuery::Height(height) => { @@ -427,7 +433,7 @@ impl Server { .height() .map_err(|err| ServerError::Internal(anyhow!("failed to get index height: {err}")))?, ) - .page(), + .page(chain), ) } @@ -448,7 +454,7 @@ impl Server { .ok_or_else(|| ServerError::NotFound(format!("transaction {txid} unknown")))?, chain, ) - .page(), + .page(chain), ) } @@ -546,6 +552,7 @@ impl Server { } async fn input( + Extension(chain): Extension, Extension(index): Extension>, Path(path): Path<(u64, usize, usize)>, ) -> Result { @@ -565,7 +572,7 @@ impl Server { .nth(path.2) .ok_or_else(not_found)?; - Ok(InputHtml { path, input }.page()) + Ok(InputHtml { path, input }.page(chain)) } async fn faq() -> Redirect { @@ -1101,6 +1108,15 @@ mod tests { ); } + #[test] + fn nav_displays_chain() { + TestServer::new().assert_response_regex( + "/", + StatusCode::OK, + ".*Ordinalsregtest.*", + ); + } + #[test] fn home_block_limit() { let test_server = TestServer::new(); diff --git a/src/subcommand/server/templates.rs b/src/subcommand/server/templates.rs index ad815966fb..a2523f68c2 100644 --- a/src/subcommand/server/templates.rs +++ b/src/subcommand/server/templates.rs @@ -22,12 +22,14 @@ mod transaction; #[derive(Boilerplate)] pub(crate) struct PageHtml { content: Box, + chain: Chain, } impl PageHtml { - pub(crate) fn new(content: T) -> Self { + pub(crate) fn new(content: T, chain: Chain) -> Self { Self { content: Box::new(content), + chain, } } } @@ -35,11 +37,11 @@ impl PageHtml { pub(crate) trait Content: Display + 'static { fn title(&self) -> String; - fn page(self) -> PageHtml + fn page(self, chain: Chain) -> PageHtml where Self: Sized, { - PageHtml::new(self) + PageHtml::new(self, chain) } } @@ -48,7 +50,7 @@ mod tests { use super::*; #[test] - fn page() { + fn page_mainnet() { struct Foo; impl Display for Foo { @@ -64,7 +66,7 @@ mod tests { } assert_regex_match!( - Foo.page().to_string(), + Foo.page(Chain::Mainnet).to_string(), " @@ -91,6 +93,54 @@ mod tests { +" + ); + } + + #[test] + fn page_signet() { + struct Foo; + + impl Display for Foo { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!(f, "

Foo

") + } + } + + impl Content for Foo { + fn title(&self) -> String { + "Foo".to_string() + } + } + + assert_regex_match!( + Foo.page(Chain::Signet).to_string(), + " + + + + + + Foo + + + + +
+ +
+
+

Foo

+
+ + " ); } diff --git a/templates/page.html b/templates/page.html index 0285acaeb8..af0770742e 100644 --- a/templates/page.html +++ b/templates/page.html @@ -11,7 +11,7 @@