Skip to content

Commit

Permalink
unlock works
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul committed May 15, 2024
1 parent a0c623e commit 562e5db
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 31 deletions.
9 changes: 8 additions & 1 deletion src/components/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ pub fn h_button(text_str: &str, icon: SvgIcon, loading: bool) -> Button<'_, Mess

Button::new(center(content))
.style(|theme, status| {
let gray = lighten(theme.palette().background, 0.5);

let border_color = match status {
Status::Disabled => gray,
_ => Color::WHITE,
};

let border = Border {
color: Color::WHITE,
color: border_color,
width: 2.,
radius: (8.).into(),
};
Expand Down
3 changes: 3 additions & 0 deletions src/components/easing.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Stolen from https://github.com/iced-rs/iced/tree/master/examples/loading_spinners

use iced::Point;

use lyon_algorithms::measure::PathMeasurements;
Expand Down Expand Up @@ -111,6 +113,7 @@ impl Builder {

fn point(p: impl Into<Point>) -> lyon_algorithms::geom::Point<f32> {
let p: Point = p.into();
#[allow(clippy::manual_clamp)]
lyon_algorithms::geom::point(p.x.min(1.0).max(0.0), p.y.min(1.0).max(0.0))
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ pub fn h_input<'a>(
placeholder: &'static str,
value: &'a str,
on_input: impl Fn(String) -> Message + 'a,
on_submit: Message,
on_submit: Option<Message>,
secure: bool,
id: Option<&'static str>,
suffix: Option<&'static str>,
) -> Element<'a, Message, Theme> {
let on_submit = on_submit.unwrap_or(Message::Noop);

let input = TextInput::new(placeholder, value)
.style(|theme: &Theme, status| {
let gray = lighten(theme.palette().background, 0.5);
Expand Down
6 changes: 4 additions & 2 deletions src/components/spinner.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Stolen from https://github.com/iced-rs/iced/tree/master/examples/loading_spinners

//! Show a circular progress indicator.
use iced::advanced::layout;
use iced::advanced::renderer;
Expand Down Expand Up @@ -26,9 +28,9 @@ const BASE_ROTATION_SPEED: u32 = u32::MAX / 80;
pub fn the_spinner() -> Element<'static, Message, Theme> {
let easing = &STANDARD;
let spinner = Circular::<Theme>::new()
.easing(&easing)
.easing(easing)
.cycle_duration(Duration::from_secs_f32(2.));
return spinner.into();
spinner.into()
}

#[allow(missing_debug_implementations)]
Expand Down
5 changes: 5 additions & 0 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::str::FromStr;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use std::time::{Duration, SystemTime};
use tokio::time::sleep;

use iced::{
futures::{channel::mpsc::Sender, SinkExt},
Expand Down Expand Up @@ -219,10 +220,14 @@ pub fn run_core() -> Subscription<Message> {

match msg {
Some(UICoreMsg::Unlock(password)) => {
log::info!("Sending unlock message");
tx.send(Message::CoreMessage(CoreUIMsg::Unlocking))
.await
.expect("should send");

// TODO: for some reason the unlocking message gets delivered at the end if I don't sleep here
sleep(Duration::from_secs(1)).await;

// attempting to unlock
let db = setup_db(
path.join("harbor.sqlite")
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ enum ReceiveStatus {
WaitingToReceive,
}

#[derive(Default, Debug, Clone)]
#[derive(Default, Debug, Clone, PartialEq)]
enum UnlockStatus {
#[default]
Locked,
Expand Down Expand Up @@ -400,6 +400,7 @@ impl HarborWallet {
Command::none()
}
CoreUIMsg::Unlocking => {
info!("Got unlocking message");
self.unlock_status = UnlockStatus::Unlocking;
Command::none()
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/mints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn mints(harbor: &HarborWallet) -> Element<Message> {
"",
&harbor.mint_invite_code_str,
Message::MintInviteCodeInputChanged,
Message::Noop,
None,
false,
None,
None,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn receive(harbor: &HarborWallet) -> Element<Message> {
"420",
&harbor.receive_amount_str,
Message::ReceiveAmountChanged,
Message::Noop,
None,
false,
None,
Some("sats"),
Expand Down
4 changes: 2 additions & 2 deletions src/routes/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn send(harbor: &HarborWallet) -> Element<Message> {
"420",
&harbor.send_amount_input_str,
Message::SendAmountInputChanged,
Message::Noop,
None,
false,
None,
Some("sats"),
Expand All @@ -34,7 +34,7 @@ pub fn send(harbor: &HarborWallet) -> Element<Message> {
"abc123...",
&harbor.send_dest_input_str,
Message::SendDestInputChanged,
Message::Noop,
None,
false,
None,
None,
Expand Down
52 changes: 30 additions & 22 deletions src/routes/unlock.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
use crate::components::{h_button, h_input, SvgIcon};
use crate::{
components::{h_button, h_input, SvgIcon},
UnlockStatus,
};
use iced::{
widget::{center, column, container, text, Svg},
Color, Theme,
Color,
};
use iced::{Alignment, Element, Length};

use crate::{HarborWallet, Message};

pub fn unlock(harbor: &HarborWallet) -> Element<Message, Theme> {
let unlock_button = h_button("Unlock", SvgIcon::DownLeft, false)
.on_press(Message::Unlock(harbor.password_input_str.clone()))
.width(Length::Fill);
pub fn unlock(harbor: &HarborWallet) -> Element<Message> {
let action = if harbor.unlock_status == UnlockStatus::Unlocking {
None
} else {
Some(Message::Unlock(harbor.password_input_str.clone()))
};

let unlock_button = h_button(
"Unlock",
SvgIcon::DownLeft,
harbor.unlock_status == UnlockStatus::Unlocking,
)
.on_press_maybe(action.clone())
.width(Length::Fill);

let password_input = h_input(
"Password",
"",
&harbor.password_input_str,
Message::PasswordInputChanged,
Message::Unlock(harbor.password_input_str.clone()),
action,
true,
Some("password_unlock_input"),
None,
Expand All @@ -27,21 +40,16 @@ pub fn unlock(harbor: &HarborWallet) -> Element<Message, Theme> {
.width(167)
.height(61);

if let Some(e) = &harbor.unlock_failure_reason {
let error_reason = text(format!("Error: {:?}", e))
let page_column = column![harbor_logo, password_input, unlock_button,]
.spacing(32)
.align_items(Alignment::Center)
.width(Length::Fixed(256.));

let page_column = page_column.push_maybe(harbor.unlock_failure_reason.as_ref().map(|r| {
text(format!("Error: {:?}", r))
.size(24)
.color(Color::from_rgb8(250, 0, 80));
.color(Color::from_rgb8(250, 0, 80))
}));

let page_columns = column![harbor_logo, password_input, unlock_button, error_reason]
.spacing(32)
.align_items(Alignment::Center)
.width(Length::Fixed(256.));
container(center(page_columns)).into()
} else {
let page_columns = column![harbor_logo, password_input, unlock_button]
.spacing(32)
.align_items(Alignment::Center)
.width(Length::Fixed(256.));
container(center(page_columns)).into()
}
container(center(page_column)).into()
}

0 comments on commit 562e5db

Please sign in to comment.