feat: swap history tauri connector

This commit is contained in:
binarybaron 2024-08-08 12:02:59 +02:00
parent cdd6635c8f
commit 2e1b6f6b43
No known key found for this signature in database
GPG key ID: 99B75D3E1476A26E
22 changed files with 1315 additions and 1297 deletions

View file

@ -21,4 +21,4 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
swap = { path = "../swap" }
tauri = { version = "2.0.0-rc.1", features = ["config-json5"] }
tauri-plugin-shell = "2.0.0-rc.0"
uuid = "1.10.0"

View file

@ -3,5 +3,5 @@
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": ["shell:allow-open"]
"permissions": []
}

View file

@ -3,11 +3,15 @@ use std::sync::Arc;
use once_cell::sync::OnceCell;
use swap::{
api::{
request::{get_balance, BalanceArgs, BalanceResponse},
request::{
get_balance, get_swap_info, get_swap_infos_all, BalanceArgs, BalanceResponse,
GetSwapInfoResponse,
},
Context,
},
cli::command::{Bitcoin, Monero},
};
use uuid::Uuid;
// Lazy load the Context
static CONTEXT: OnceCell<Arc<Context>> = OnceCell::new();
@ -26,6 +30,15 @@ async fn balance() -> Result<BalanceResponse, String> {
.map_err(|e| e.to_string())
}
#[tauri::command]
async fn swap_infos_all() -> Result<Vec<GetSwapInfoResponse>, String> {
let context = CONTEXT.get().unwrap();
get_swap_infos_all(context.clone())
.await
.map_err(|e| e.to_string())
}
fn setup<'a>(app: &'a mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
tauri::async_runtime::block_on(async {
let context = Context::build(
@ -56,8 +69,7 @@ fn setup<'a>(app: &'a mut tauri::App) -> Result<(), Box<dyn std::error::Error>>
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.invoke_handler(tauri::generate_handler![balance])
.invoke_handler(tauri::generate_handler![balance, swap_infos_all])
.setup(setup)
.run(tauri::generate_context!())
.expect("error while running tauri application");