chore: Refactor tauri commands

This commit is contained in:
binarybaron 2024-08-08 12:28:33 +02:00
parent 2e1b6f6b43
commit 4f336e98a1
No known key found for this signature in database
GPG key ID: 99B75D3E1476A26E
3 changed files with 13 additions and 15 deletions

View file

@ -1,5 +1,4 @@
import { invoke } from "@tauri-apps/api/core";
import { BalanceBitcoinResponse } from "models/rpcModel";
import { store } from "./store/storeRenderer";
import { rpcSetBalance, rpcSetSwapInfo } from "store/features/rpcSlice";
@ -14,6 +13,6 @@ export async function checkBitcoinBalance() {
export async function getRawSwapInfos() {
const response = await invoke("swap_infos_all");
console.log(response);
(response as any[]).forEach((info) => store.dispatch(rpcSetSwapInfo(info)));
}

View file

@ -1,7 +1,7 @@
[package]
name = "unstoppableswap-gui-rs"
version = "0.0.0"
authors = ["binarybaron", "einliterflasche", "unstoppableswap"]
authors = [ "binarybaron", "einliterflasche", "unstoppableswap" ]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -9,16 +9,16 @@ description = "A Tauri App"
[lib]
name = "unstoppableswap_gui_rs_lib"
crate-type = ["lib", "cdylib", "staticlib"]
crate-type = [ "lib", "cdylib", "staticlib" ]
[build-dependencies]
tauri-build = { version = "2.0.0-rc.1", features = ["config-json5"] }
tauri-build = { version = "2.0.0-rc.1", features = [ "config-json5" ] }
[dependencies]
anyhow = "1"
once_cell = "1"
serde = { version = "1", features = ["derive"] }
serde = { version = "1", features = [ "derive" ] }
serde_json = "1"
swap = { path = "../swap" }
tauri = { version = "2.0.0-rc.1", features = ["config-json5"] }
tauri = { version = "2.0.0-rc.1", features = [ "config-json5" ] }
uuid = "1.10.0"

View file

@ -4,23 +4,22 @@ use once_cell::sync::OnceCell;
use swap::{
api::{
request::{
get_balance, get_swap_info, get_swap_infos_all, BalanceArgs, BalanceResponse,
GetSwapInfoResponse,
get_balance as get_balance_impl, get_swap_infos_all as get_swap_infos_all_impl,
BalanceArgs, BalanceResponse, GetSwapInfoResponse,
},
Context,
},
cli::command::{Bitcoin, Monero},
};
use uuid::Uuid;
// Lazy load the Context
static CONTEXT: OnceCell<Arc<Context>> = OnceCell::new();
#[tauri::command]
async fn balance() -> Result<BalanceResponse, String> {
async fn get_balance() -> Result<BalanceResponse, String> {
let context = CONTEXT.get().unwrap();
get_balance(
get_balance_impl(
BalanceArgs {
force_refresh: true,
},
@ -31,10 +30,10 @@ async fn balance() -> Result<BalanceResponse, String> {
}
#[tauri::command]
async fn swap_infos_all() -> Result<Vec<GetSwapInfoResponse>, String> {
async fn get_swap_infos_all() -> Result<Vec<GetSwapInfoResponse>, String> {
let context = CONTEXT.get().unwrap();
get_swap_infos_all(context.clone())
get_swap_infos_all_impl(context.clone())
.await
.map_err(|e| e.to_string())
}
@ -69,7 +68,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()
.invoke_handler(tauri::generate_handler![balance, swap_infos_all])
.invoke_handler(tauri::generate_handler![get_balance, get_swap_infos_all])
.setup(setup)
.run(tauri::generate_context!())
.expect("error while running tauri application");