Skip to content

Commit

Permalink
Merge pull request #18 from MutinyWallet/add-mint-screen
Browse files Browse the repository at this point in the history
add mint screen
  • Loading branch information
benthecarman authored May 14, 2024
2 parents 2c906f9 + 541aa19 commit fd3f341
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 20 deletions.
2 changes: 1 addition & 1 deletion assets/icons/heart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions assets/icons/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub enum CoreUIMsg {
ReceiveFailed(String),
BalanceUpdated(Amount),
AddFederationFailed(String),
AddFederationSuccess,
Unlocking,
UnlockSuccess,
UnlockFailed(String),
Expand All @@ -61,12 +62,17 @@ impl UIHandle {
}

pub async fn receive(&self, amount: u64) {
self.msg_send(UICoreMsg::ReceiveLightning(Amount::from_sats(amount))).await;
self.msg_send(UICoreMsg::ReceiveLightning(Amount::from_sats(amount)))
.await;
}

pub async fn unlock(&self, password: String) {
self.msg_send(UICoreMsg::Unlock(password)).await;
}

pub async fn add_federation(&self, invite: InviteCode) {
self.msg_send(UICoreMsg::AddFederation(invite)).await;
}
}

impl CoreHandle {
Expand Down
2 changes: 2 additions & 0 deletions src/components/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub enum SvgIcon {
Squirrel,
UpRight,
Copy,
Plus,
}

pub fn map_icon(icon: SvgIcon) -> Svg<'static, Theme> {
Expand All @@ -25,5 +26,6 @@ pub fn map_icon(icon: SvgIcon) -> Svg<'static, Theme> {
SvgIcon::Squirrel => Svg::from_path("assets/icons/squirrel.svg"),
SvgIcon::UpRight => Svg::from_path("assets/icons/up_right.svg"),
SvgIcon::Copy => Svg::from_path("assets/icons/copy.svg"),
SvgIcon::Plus => Svg::from_path("assets/icons/plus.svg"),
}
}
2 changes: 2 additions & 0 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ pub fn run_core() -> Subscription<Message> {
error!("Error adding federation: {e}");
core.msg(CoreUIMsg::AddFederationFailed(e.to_string()))
.await;
} else {
core.msg(CoreUIMsg::AddFederationSuccess).await;
}
}
// TODO: actually use this to unlock
Expand Down
44 changes: 39 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::run_core;
use fedimint_core::api::InviteCode;
use fedimint_core::Amount;
use fedimint_ln_common::lightning_invoice::Bolt11Invoice;
use iced::widget::qr_code::Data;
Expand Down Expand Up @@ -63,6 +64,8 @@ pub struct HarborWallet {
receive_amount_str: String,
receive_invoice: Option<Bolt11Invoice>,
receive_qr_data: Option<Data>,
mint_invite_code_str: String,
add_federation_failure_reason: Option<String>,
}

impl Default for HarborWallet {
Expand Down Expand Up @@ -105,13 +108,15 @@ pub enum Message {
SendDestInputChanged(String),
SendAmountInputChanged(String),
PasswordInputChanged(String),
MintInviteCodeInputChanged(String),
CopyToClipboard(String),
// Async commands we fire from the UI to core
Noop,
Send(String),
Receive(u64),
GenerateInvoice,
Unlock(String),
AddFederation(String),
// Core messages we get from core
CoreMessage(CoreUIMsg),
}
Expand All @@ -135,6 +140,8 @@ impl HarborWallet {
receive_status: ReceiveStatus::Idle,
receive_invoice: None,
receive_qr_data: None,
mint_invite_code_str: String::new(),
add_federation_failure_reason: None,
}
}

Expand All @@ -143,9 +150,7 @@ impl HarborWallet {
}

async fn async_send(ui_handle: Option<Arc<bridge::UIHandle>>, invoice: Bolt11Invoice) {
println!("Got to async_send");
if let Some(ui_handle) = ui_handle {
println!("Have a ui_handle, sending the invoice over");
ui_handle.clone().send(invoice).await;
} else {
panic!("UI handle is None");
Expand All @@ -168,6 +173,14 @@ impl HarborWallet {
}
}

async fn async_add_federation(ui_handle: Option<Arc<bridge::UIHandle>>, invite: InviteCode) {
if let Some(ui_handle) = ui_handle {
ui_handle.clone().add_federation(invite).await;
} else {
panic!("UI handle is None");
}
}

fn update(&mut self, message: Message) -> Command<Message> {
match message {
// Setup
Expand Down Expand Up @@ -205,6 +218,10 @@ impl HarborWallet {
self.password_input_str = input;
Command::none()
}
Message::MintInviteCodeInputChanged(input) => {
self.mint_invite_code_str = input;
Command::none()
}
// Async commands we fire from the UI to core
Message::Noop => Command::none(),
Message::Send(invoice_str) => match self.send_status {
Expand Down Expand Up @@ -257,6 +274,18 @@ impl HarborWallet {
})
}
},
Message::AddFederation(invite_code) => {
let invite = InviteCode::from_str(&invite_code);
if let Ok(invite) = invite {
Command::perform(
Self::async_add_federation(self.ui_handle.clone(), invite),
|_| Message::Noop,
)
} else {
self.add_federation_failure_reason = Some("Invalid invite code".to_string());
Command::none()
}
}
Message::CopyToClipboard(s) => {
println!("Copying to clipboard: {s}");
clipboard::write(s)
Expand All @@ -281,7 +310,7 @@ impl HarborWallet {
info!("Receive success: {params:?}");
self.receive_status = ReceiveStatus::Idle;
Command::none()
},
}
CoreUIMsg::ReceiveFailed(reason) => {
self.receive_status = ReceiveStatus::Idle;
self.receive_failure_reason = Some(reason);
Expand All @@ -308,8 +337,12 @@ impl HarborWallet {
self.receive_invoice = Some(invoice);
Command::none()
}
CoreUIMsg::AddFederationFailed(_) => {
// todo show error
CoreUIMsg::AddFederationFailed(reason) => {
self.add_federation_failure_reason = Some(reason);
Command::none()
}
CoreUIMsg::AddFederationSuccess => {
self.mint_invite_code_str = String::new();
Command::none()
}
CoreUIMsg::Unlocking => {
Expand Down Expand Up @@ -338,6 +371,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(),
_ => row![sidebar, crate::routes::home(self)].into(),
};

Expand Down
51 changes: 38 additions & 13 deletions src/routes/mints.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
use iced::widget::{column, container, scrollable};
use iced::Length;
use iced::{Alignment, Element};
use iced::widget::{column, container, scrollable, text};
use iced::{Color, Element};
use iced::{Length, Padding};

use crate::components::{h_button, h_header, h_input, SvgIcon};
use crate::{HarborWallet, Message};

pub fn mints(_harbor: &HarborWallet) -> Element<Message> {
container(
scrollable(
column!["These are the mints!",]
.spacing(32)
.align_items(Alignment::Center)
.width(Length::Fill),
)
.height(Length::Fill),
)
pub fn mints(harbor: &HarborWallet) -> Element<Message> {
let header = h_header("Mints", "Manage your mints here.");

let mint_input = h_input(
"Mint Invite Code",
"",
&harbor.mint_invite_code_str,
Message::MintInviteCodeInputChanged,
Message::Noop,
false,
None,
None,
);

let add_mint_button = h_button("Add Mint", SvgIcon::Plus)
.on_press(Message::AddFederation(harbor.mint_invite_code_str.clone()));

let column = column![header, mint_input, add_mint_button].spacing(48);

// TODO: better error styling
let column = column.push_maybe(
harbor
.add_federation_failure_reason
.as_ref()
.map(|r| text(r).size(18).color(Color::from_rgb8(255, 0, 0))),
);

container(scrollable(
column
.spacing(48)
.width(Length::Fill)
.max_width(512)
.padding(Padding::new(48.)),
))
.into()
}

0 comments on commit fd3f341

Please sign in to comment.