Skip to content

Commit

Permalink
feat: added modules to peek
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlwn123 committed Jun 10, 2024
1 parent 60648f9 commit 043aec2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ clippy:
cargo clippy --all-features --tests -- -D warnings

reset-db:
diesel migration revert --all --database-url=harbor.sqlite && diesel migration run --database-url=harbor.sqlite
diesel migration revert --all --database-url=harbor.sqlite && diesel migration run --database-url=harbor.sqlite
19 changes: 18 additions & 1 deletion src/components/federation_item.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fedimint_core::config::FederationId;
use fedimint_core::{config::FederationId, core::ModuleKind};
use iced::{
widget::{column, row, text},
Alignment, Element,
Expand All @@ -15,6 +15,7 @@ pub struct FederationItem {
pub name: String,
pub balance: u64,
pub guardians: Option<Vec<String>>,
pub module_kinds: Option<Vec<ModuleKind>>,
}

pub fn h_federation_item(item: &FederationItem) -> Element<Message> {
Expand All @@ -23,6 +24,7 @@ pub fn h_federation_item(item: &FederationItem) -> Element<Message> {
name,
balance,
guardians: _,
module_kinds: _,
} = item;
let title = row![map_icon(SvgIcon::People, 24., 24.), text(name).size(24)]
.align_items(Alignment::Center)
Expand All @@ -42,6 +44,7 @@ pub fn h_federation_item2(item: &FederationItem) -> Element<Message> {
name,
balance: _,
guardians,
module_kinds,
} = item;

let name_row = row![
Expand All @@ -67,5 +70,19 @@ pub fn h_federation_item2(item: &FederationItem) -> Element<Message> {
column = column.push(guardians_row);
}

if let Some(module_kinds) = module_kinds {
let module_str = module_kinds
.iter()
.map(|m| m.to_string())
.collect::<Vec<String>>()
.join(", ");
let modules_row = row![
bold_text("Modules: ".to_string(), 24),
regular_text(module_str, 24),
]
.spacing(8);
column = column.push(modules_row);
}

column.into()
}
1 change: 1 addition & 0 deletions src/components/screen_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn h_screen_header(harbor: &HarborWallet, show_balance: bool) -> Element<Mes
id: _,
balance: _,
guardians: _guardians,
module_kinds: _module_kinds,
} = item;
let people_icon = map_icon(SvgIcon::People, 24., 24.);
let current_federation = row![people_icon, text(name).size(24)]
Expand Down
1 change: 1 addition & 0 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ impl HarborCore {
// TODO: get the balance per fedimint
balance: 420,
guardians: None,
module_kinds: None,
})
.collect::<Vec<FederationItem>>()
}
Expand Down
1 change: 1 addition & 0 deletions src/fedimint_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub(crate) struct FedimintClient {
stop: Arc<AtomicBool>,
}

#[allow(dead_code)]
#[derive(Debug, Clone)]
pub enum FederationInviteOrId {
Invite(InviteCode),
Expand Down
11 changes: 11 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use components::{FederationItem, Toast, ToastManager, ToastStatus, TransactionIt
use core::run_core;
use fedimint_core::api::InviteCode;
use fedimint_core::config::FederationId;
use fedimint_core::core::ModuleKind;
use fedimint_ln_common::lightning_invoice::Bolt11Invoice;
use iced::widget::qr_code::Data;
use routes::Route;
Expand Down Expand Up @@ -459,6 +460,7 @@ impl HarborWallet {
Message::PeekFederation(invite_code) => {
let invite = InviteCode::from_str(&invite_code);
if let Ok(invite) = invite {
self.add_federation_failure_reason = None;
let id = Uuid::new_v4(); // todo use this id somewhere
Command::perform(
Self::async_peek_federation(self.ui_handle.clone(), id, invite),
Expand Down Expand Up @@ -558,6 +560,7 @@ impl HarborWallet {
}
CoreUIMsg::AddFederationFailed(reason) => {
self.add_federation_failure_reason = Some(reason);
self.peek_federation_item = None;
Command::none()
}
CoreUIMsg::FederationInfo(config) => {
Expand All @@ -571,6 +574,12 @@ impl HarborWallet {
.map(|url| url.name.clone())
.collect();

let module_kinds = config
.modules
.into_values()
.map(|module_config| module_config.kind().to_owned())
.collect::<Vec<ModuleKind>>();

let name = match name {
Ok(Some(n)) => n,
_ => "Unknown".to_string(),
Expand All @@ -582,6 +591,7 @@ impl HarborWallet {
name,
balance: 0,
guardians: Some(guardians),
module_kinds: Some(module_kinds),
};

self.peek_federation_item = Some(item);
Expand All @@ -591,6 +601,7 @@ impl HarborWallet {
CoreUIMsg::AddFederationSuccess => {
self.mint_invite_code_str = String::new();
self.active_route = Route::Mints(routes::MintSubroute::List);
self.peek_federation_item = None;
Command::none()
}
CoreUIMsg::FederationListUpdated(list) => {
Expand Down

0 comments on commit 043aec2

Please sign in to comment.