Skip to content

Commit

Permalink
feat(gui): Display error if exists after swap is released
Browse files Browse the repository at this point in the history
  • Loading branch information
binarybaron committed Aug 28, 2024
1 parent 348894c commit fdab275
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 118 deletions.
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} />;
}

0 comments on commit fdab275

Please sign in to comment.