Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gui): Display error if exists after swap is released #41

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions .github/workflows/build-release-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ jobs:
target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive_ext: tar
# This has been temporarily disabled. Cross compilation is currently broken due to the missing system dependencies (libwebkit)
#- bin: swap
# target: armv7-unknown-linux-gnueabihf
# os: ubuntu-latest
# archive_ext: tar
- bin: swap
target: armv7-unknown-linux-gnueabihf
os: ubuntu-latest
archive_ext: tar
- bin: swap
target: x86_64-apple-darwin
os: macos-12
Expand All @@ -39,11 +38,10 @@ jobs:
target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive_ext: tar
# This has been temporarily disabled. Cross compilation is currently broken due to the missing system dependencies (libwebkit)
#- bin: asb
# target: armv7-unknown-linux-gnueabihf
# os: ubuntu-latest
# archive_ext: tar
- bin: asb
target: armv7-unknown-linux-gnueabihf
os: ubuntu-latest
archive_ext: tar
- bin: asb
target: x86_64-apple-darwin
os: macos-12
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ jobs:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
#- target: armv7-unknown-linux-gnueabihf
# os: ubuntu-latest
- target: armv7-unknown-linux-gnueabihf
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-12
- target: aarch64-apple-darwin
Expand Down
1 change: 1 addition & 0 deletions src-gui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pnpm-debug.log*
lerna-debug.log*

node_modules
.vite
dist
dist-ssr
*.local
Expand Down
100 changes: 3 additions & 97 deletions src-gui/src/models/tauriModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,102 +138,6 @@ 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 {
amount: number;
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 {
swap_id: string;
}

export type TauriSwapProgressEvent =
| { type: "Initiated", content?: undefined }
| { type: "ReceivedQuote", content: BidQuote }
Expand Down Expand Up @@ -275,7 +179,9 @@ export type TauriSwapProgressEvent =
| { type: "CooperativeRedeemRejected", content: {
reason: string;
}}
| { type: "Released", content?: undefined };
| { type: "Released", content: {
error?: string;
}};

export interface TauriSwapProgressEventWrapper {
swap_id: string;
Expand Down
5 changes: 5 additions & 0 deletions src-gui/src/models/tauriModelExt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import {
TauriSwapProgressEvent,
} from "./tauriModel";

export type TauriSwapProgressEventType<T extends string> = Extract<
TauriSwapProgressEvent,
{ type: T }
>;

export type TauriSwapProgressEventContent<
T extends TauriSwapProgressEvent["type"],
> = Extract<TauriSwapProgressEvent, { type: T }>["content"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ export default function SwapStatePage({
case "CooperativeRedeemRejected":
return <BitcoinPunishedPage />;
case "Released":
return <ProcessExitedPage prevState={state.prev} swapId={state.swapId} />;
return (
<ProcessExitedPage
currState={state.curr}
prevState={state.prev}
swapId={state.swapId}
/>
);
default:
// TODO: Use this when we have all states implemented, ensures we don't forget to implement a state
// return exhaustiveGuard(state.curr.type);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { Box, DialogContentText } from "@material-ui/core";
import { SwapSpawnType } from "models/cliModel";
import { SwapStateProcessExited } from "models/storeModel";
import { TauriSwapProgressEventContent } from "models/tauriModelExt";
import { useActiveSwapInfo, useAppSelector } from "store/hooks";
import CliLogsBox from "../../../../other/RenderedCliLog";

export default function ProcessExitedAndNotDonePage({
state,
currState,
}: {
state: SwapStateProcessExited;
currState: TauriSwapProgressEventContent<"Released">;
}) {
const swap = useActiveSwapInfo();
const logs = useAppSelector((s) => s.swap.logs);
const spawnType = useAppSelector((s) => s.swap.spawnType);

function getText() {
const isCancelRefund = spawnType === SwapSpawnType.CANCEL_REFUND;
const hasRpcError = state.rpcError != null;
const hasRpcError = currState.error != null;
const hasSwap = swap != null;

const messages = [];
Expand Down Expand Up @@ -58,11 +58,8 @@ export default function ProcessExitedAndNotDonePage({
gap: "0.5rem",
}}
>
{state.rpcError && (
<CliLogsBox
logs={[state.rpcError]}
label="Error returned by the Swap Daemon"
/>
{currState.error != null && (
<CliLogsBox logs={[currState.error]} label="Error" />
)}
<CliLogsBox logs={logs} label="Logs relevant to the swap" />
</Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { TauriSwapProgressEvent } from "models/tauriModel";
import { TauriSwapProgressEventType } from "models/tauriModelExt";
import SwapStatePage from "../SwapStatePage";
import ProcessExitedAndNotDonePage from "./ProcessExitedAndNotDonePage";

export default function ProcessExitedPage({
prevState,
currState,
swapId,
}: {
prevState: TauriSwapProgressEvent | null;
currState: TauriSwapProgressEventType<"Released">;
swapId: string;
}) {
// If we have a previous state, we can show the user the last state of the swap
Expand All @@ -27,15 +31,5 @@ export default function ProcessExitedPage({
);
}

// TODO: Display something useful here
return (
<>
If the swap is not a "done" state (or we don't have a db state because the
swap did complete the SwapSetup yet) we should tell the user and show logs
Not implemented yet
</>
);

// If the swap is not a "done" state (or we don't have a db state because the swap did complete the SwapSetup yet) we should tell the user and show logs
// return <ProcessExitedAndNotDonePage state={state} />;
return <ProcessExitedAndNotDonePage currState={currState.content} />;
}
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ anyhow = "1"
once_cell = "1"
serde = { version = "1", features = [ "derive" ] }
serde_json = "1"
swap = { path = "../swap" }
swap = { path = "../swap", features = [ "tauri" ] }
tauri = { version = "2.0.0-rc.1", features = [ "config-json5" ] }
5 changes: 3 additions & 2 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use swap::cli::{
BalanceArgs, BuyXmrArgs, GetHistoryArgs, GetSwapInfosAllArgs, ResumeSwapArgs,
SuspendCurrentSwapArgs, WithdrawBtcArgs,
},
tauri_bindings::TauriHandle,
Context, ContextBuilder,
},
command::{Bitcoin, Monero},
Expand Down Expand Up @@ -86,7 +87,7 @@ 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(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
tauri::async_runtime::block_on(async {
let context = ContextBuilder::new(true)
.with_bitcoin(Bitcoin {
Expand All @@ -98,7 +99,7 @@ fn setup<'a>(app: &'a mut tauri::App) -> Result<(), Box<dyn std::error::Error>>
})
.with_json(true)
.with_debug(true)
.with_tauri(app.app_handle().to_owned())
.with_tauri(TauriHandle::new(app.app_handle().to_owned()))
.build()
.await
.expect("failed to create context");
Expand Down
5 changes: 4 additions & 1 deletion swap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ description = "XMR/BTC trustless atomic swaps."
[lib]
name = "swap"

[features]
tauri = [ "dep:tauri" ]

[dependencies]
anyhow = "1"
async-compression = { version = "0.3", features = [ "bzip2", "tokio" ] }
Expand Down Expand Up @@ -86,7 +89,7 @@ sqlx = { version = "0.6.3", features = [
] }
structopt = "0.3"
strum = { version = "0.26", features = [ "derive" ] }
tauri = { version = "2.0.0-rc.1", features = [ "config-json5" ] }
tauri = { version = "2.0.0-rc.1", features = [ "config-json5" ], optional = true }
thiserror = "1"
time = "0.3"
tokio = { version = "1", features = [
Expand Down
12 changes: 6 additions & 6 deletions swap/src/cli/api.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod request;
pub mod tauri_bindings;

use crate::cli::command::{Bitcoin, Monero, Tor};
use crate::database::open_db;
use crate::env::{Config as EnvConfig, GetConfig, Mainnet, Testnet};
Expand All @@ -14,7 +15,6 @@ use std::fmt;
use std::future::Future;
use std::path::PathBuf;
use std::sync::{Arc, Mutex as SyncMutex, Once};
use tauri::AppHandle;
use tauri_bindings::TauriHandle;
use tokio::sync::{broadcast, broadcast::Sender, Mutex as TokioMutex, RwLock};
use tokio::task::JoinHandle;
Expand Down Expand Up @@ -193,7 +193,7 @@ pub struct ContextBuilder {
is_testnet: bool,
debug: bool,
json: bool,
tauri_handle: Option<AppHandle>,
tauri_handle: Option<TauriHandle>,
}

impl ContextBuilder {
Expand Down Expand Up @@ -246,7 +246,7 @@ impl ContextBuilder {
}

/// Attach a handle to Tauri to the Context for emitting events etc.
pub fn with_tauri(mut self, tauri: impl Into<Option<AppHandle>>) -> Self {
pub fn with_tauri(mut self, tauri: impl Into<Option<TauriHandle>>) -> Self {
self.tauri_handle = tauri.into();
self
}
Expand Down Expand Up @@ -330,16 +330,16 @@ impl ContextBuilder {
},
swap_lock: Arc::new(SwapLock::new()),
tasks: Arc::new(PendingTaskList::default()),
tauri_handle: self.tauri_handle.map(TauriHandle::new),
tauri_handle: self.tauri_handle,
};

Ok(context)
}
}

impl Context {
pub fn with_tauri_handle(mut self, tauri_handle: AppHandle) -> Self {
self.tauri_handle = Some(TauriHandle::new(tauri_handle));
pub fn with_tauri_handle(mut self, tauri_handle: impl Into<Option<TauriHandle>>) -> Self {
self.tauri_handle = tauri_handle.into();

self
}
Expand Down
Loading
Loading