diff --git a/src/components/caption_text.rs b/src/components/caption_text.rs index 347cc42..55e49e5 100644 --- a/src/components/caption_text.rs +++ b/src/components/caption_text.rs @@ -1,17 +1,10 @@ use iced::widget::text; -use iced::widget::text::Style; -use iced::{Element, Theme}; +use iced::Element; use crate::Message; -use super::lighten; +use super::subtitle; pub fn h_caption_text(string: &'static str) -> Element<'static, Message> { - text(string) - .size(18) - .style(|theme: &Theme| { - let gray = lighten(theme.palette().background, 0.5); - Style { color: Some(gray) } - }) - .into() + text(string).size(18).style(subtitle).into() } diff --git a/src/components/federation_item.rs b/src/components/federation_item.rs index 9f10287..b1997ba 100644 --- a/src/components/federation_item.rs +++ b/src/components/federation_item.rs @@ -1,20 +1,30 @@ use fedimint_core::config::FederationId; use iced::{ - widget::{row, text}, - Element, + widget::{column, row, text}, + Alignment, Element, }; use crate::Message; +use super::{format_amount, map_icon, subtitle, SvgIcon}; + #[derive(Debug, Clone)] pub struct FederationItem { pub id: FederationId, pub name: String, + pub balance: u64, } pub fn h_federation_item(item: &FederationItem) -> Element { - let FederationItem { id, name } = item; - let row = row![text(name).size(24), text(format!("{id:?}")).size(24),].spacing(16); + let FederationItem { id, name, balance } = item; + let title = row![map_icon(SvgIcon::People, 24., 24.), text(name).size(24)] + .align_items(Alignment::Center) + .spacing(16); + let balance = text(format_amount(*balance)).size(24); + + let id = text(format!("{id}")).size(18).style(subtitle); + + let column = column![title, balance, id].spacing(16); - row.into() + column.into() } diff --git a/src/components/header.rs b/src/components/header.rs index 0f58268..9cd7363 100644 --- a/src/components/header.rs +++ b/src/components/header.rs @@ -1,18 +1,14 @@ -use iced::widget::text::Style; use iced::widget::{column, text}; -use iced::{Element, Theme}; +use iced::Element; use crate::Message; -use super::lighten; +use super::subtitle as subtitle_style; pub fn h_header(title: &'static str, subtitle: &'static str) -> Element<'static, Message> { column![ text(title).size(32), - text(subtitle).size(18).style(|theme: &Theme| { - let gray = lighten(theme.palette().background, 0.5); - Style { color: Some(gray) } - }) + text(subtitle).size(18).style(subtitle_style) ] .spacing(8) .into() diff --git a/src/components/mod.rs b/src/components/mod.rs index e747508..fa7a1a0 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -48,3 +48,6 @@ pub use toast::*; mod colors; pub use colors::*; + +mod styles; +pub use styles::*; diff --git a/src/components/screen_header.rs b/src/components/screen_header.rs index 94c5a04..ea89ed3 100644 --- a/src/components/screen_header.rs +++ b/src/components/screen_header.rs @@ -9,7 +9,11 @@ use super::{format_amount, hr, map_icon, vr, FederationItem, SvgIcon}; pub fn h_screen_header(harbor: &HarborWallet, show_balance: bool) -> Element { if let Some(item) = harbor.federation_list.first() { - let FederationItem { name, id: _id } = item; + let FederationItem { + name, + id: _, + balance: _, + } = item; let people_icon = map_icon(SvgIcon::People, 24., 24.); let current_federation = row![people_icon, text(name).size(24)] .align_items(Alignment::Center) diff --git a/src/components/sidebar.rs b/src/components/sidebar.rs index 3499cf7..28b9360 100644 --- a/src/components/sidebar.rs +++ b/src/components/sidebar.rs @@ -1,4 +1,5 @@ use crate::components::SvgIcon; +use crate::routes::MintSubroute; use iced::widget::container::Style; use iced::widget::{column, container, vertical_space, Svg}; use iced::Border; @@ -16,8 +17,13 @@ pub fn sidebar(harbor: &HarborWallet) -> Element { .height(61), sidebar_button("Home", SvgIcon::Home, Route::Home, harbor.active_route) .on_press(Message::Navigate(Route::Home)), - sidebar_button("Mints", SvgIcon::People, Route::Mints, harbor.active_route) - .on_press(Message::Navigate(Route::Mints)), + sidebar_button( + "Mints", + SvgIcon::People, + Route::Mints(MintSubroute::List), + harbor.active_route + ) + .on_press(Message::Navigate(Route::Mints(MintSubroute::List))), sidebar_button( "Transfer", SvgIcon::LeftRight, diff --git a/src/components/styles.rs b/src/components/styles.rs new file mode 100644 index 0000000..f58d376 --- /dev/null +++ b/src/components/styles.rs @@ -0,0 +1,8 @@ +use iced::{widget::text::Style, Theme}; + +use super::lighten; + +pub fn subtitle(theme: &Theme) -> Style { + let gray = lighten(theme.palette().background, 0.5); + Style { color: Some(gray) } +} diff --git a/src/components/transaction_item.rs b/src/components/transaction_item.rs index 25dea41..71d761c 100644 --- a/src/components/transaction_item.rs +++ b/src/components/transaction_item.rs @@ -1,11 +1,11 @@ use iced::{ - widget::{column, row, svg, text, text::Style}, - Element, Theme, + widget::{column, row, svg, text}, + Element, }; use crate::Message; -use super::{format_amount, format_timestamp, lighten, map_icon, MUTINY_GREEN, MUTINY_RED}; +use super::{format_amount, format_timestamp, map_icon, subtitle, MUTINY_GREEN, MUTINY_RED}; #[derive(Debug, Clone, Copy, PartialEq)] pub enum TransactionItemKind { @@ -78,12 +78,7 @@ pub fn h_transaction_item(item: &TransactionItem) -> Element { .align_items(iced::Alignment::Center) .spacing(16); - let timestamp = text(format_timestamp(timestamp)) - .size(18) - .style(|theme: &Theme| { - let gray = lighten(theme.palette().background, 0.5); - Style { color: Some(gray) } - }); + let timestamp = text(format_timestamp(timestamp)).size(18).style(subtitle); let col = column![row, timestamp].spacing(8); diff --git a/src/core.rs b/src/core.rs index a8a301f..d5de2c7 100644 --- a/src/core.rs +++ b/src/core.rs @@ -348,6 +348,8 @@ impl HarborCore { .fedimint_client .get_meta("federation_name") .unwrap_or("Unknown".to_string()), + // TODO: get the balance per fedimint + balance: 420, }) .collect::>() } diff --git a/src/main.rs b/src/main.rs index 42225f4..571e5ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -550,7 +550,12 @@ impl HarborWallet { _ => "Unknown".to_string(), }; - let item = FederationItem { id, name }; + // TODO: what to do about balance in this case? Maybe it should be Option? + let item = FederationItem { + id, + name, + balance: 0, + }; self.peek_federation_item = Some(item); @@ -609,7 +614,7 @@ impl HarborWallet { Route::Home => row![sidebar, crate::routes::home(self)].into(), Route::Receive => row![sidebar, crate::routes::receive(self)].into(), Route::Send => row![sidebar, crate::routes::send(self)].into(), - Route::Mints => row![sidebar, crate::routes::mints(self)].into(), + Route::Mints(_) => row![sidebar, crate::routes::mints(self)].into(), Route::Donate => row![sidebar, crate::routes::donate(self)].into(), Route::History => row![sidebar, crate::routes::history(self)].into(), Route::Transfer => row![sidebar, crate::routes::transfer(self)].into(), diff --git a/src/routes/home.rs b/src/routes/home.rs index 51d7717..9ac5047 100644 --- a/src/routes/home.rs +++ b/src/routes/home.rs @@ -12,8 +12,8 @@ pub fn home(harbor: &HarborWallet) -> Element { let send_button = h_button("Send", SvgIcon::UpRight, false).on_press(Message::Navigate(Route::Send)); let receive_button = - h_button("Receive", SvgIcon::DownLeft, false).on_press(Message::Navigate(Route::Receive)); - let buttons = row![send_button, receive_button].spacing(32); + h_button("Deposit", SvgIcon::DownLeft, false).on_press(Message::Navigate(Route::Receive)); + let buttons = row![receive_button, send_button].spacing(32); column![ h_screen_header(harbor, false), diff --git a/src/routes/mints.rs b/src/routes/mints.rs index dc4e922..5ecf2d6 100644 --- a/src/routes/mints.rs +++ b/src/routes/mints.rs @@ -4,9 +4,34 @@ use iced::{Color, Element}; use crate::components::{basic_layout, h_button, h_federation_item, h_header, h_input, SvgIcon}; use crate::{HarborWallet, Message}; -pub fn mints(harbor: &HarborWallet) -> Element { +use super::{MintSubroute, Route}; + +fn mints_list(harbor: &HarborWallet) -> Element { let header = h_header("Mints", "Manage your mints here."); + let list = if harbor.federation_list.is_empty() { + column![text("No federations added yet.").size(18)] + } else { + harbor + .federation_list + .iter() + .fold(column![], |column, item| { + column.push(h_federation_item(item)) + }) + .spacing(48) + }; + + let add_mint_button = h_button("Add Mint", SvgIcon::Plus, false) + .on_press(Message::Navigate(Route::Mints(MintSubroute::Add))); + + let column = column![header, list, add_mint_button].spacing(48); + + basic_layout(column) +} + +fn mints_add(harbor: &HarborWallet) -> Element { + let header = h_header("Add Mint", "Add a new mint to your wallet."); + let mint_input = h_input( "Mint Invite Code", "", @@ -21,10 +46,16 @@ pub fn mints(harbor: &HarborWallet) -> Element { let add_mint_button = h_button("Add Mint", SvgIcon::Plus, false) .on_press(Message::AddFederation(harbor.mint_invite_code_str.clone())); - let peek_mint_button = h_button("Peek Mint", SvgIcon::Squirrel, false) - .on_press(Message::PeekFederation(harbor.mint_invite_code_str.clone())); + // let peek_mint_button = h_button("Peek Mint", SvgIcon::Squirrel, false) + // .on_press(Message::PeekFederation(harbor.mint_invite_code_str.clone())); - let column = column![header, mint_input, peek_mint_button, add_mint_button].spacing(48); + let column = column![ + header, + mint_input, + // peek_mint_button, + add_mint_button + ] + .spacing(48); // TODO: better error styling let column = column.push_maybe( @@ -34,25 +65,12 @@ pub fn mints(harbor: &HarborWallet) -> Element { .map(|r| text(r).size(18).color(Color::from_rgb8(255, 0, 0))), ); - let column = column.push_maybe( - harbor - .peek_federation_item - .as_ref() - .map(|item| h_federation_item(item)), - ); - - let column = if harbor.federation_list.is_empty() { - column.push(text("No federations added yet.").size(18)) - } else { - let federation_list = harbor - .federation_list - .iter() - .fold(column![], |column, item| { - column.push(h_federation_item(item)) - }); - - column.push(federation_list) - }; - basic_layout(column.spacing(48)) } + +pub fn mints(harbor: &HarborWallet) -> Element { + match harbor.active_route { + Route::Mints(MintSubroute::Add) => mints_add(harbor), + _ => mints_list(harbor), + } +} diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 54ccc31..8046131 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -25,12 +25,19 @@ pub use history::*; pub mod settings; pub use settings::*; +#[derive(Default, PartialEq, Debug, Clone, Copy)] +pub enum MintSubroute { + #[default] + List, + Add, +} + #[derive(Default, PartialEq, Debug, Clone, Copy)] pub enum Route { #[default] Unlock, Home, - Mints, + Mints(MintSubroute), Transfer, History, Settings, diff --git a/src/routes/receive.rs b/src/routes/receive.rs index 26e9be8..5d41047 100644 --- a/src/routes/receive.rs +++ b/src/routes/receive.rs @@ -36,7 +36,7 @@ pub fn receive(harbor: &HarborWallet) -> Element { let column = match (&harbor.receive_success_msg, receive_string) { // Starting state (None, None) => { - let header = h_header("Receive", "Receive on-chain or via lightning."); + let header = h_header("Deposit", "Receive on-chain or via lightning."); let lightning_choice = radio( "Lightning", @@ -61,7 +61,7 @@ pub fn receive(harbor: &HarborWallet) -> Element { ); let onchain = column![onchain_choice, onchain_caption,].spacing(8); - let method_choice_label = text("Receive method").size(24); + let method_choice_label = text("Method").size(24); let method_choice = column![method_choice_label, lightning, onchain].spacing(16); let amount_input = h_input(