Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Bug_0xblank #398

Merged
merged 16 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/nextjs/components/scaffold-stark/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export const Address = ({
checkSumAddress || address || "",
);

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets put it in the utils file (i think we have this util already). we don't want duplicates of the same function since they would be a pain to maintain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was given another recommendation that 0x be accepted as felt252 and that I should add a 0 to 0x to be accepted

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, aligned on that end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make sure 0x0x0 does not work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'll check that it aligns with that

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

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

return (
Expand Down
10 changes: 9 additions & 1 deletion packages/nextjs/components/scaffold-stark/Faucet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const Faucet = () => {

const { chain: ConnectedChain } = useNetwork();
const { provider: publicClient } = useProvider();
const isValidHexAddress = (value: string): boolean => {
const hexAddressRegex = /^0x[0-9a-fA-F]+$/;
return hexAddressRegex.test(value);
};

useEffect(() => {
const checkChain = async () => {
Expand Down Expand Up @@ -114,7 +118,11 @@ export const Faucet = () => {
<AddressInput
placeholder="Destination Address"
value={inputAddress ?? ""}
onChange={(value) => setInputAddress(value as AddressType)}
onChange={(value) => {
if (isValidHexAddress(value)) {
setInputAddress(value as AddressType);
}
}}
/>
<EtherInput
placeholder="Amount to send"
Expand Down
Loading