mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-10 23:40:23 -04:00
fix(tauri, gui): Allow Tauri command to be called with empty arguments
- Allow Tauri command to be called with empty arguments - Add struct for GetSwapInfosAllArgs
This commit is contained in:
parent
de1f77bf80
commit
ca25e0454f
5 changed files with 185 additions and 1239 deletions
|
@ -3,8 +3,8 @@ use std::sync::Arc;
|
|||
use swap::cli::{
|
||||
api::{
|
||||
request::{
|
||||
BalanceArgs, BuyXmrArgs, GetHistoryArgs, ResumeSwapArgs, SuspendCurrentSwapArgs,
|
||||
WithdrawBtcArgs,
|
||||
BalanceArgs, BuyXmrArgs, GetHistoryArgs, GetSwapInfosAllArgs, ResumeSwapArgs,
|
||||
SuspendCurrentSwapArgs, WithdrawBtcArgs,
|
||||
},
|
||||
Context, ContextBuilder,
|
||||
},
|
||||
|
@ -36,6 +36,17 @@ impl<T, E: ToString> ToStringResult<T> for Result<T, E> {
|
|||
/// async fn get_balance(context: tauri::State<'...>, args: BalanceArgs) -> Result<BalanceArgs::Response, String> {
|
||||
/// args.handle(context.inner().clone()).await.to_string_result()
|
||||
/// }
|
||||
///
|
||||
/// # Example 2
|
||||
/// ```ignored
|
||||
/// tauri_command!(get_balance, BalanceArgs, no_args);
|
||||
/// ```
|
||||
/// will resolve to
|
||||
/// ```ignored
|
||||
/// #[tauri::command]
|
||||
/// async fn get_balance(context: tauri::State<'...>) -> Result<BalanceArgs::Response, String> {
|
||||
/// BalanceArgs {}.handle(context.inner().clone()).await.to_string_result()
|
||||
/// }
|
||||
/// ```
|
||||
macro_rules! tauri_command {
|
||||
($fn_name:ident, $request_name:ident) => {
|
||||
|
@ -52,14 +63,28 @@ macro_rules! tauri_command {
|
|||
.to_string_result()
|
||||
}
|
||||
};
|
||||
($fn_name:ident, $request_name:ident, no_args) => {
|
||||
#[tauri::command]
|
||||
async fn $fn_name(
|
||||
context: tauri::State<'_, Arc<Context>>,
|
||||
) -> Result<<$request_name as swap::cli::api::request::Request>::Response, String> {
|
||||
<$request_name as swap::cli::api::request::Request>::request(
|
||||
$request_name {},
|
||||
context.inner().clone(),
|
||||
)
|
||||
.await
|
||||
.to_string_result()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
tauri_command!(get_balance, BalanceArgs);
|
||||
tauri_command!(get_swap_infos_all, BalanceArgs);
|
||||
tauri_command!(buy_xmr, BuyXmrArgs);
|
||||
tauri_command!(get_history, GetHistoryArgs);
|
||||
tauri_command!(resume_swap, ResumeSwapArgs);
|
||||
tauri_command!(withdraw_btc, WithdrawBtcArgs);
|
||||
tauri_command!(suspend_current_swap, SuspendCurrentSwapArgs);
|
||||
tauri_command!(suspend_current_swap, SuspendCurrentSwapArgs, no_args);
|
||||
tauri_command!(get_swap_infos_all, GetSwapInfosAllArgs, no_args);
|
||||
tauri_command!(get_history, GetHistoryArgs, no_args);
|
||||
|
||||
fn setup<'a>(app: &'a mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
|
||||
tauri::async_runtime::block_on(async {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue