Skip to content

Commit

Permalink
wip mint list
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul committed Jun 3, 2024
1 parent c8289dc commit 187ff3a
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 65 deletions.
13 changes: 3 additions & 10 deletions src/components/caption_text.rs
Original file line number Diff line number Diff line change
@@ -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()
}
20 changes: 15 additions & 5 deletions src/components/federation_item.rs
Original file line number Diff line number Diff line change
@@ -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<Message> {
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()
}
10 changes: 3 additions & 7 deletions src/components/header.rs
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
3 changes: 3 additions & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ pub use toast::*;

mod colors;
pub use colors::*;

mod styles;
pub use styles::*;
6 changes: 5 additions & 1 deletion src/components/screen_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message> {
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)
Expand Down
10 changes: 8 additions & 2 deletions src/components/sidebar.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,8 +17,13 @@ pub fn sidebar(harbor: &HarborWallet) -> Element<Message> {
.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,
Expand Down
8 changes: 8 additions & 0 deletions src/components/styles.rs
Original file line number Diff line number Diff line change
@@ -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) }
}
13 changes: 4 additions & 9 deletions src/components/transaction_item.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -78,12 +78,7 @@ pub fn h_transaction_item(item: &TransactionItem) -> Element<Message> {
.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);

Expand Down
2 changes: 2 additions & 0 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<FederationItem>>()
}
Expand Down
9 changes: 7 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>?
let item = FederationItem {
id,
name,
balance: 0,
};

self.peek_federation_item = Some(item);

Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/routes/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub fn home(harbor: &HarborWallet) -> Element<Message> {
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),
Expand Down
66 changes: 42 additions & 24 deletions src/routes/mints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message> {
use super::{MintSubroute, Route};

fn mints_list(harbor: &HarborWallet) -> Element<Message> {
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<Message> {
let header = h_header("Add Mint", "Add a new mint to your wallet.");

let mint_input = h_input(
"Mint Invite Code",
"",
Expand All @@ -21,10 +46,16 @@ pub fn mints(harbor: &HarborWallet) -> Element<Message> {
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(
Expand All @@ -34,25 +65,12 @@ pub fn mints(harbor: &HarborWallet) -> Element<Message> {
.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<Message> {
match harbor.active_route {
Route::Mints(MintSubroute::Add) => mints_add(harbor),
_ => mints_list(harbor),
}
}
9 changes: 8 additions & 1 deletion src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/routes/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn receive(harbor: &HarborWallet) -> Element<Message> {
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",
Expand All @@ -61,7 +61,7 @@ pub fn receive(harbor: &HarborWallet) -> Element<Message> {
);
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(
Expand Down

0 comments on commit 187ff3a

Please sign in to comment.