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

Fix how the ui handles non-checksummed addresses #990

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isHexString } from "@ethersproject/bytes";
import { isAddress } from "@ethersproject/address";
import { getAddress } from "@ethersproject/address";
import React, {
ChangeEventHandler,
FormEventHandler,
Expand Down Expand Up @@ -68,20 +68,27 @@ const ChainAddressForm = ({

const handleAddressChange: ChangeEventHandler<HTMLInputElement> = (e) => {
const tempAddr = e.target.value;
setAddress(tempAddr);
const isValid = isAddress(tempAddr);
if (!isValid) {
let checksummedAddress: string;
try {
// getAddress: returns the checksummed address only if you pass all lowercase
// if you pass a wrong checksum then in throws, so I'm converting the address
// to lowercase
checksummedAddress = getAddress(tempAddr.toLowerCase());
setAddress(checksummedAddress);
setIsInvalidAddress(false);
} catch (e) {
setFoundMatches(undefined);
setAddress(tempAddr);
return setIsInvalidAddress(true);
}
setIsInvalidAddress(false);

checkAllByAddresses(
tempAddr,
checksummedAddress,
sourcifyChains.map((c) => c.chainId.toString()).join(",")
).then((res) => {
// checkAllByAddresses inputs and outptus multiple addresses.
const currentAddressMatches = res.find(
(match) => (match.address = tempAddr)
(match) => (match.address = checksummedAddress)
);
setFoundMatches(currentAddressMatches);
});
Expand Down