fedimint_gateway_ui/
bitcoin.rs1use fedimint_gateway_common::ChainSource;
2use fedimint_logging::LOG_GATEWAY_UI;
3use maud::{Markup, html};
4use tracing::debug;
5
6use crate::DynGatewayApi;
7
8pub async fn render<E>(api: &DynGatewayApi<E>) -> Markup
9where
10 E: std::fmt::Display,
11{
12 debug!(target: LOG_GATEWAY_UI, "Getting bitcoin chain source...");
13 let (chain_source, network) = api.get_chain_source().await;
14
15 html! {
16 div class="card h-100" {
17 div class="card-header dashboard-header d-flex justify-content-between align-items-center" {
18 span { "Bitcoin Connection" }
19
20 @if matches!(chain_source, ChainSource::Bitcoind { .. }) {
21 button
22 id="btc-password-toggle-btn"
23 class="btn btn-sm btn-secondary"
24 type="button"
25 onclick="toggleBtcPassword()"
26 {
27 "Show"
28 }
29 }
30 }
31
32 div class="card-body" {
33 table class="table table-sm mb-0" {
34 tbody {
35 tr {
36 th { "Network" }
37 td { (network) }
38 }
39
40 @match &chain_source {
41 ChainSource::Bitcoind { username, password, server_url } => {
42 tr {
43 th { "Type" }
44 td { "Bitcoind" }
45 }
46 tr {
47 th { "Server URL" }
48 td { (server_url) }
49 }
50 tr {
51 th { "Username" }
52 td { (username) }
53 }
54 tr {
55 th { "Password" }
56 td id="btc-password" data-password=(password) { "••••••" }
57 }
58 },
59 ChainSource::Esplora { server_url } => {
60 tr {
61 th { "Type" }
62 td { "Esplora" }
63 }
64 tr {
65 th { "Server URL" }
66 td { (server_url) }
67 }
68 }
69 }
70 }
71 }
72 }
73 }
74
75 @if matches!(chain_source, ChainSource::Bitcoind { .. }) {
76 script {
77 (maud::PreEscaped(r#"
78 function toggleBtcPassword() {
79 const btn = document.getElementById("btc-password-toggle-btn");
80 const pwdEl = document.getElementById("btc-password");
81 const showing = btn.dataset.showing === "true";
82
83 if (showing) {
84 pwdEl.textContent = "••••••";
85 } else {
86 pwdEl.textContent = pwdEl.dataset.password;
87 }
88
89 btn.textContent = showing ? "Show" : "Hide";
90 btn.dataset.showing = (!showing).toString();
91 }
92 "#))
93 }
94 }
95 }
96}