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 ff1783a
Show file tree
Hide file tree
Showing 32 changed files with 866 additions and 404 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
28 changes: 11 additions & 17 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,9 @@ export const CreateButton = () => {
notify,
ref,
t,
isRecklessMode,
newKey,
deriveKey,
recoveryFileBackupDone,
} = useGlobalContext();
const {
invoice,
Expand All @@ -63,8 +65,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 +292,7 @@ export const CreateButton = () => {
invoice(),
ref(),
useRif,
newKey,
);
break;

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

Expand All @@ -317,11 +320,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,20 +353,10 @@ 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())
) {
if (recoveryFileBackupDone()) {
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
Loading

0 comments on commit ff1783a

Please sign in to comment.