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

@ -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");