From 4d1bd23770d75b4f338209fac55adab27ccb46fd Mon Sep 17 00:00:00 2001 From: jackstar12 Date: Sun, 12 Jan 2025 14:24:29 +0100 Subject: [PATCH] fix: check refund address in effect instead of input event handler to react to swap changes --- src/components/RefundButton.tsx | 35 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/components/RefundButton.tsx b/src/components/RefundButton.tsx index b65c35ce..6b628999 100644 --- a/src/components/RefundButton.tsx +++ b/src/components/RefundButton.tsx @@ -3,7 +3,14 @@ import { OutputType } from "boltz-core"; import { Signature, TransactionResponse } from "ethers"; import { Network as LiquidNetwork } from "liquidjs-lib/src/networks"; import log from "loglevel"; -import { Accessor, Setter, Show, createResource, createSignal } from "solid-js"; +import { + Accessor, + Setter, + Show, + createEffect, + createResource, + createSignal, +} from "solid-js"; import { ChainSwap, SubmarineSwap } from "src/utils/swapCreator"; import RefundEta from "../components/RefundEta"; @@ -124,34 +131,30 @@ export const RefundBtc = (props: { const [valid, setValid] = createSignal(false); const [refundRunning, setRefundRunning] = createSignal(false); - const refundAddressChange = (evt: InputEvent, asset: string) => { - const input = evt.currentTarget as HTMLInputElement; - const inputValue = input.value.trim(); - - setRefundAddress(inputValue); + createEffect(() => { + const asset = props.swap()?.assetSend; + if (!asset) return; const lockupAddress = props.swap().type === SwapType.Submarine ? (props.swap() as SubmarineSwap).address : (props.swap() as ChainSwap).lockupDetails.lockupAddress; - if (inputValue === lockupAddress) { + if (refundAddress() === lockupAddress) { log.debug("refunds to lockup address are blocked"); - return false; + setValid(false); } try { getAddress(asset).toOutputScript( - inputValue, + refundAddress(), getNetwork(asset) as LiquidNetwork, ); - input.setCustomValidity(""); - return true; + setValid(true); } catch (e) { log.debug("parsing refund address failed", e); - input.setCustomValidity("invalid address"); - return false; + setValid(false); } - }; + }); const refundAction = async () => { setRefundRunning(true); @@ -262,9 +265,7 @@ export const RefundBtc = (props: { id="refundAddress" disabled={lockupTransaction.state == "errored"} value={refundAddress()} - onInput={(e) => - setValid(refundAddressChange(e, props.swap()?.assetSend)) - } + onInput={(e) => setRefundAddress(e.target.value.trim())} type="text" name="refundAddress" placeholder={