Skip to content

Commit

Permalink
Fix rounding issue when converting to wei
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Sep 16, 2024
1 parent 1cf1f8d commit a5c96f4
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useEffect, useState } from "react";
import { parseUnits } from "viem";
import { CommonInputProps, InputBase, IntegerVariant, isValidInteger } from "~~/components/scaffold-eth";

type IntegerInputProps = CommonInputProps<string | bigint> & {
Expand All @@ -23,7 +24,7 @@ export const IntegerInput = ({
if (typeof value === "bigint") {
return onChange(value * 10n ** 18n);
}
return onChange(BigInt(Math.round(Number(value) * 10 ** 18)));
return onChange(parseUnits(value, 18));
}, [onChange, value]);

useEffect(() => {
Expand Down

0 comments on commit a5c96f4

Please sign in to comment.