fedimint_server_ui/dashboard/modules/mintv2.rs
1use maud::{Markup, PreEscaped, html};
2
3// Function to render the Mint V2 module UI section
4pub async fn render(mint: &fedimint_mintv2_server::Mint) -> Markup {
5 let distribution = mint.note_distribution_ui().await;
6
7 let labels: Vec<String> = distribution.keys().map(|d| format!("2^{}", d.0)).collect();
8 let counts: Vec<u64> = distribution.values().copied().collect();
9
10 html! {
11 div class="card h-100" {
12 div class="card-header dashboard-header" { "Mint V2" }
13 div class="card-body" {
14 @if distribution.is_empty() {
15 p class="text-muted mb-0" { "No notes have been issued yet." }
16 } @else {
17 canvas id="mintv2-chart" {}
18 script src="/assets/chart.umd.min.js" {}
19 (PreEscaped(format!(
20 r#"<script>
21 document.addEventListener('DOMContentLoaded', function() {{
22 new Chart(document.getElementById('mintv2-chart'), {{
23 type: 'bar',
24 data: {{
25 labels: {labels},
26 datasets: [{{
27 label: 'Outstanding Notes',
28 data: {counts:?},
29 borderWidth: 1
30 }}]
31 }},
32 options: {{
33 responsive: true,
34 plugins: {{
35 legend: {{ display: false }},
36 tooltip: {{ enabled: false }}
37 }},
38 scales: {{
39 x: {{
40 title: {{
41 display: true,
42 text: 'Denomination'
43 }}
44 }},
45 y: {{
46 beginAtZero: true,
47 title: {{
48 display: true,
49 text: 'Outstanding Note Count'
50 }}
51 }}
52 }}
53 }}
54 }});
55 }});
56 </script>"#,
57 labels = serde_json::to_string(&labels)
58 .expect("Failed to serialize labels"),
59 )))
60 }
61 }
62 }
63 }
64}