Skip to content

Commit

Permalink
fix: show EVM coop refund on lockup failed (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 authored Mar 19, 2024
1 parent 9d4603e commit 992959b
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/status/TransactionLockupFailed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { Show } from "solid-js";
import DownloadRefund from "../components/DownloadRefund";
import RefundButton from "../components/RefundButton";
import RefundEta from "../components/RefundEta";
import { RBTC } from "../consts";
import { useGlobalContext } from "../context/Global";
import { usePayContext } from "../context/Pay";
import NotFound from "../pages/NotFound";

const ShowTimeout = () => (
<>
Expand All @@ -17,20 +19,26 @@ const ShowTimeout = () => (
const TransactionLockupFailed = () => {
const { failureReason, swap } = usePayContext();
const { t } = useGlobalContext();
const isTaproot = swap().version === OutputType.Taproot;

return (
<div>
<h2>{t("lockup_failed")}</h2>
<p>
{t("failure_reason")}: {failureReason()}
</p>
<hr />
<Show when={isTaproot} fallback={<ShowTimeout />}>
<RefundButton swap={swap} />
</Show>
<hr />
</div>
<Show when={swap() !== null} fallback={<NotFound />}>
<div>
<h2>{t("lockup_failed")}</h2>
<p>
{t("failure_reason")}: {failureReason()}
</p>
<hr />
<Show
when={
swap().version === OutputType.Taproot ||
swap().asset === RBTC
}
fallback={<ShowTimeout />}>
<RefundButton swap={swap} />
</Show>
<hr />
</div>
</Show>
);
};

Expand Down
74 changes: 74 additions & 0 deletions tests/status/TransactionLockupFailed.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { render, screen } from "@solidjs/testing-library";
import { OutputType } from "boltz-core";

import { BTC, RBTC } from "../../src/consts";
import i18n from "../../src/i18n/i18n";
import TransactionLockupFailed from "../../src/status/TransactionLockupFailed";
import { TestComponent, contextWrapper, payContext } from "../helper";

describe("TransactionLockupFailed", () => {
beforeEach(() => {
jest.clearAllMocks();
});

test.each([OutputType.Bech32, OutputType.Compatibility, undefined])(
"should show timeout for legacy swaps",
async (type) => {
render(
() => (
<>
<TestComponent />
<TransactionLockupFailed />
</>
),
{
wrapper: contextWrapper,
},
);
payContext.setTimeoutEta(1);
payContext.setSwap({ asset: BTC, version: type });

await expect(
screen.findByText(i18n.en.refund_explainer),
).resolves.not.toBeUndefined();
},
);

test("should show refund button for Taproot swaps", async () => {
render(
() => (
<>
<TestComponent />
<TransactionLockupFailed />
</>
),
{
wrapper: contextWrapper,
},
);
payContext.setSwap({ asset: BTC, version: OutputType.Taproot });

await expect(
screen.findByText(i18n.en.refund),
).resolves.not.toBeUndefined();
});

test("should show refund button for RBTC swaps", async () => {
render(
() => (
<>
<TestComponent />
<TransactionLockupFailed />
</>
),
{
wrapper: contextWrapper,
},
);
payContext.setSwap({ asset: RBTC });

await expect(
screen.findByText(i18n.en.refund),
).resolves.not.toBeUndefined();
});
});

0 comments on commit 992959b

Please sign in to comment.