mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-05-03 15:24:53 -04:00
chore: Refactor tauri commands
This commit is contained in:
parent
2e1b6f6b43
commit
4f336e98a1
3 changed files with 13 additions and 15 deletions
|
@ -1,5 +1,4 @@
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { BalanceBitcoinResponse } from "models/rpcModel";
|
|
||||||
import { store } from "./store/storeRenderer";
|
import { store } from "./store/storeRenderer";
|
||||||
import { rpcSetBalance, rpcSetSwapInfo } from "store/features/rpcSlice";
|
import { rpcSetBalance, rpcSetSwapInfo } from "store/features/rpcSlice";
|
||||||
|
|
||||||
|
@ -14,6 +13,6 @@ export async function checkBitcoinBalance() {
|
||||||
|
|
||||||
export async function getRawSwapInfos() {
|
export async function getRawSwapInfos() {
|
||||||
const response = await invoke("swap_infos_all");
|
const response = await invoke("swap_infos_all");
|
||||||
console.log(response);
|
|
||||||
(response as any[]).forEach((info) => store.dispatch(rpcSetSwapInfo(info)));
|
(response as any[]).forEach((info) => store.dispatch(rpcSetSwapInfo(info)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "unstoppableswap-gui-rs"
|
name = "unstoppableswap-gui-rs"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
authors = ["binarybaron", "einliterflasche", "unstoppableswap"]
|
authors = [ "binarybaron", "einliterflasche", "unstoppableswap" ]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# 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]
|
[lib]
|
||||||
name = "unstoppableswap_gui_rs_lib"
|
name = "unstoppableswap_gui_rs_lib"
|
||||||
crate-type = ["lib", "cdylib", "staticlib"]
|
crate-type = [ "lib", "cdylib", "staticlib" ]
|
||||||
|
|
||||||
[build-dependencies]
|
[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]
|
[dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
once_cell = "1"
|
once_cell = "1"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = [ "derive" ] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
swap = { path = "../swap" }
|
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"
|
uuid = "1.10.0"
|
||||||
|
|
|
@ -4,23 +4,22 @@ use once_cell::sync::OnceCell;
|
||||||
use swap::{
|
use swap::{
|
||||||
api::{
|
api::{
|
||||||
request::{
|
request::{
|
||||||
get_balance, get_swap_info, get_swap_infos_all, BalanceArgs, BalanceResponse,
|
get_balance as get_balance_impl, get_swap_infos_all as get_swap_infos_all_impl,
|
||||||
GetSwapInfoResponse,
|
BalanceArgs, BalanceResponse, GetSwapInfoResponse,
|
||||||
},
|
},
|
||||||
Context,
|
Context,
|
||||||
},
|
},
|
||||||
cli::command::{Bitcoin, Monero},
|
cli::command::{Bitcoin, Monero},
|
||||||
};
|
};
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
// Lazy load the Context
|
// Lazy load the Context
|
||||||
static CONTEXT: OnceCell<Arc<Context>> = OnceCell::new();
|
static CONTEXT: OnceCell<Arc<Context>> = OnceCell::new();
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn balance() -> Result<BalanceResponse, String> {
|
async fn get_balance() -> Result<BalanceResponse, String> {
|
||||||
let context = CONTEXT.get().unwrap();
|
let context = CONTEXT.get().unwrap();
|
||||||
|
|
||||||
get_balance(
|
get_balance_impl(
|
||||||
BalanceArgs {
|
BalanceArgs {
|
||||||
force_refresh: true,
|
force_refresh: true,
|
||||||
},
|
},
|
||||||
|
@ -31,10 +30,10 @@ async fn balance() -> Result<BalanceResponse, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[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();
|
let context = CONTEXT.get().unwrap();
|
||||||
|
|
||||||
get_swap_infos_all(context.clone())
|
get_swap_infos_all_impl(context.clone())
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())
|
.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)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
tauri::Builder::default()
|
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)
|
.setup(setup)
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue