committed by
William Casarin
parent
ee0029268f
commit
dda7256f51
@@ -10,6 +10,7 @@ use crate::filter::FilterState;
|
||||
use crate::frame_history::FrameHistory;
|
||||
use crate::imgcache::ImageCache;
|
||||
use crate::key_storage::KeyStorageType;
|
||||
use crate::login_manager::LoginState;
|
||||
use crate::note::NoteRef;
|
||||
use crate::notecache::{CachedNote, NoteCache};
|
||||
use crate::relay_pool_manager::RelayPoolManager;
|
||||
@@ -57,6 +58,7 @@ pub struct Damus {
|
||||
pub threads: Threads,
|
||||
pub img_cache: ImageCache,
|
||||
pub accounts: AccountManager,
|
||||
pub login_state: LoginState,
|
||||
pub subscriptions: Subscriptions,
|
||||
|
||||
frame_history: crate::frame_history::FrameHistory,
|
||||
@@ -700,6 +702,7 @@ impl Damus {
|
||||
frame_history: FrameHistory::default(),
|
||||
show_account_switcher: false,
|
||||
account_management_view_state: RoutableWidgetState::default(),
|
||||
login_state: LoginState::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -743,6 +746,7 @@ impl Damus {
|
||||
frame_history: FrameHistory::default(),
|
||||
show_account_switcher: false,
|
||||
account_management_view_state: RoutableWidgetState::default(),
|
||||
login_state: LoginState::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,20 +6,22 @@ use poll_promise::Promise;
|
||||
|
||||
/// The UI view interface to log in to a nostr account.
|
||||
#[derive(Default)]
|
||||
pub struct LoginManager {
|
||||
pub struct LoginState {
|
||||
login_key: String,
|
||||
promise_query: Option<(String, Promise<Result<Keypair, LoginError>>)>,
|
||||
error: Option<LoginError>,
|
||||
key_on_error: Option<String>,
|
||||
should_create_new: bool,
|
||||
}
|
||||
|
||||
impl<'a> LoginManager {
|
||||
impl<'a> LoginState {
|
||||
pub fn new() -> Self {
|
||||
LoginManager {
|
||||
LoginState {
|
||||
login_key: String::new(),
|
||||
promise_query: None,
|
||||
error: None,
|
||||
key_on_error: None,
|
||||
should_create_new: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +87,14 @@ impl<'a> LoginManager {
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn should_create_new(&mut self) {
|
||||
self.should_create_new = true;
|
||||
}
|
||||
|
||||
pub fn check_for_create_new(&self) -> bool {
|
||||
self.should_create_new
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -96,7 +106,7 @@ mod tests {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn test_retrieve_key() {
|
||||
let mut manager = LoginManager::new();
|
||||
let mut manager = LoginState::new();
|
||||
let expected_str = "3efdaebb1d8923ebd99c9e7ace3b4194ab45512e2be79c1b7d68d9243e0d2681";
|
||||
let expected_key = Keypair::only_pubkey(Pubkey::from_hex(expected_str).unwrap());
|
||||
|
||||
|
||||
@@ -1,29 +1,32 @@
|
||||
use crate::app_style::NotedeckTextStyle;
|
||||
use crate::key_parsing::LoginError;
|
||||
use crate::login_manager::LoginManager;
|
||||
use crate::login_manager::LoginState;
|
||||
use crate::ui::{Preview, PreviewConfig, View};
|
||||
use egui::{Align, Button, Color32, Frame, Margin, Response, RichText, Ui, Vec2};
|
||||
use egui::{Image, TextEdit};
|
||||
use egui::TextEdit;
|
||||
use egui::{Align, Button, Color32, Frame, InnerResponse, Margin, RichText, Vec2};
|
||||
use enostr::Keypair;
|
||||
|
||||
pub struct AccountLoginView<'a> {
|
||||
manager: &'a mut LoginManager,
|
||||
manager: &'a mut LoginState,
|
||||
}
|
||||
|
||||
pub enum AccountLoginResponse {
|
||||
CreateNew,
|
||||
LoginWith(Keypair),
|
||||
}
|
||||
|
||||
impl<'a> AccountLoginView<'a> {
|
||||
pub fn new(manager: &'a mut LoginManager) -> Self {
|
||||
AccountLoginView { manager }
|
||||
pub fn new(state: &'a mut LoginState) -> Self {
|
||||
AccountLoginView { manager: state }
|
||||
}
|
||||
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) -> Response {
|
||||
pub fn ui(&mut self, ui: &mut egui::Ui) -> InnerResponse<Option<AccountLoginResponse>> {
|
||||
Frame::none()
|
||||
.outer_margin(12.0)
|
||||
.show(ui, |ui| {
|
||||
self.show(ui);
|
||||
})
|
||||
.response
|
||||
.show(ui, |ui| self.show(ui))
|
||||
}
|
||||
|
||||
fn show(&mut self, ui: &mut egui::Ui) -> egui::Response {
|
||||
fn show(&mut self, ui: &mut egui::Ui) -> Option<AccountLoginResponse> {
|
||||
ui.vertical(|ui| {
|
||||
ui.vertical_centered(|ui| {
|
||||
ui.add_space(32.0);
|
||||
@@ -55,11 +58,19 @@ impl<'a> AccountLoginView<'a> {
|
||||
.add(Button::new(RichText::new("Create Account")).frame(false))
|
||||
.clicked()
|
||||
{
|
||||
// TODO: navigate to 'create account' screen
|
||||
self.manager.should_create_new();
|
||||
}
|
||||
});
|
||||
})
|
||||
.response
|
||||
});
|
||||
|
||||
if self.manager.check_for_create_new() {
|
||||
return Some(AccountLoginResponse::CreateNew);
|
||||
}
|
||||
|
||||
if let Some(keypair) = self.manager.check_for_successful_login() {
|
||||
return Some(AccountLoginResponse::LoginWith(keypair));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn loading_and_error(&mut self, ui: &mut egui::Ui) {
|
||||
@@ -99,37 +110,12 @@ fn login_title_text() -> RichText {
|
||||
.strong()
|
||||
}
|
||||
|
||||
fn login_info_text() -> RichText {
|
||||
RichText::new("The best alternative to tweetDeck built in nostr protocol")
|
||||
.text_style(NotedeckTextStyle::Heading3.text_style())
|
||||
}
|
||||
|
||||
fn login_window_info_text(ui: &Ui) -> RichText {
|
||||
RichText::new("Enter your private key to start using Notedeck")
|
||||
.text_style(NotedeckTextStyle::Body.text_style())
|
||||
.color(ui.visuals().noninteractive().fg_stroke.color)
|
||||
}
|
||||
|
||||
fn login_textedit_info_text() -> RichText {
|
||||
RichText::new("Enter your key")
|
||||
.strong()
|
||||
.text_style(NotedeckTextStyle::Body.text_style())
|
||||
}
|
||||
|
||||
fn logo_unformatted() -> Image<'static> {
|
||||
let logo_gradient_data = egui::include_image!("../../assets/Logo-Gradient-2x.png");
|
||||
return egui::Image::new(logo_gradient_data);
|
||||
}
|
||||
|
||||
fn generate_info_text() -> RichText {
|
||||
RichText::new("Quickly generate your keys. Make sure you save them safely.")
|
||||
.text_style(NotedeckTextStyle::Body.text_style())
|
||||
}
|
||||
|
||||
fn generate_keys_button() -> Button<'static> {
|
||||
Button::new(RichText::new("Generate keys").text_style(NotedeckTextStyle::Body.text_style()))
|
||||
}
|
||||
|
||||
fn login_button() -> Button<'static> {
|
||||
Button::new(
|
||||
RichText::new("Login now — let's do this!")
|
||||
@@ -140,7 +126,7 @@ fn login_button() -> Button<'static> {
|
||||
.min_size(Vec2::new(0.0, 40.0))
|
||||
}
|
||||
|
||||
fn login_textedit(manager: &mut LoginManager) -> TextEdit {
|
||||
fn login_textedit(manager: &mut LoginState) -> TextEdit {
|
||||
manager.get_login_textedit(|text| {
|
||||
egui::TextEdit::singleline(text)
|
||||
.hint_text(
|
||||
@@ -156,7 +142,7 @@ mod preview {
|
||||
use super::*;
|
||||
|
||||
pub struct AccountLoginPreview {
|
||||
manager: LoginManager,
|
||||
manager: LoginState,
|
||||
}
|
||||
|
||||
impl View for AccountLoginPreview {
|
||||
@@ -169,7 +155,8 @@ mod preview {
|
||||
type Prev = AccountLoginPreview;
|
||||
|
||||
fn preview(cfg: PreviewConfig) -> Self::Prev {
|
||||
let manager = LoginManager::new();
|
||||
let _ = cfg;
|
||||
let manager = LoginState::new();
|
||||
AccountLoginPreview { manager }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user