Skip to content

Commit

Permalink
feat: Submarine Swap preimage copy button
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Nov 11, 2024
1 parent f5ebe1f commit 87f3feb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions e2e/submarineSwap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ test.describe("Submarine swap", () => {

await generateBitcoinBlock();
// TODO: verify amounts
// TODO: preimage copy button
});

test("Create with LNURL", async ({ page }) => {
Expand Down
1 change: 1 addition & 0 deletions src/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ const dict = {
timeout: "Timeout",
wallet_connect_failed: "Wallet connection failed: {{ error }}",
ledger_open_app_prompt: "Open Ethereum or RSK app",
copy_preimage: "Copy preimage",
},
de: {
language: "Deutsch",
Expand Down
26 changes: 24 additions & 2 deletions src/status/TransactionClaimed.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { useNavigate } from "@solidjs/router";
import { BigNumber } from "bignumber.js";
import { Show, createEffect, createSignal } from "solid-js";
import { Show, createEffect, createResource, createSignal } from "solid-js";

import CopyButton from "../components/CopyButton";
import LoadingSpinner from "../components/LoadingSpinner";
import { RBTC } from "../consts/Assets";
import { SwapType } from "../consts/Enums";
import { useGlobalContext } from "../context/Global";
import { usePayContext } from "../context/Pay";
import { getSubmarinePreimage } from "../utils/boltzClient";
import { formatAmount } from "../utils/denomination";
import { SubmarineSwap } from "../utils/swapCreator";

const Broadcasting = () => {
const { t } = useGlobalContext();
Expand All @@ -23,12 +26,28 @@ const Broadcasting = () => {
const TransactionClaimed = () => {
const navigate = useNavigate();
const { swap } = usePayContext();
const { t, denomination, separator } = useGlobalContext();
const { t, denomination, separator, setSwapStorage } = useGlobalContext();

const [claimBroadcast, setClaimBroadcast] = createSignal<
boolean | undefined
>(undefined);

const [preimage] = createResource(async () => {
const submarine = swap() as SubmarineSwap;
if (submarine.type !== SwapType.Submarine) {
return undefined;
}

if (submarine.preimage !== undefined) {
return submarine.preimage;
}

const res = await getSubmarinePreimage(submarine.id);
submarine.preimage = res.preimage;
await setSwapStorage(submarine);
return res.preimage;
});

createEffect(() => {
const s = swap();
if (s === undefined || s === null) {
Expand Down Expand Up @@ -62,6 +81,9 @@ const TransactionClaimed = () => {
<span class="btn" onClick={() => navigate("/swap")}>
{t("new_swap")}
</span>
<Show when={!preimage.loading && preimage() !== undefined}>
<CopyButton label={"copy_preimage"} data={preimage()} />
</Show>
</Show>
</div>
);
Expand Down
3 changes: 3 additions & 0 deletions src/utils/boltzClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ export const getChainSwapNewQuote = (id: string) =>
export const acceptChainSwapNewQuote = (id: string, amount: number) =>
fetcher<object>(`/v2/swap/chain/${id}/quote`, { amount });

export const getSubmarinePreimage = (id: string) =>
fetcher<{ preimage: string }>(`/v2/swap/submarine/${id}/preimage`);

export {
Pairs,
Contracts,
Expand Down
1 change: 1 addition & 0 deletions src/utils/swapCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type SwapBase = {
export type SubmarineSwap = SwapBase &
SubmarineCreatedResponse & {
invoice: string;
preimage?: string;
refundPrivateKey?: string;
};

Expand Down

0 comments on commit 87f3feb

Please sign in to comment.