Skip to content

Commit

Permalink
feat: show EVM lockup transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Nov 4, 2024
1 parent eb5bc5e commit 947a05b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 31 deletions.
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

0 comments on commit 947a05b

Please sign in to comment.