clean up
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m58s
Rust / build (ubuntu-latest, stable) (pull_request) Failing after 1m50s
Rust / build (macos-latest, stable) (push) Has been cancelled
Rust / build (windows-latest, stable) (push) Has been cancelled
Rust / build (macos-latest, stable) (pull_request) Has been cancelled
Rust / build (windows-latest, stable) (pull_request) Has been cancelled

This commit is contained in:
2026-03-02 09:01:44 +07:00
parent 703c4923ca
commit 0c7104de85
11 changed files with 103 additions and 122 deletions

View File

@@ -40,10 +40,9 @@ pub const WOT_RELAYS: [&str; 1] = ["wss://relay.vertexlab.io"];
pub const SEARCH_RELAYS: [&str; 2] = ["wss://antiprimal.net", "wss://search.nos.today"];
/// Default bootstrap relays
pub const BOOTSTRAP_RELAYS: [&str; 4] = [
"wss://nos.lol",
"wss://relay.damus.io",
pub const BOOTSTRAP_RELAYS: [&str; 3] = [
"wss://relay.primal.net",
"wss://indexer.coracle.social",
"wss://user.kindpag.es",
];

View File

@@ -42,16 +42,6 @@ struct GlobalNostrRegistry(Entity<NostrRegistry>);
impl Global for GlobalNostrRegistry {}
/// Signer event.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum SignerEvent {
/// A new signer has been set
Set,
/// An error occurred
Error(String),
}
/// Nostr Registry
#[derive(Debug)]
pub struct NostrRegistry {
@@ -75,12 +65,6 @@ pub struct NostrRegistry {
/// Relay list state
pub relay_list_state: RelayState,
/// Whether Coop is connected to all bootstrap relays
pub connected: bool,
/// Whether Coop is creating a new signer
pub creating: bool,
/// Tasks for asynchronous operations
tasks: Vec<Task<Result<(), Error>>>,
}
@@ -140,8 +124,6 @@ impl NostrRegistry {
app_keys,
gossip,
relay_list_state: RelayState::Idle,
connected: false,
creating: false,
tasks: vec![],
}
}
@@ -161,12 +143,6 @@ impl NostrRegistry {
self.npubs.clone()
}
/// Set the connected status of the client
fn set_connected(&mut self, cx: &mut Context<Self>) {
self.connected = true;
cx.notify();
}
/// Connect to the bootstrapping relays
fn connect(&mut self, cx: &mut Context<Self>) {
let client = self.client();
@@ -185,13 +161,12 @@ impl NostrRegistry {
}
// Connect to all added relays
client.connect().and_wait(Duration::from_secs(5)).await;
client.connect().and_wait(Duration::from_secs(2)).await;
})
.await;
// Update the state
this.update(cx, |this, cx| {
this.set_connected(cx);
this.get_npubs(cx);
})?;
@@ -317,12 +292,6 @@ impl NostrRegistry {
}));
}
/// Set whether Coop is creating a new signer
fn set_creating(&mut self, creating: bool, cx: &mut Context<Self>) {
self.creating = creating;
cx.notify();
}
/// Create a new identity
fn create_identity(&mut self, cx: &mut Context<Self>) {
let client = self.client();
@@ -335,9 +304,6 @@ impl NostrRegistry {
// Create a write credential task
let write_credential = cx.write_credentials(&username, &username, &secret);
// Set the creating signer status
self.set_creating(true, cx);
// Run async tasks in background
let task: Task<Result<(), Error>> = cx.background_spawn(async move {
let signer = async_keys.into_nostr_signer();
@@ -394,8 +360,8 @@ impl NostrRegistry {
// Wait for the task to complete
task.await?;
// Set signer
this.update(cx, |this, cx| {
this.set_creating(false, cx);
this.set_signer(keys, cx);
})?;
@@ -416,8 +382,8 @@ impl NostrRegistry {
cx.spawn(async move |_cx| {
let (_, secret) = read_credential
.await
.map_err(|_| anyhow!("Failed to get signer"))?
.ok_or_else(|| anyhow!("Failed to get signer"))?;
.map_err(|_| anyhow!("Failed to get signer. Please re-import the secret key"))?
.ok_or_else(|| anyhow!("Failed to get signer. Please re-import the secret key"))?;
// Try to parse as a direct secret key first
if let Ok(secret_key) = SecretKey::from_slice(&secret) {
@@ -507,7 +473,7 @@ impl NostrRegistry {
let secret = keys.secret_key().to_secret_bytes();
// Write the credential to the keyring
let write_credential = cx.write_credentials(&username, &username, &secret);
let write_credential = cx.write_credentials(&username, "keys", &secret);
self.tasks.push(cx.spawn(async move |this, cx| {
match write_credential.await {
@@ -546,7 +512,7 @@ impl NostrRegistry {
Ok((public_key, uri)) => {
let username = public_key.to_bech32().unwrap();
let write_credential = this.read_with(cx, |_this, cx| {
cx.write_credentials(&username, &username, uri.to_string().as_bytes())
cx.write_credentials(&username, "nostrconnect", uri.to_string().as_bytes())
})?;
match write_credential.await {
@@ -1020,6 +986,16 @@ fn default_messaging_relays() -> Vec<RelayUrl> {
]
}
/// Signer event.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum SignerEvent {
/// A new signer has been set
Set,
/// An error occurred
Error(String),
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub enum RelayState {
#[default]