mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-12-10 06:15:35 -05:00
wip: WithdrawDialog migrated to Tauri IPC
This commit is contained in:
parent
92034a5be8
commit
47821cbe79
14 changed files with 185 additions and 166 deletions
|
|
@ -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,15 +9,15 @@ description = "GUI for XMR<>BTC Atomic Swaps written in Rust"
|
|||
|
||||
[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" ] }
|
||||
|
|
|
|||
|
|
@ -1,20 +1,17 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use once_cell::sync::OnceCell;
|
||||
use std::result::Result;
|
||||
use std::sync::Arc;
|
||||
use swap::{
|
||||
api::{
|
||||
request::{
|
||||
get_balance as get_balance_impl, get_swap_infos_all as get_swap_infos_all_impl,
|
||||
BalanceArgs, BalanceResponse, GetSwapInfoResponse,
|
||||
withdraw_btc as withdraw_btc_impl, BalanceArgs, BalanceResponse, GetSwapInfoResponse,
|
||||
WithdrawBtcArgs, WithdrawBtcResponse,
|
||||
},
|
||||
Context,
|
||||
},
|
||||
cli::command::{Bitcoin, Monero},
|
||||
};
|
||||
|
||||
// Lazy load the Context
|
||||
static CONTEXT: OnceCell<Arc<Context>> = OnceCell::new();
|
||||
use tauri::{Manager, State};
|
||||
|
||||
trait ToStringResult<T> {
|
||||
fn to_string_result(self) -> Result<T, String>;
|
||||
|
|
@ -31,24 +28,46 @@ impl<T, E: ToString> ToStringResult<T> for Result<T, E> {
|
|||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn get_balance() -> Result<BalanceResponse, String> {
|
||||
let context = CONTEXT.get().unwrap();
|
||||
|
||||
async fn get_balance(context: State<'_, Arc<Context>>) -> Result<BalanceResponse, String> {
|
||||
get_balance_impl(
|
||||
BalanceArgs {
|
||||
force_refresh: true,
|
||||
},
|
||||
context.clone(),
|
||||
context.inner().clone(),
|
||||
)
|
||||
.await
|
||||
.to_string_result()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn get_swap_infos_all() -> Result<Vec<GetSwapInfoResponse>, String> {
|
||||
let context = CONTEXT.get().unwrap();
|
||||
async fn get_swap_infos_all(
|
||||
context: State<'_, Arc<Context>>,
|
||||
) -> Result<Vec<GetSwapInfoResponse>, String> {
|
||||
get_swap_infos_all_impl(context.inner().clone())
|
||||
.await
|
||||
.to_string_result()
|
||||
}
|
||||
|
||||
get_swap_infos_all_impl(context.clone())
|
||||
/*macro_rules! tauri_command {
|
||||
($command_name:ident, $command_args:ident, $command_response:ident) => {
|
||||
#[tauri::command]
|
||||
async fn $command_name(
|
||||
context: State<'_, Context>,
|
||||
args: $command_args,
|
||||
) -> Result<$command_response, String> {
|
||||
swap::api::request::$command_name(args, context)
|
||||
.await
|
||||
.to_string_result()
|
||||
}
|
||||
};
|
||||
}*/
|
||||
|
||||
#[tauri::command]
|
||||
async fn withdraw_btc(
|
||||
context: State<'_, Arc<Context>>,
|
||||
args: WithdrawBtcArgs,
|
||||
) -> Result<WithdrawBtcResponse, String> {
|
||||
withdraw_btc_impl(args, context.inner().clone())
|
||||
.await
|
||||
.to_string_result()
|
||||
}
|
||||
|
|
@ -73,9 +92,7 @@ fn setup<'a>(app: &'a mut tauri::App) -> Result<(), Box<dyn std::error::Error>>
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
CONTEXT
|
||||
.set(Arc::new(context))
|
||||
.expect("Failed to initialize cli context");
|
||||
app.manage(Arc::new(context));
|
||||
});
|
||||
|
||||
Ok(())
|
||||
|
|
@ -84,7 +101,11 @@ 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![get_balance, get_swap_infos_all])
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
get_balance,
|
||||
get_swap_infos_all,
|
||||
withdraw_btc
|
||||
])
|
||||
.setup(setup)
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue