Skip to content

Commit

Permalink
Update Bug_0xblank (#398)
Browse files Browse the repository at this point in the history
Co-authored-by: root <root@DESKTOP-5QGDUGP>
  • Loading branch information
KevinMB0220 and root authored Dec 28, 2024
1 parent e47c5e3 commit f46ced0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
22 changes: 20 additions & 2 deletions packages/nextjs/components/scaffold-stark/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export const Address = ({

const checkSumAddress = useMemo(() => {
if (!address) return undefined;

if (address.toLowerCase() === "0x") {
return "0x0";
}

return getChecksumAddress(address);
}, [address]);

Expand All @@ -60,6 +65,19 @@ export const Address = ({
checkSumAddress || address || "",
);

const isValidHexAddress = (value: string): boolean => {
if (value.toLowerCase() === "0x") {
value = "0x0";
}

if (value.toLowerCase() === "0x0x0") {
return false;
}

const hexAddressRegex = /^0x[0-9a-fA-F]+$/;
return hexAddressRegex.test(value);
};

const [displayAddress, setDisplayAddress] = useState(
checkSumAddress?.slice(0, 6) + "..." + checkSumAddress?.slice(-4),
);
Expand Down Expand Up @@ -96,8 +114,8 @@ export const Address = ({
);
}

if (!validateChecksumAddress(checkSumAddress)) {
return <span className="text-error">Wrong address</span>;
if (!checkSumAddress) {
return <span className="text-error">Invalid address format</span>;
}

return (
Expand Down
19 changes: 18 additions & 1 deletion packages/nextjs/components/scaffold-stark/Input/AddressInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,24 @@ export const AddressInput = ({

const handleChange = useCallback(
(newValue: Address) => {
//setEnteredEnsName(undefined);
const sanitizedValue = newValue.toLowerCase();

if (sanitizedValue === "0x") {
onChange("0x0" as Address);
return;
}

const isValid =
/^(0x)([a-fA-F0-9]{40})$/.test(sanitizedValue) &&
!/0x.*0x/.test(sanitizedValue);
if (!isValid) {
return;
}

if (sanitizedValue.length !== 42) {
return;
}

onChange(newValue);
},
[onChange],
Expand Down

0 comments on commit f46ced0

Please sign in to comment.