Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pending state to mint preview and join #100

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 53 additions & 22 deletions harbor-ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ pub enum ReceiveMethod {
OnChain,
}

#[derive(Default, Debug, Clone, PartialEq)]
pub enum PeekStatus {
#[default]
Idle,
Peeking,
}

#[derive(Default, Debug, Clone, PartialEq)]
pub enum AddFederationStatus {
#[default]
Idle,
Adding,
}

#[derive(Debug, Clone)]
pub enum Message {
// Setup
Expand Down Expand Up @@ -167,17 +181,17 @@ pub struct HarborWallet {
receive_qr_data: Option<Data>,
receive_method: ReceiveMethod,
// Mints
peek_federation_failure_reason: Option<String>,
peek_federation_item: Option<FederationItem>,
mint_invite_code_str: String,
add_federation_failure_reason: Option<String>,
// Donate
donate_amount_str: String,
// Settings
settings_show_seed_words: bool,
seed_words: Option<String>,
current_send_id: Option<Uuid>,
current_receive_id: Option<Uuid>,
peek_status: PeekStatus,
add_federation_status: AddFederationStatus,
}

impl HarborWallet {
Expand Down Expand Up @@ -297,10 +311,10 @@ impl HarborWallet {
}

fn clear_add_federation_state(&mut self) {
self.add_federation_failure_reason = None;
self.peek_federation_failure_reason = None;
self.peek_federation_item = None;
self.mint_invite_code_str = String::new();
self.peek_status = PeekStatus::Idle;
self.add_federation_status = AddFederationStatus::Idle;
}

fn update(&mut self, message: Message) -> Task<Message> {
Expand Down Expand Up @@ -561,27 +575,37 @@ impl HarborWallet {
let invite = InviteCode::from_str(&invite_code);
if let Ok(invite) = invite {
let id = Uuid::new_v4(); // todo use this id somewhere
Task::perform(
Self::async_add_federation(self.ui_handle.clone(), id, invite),
|_| Message::Noop,
)
Task::perform(
Self::async_add_federation(self.ui_handle.clone(), id, invite),
|_| Message::Noop,
)
} else {
self.add_federation_failure_reason = Some("Invalid invite code".to_string());
Task::none()
Task::perform(async {}, move |_| {
Message::AddToast(Toast {
title: "Failed to join mint".to_string(),
body: "Invalid invite code".to_string(),
status: ToastStatus::Bad,
})
})
}
}
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
Task::perform(
Self::async_peek_federation(self.ui_handle.clone(), id, invite),
|_| Message::Noop,
)
} else {
self.peek_federation_failure_reason = Some("Invalid invite code".to_string());
Task::none()
self.peek_status = PeekStatus::Peeking;
let id = Uuid::new_v4();
Task::perform(
Self::async_peek_federation(self.ui_handle.clone(), id, invite),
|_| Message::Noop,
)
} else {
Task::perform(async {}, |_| {
Message::AddToast(Toast {
title: "Failed to preview mint".to_string(),
body: "Invalid invite code".to_string(),
status: ToastStatus::Bad,
})
})
}
}
Message::ChangeFederation(id) => {
Expand Down Expand Up @@ -681,9 +705,15 @@ impl HarborWallet {
Task::none()
}
CoreUIMsg::AddFederationFailed(reason) => {
self.add_federation_failure_reason = Some(reason);
let reason = reason.clone();
self.peek_federation_item = None;
Task::none()
Task::perform(async {}, move |_| {
Message::AddToast(Toast {
title: "Failed to join mint".to_string(),
body: reason.clone(),
status: ToastStatus::Bad,
})
})
}
CoreUIMsg::FederationInfo(config) => {
// todo update the UI with the new config
Expand Down Expand Up @@ -717,13 +747,14 @@ impl HarborWallet {
};

self.peek_federation_item = Some(item);

self.peek_status = PeekStatus::Idle;
Task::none()
}
CoreUIMsg::AddFederationSuccess => {
self.mint_invite_code_str = String::new();
self.active_route = Route::Mints(routes::MintSubroute::List);
self.peek_federation_item = None;
self.add_federation_status = AddFederationStatus::Idle;
Task::none()
}
CoreUIMsg::FederationListUpdated(list) => {
Expand Down
41 changes: 13 additions & 28 deletions harbor-ui/src/routes/mints.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use iced::widget::{column, text};
use iced::{Color, Element};
use iced::Element;

use crate::components::{basic_layout, h_button, h_federation_item, h_header, h_input, SvgIcon};
use crate::{HarborWallet, Message};
use crate::{AddFederationStatus, HarborWallet, Message, PeekStatus};

use super::{MintSubroute, Route};

Expand Down Expand Up @@ -47,51 +47,36 @@ fn mints_add(harbor: &HarborWallet) -> Element<Message> {
None,
);

let peek_mint_button = h_button("Preview", SvgIcon::Eye, false)
let peek_mint_button = h_button("Preview", SvgIcon::Eye, harbor.peek_status == PeekStatus::Peeking)
.on_press(Message::PeekFederation(harbor.mint_invite_code_str.clone()));

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

let column = column.push_maybe(
harbor
.peek_federation_failure_reason
.as_ref()
.map(|r| text(r).size(18).color(Color::from_rgb8(255, 0, 0))),
);

column
column![header, mint_input, peek_mint_button].spacing(48)
}

Some(peek_federation_item) => {
let federation_preview = h_federation_item(peek_federation_item, false);

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

let start_over_button = h_button("Start Over", SvgIcon::Restart, false)
.on_press(Message::CancelAddFederation);

let column = column![
column![
header,
federation_preview,
add_mint_button,
start_over_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))),
);

column
.spacing(48)
}
};

basic_layout(column.spacing(48))
basic_layout(column)
}

pub fn mints(harbor: &HarborWallet) -> Element<Message> {
Expand Down