refactor app state

This commit is contained in:
2024-11-24 15:17:35 +07:00
parent 17e7766401
commit db7e28a78a
12 changed files with 49 additions and 65 deletions

View File

@@ -8,5 +8,3 @@ gpui.workspace = true
nostr-sdk.workspace = true
dirs.workspace = true
tokio.workspace = true
keyring-search.workspace = true
keyring.workspace = true

View File

@@ -1,5 +1,4 @@
use gpui::Global;
use keyring::Entry;
use nostr_sdk::prelude::*;
use state::get_client;
@@ -18,15 +17,4 @@ impl NostrClient {
Self { client }
}
pub fn add_account(&self, keys: Keys) -> Result<()> {
let public_key = keys.public_key().to_bech32()?;
let secret = keys.secret_key().to_secret_hex();
let entry = Entry::new("Coop Safe Storage", &public_key)?;
// Add secret to keyring
entry.set_password(&secret)?;
Ok(())
}
}

View File

@@ -1,6 +1,6 @@
use dirs::config_dir;
use nostr_sdk::prelude::*;
use std::fs;
use std::{fs, time::Duration};
use tokio::sync::OnceCell;
pub static CLIENT: OnceCell<Client> = OnceCell::const_new();
@@ -17,15 +17,17 @@ pub async fn get_client() -> &'static Client {
.expect("Database is NOT initialized");
// Setup Nostr Client
let client = ClientBuilder::default().database(lmdb).build();
let opts = Options::new().gossip(true).timeout(Duration::from_secs(5));
let client = ClientBuilder::default().database(lmdb).opts(opts).build();
// Add some bootstrap relays
let _ = client.add_relay("wss://relay.damus.io").await;
let _ = client.add_relay("wss://relay.primal.net").await;
let _ = client.add_relay("wss://nostr.fmt.wiz.biz").await;
let _ = client.add_relay("wss://directory.yabu.me").await;
let _ = client.add_relay("wss://purplepag.es").await;
let _ = client.add_relay("wss://user.kindpag.es/").await;
let _ = client.add_discovery_relay("wss://user.kindpag.es/").await;
let _ = client.add_discovery_relay("wss://purplepag.es").await;
// Connect to all relays
client.connect().await;