update
This commit is contained in:
@@ -47,12 +47,12 @@ impl Global for GlobalNostrRegistry {}
|
|||||||
/// Signer event.
|
/// Signer event.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum StateEvent {
|
pub enum StateEvent {
|
||||||
|
/// The state is busy
|
||||||
|
Busy,
|
||||||
|
/// User has no signer
|
||||||
|
NoSigner,
|
||||||
/// The signer has changed
|
/// The signer has changed
|
||||||
SignerChanged,
|
SignerChanged,
|
||||||
/// Connecting to the bootstrapping relay
|
|
||||||
Connecting,
|
|
||||||
/// Connected to the bootstrapping relay
|
|
||||||
Connected,
|
|
||||||
/// An error occurred
|
/// An error occurred
|
||||||
Error(String),
|
Error(String),
|
||||||
}
|
}
|
||||||
@@ -65,14 +65,6 @@ impl StateEvent {
|
|||||||
Self::Error(error.into())
|
Self::Error(error.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_connecting(&self) -> bool {
|
|
||||||
matches!(self, StateEvent::Connecting)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_connected(&self) -> bool {
|
|
||||||
matches!(self, StateEvent::Connected)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn signer_changed(&self) -> bool {
|
pub fn signer_changed(&self) -> bool {
|
||||||
matches!(self, StateEvent::SignerChanged)
|
matches!(self, StateEvent::SignerChanged)
|
||||||
}
|
}
|
||||||
@@ -198,9 +190,6 @@ impl NostrRegistry {
|
|||||||
fn connect_bootstrap_relays(&mut self, cx: &mut Context<Self>) {
|
fn connect_bootstrap_relays(&mut self, cx: &mut Context<Self>) {
|
||||||
let client = self.client();
|
let client = self.client();
|
||||||
|
|
||||||
// Emit connecting event
|
|
||||||
cx.emit(StateEvent::Connecting);
|
|
||||||
|
|
||||||
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
|
||||||
// Add indexer relay to the relay pool
|
// Add indexer relay to the relay pool
|
||||||
for url in INDEXER_RELAYS.into_iter() {
|
for url in INDEXER_RELAYS.into_iter() {
|
||||||
@@ -226,12 +215,7 @@ impl NostrRegistry {
|
|||||||
this.update(cx, |_this, cx| {
|
this.update(cx, |_this, cx| {
|
||||||
cx.emit(StateEvent::error(e.to_string()));
|
cx.emit(StateEvent::error(e.to_string()));
|
||||||
})?;
|
})?;
|
||||||
} else {
|
|
||||||
this.update(cx, |_this, cx| {
|
|
||||||
cx.emit(StateEvent::Connected);
|
|
||||||
})?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -273,7 +257,7 @@ impl NostrRegistry {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
this.update(cx, |_, cx| {
|
this.update(cx, |_, cx| {
|
||||||
cx.notify();
|
cx.emit(StateEvent::NoSigner);
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ impl ImportIdentity {
|
|||||||
let value = self.key_input.read(cx).value();
|
let value = self.key_input.read(cx).value();
|
||||||
let password = self.pass_input.read(cx).value();
|
let password = self.pass_input.read(cx).value();
|
||||||
|
|
||||||
|
// Set loading state
|
||||||
|
self.set_loading(true, cx);
|
||||||
|
|
||||||
if value.starts_with("ncryptsec1") {
|
if value.starts_with("ncryptsec1") {
|
||||||
self.ncryptsec(value, password, window, cx);
|
self.ncryptsec(value, password, window, cx);
|
||||||
return;
|
return;
|
||||||
@@ -86,7 +89,6 @@ impl ImportIdentity {
|
|||||||
nostr.update(cx, |this, cx| {
|
nostr.update(cx, |this, cx| {
|
||||||
this.set_signer(keys, cx);
|
this.set_signer(keys, cx);
|
||||||
});
|
});
|
||||||
window.close_modal(cx);
|
|
||||||
} else {
|
} else {
|
||||||
self.set_error("Invalid key", cx);
|
self.set_error("Invalid key", cx);
|
||||||
}
|
}
|
||||||
@@ -165,10 +167,17 @@ impl ImportIdentity {
|
|||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_loading(&mut self, status: bool, cx: &mut Context<Self>) {
|
||||||
|
self.loading = status;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
|
||||||
fn set_error<S>(&mut self, message: S, cx: &mut Context<Self>)
|
fn set_error<S>(&mut self, message: S, cx: &mut Context<Self>)
|
||||||
where
|
where
|
||||||
S: Into<SharedString>,
|
S: Into<SharedString>,
|
||||||
{
|
{
|
||||||
|
self.set_loading(false, cx);
|
||||||
|
|
||||||
// Update error message
|
// Update error message
|
||||||
self.error.update(cx, |this, cx| {
|
self.error.update(cx, |this, cx| {
|
||||||
*this = Some(message.into());
|
*this = Some(message.into());
|
||||||
@@ -223,7 +232,7 @@ impl Render for ImportIdentity {
|
|||||||
this.child(
|
this.child(
|
||||||
div()
|
div()
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.text_color(cx.theme().warning_active)
|
.text_color(cx.theme().text_warning)
|
||||||
.child(MSG),
|
.child(MSG),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ pub fn init(window: &mut Window, cx: &mut App) -> Entity<Workspace> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct DeviceNotifcation;
|
struct DeviceNotifcation;
|
||||||
struct RelayNotifcation;
|
|
||||||
struct MsgRelayNotification;
|
struct MsgRelayNotification;
|
||||||
|
|
||||||
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
#[derive(Action, Clone, PartialEq, Eq, Deserialize)]
|
||||||
@@ -86,8 +85,6 @@ impl Workspace {
|
|||||||
cx.observe_in(&nostr, window, move |this, nostr, window, cx| {
|
cx.observe_in(&nostr, window, move |this, nostr, window, cx| {
|
||||||
if nostr.read(cx).current_user().is_some() {
|
if nostr.read(cx).current_user().is_some() {
|
||||||
this.set_center_layout(window, cx);
|
this.set_center_layout(window, cx);
|
||||||
} else {
|
|
||||||
this.import_identity(window, cx);
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -103,25 +100,15 @@ impl Workspace {
|
|||||||
// Subscribe to the nostr events
|
// Subscribe to the nostr events
|
||||||
cx.subscribe_in(&nostr, window, move |this, _state, event, window, cx| {
|
cx.subscribe_in(&nostr, window, move |this, _state, event, window, cx| {
|
||||||
match event {
|
match event {
|
||||||
StateEvent::Connecting => {
|
|
||||||
let note = Notification::new()
|
|
||||||
.id::<RelayNotifcation>()
|
|
||||||
.message("Connecting to the bootstrap relays...")
|
|
||||||
.with_kind(NotificationKind::Info);
|
|
||||||
|
|
||||||
window.push_notification(note, cx);
|
|
||||||
}
|
|
||||||
StateEvent::Connected => {
|
|
||||||
let note = Notification::new()
|
|
||||||
.id::<RelayNotifcation>()
|
|
||||||
.message("Connected to the bootstrap relays")
|
|
||||||
.with_kind(NotificationKind::Success);
|
|
||||||
|
|
||||||
window.push_notification(note, cx);
|
|
||||||
}
|
|
||||||
StateEvent::SignerChanged => {
|
StateEvent::SignerChanged => {
|
||||||
this.set_center_layout(window, cx);
|
this.set_center_layout(window, cx);
|
||||||
window.close_all_modals(cx);
|
|
||||||
|
cx.defer_in(window, |_this, window, cx| {
|
||||||
|
window.close_all_modals(cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
StateEvent::NoSigner => {
|
||||||
|
this.import_identity(window, cx);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user