Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show EVM lockup transactions #715

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 50 additions & 26 deletions src/components/BlockExplorerLink.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Accessor, Show, createEffect, createSignal } from "solid-js";
import {
Accessor,
Match,
Show,
Switch,
createEffect,
createSignal,
} from "solid-js";

import { RBTC } from "../consts/Assets";
import { SwapType } from "../consts/Enums";
Expand Down Expand Up @@ -43,6 +50,8 @@ const BlockExplorerLink = (props: {
swap: Accessor<SomeSwap>;
swapStatus: Accessor<string>;
}) => {
const isRsk = () => getRelevantAssetForSwap(props.swap()) === RBTC;

return (
<Show
when={props.swap().type !== SwapType.Chain}
Expand All @@ -52,37 +61,52 @@ const BlockExplorerLink = (props: {
swapStatus={props.swapStatus}
/>
}>
{/* Showing addresses makes no sense for EVM based chains */}
<Show
when={getRelevantAssetForSwap(props.swap()) !== RBTC}
fallback={
<Show when={props.swap().claimTx !== undefined}>
<Switch>
<Match when={!isRsk()}>
{/* Refund transactions are handled in SwapRefunded */}
<Show
when={
getRelevantAssetForSwap(props.swap()) &&
props.swapStatus() !== null &&
props.swapStatus() !== "invoice.set" &&
props.swapStatus() !== "swap.created"
}>
<BlockExplorer
asset={getRelevantAssetForSwap(props.swap())}
txId={props.swap().claimTx}
address={
props.swap().type === SwapType.Submarine
? (props.swap() as SubmarineSwap).address
: (props.swap() as ReverseSwap)
.lockupAddress
}
/>
</Show>
</Match>

{/* Showing addresses makes no sense for EVM based chains */}
<Match when={isRsk()}>
<Show
when={props.swap().claimTx !== undefined}
fallback={
<Show when={props.swap().lockupTx}>
<BlockExplorer
asset={getRelevantAssetForSwap(
props.swap(),
)}
txId={props.swap().lockupTx}
typeLabel={"lockup_tx"}
/>
</Show>
}>
<BlockExplorer
asset={getRelevantAssetForSwap(props.swap())}
txId={props.swap().claimTx}
typeLabel={"claim_tx"}
/>
</Show>
}>
{/* Refund transactions are handled in SwapRefunded */}
<Show
when={
getRelevantAssetForSwap(props.swap()) &&
props.swapStatus() !== null &&
props.swapStatus() !== "invoice.set" &&
props.swapStatus() !== "swap.created"
}>
<BlockExplorer
asset={getRelevantAssetForSwap(props.swap())}
txId={props.swap().claimTx}
address={
props.swap().type === SwapType.Submarine
? (props.swap() as SubmarineSwap).address
: (props.swap() as ReverseSwap).lockupAddress
}
/>
</Show>
</Show>
</Match>
</Switch>
</Show>
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/components/LockupEvm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Show, createEffect, createSignal } from "solid-js";

import { useGlobalContext } from "../context/Global";
import { usePayContext } from "../context/Pay";
import { customDerivationPathRdns, useWeb3Signer } from "../context/Web3";
import { HardwareSigner } from "../utils/hardware/HadwareSigner";
import { prefix0x, satoshiToWei } from "../utils/rootstock";
Expand Down Expand Up @@ -30,6 +31,7 @@ const LockupEvm = (props: {
derivationPath?: string;
timeoutBlockHeight: number;
}) => {
const { setSwap } = usePayContext();
const { getEtherSwap, signer, providers } = useWeb3Signer();
const { t, getSwap, setSwapStorage } = useGlobalContext();

Expand Down Expand Up @@ -75,6 +77,7 @@ const LockupEvm = (props: {
).getDerivationPath();
}

setSwap(currentSwap);
await setSwapStorage(currentSwap);
}}
children={<ConnectWallet />}
Expand Down
25 changes: 20 additions & 5 deletions src/components/SwapChecker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type SwapStatus = {
status: string;

failureReason?: string;
transaction: SwapStatusTransaction;
transaction?: SwapStatusTransaction;
};

const reconnectInterval = 5_000;
Expand Down Expand Up @@ -75,6 +75,10 @@ class BoltzWebSocket {
};

public subscribeUpdates = (ids: string[]) => {
if (ids.every((id) => this.relevantIds.has(id))) {
return;
}

ids.forEach((id) => this.relevantIds.add(id));
if (this.ws.readyState !== WebSocket.OPEN) {
return;
Expand Down Expand Up @@ -188,10 +192,21 @@ export const SwapChecker = () => {
return;
}

if (
currentSwap.version !== OutputType.Taproot ||
getRelevantAssetForSwap(currentSwap) === RBTC
) {
if (getRelevantAssetForSwap(currentSwap) === RBTC) {
if (
data.status === swapStatusPending.TransactionMempool &&
data.transaction !== undefined
) {
currentSwap.lockupTx = data.transaction.id;

setSwap(currentSwap);
await setSwapStorage(currentSwap);
}

return;
}

if (currentSwap.version !== OutputType.Taproot) {
return;
}

Expand Down