mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-05-02 06:46:06 -04:00
fix(tauri): Emit 'Initiated' progress event once swap lock is aquired (#112)
* fix(tauri): Emit 'Initiated' progress event once swap lock is aquired
This commit is contained in:
parent
83f831ccac
commit
ec86fa13cd
5 changed files with 39 additions and 38 deletions
|
@ -15,13 +15,13 @@ type PathStep = [type: PathType, step: number, isError: boolean];
|
|||
* @param latestState - The latest state of the swap process
|
||||
* @returns A tuple containing [PathType, activeStep, errorFlag]
|
||||
*/
|
||||
function getActiveStep(state: SwapState | null): PathStep {
|
||||
function getActiveStep(state: SwapState | null): PathStep | null {
|
||||
// In case we cannot infer a correct step from the state
|
||||
function fallbackStep(reason: string) {
|
||||
console.error(
|
||||
`Unable to choose correct stepper type (reason: ${reason}, state: ${JSON.stringify(state)}`,
|
||||
);
|
||||
return [PathType.HAPPY_PATH, 0, true] as PathStep;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (state === null) {
|
||||
|
@ -52,7 +52,7 @@ function getActiveStep(state: SwapState | null): PathStep {
|
|||
// Step 0: Initializing the swap
|
||||
// These states represent the very beginning of the swap process
|
||||
// No funds have been locked
|
||||
case "Initiated":
|
||||
case "RequestingQuote":
|
||||
case "ReceivedQuote":
|
||||
case "WaitingForBtcDeposit":
|
||||
case "Started":
|
||||
|
@ -86,12 +86,7 @@ function getActiveStep(state: SwapState | null): PathStep {
|
|||
// XMR redemption transaction is in mempool, swap is essentially complete
|
||||
case "XmrRedeemInMempool":
|
||||
return [PathType.HAPPY_PATH, 4, false];
|
||||
|
||||
// Edge Case of Happy Path where the swap is safely aborted. We "fail" at the first step.
|
||||
// TODO: There's no equivalent for this with the Tauri events
|
||||
// case BobStateName.SafelyAborted:
|
||||
// return [PathType.HAPPY_PATH, 0, true];
|
||||
|
||||
|
||||
// Unhappy Path States
|
||||
|
||||
// Step 1: Cancel timelock has expired. Waiting for cancel transaction to be published
|
||||
|
@ -117,10 +112,13 @@ function getActiveStep(state: SwapState | null): PathStep {
|
|||
return [PathType.UNHAPPY_PATH, 1, isReleased];
|
||||
case "CooperativeRedeemRejected":
|
||||
return [PathType.UNHAPPY_PATH, 1, true];
|
||||
|
||||
case "Resuming":
|
||||
return null;
|
||||
default:
|
||||
return fallbackStep("No step is assigned to the current state");
|
||||
// TODO: Make this guard work. It should force the compiler to check if we have covered all possible cases.
|
||||
// return exhaustiveGuard(latestState.type);
|
||||
// TODO: Make this guard work. It should force the compiler to check if we have covered all possible cases.
|
||||
// return exhaustiveGuard(latestState.type);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,7 +166,13 @@ export default function SwapStateStepper({
|
|||
}: {
|
||||
state: SwapState | null;
|
||||
}) {
|
||||
const [pathType, activeStep, error] = getActiveStep(state);
|
||||
const result = getActiveStep(state);
|
||||
|
||||
if (result === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const [pathType, activeStep, error] = result;
|
||||
|
||||
const steps =
|
||||
pathType === PathType.HAPPY_PATH
|
||||
|
|
|
@ -14,7 +14,6 @@ import ReceivedQuotePage from "./in_progress/ReceivedQuotePage";
|
|||
import StartedPage from "./in_progress/StartedPage";
|
||||
import XmrLockedPage from "./in_progress/XmrLockedPage";
|
||||
import XmrLockTxInMempoolPage from "./in_progress/XmrLockInMempoolPage";
|
||||
import InitiatedPage from "./init/InitiatedPage";
|
||||
import InitPage from "./init/InitPage";
|
||||
import WaitingForBitcoinDepositPage from "./init/WaitingForBitcoinDepositPage";
|
||||
|
||||
|
@ -24,8 +23,10 @@ export default function SwapStatePage({ state }: { state: SwapState | null }) {
|
|||
}
|
||||
|
||||
switch (state.curr.type) {
|
||||
case "Initiated":
|
||||
return <InitiatedPage />;
|
||||
case "RequestingQuote":
|
||||
return <CircularProgressWithSubtitle description="Requesting quote..." />;
|
||||
case "Resuming":
|
||||
return <CircularProgressWithSubtitle description="Resuming swap..." />;
|
||||
case "ReceivedQuote":
|
||||
return <ReceivedQuotePage />;
|
||||
case "WaitingForBtcDeposit":
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
import { SwapSpawnType } from "models/cliModel";
|
||||
import { useAppSelector } from "store/hooks";
|
||||
import CircularProgressWithSubtitle from "../../CircularProgressWithSubtitle";
|
||||
|
||||
export default function InitiatedPage() {
|
||||
const description = useAppSelector((s) => {
|
||||
switch (s.swap.spawnType) {
|
||||
case SwapSpawnType.INIT:
|
||||
return "Requesting quote from provider...";
|
||||
case SwapSpawnType.RESUME:
|
||||
return "Resuming swap...";
|
||||
case SwapSpawnType.CANCEL_REFUND:
|
||||
return "Attempting to cancel & refund swap...";
|
||||
default:
|
||||
// Should never be hit
|
||||
return "Initiating swap...";
|
||||
}
|
||||
});
|
||||
|
||||
return <CircularProgressWithSubtitle description={description} />;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue