From 82215e5ad23131dacdedcaec5c2567a5c0793a10 Mon Sep 17 00:00:00 2001 From: RGGH Date: Sat, 25 Nov 2023 19:02:54 +0000 Subject: [PATCH] add html for root --- src/web/routes_login.rs | 50 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/web/routes_login.rs b/src/web/routes_login.rs index c503d18..18a50ab 100644 --- a/src/web/routes_login.rs +++ b/src/web/routes_login.rs @@ -1,5 +1,7 @@ -use bdk::bitcoin::Network; -use bdk::database::MemoryDatabase; +use rstml_component::{move_html, write_html, For, HtmlComponent, HtmlContent}; +use rstml_component_axum::HtmlContentAxiosExt; + +use std::net::SocketAddr; use std::collections::HashMap; use crate::web; @@ -10,6 +12,7 @@ use axum::extract::Query; use axum::http::{Response, StatusCode}; use axum::routing::{get, post}; use axum::Router; +use axum::response::IntoResponse; use axum::{Extension, Json}; use serde::Deserialize; use serde_json::{json, Value}; @@ -18,14 +21,17 @@ use bdk::keys::{ bip39::{Language, Mnemonic, WordCount}, DerivableKey, ExtendedKey, GeneratableKey, GeneratedKey, }; +use bdk::database::MemoryDatabase; use bdk::template::Bip84; use bdk::wallet::AddressIndex; use bdk::{miniscript, KeychainKind, Wallet}; +use bdk::bitcoin::Network; pub fn routes() -> Router { Router::new() .route("/api/login", post(api_login)) .route("/api/gen_wallet", get(gen_wallet)) + .route("/", get(index)) } async fn api_login(payload: Json) -> Result> { @@ -82,3 +88,43 @@ async fn gen_wallet(Query(params): Query>) -> Json Self { + Self { title, author } + } +} + +impl HtmlContent for Book { + fn fmt(self, formatter: &mut rstml_component::HtmlFormatter) -> std::fmt::Result { + write_html!(formatter, +
+

{self.title}

+

"("{self.author}")"

+
+ ) + } +} + +// Your Axum handler +async fn index() -> impl IntoResponse { + let books = [ + ("BDK", "Bitcoin Dev Kit"), + ("Axum", "API"), + ]; + + move_html!( +
+ + { |f, book| Book::new(book.0, book.1).fmt(f) } + +
+ ) + .into_html() +}