mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-06-08 07:03:02 -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
|
@ -26,47 +26,6 @@ export interface BuyXmrArgs {
|
||||||
monero_receive_address: string;
|
monero_receive_address: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ResumeArgs {
|
|
||||||
swap_id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CancelAndRefundArgs {
|
|
||||||
swap_id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface MoneroRecoveryArgs {
|
|
||||||
swap_id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WithdrawBtcArgs {
|
|
||||||
amount?: number;
|
|
||||||
address: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BalanceArgs {
|
|
||||||
force_refresh: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ListSellersArgs {
|
|
||||||
rendezvous_point: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface StartDaemonArgs {
|
|
||||||
server_address: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface GetSwapInfoArgs {
|
|
||||||
swap_id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ResumeSwapResponse {
|
|
||||||
result: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BalanceResponse {
|
|
||||||
balance: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Represents a quote for buying XMR. */
|
/** Represents a quote for buying XMR. */
|
||||||
export interface BidQuote {
|
export interface BidQuote {
|
||||||
/** The price at which the maker is willing to buy at. */
|
/** The price at which the maker is willing to buy at. */
|
||||||
|
@ -85,13 +44,42 @@ export interface BuyXmrResponse {
|
||||||
quote: BidQuote;
|
quote: BidQuote;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetHistoryEntry {
|
export interface ResumeSwapArgs {
|
||||||
swap_id: string;
|
swap_id: string;
|
||||||
state: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GetHistoryResponse {
|
export interface ResumeSwapResponse {
|
||||||
swaps: GetHistoryEntry[];
|
result: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CancelAndRefundArgs {
|
||||||
|
swap_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MoneroRecoveryArgs {
|
||||||
|
swap_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WithdrawBtcArgs {
|
||||||
|
amount?: number;
|
||||||
|
address: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WithdrawBtcResponse {
|
||||||
|
amount: number;
|
||||||
|
txid: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ListSellersArgs {
|
||||||
|
rendezvous_point: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StartDaemonArgs {
|
||||||
|
server_address: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetSwapInfoArgs {
|
||||||
|
swap_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Seller {
|
export interface Seller {
|
||||||
|
@ -126,11 +114,122 @@ export interface GetSwapInfoResponse {
|
||||||
timelock?: ExpiredTimelocks;
|
timelock?: ExpiredTimelocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BalanceArgs {
|
||||||
|
force_refresh: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BalanceResponse {
|
||||||
|
balance: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetHistoryArgs {
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetHistoryEntry {
|
||||||
|
swap_id: string;
|
||||||
|
state: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetHistoryResponse {
|
||||||
|
swaps: GetHistoryEntry[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SuspendCurrentSwapResponse {
|
||||||
|
swap_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BuyXmrArgs {
|
||||||
|
seller: string;
|
||||||
|
bitcoin_change_address: string;
|
||||||
|
monero_receive_address: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BuyXmrResponse {
|
||||||
|
swap_id: string;
|
||||||
|
quote: BidQuote;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResumeSwapArgs {
|
||||||
|
swap_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResumeSwapResponse {
|
||||||
|
result: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CancelAndRefundArgs {
|
||||||
|
swap_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MoneroRecoveryArgs {
|
||||||
|
swap_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WithdrawBtcArgs {
|
||||||
|
amount?: number;
|
||||||
|
address: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface WithdrawBtcResponse {
|
export interface WithdrawBtcResponse {
|
||||||
amount: number;
|
amount: number;
|
||||||
txid: string;
|
txid: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ListSellersArgs {
|
||||||
|
rendezvous_point: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StartDaemonArgs {
|
||||||
|
server_address: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetSwapInfoArgs {
|
||||||
|
swap_id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetSwapInfoResponse {
|
||||||
|
swap_id: string;
|
||||||
|
seller: Seller;
|
||||||
|
completed: boolean;
|
||||||
|
start_date: string;
|
||||||
|
state_name: string;
|
||||||
|
xmr_amount: number;
|
||||||
|
btc_amount: number;
|
||||||
|
tx_lock_id: string;
|
||||||
|
tx_cancel_fee: number;
|
||||||
|
tx_refund_fee: number;
|
||||||
|
tx_lock_fee: number;
|
||||||
|
btc_refund_address: string;
|
||||||
|
cancel_timelock: CancelTimelock;
|
||||||
|
punish_timelock: PunishTimelock;
|
||||||
|
timelock?: ExpiredTimelocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BalanceArgs {
|
||||||
|
force_refresh: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BalanceResponse {
|
||||||
|
balance: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetHistoryArgs {
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetHistoryEntry {
|
||||||
|
swap_id: string;
|
||||||
|
state: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GetHistoryResponse {
|
||||||
|
swaps: GetHistoryEntry[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Seller {
|
||||||
|
peer_id: string;
|
||||||
|
addresses: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface SuspendCurrentSwapResponse {
|
export interface SuspendCurrentSwapResponse {
|
||||||
swap_id: string;
|
swap_id: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ async function invoke<ARGS, RESPONSE>(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function invokeNoArgs<RESPONSE>(command: string): Promise<RESPONSE> {
|
async function invokeNoArgs<RESPONSE>(command: string): Promise<RESPONSE> {
|
||||||
return invokeUnsafe(command, {}) as Promise<RESPONSE>;
|
return invokeUnsafe(command) as Promise<RESPONSE>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkBitcoinBalance() {
|
export async function checkBitcoinBalance() {
|
||||||
|
|
|
@ -3,8 +3,8 @@ use std::sync::Arc;
|
||||||
use swap::cli::{
|
use swap::cli::{
|
||||||
api::{
|
api::{
|
||||||
request::{
|
request::{
|
||||||
BalanceArgs, BuyXmrArgs, GetHistoryArgs, ResumeSwapArgs, SuspendCurrentSwapArgs,
|
BalanceArgs, BuyXmrArgs, GetHistoryArgs, GetSwapInfosAllArgs, ResumeSwapArgs,
|
||||||
WithdrawBtcArgs,
|
SuspendCurrentSwapArgs, WithdrawBtcArgs,
|
||||||
},
|
},
|
||||||
Context, ContextBuilder,
|
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> {
|
/// async fn get_balance(context: tauri::State<'...>, args: BalanceArgs) -> Result<BalanceArgs::Response, String> {
|
||||||
/// args.handle(context.inner().clone()).await.to_string_result()
|
/// 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 {
|
macro_rules! tauri_command {
|
||||||
($fn_name:ident, $request_name:ident) => {
|
($fn_name:ident, $request_name:ident) => {
|
||||||
|
@ -52,14 +63,28 @@ macro_rules! tauri_command {
|
||||||
.to_string_result()
|
.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_balance, BalanceArgs);
|
||||||
tauri_command!(get_swap_infos_all, BalanceArgs);
|
|
||||||
tauri_command!(buy_xmr, BuyXmrArgs);
|
tauri_command!(buy_xmr, BuyXmrArgs);
|
||||||
tauri_command!(get_history, GetHistoryArgs);
|
|
||||||
tauri_command!(resume_swap, ResumeSwapArgs);
|
tauri_command!(resume_swap, ResumeSwapArgs);
|
||||||
tauri_command!(withdraw_btc, WithdrawBtcArgs);
|
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>> {
|
fn setup<'a>(app: &'a mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
tauri::async_runtime::block_on(async {
|
tauri::async_runtime::block_on(async {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -344,6 +344,16 @@ impl Request for GetConfigArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct GetSwapInfosAllArgs;
|
||||||
|
|
||||||
|
impl Request for GetSwapInfosAllArgs {
|
||||||
|
type Response = Vec<GetSwapInfoResponse>;
|
||||||
|
|
||||||
|
async fn request(self, ctx: Arc<Context>) -> Result<Self::Response> {
|
||||||
|
get_swap_infos_all(ctx).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tracing::instrument(fields(method = "suspend_current_swap"), skip(context))]
|
#[tracing::instrument(fields(method = "suspend_current_swap"), skip(context))]
|
||||||
pub async fn suspend_current_swap(context: Arc<Context>) -> Result<SuspendCurrentSwapResponse> {
|
pub async fn suspend_current_swap(context: Arc<Context>) -> Result<SuspendCurrentSwapResponse> {
|
||||||
let swap_id = context.swap_lock.get_current_swap_id().await;
|
let swap_id = context.swap_lock.get_current_swap_id().await;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue