Skip to content

Commit

Permalink
Display checksum-ed addresses
Browse files Browse the repository at this point in the history
Fixes #2222
  • Loading branch information
tom2drum committed Sep 13, 2024
1 parent 6770347 commit a54d0f4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/address/getCheckedSummedAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getAddress } from 'viem';

export default function getCheckedSummedAddress(address: string): string {
try {
return getAddress(address);
} catch (error) {
return address;
}
}
6 changes: 4 additions & 2 deletions ui/pages/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { EntityTag } from 'ui/shared/EntityTags/types';
import type { RoutedTab } from 'ui/shared/Tabs/types';

import config from 'configs/app';
import getCheckedSummedAddress from 'lib/address/getCheckedSummedAddress';
import useAddressMetadataInfoQuery from 'lib/address/useAddressMetadataInfoQuery';
import useApiQuery from 'lib/api/useApiQuery';
import { useAppContext } from 'lib/contexts/app';
Expand Down Expand Up @@ -60,6 +61,7 @@ const AddressPageContent = () => {

const tabsScrollRef = React.useRef<HTMLDivElement>(null);
const hash = getQueryParamString(router.query.hash);
const checkSummedHash = React.useMemo(() => getCheckedSummedAddress(hash), [ hash ]);

const areQueriesEnabled = !useCheckDomainNameParam(hash);
const addressQuery = useAddressQuery({ hash, isEnabled: areQueriesEnabled });
Expand Down Expand Up @@ -310,7 +312,7 @@ const AddressPageContent = () => {
/>
) }
<AddressEntity
address={{ ...addressQuery.data, hash, name: '', ens_domain_name: '', implementations: null }}
address={{ ...addressQuery.data, hash: checkSummedHash, name: '', ens_domain_name: '', implementations: null }}
isLoading={ isLoading }
fontFamily="heading"
fontSize="lg"
Expand All @@ -325,7 +327,7 @@ const AddressPageContent = () => {
{ !isLoading && !addressQuery.data?.is_contract && config.features.account.isEnabled && (
<AddressFavoriteButton hash={ hash } watchListId={ addressQuery.data?.watchlist_address_id }/>
) }
<AddressQrCode address={{ hash }} isLoading={ isLoading }/>
<AddressQrCode address={{ hash: checkSummedHash }} isLoading={ isLoading }/>
<AccountActionsMenu isLoading={ isLoading }/>
<HStack ml="auto" gap={ 2 }/>
{ !isLoading && addressQuery.data?.is_contract && addressQuery.data?.is_verified && config.UI.views.address.solidityscanEnabled &&
Expand Down

0 comments on commit a54d0f4

Please sign in to comment.