Skip to content

Commit

Permalink
fix: bigints
Browse files Browse the repository at this point in the history
  • Loading branch information
clmntsnr committed Dec 24, 2024
1 parent 3c7df7c commit 604de55
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/primitives/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,22 @@ function Input({ look, size, state, className, ...props }: InputProps) {

Input.BigInt = function InputBigInt({ state, base, ...props }: InputProps<bigint> & { base: number }) {
const [internal, setInternal] = useState<bigint>();
const [displayed, setDisplayed] = useState("0.0");
const [displayed, setDisplayed] = useState<string>();
const [_getter, setter] = state ?? [];

const _value = useMemo(() => {
const _value = !state ? internal : state?.[0];
const transformed = formatUnits(_value ?? 0n, base);

if (_value === undefined || _value === 0n) return displayed;
return transformed ?? displayed;
}, [internal, state, displayed, base]);

const setValue = useCallback(
(v: string | undefined) => {
try {
if (v === undefined) {
setter?.(0n) ?? setInternal(0n);
setter?.(v) ?? setInternal(v);
return;
}

Expand Down

0 comments on commit 604de55

Please sign in to comment.