fedimint_gateway_ui/
connect_fed.rs

1use std::fmt::Display;
2
3use axum::Form;
4use axum::extract::State;
5use axum::response::IntoResponse;
6use fedimint_gateway_common::ConnectFedPayload;
7use fedimint_ui_common::UiState;
8use fedimint_ui_common::auth::UserAuth;
9use maud::{Markup, html};
10
11use crate::{CONNECT_FEDERATION_ROUTE, DynGatewayApi, redirect_error, redirect_success};
12
13pub fn render() -> Markup {
14    html!(
15        div class="card h-100" {
16            div class="card-header dashboard-header" { "Connect a new Federation" }
17            div class="card-body" {
18                form method="post" action=(CONNECT_FEDERATION_ROUTE) {
19                    div class="mb-3" {
20                        label class="form-label" { "Invite Code" }
21                        input type="text" class="form-control" name="invite_code" required;
22                    }
23                    button type="submit" class="btn btn-primary" { "Submit" }
24                }
25            }
26        }
27    )
28}
29
30pub async fn connect_federation_handler<E: Display>(
31    State(state): State<UiState<DynGatewayApi<E>>>,
32    _auth: UserAuth,
33    Form(payload): Form<ConnectFedPayload>,
34) -> impl IntoResponse {
35    match state.api.handle_connect_federation(payload).await {
36        Ok(info) => {
37            // Redirect back to dashboard on success
38            redirect_success(format!(
39                "Successfully joined {}",
40                info.federation_name
41                    .unwrap_or("Unnamed Federation".to_string())
42            ))
43            .into_response()
44        }
45        Err(err) => redirect_error(format!("Failed to join federation: {err}")).into_response(),
46    }
47}