Commit 347b85fd authored by tom goriunov's avatar tom goriunov Committed by GitHub

Rootstock checksum is not applied on the address page (#2500)

Fixes #2494
parent 96f2e119
import { getAddress } from 'viem'; import { getAddress } from 'viem';
import config from 'configs/app';
export default function getCheckedSummedAddress(address: string): string { export default function getCheckedSummedAddress(address: string): string {
try { try {
return getAddress(address); return getAddress(
address,
// We need to pass chainId to getAddress to make it work correctly for some chains, e.g. Rootstock
config.chain.id ? Number(config.chain.id) : undefined,
);
} catch (error) { } catch (error) {
return address; return address;
} }
......
...@@ -69,7 +69,6 @@ const AddressPageContent = () => { ...@@ -69,7 +69,6 @@ const AddressPageContent = () => {
const tabsScrollRef = React.useRef<HTMLDivElement>(null); const tabsScrollRef = React.useRef<HTMLDivElement>(null);
const hash = getQueryParamString(router.query.hash); const hash = getQueryParamString(router.query.hash);
const checkSummedHash = React.useMemo(() => getCheckedSummedAddress(hash), [ hash ]);
const checkDomainName = useCheckDomainNameParam(hash); const checkDomainName = useCheckDomainNameParam(hash);
const checkAddressFormat = useCheckAddressFormat(hash); const checkAddressFormat = useCheckAddressFormat(hash);
...@@ -364,6 +363,10 @@ const AddressPageContent = () => { ...@@ -364,6 +363,10 @@ const AddressPageContent = () => {
return; return;
}, [ appProps.referrer ]); }, [ appProps.referrer ]);
// API always returns hash in check-summed format except for addresses that are not in the database
// In this case it returns 404 with empty payload, so we calculate check-summed hash on the client
const checkSummedHash = React.useMemo(() => addressQuery.data?.hash ?? getCheckedSummedAddress(hash), [ hash, addressQuery.data?.hash ]);
const titleSecondRow = ( const titleSecondRow = (
<Flex alignItems="center" w="100%" columnGap={ 2 } rowGap={ 2 } flexWrap={{ base: 'wrap', lg: 'nowrap' }}> <Flex alignItems="center" w="100%" columnGap={ 2 } rowGap={ 2 } flexWrap={{ base: 'wrap', lg: 'nowrap' }}>
{ addressQuery.data?.ens_domain_name && ( { addressQuery.data?.ens_domain_name && (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment