Skip to content

Commit

Permalink
feat: swap recovery rescan
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Feb 25, 2025
1 parent 27da26e commit 898eb3f
Show file tree
Hide file tree
Showing 37 changed files with 1,051 additions and 459 deletions.
97 changes: 30 additions & 67 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"@reown/appkit": "^1.6.8",
"@reown/appkit-adapter-ethers": "^1.6.8",
"@scure/base": "^1.2.4",
"@scure/bip32": "^1.6.2",
"@solid-primitives/i18n": "^2.1.1",
"@solid-primitives/storage": "^4.2.1",
"@solidjs/router": "^0.15.2",
Expand Down
14 changes: 9 additions & 5 deletions src/components/CreateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export const CreateButton = () => {
notify,
ref,
t,
isRecklessMode,
newKey,
deriveKey,
recoveryFileBackupDone,
} = useGlobalContext();
const {
invoice,
Expand Down Expand Up @@ -291,6 +293,7 @@ export const CreateButton = () => {
invoice(),
ref(),
useRif,
newKey,
);
break;

Expand All @@ -304,6 +307,7 @@ export const CreateButton = () => {
claimAddress,
ref(),
useRif,
newKey,
);
break;

Expand All @@ -317,11 +321,12 @@ export const CreateButton = () => {
claimAddress,
ref(),
useRif,
newKey,
);
break;
}

if (!(await validateResponse(data, getEtherSwap))) {
if (!(await validateResponse(data, deriveKey, getEtherSwap))) {
navigate("/error");
return;
}
Expand Down Expand Up @@ -352,17 +357,16 @@ export const CreateButton = () => {
// Mobile EVM browsers struggle with downloading files
const isMobileEvmBrowser = () => isMobile() && hasBrowserWallet();

// No backups needed for Reverse Swaps or when we send RBTC
if (
isRecklessMode() ||
recoveryFileBackupDone() ||
swapType() === SwapType.Reverse ||
assetSend() === RBTC ||
// Only disable refund files on mobile EVM browsers when one side is RSK
(assetReceive() === RBTC && isMobileEvmBrowser())
) {
navigate("/swap/" + data.id);
} else {
navigate("/swap/refund/" + data.id);
navigate("/backup/" + data.id);
}
} catch (err) {
if (err === "invalid pair hash") {
Expand Down
57 changes: 0 additions & 57 deletions src/components/DownloadRefund.tsx

This file was deleted.

8 changes: 7 additions & 1 deletion src/components/RefundButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ChainSwap, SubmarineSwap } from "src/utils/swapCreator";
import RefundEta from "../components/RefundEta";
import { RBTC } from "../consts/Assets";
import { SwapType } from "../consts/Enums";
import { useGlobalContext } from "../context/Global";
import { deriveKeyFn, useGlobalContext } from "../context/Global";
import { usePayContext } from "../context/Pay";
import { useWeb3Signer } from "../context/Web3";
import {
Expand Down Expand Up @@ -112,6 +112,7 @@ export const RefundBtc = (props: {
swap: Accessor<SubmarineSwap | ChainSwap>;
setRefundTxId?: Setter<string>;
buttonOverride?: string;
deriveKeyFn?: deriveKeyFn;
}) => {
const {
getSwap,
Expand All @@ -121,6 +122,7 @@ export const RefundBtc = (props: {
notify,
externalBroadcast,
t,
deriveKey,
} = useGlobalContext();
const { setSwap } = usePayContext();

Expand Down Expand Up @@ -163,6 +165,7 @@ export const RefundBtc = (props: {

try {
const res = await refund(
props.deriveKeyFn || deriveKey,
props.swap(),
refundAddress(),
lockupTransaction(),
Expand All @@ -182,6 +185,8 @@ export const RefundBtc = (props: {
if (props.setRefundTxId) {
props.setRefundTxId(res.refundTx);
}

setRefundAddress("");
} catch (error) {
log.warn("refund failed", error);
if (typeof error === "string") {
Expand Down Expand Up @@ -295,6 +300,7 @@ const RefundButton = (props: {
swap: Accessor<SubmarineSwap | ChainSwap>;
setRefundTxId?: Setter<string>;
buttonOverride?: string;
deriveKeyFn?: deriveKeyFn;
}) => {
const [preimageHash] = createResource(async () => {
return (await decodeInvoice((props.swap() as SubmarineSwap).invoice))
Expand Down
22 changes: 11 additions & 11 deletions src/components/SwapChecker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { OutputType } from "boltz-core";
import log from "loglevel";
import { createEffect, onCleanup, onMount } from "solid-js";

import { config } from "../config";
import { BTC, LBTC, RBTC } from "../consts/Assets";
import { SwapType } from "../consts/Enums";
import {
Expand Down Expand Up @@ -53,7 +52,6 @@ class BoltzWebSocket {

constructor(
private readonly url: string,
private readonly wsFallback: string | undefined,
private readonly relevantIds: Set<string>,
private readonly prepareSwap: (id: string, status: SwapStatus) => void,
private readonly claimSwap: (
Expand All @@ -64,12 +62,7 @@ class BoltzWebSocket {

public connect = () => {
log.debug("Opening WebSocket");
this.openWebSocket(`${this.url}/v2/ws`).catch(() => {
if (this.wsFallback !== undefined) {
log.debug("Opening fallback WebSocket");
void this.openWebSocket(this.wsFallback).then().catch();
}
});
void this.openWebSocket(`${this.url}/v2/ws`);
};

public close = () => {
Expand Down Expand Up @@ -179,6 +172,7 @@ export const SwapChecker = () => {
setSwapStorage,
externalBroadcast,
t,
deriveKey,
} = useGlobalContext();

let ws: BoltzWebSocket | undefined = undefined;
Expand Down Expand Up @@ -266,6 +260,7 @@ export const SwapChecker = () => {
) {
try {
const res = await claim(
deriveKey,
currentSwap as ReverseSwap | ChainSwap,
data.transaction as { hex: string },
true,
Expand Down Expand Up @@ -294,7 +289,10 @@ export const SwapChecker = () => {
data.status === swapStatusPending.TransactionClaimPending
) {
try {
await createSubmarineSignature(currentSwap as SubmarineSwap);
await createSubmarineSignature(
deriveKey,
currentSwap as SubmarineSwap,
);
notify(
"success",
t("swap_completed", { id: currentSwap.id }),
Expand Down Expand Up @@ -329,7 +327,10 @@ export const SwapChecker = () => {
log.debug(
`Helping server claim ${swap.assetSend} of Chain Swap ${swap.id}`,
);
const sig = await createTheirPartialChainSwapSignature(swap);
const sig = await createTheirPartialChainSwapSignature(
deriveKey,
swap,
);
await postChainSwapDetails(swap.id, undefined, sig);
} catch (e) {
log.warn(
Expand All @@ -350,7 +351,6 @@ export const SwapChecker = () => {

ws = new BoltzWebSocket(
getApiUrl(),
config.apiUrl.wsFallback,
new Set<string>(swapsToCheck.map((s) => s.id)),
prepareSwap,
claimSwap,
Expand Down
Loading

0 comments on commit 898eb3f

Please sign in to comment.