feat: add check active account before init client

This commit is contained in:
2024-02-05 13:36:10 +07:00
parent 2a58326cd1
commit 08fa7de01d
9 changed files with 85 additions and 76 deletions

View File

@@ -1,11 +1,11 @@
use crate::AppState;
use crate::Nostr;
use nostr_sdk::prelude::*;
use std::time::Duration;
use tauri::State;
#[tauri::command(async)]
pub async fn get_event(id: String, app_state: State<'_, AppState>) -> Result<String, ()> {
let client = &app_state.nostr;
pub async fn get_event(id: String, nostr: State<'_, Nostr>) -> Result<String, ()> {
let client = &nostr.client;
let event_id = EventId::from_bech32(id).unwrap();
let filter = Filter::new().id(event_id);

View File

@@ -1,4 +1,4 @@
use crate::AppState;
use crate::Nostr;
use nostr_sdk::prelude::*;
use tauri::State;
@@ -29,8 +29,8 @@ pub fn get_public_key(secret_key: SecretKey) -> Result<String, ()> {
}
#[tauri::command]
pub async fn update_signer(key: String, app_state: State<'_, AppState>) -> Result<(), ()> {
let client = &app_state.nostr;
pub async fn update_signer(key: String, nostr: State<'_, Nostr>) -> Result<(), ()> {
let client = &nostr.client;
let secret_key = SecretKey::from_bech32(key).unwrap();
let keys = Keys::new(secret_key);
let signer = ClientSigner::Keys(keys);
@@ -41,8 +41,8 @@ pub async fn update_signer(key: String, app_state: State<'_, AppState>) -> Resul
}
#[tauri::command]
pub async fn verify_signer(app_state: State<'_, AppState>) -> Result<bool, ()> {
let client = &app_state.nostr;
pub async fn verify_signer(nostr: State<'_, Nostr>) -> Result<bool, ()> {
let client = &nostr.client;
let status = client.signer().await.is_ok();
Ok(status)

View File

@@ -1,11 +1,11 @@
use crate::AppState;
use crate::Nostr;
use nostr_sdk::prelude::*;
use std::time::Duration;
use tauri::State;
#[tauri::command(async)]
pub async fn get_metadata(npub: String, app_state: State<'_, AppState>) -> Result<Metadata, ()> {
let client = &app_state.nostr;
pub async fn get_metadata(npub: String, nostr: State<'_, Nostr>) -> Result<Metadata, ()> {
let client = &nostr.client;
let public_key = XOnlyPublicKey::from_bech32(npub).unwrap();