Skip to content

Commit

Permalink
Merge pull request #30 from MutinyWallet/receive-method-choice
Browse files Browse the repository at this point in the history
receive method chooser
  • Loading branch information
benthecarman authored May 16, 2024
2 parents 00960a1 + b6273c0 commit 3f07744
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 12 deletions.
14 changes: 14 additions & 0 deletions assets/icons/qr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/components/caption_text.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use iced::widget::text;
use iced::widget::text::Style;
use iced::{Element, Theme};

use crate::Message;

use super::lighten;

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()
}
2 changes: 2 additions & 0 deletions src/components/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum SvgIcon {
UpRight,
Copy,
Plus,
Qr,
}

pub fn map_icon(icon: SvgIcon) -> Svg<'static, Theme> {
Expand All @@ -27,5 +28,6 @@ pub fn map_icon(icon: SvgIcon) -> Svg<'static, Theme> {
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"),
SvgIcon::Qr => Svg::from_path("assets/icons/qr.svg"),
}
}
3 changes: 3 additions & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ pub use spinner::*;

mod transaction_item;
pub use transaction_item::*;

mod caption_text;
pub use caption_text::*;
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ enum UnlockStatus {
Unlocking,
}

#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
pub enum ReceiveMethod {
#[default]
Lightning,
OnChain,
}

#[derive(Debug, Clone)]
pub enum Message {
// Setup
Expand All @@ -84,6 +91,7 @@ pub enum Message {
MintInviteCodeInputChanged(String),
DonateAmountChanged(String),
CopyToClipboard(String),
ReceiveMethodChanged(ReceiveMethod),
// Async commands we fire from the UI to core
Noop,
Send(String),
Expand Down Expand Up @@ -118,6 +126,7 @@ pub struct HarborWallet {
receive_invoice: Option<Bolt11Invoice>,
receive_address: Option<Address>,
receive_qr_data: Option<Data>,
receive_method: ReceiveMethod,
mint_invite_code_str: String,
add_federation_failure_reason: Option<String>,
donate_amount_str: String,
Expand Down Expand Up @@ -245,6 +254,10 @@ impl HarborWallet {
self.receive_status = ReceiveStatus::Idle;
Command::none()
}
Message::ReceiveMethodChanged(method) => {
self.receive_method = method;
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
53 changes: 41 additions & 12 deletions src/routes/receive.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
use iced::widget::container::Style;
use iced::widget::{column, container, qr_code, scrollable, text};
use iced::widget::{column, container, qr_code, radio, scrollable, text};
use iced::{Border, Element, Font, Padding};
use iced::{Color, Length};

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

pub fn receive(harbor: &HarborWallet) -> Element<Message> {
let lightning_choice = radio(
"Lightning",
ReceiveMethod::Lightning,
Some(harbor.receive_method),
Message::ReceiveMethodChanged,
)
.text_size(18);

let lightning_caption = h_caption_text("Good for small amounts. Instant settlement, low fees.");

let lightning = column![lightning_choice, lightning_caption,].spacing(8);

let onchain_choice = radio(
"On-chain",
ReceiveMethod::OnChain,
Some(harbor.receive_method),
Message::ReceiveMethodChanged,
)
.text_size(18);

let onchain_caption = h_caption_text(
"Good for large amounts. Requires on-chain fees and 10 block confirmations.",
);

let onchain = column![onchain_choice, onchain_caption,].spacing(8);

let method_choice_label = text("Receive method").size(24);

let method_choice = column![method_choice_label, lightning, onchain].spacing(16);

let receive_string = harbor
.receive_invoice
.as_ref()
Expand Down Expand Up @@ -70,21 +100,20 @@ pub fn receive(harbor: &HarborWallet) -> Element<Message> {
Some("sats"),
);

// TODO how to separate lighting and onchain?
let generating = harbor.receive_status == ReceiveStatus::Generating;

let generate_button = h_button("Generate Invoice", SvgIcon::DownLeft, generating)
let generate_button = h_button("Generate Invoice", SvgIcon::Qr, generating)
.on_press(Message::GenerateInvoice);

let generate_address_button = h_button("Generate Address", SvgIcon::Squirrel, generating)
let generate_address_button = h_button("Generate Address", SvgIcon::Qr, generating)
.on_press(Message::GenerateAddress);

column![
header,
amount_input,
generate_button,
generate_address_button
]
match harbor.receive_method {
ReceiveMethod::Lightning => {
column![header, method_choice, amount_input, generate_button]
}
ReceiveMethod::OnChain => column![header, method_choice, generate_address_button],
}
};

container(scrollable(
Expand Down

0 comments on commit 3f07744

Please sign in to comment.