Skip to content

Commit

Permalink
Create new address binding on AddressInput
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteAtATime committed Apr 13, 2024
1 parent e2cbae0 commit a82434f
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
import { blo } from "blo";
import { normalize } from "viem/ens";
// eslint-disable-next-line no-undef
let { value = $bindable(), name, placeholder, onchange, disabled }: CommonInputProps<Address | string> = $props();
let {
// eslint-disable-next-line no-undef
value = $bindable(),
// eslint-disable-next-line no-undef
address = $bindable(),
name,
placeholder,
onchange,
disabled,
}: CommonInputProps<Address | string> & { address?: string | undefined; ens?: string | undefined } = $props();
let rawDebouncedValue: string | undefined = $state(undefined);
let debouncedTimeout: number | undefined;
Expand All @@ -24,6 +32,15 @@
}, 500);
});
$effect(() => {
if (value && isAddress(value)) address = value;
else address = undefined;
});
$effect(() => {
if (address) value = address;
});
// If the user enters an address, don't delay
const debouncedValue = $derived(isAddress(value) ? value : rawDebouncedValue);
const isDebouncedValueLive = $derived(debouncedValue === value);
Expand Down

0 comments on commit a82434f

Please sign in to comment.