Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
feat: Display a different text on ProcessExitedAndNotDonePage dependi…
Browse files Browse the repository at this point in the history
…ng on type of operation
  • Loading branch information
binarybaron committed Jul 1, 2024
1 parent 2fef71c commit bf33ecb
Showing 1 changed file with 38 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Box, DialogContentText } from '@material-ui/core';
import { useActiveSwapInfo, useAppSelector } from 'store/hooks';
import { SwapStateProcessExited } from 'models/storeModel';
import CliLogsBox from '../../../../other/RenderedCliLog';
import { SwapSpawnType } from 'models/cliModel';

export default function ProcessExitedAndNotDonePage({
state,
Expand All @@ -10,38 +11,60 @@ export default function ProcessExitedAndNotDonePage({
}) {
const swap = useActiveSwapInfo();
const logs = useAppSelector((s) => s.swap.logs);
const spawnType = useAppSelector((s) => s.swap.spawnType);

const text = swap ? (
<>
The swap exited unexpectedly without completing. The current state is
&quot;{swap.stateName}&quot;. You might have to manually take some action.
</>
) : (
<>
The swap exited unexpectedly before any funds were locked and without
completing.
</>
);
function getText() {
const isCancelRefund = spawnType === SwapSpawnType.CANCEL_REFUND;
const hasRpcError = state.rpcError != null;
const hasSwap = swap != null;

let messages = [];

messages.push(
isCancelRefund
? 'The manual cancel and refund was unsuccessful.'
: 'The swap exited unexpectedly without completing.',
);

if (!hasSwap && !isCancelRefund) {
messages.push('No funds were locked.');
}

messages.push(
hasRpcError
? 'Check the error and the logs below for more information.'
: 'Check the logs below for more information.',
);

if (hasSwap) {
messages.push(`The swap is in the "${swap.stateName}" state.`);
if (!isCancelRefund) {
messages.push(
'Try resuming the swap or attempt to initiate a manual cancel and refund.',
);
}
}

return messages.join(' ');
}

return (
<Box>
<DialogContentText>
{text} Please check the logs displayed below for more information.
</DialogContentText>
<DialogContentText>{getText()}</DialogContentText>
<Box
style={{
display: 'flex',
flexDirection: 'column',
gap: '0.5rem',
}}
>
<CliLogsBox logs={logs} label="Logs relevant to the swap" />
{state.rpcError && (
<CliLogsBox
logs={[state.rpcError]}
label="Error returned by the Swap Daemon"
/>
)}
<CliLogsBox logs={logs} label="Logs relevant to the swap" />
</Box>
</Box>
);
Expand Down

0 comments on commit bf33ecb

Please sign in to comment.