Skip to content

Commit

Permalink
refactor: proper resource implementation for lockupTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstar12 committed Jan 9, 2025
1 parent 52b9097 commit a57f849
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions src/components/RefundButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Setter,
Show,
Switch,
createEffect,
createResource,
createSignal,
} from "solid-js";
Expand Down Expand Up @@ -215,31 +214,24 @@ const RefundButton = (props: {
setRefundRunning(false);
};

const [lockupTransaction, { refetch: refetchLockup }] = createResource(
async () => {
if (!props.swap()) {
return undefined;
}

const transactionToRefund = await getLockupTransaction(
props.swap().id,
props.swap().type,
);

// show refund ETA for legacy swaps
if (props.swap().version !== OutputType.Taproot) {
setTimeoutEta(transactionToRefund.timeoutEta);
setTimeoutBlockheight(transactionToRefund.timeoutBlockHeight);
}
// eslint-disable-next-line solid/reactivity
const [lockupTransaction] = createResource(props.swap, async (swap) => {
if (!swap) {
return undefined;
}

return transactionToRefund;
},
);
const transactionToRefund = await getLockupTransaction(
swap.id,
swap.type,
);

createEffect(() => {
if (props.swap() !== undefined) {
refetchLockup(null);
// show refund ETA for legacy swaps
if (swap.version !== OutputType.Taproot) {
setTimeoutEta(transactionToRefund.timeoutEta);
setTimeoutBlockheight(transactionToRefund.timeoutBlockHeight);
}

return transactionToRefund;
});

const [preimageHash] = createResource(async () => {
Expand Down Expand Up @@ -304,7 +296,7 @@ const RefundButton = (props: {
</Show>
}>
<Switch>
<Match when={lockupTransaction.state === "ready"}>
<Match when={lockupTransaction.state === "ready" || lockupTransaction.state == "unresolved"}>
<Show when={timeoutEta() > 0 || timeoutBlockheight() > 0}>
<RefundEta
timeoutEta={timeoutEta}
Expand Down

0 comments on commit a57f849

Please sign in to comment.