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 10, 2025
1 parent 371f9d1 commit 448a9d3
Show file tree
Hide file tree
Showing 26 changed files with 432 additions and 435 deletions.
93 changes: 41 additions & 52 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.5",
"@reown/appkit-adapter-ethers": "^1.6.5",
"@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
29 changes: 9 additions & 20 deletions src/components/CreateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { fetchBolt12Invoice, getPairs } from "../utils/boltzClient";
import { formatAmount } from "../utils/denomination";
import { formatError } from "../utils/errors";
import { HardwareSigner } from "../utils/hardware/HadwareSigner";
import { coalesceLn, isMobile } from "../utils/helper";
import { coalesceLn } from "../utils/helper";
import { fetchBip353, fetchLnurl } from "../utils/invoice";
import {
SomeSwap,
Expand All @@ -36,7 +36,8 @@ export const CreateButton = () => {
notify,
ref,
t,
isRecklessMode,
newKey,
deriveKey,
} = useGlobalContext();
const {
invoice,
Expand All @@ -63,8 +64,7 @@ export const CreateButton = () => {
bolt12Offer,
setBolt12Offer,
} = useCreateContext();
const { getEtherSwap, signer, providers, hasBrowserWallet } =
useWeb3Signer();
const { getEtherSwap, signer, providers } = useWeb3Signer();

const [buttonDisable, setButtonDisable] = createSignal(false);
const [buttonClass, setButtonClass] = createSignal("btn");
Expand Down Expand Up @@ -291,6 +291,7 @@ export const CreateButton = () => {
invoice(),
ref(),
useRif,
newKey,
);
break;

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

Expand All @@ -317,11 +319,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 @@ -349,21 +352,7 @@ export const CreateButton = () => {
setOnchainAddress("");
setAddressValid(false);

// Mobile EVM browsers struggle with downloading files
const isMobileEvmBrowser = () => isMobile() && hasBrowserWallet();

// No backups needed for Reverse Swaps or when we send RBTC
if (
isRecklessMode() ||
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("/swap/" + data.id);
} catch (err) {
if (err === "invalid pair hash") {
setPairs(await getPairs());
Expand Down
57 changes: 0 additions & 57 deletions src/components/DownloadRefund.tsx

This file was deleted.

2 changes: 2 additions & 0 deletions src/components/RefundButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const RefundBtc = (props: {
notify,
externalBroadcast,
t,
deriveKey,
} = useGlobalContext();
const { setSwap } = usePayContext();

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

try {
const res = await refund(
deriveKey,
props.swap(),
refundAddress(),
lockupTransaction(),
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 448a9d3

Please sign in to comment.