chore: update keys.rs and relay.rs (#193)

This commit is contained in:
XIAO YU 2024-05-26 09:28:16 +09:00 committed by GitHub
parent bba324ea53
commit b90ad1421f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 7 deletions

View File

@ -88,12 +88,12 @@ pub async fn save_account(
#[specta::specta]
pub async fn load_account(npub: &str, state: State<'_, Nostr>) -> Result<bool, String> {
let client = &state.client;
let keyring = Entry::new(&npub, "nostr_secret").unwrap();
let keyring = Entry::new(npub, "nostr_secret").unwrap();
match keyring.get_password() {
Ok(password) => {
if password.starts_with("bunker://") {
let local_keyring = Entry::new(&npub, "bunker_local_account").unwrap();
let local_keyring = Entry::new(npub, "bunker_local_account").unwrap();
match local_keyring.get_password() {
Ok(local_password) => {

View File

@ -19,7 +19,7 @@ pub async fn get_relays(state: State<'_, Nostr>) -> Result<Relays, ()> {
// Get connected relays
let list = client.relays().await;
let connected_relays: Vec<String> = list.into_iter().map(|(url, _)| url.to_string()).collect();
let connected_relays: Vec<String> = list.into_keys().map(|url| url.to_string()).collect();
// Get NIP-65 relay list
let signer = client.signer().await.unwrap();
@ -80,9 +80,9 @@ pub async fn get_relays(state: State<'_, Nostr>) -> Result<Relays, ()> {
pub async fn connect_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool, ()> {
let client = &state.client;
if let Ok(status) = client.add_relay(relay).await {
if status == true {
if status {
println!("connecting to relay: {}", relay);
let _ = client.connect_relay(relay);
let _ = client.connect_relay(relay).await;
Ok(true)
} else {
Ok(false)
@ -96,8 +96,8 @@ pub async fn connect_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool,
#[specta::specta]
pub async fn remove_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool, ()> {
let client = &state.client;
if let Ok(_) = client.remove_relay(relay).await {
let _ = client.disconnect_relay(relay);
if (client.remove_relay(relay).await).is_ok() {
let _ = client.disconnect_relay(relay).await;
Ok(true)
} else {
Ok(false)