From bbc37ef125e2f64060d9aee16a106c87a78896de Mon Sep 17 00:00:00 2001 From: tom goriunov Date: Fri, 13 Sep 2024 22:05:13 +0400 Subject: [PATCH] Display checksum-ed addresses (#2240) Fixes #2222 --- lib/address/getCheckedSummedAddress.ts | 9 +++++++++ ui/pages/Address.tsx | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 lib/address/getCheckedSummedAddress.ts diff --git a/lib/address/getCheckedSummedAddress.ts b/lib/address/getCheckedSummedAddress.ts new file mode 100644 index 0000000000..6cf744620d --- /dev/null +++ b/lib/address/getCheckedSummedAddress.ts @@ -0,0 +1,9 @@ +import { getAddress } from 'viem'; + +export default function getCheckedSummedAddress(address: string): string { + try { + return getAddress(address); + } catch (error) { + return address; + } +} diff --git a/ui/pages/Address.tsx b/ui/pages/Address.tsx index 1163db5597..6b79b34932 100644 --- a/ui/pages/Address.tsx +++ b/ui/pages/Address.tsx @@ -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'; @@ -60,6 +61,7 @@ const AddressPageContent = () => { const tabsScrollRef = React.useRef(null); const hash = getQueryParamString(router.query.hash); + const checkSummedHash = React.useMemo(() => getCheckedSummedAddress(hash), [ hash ]); const areQueriesEnabled = !useCheckDomainNameParam(hash); const addressQuery = useAddressQuery({ hash, isEnabled: areQueriesEnabled }); @@ -310,7 +312,7 @@ const AddressPageContent = () => { /> ) } { { !isLoading && !addressQuery.data?.is_contract && config.features.account.isEnabled && ( ) } - + { !isLoading && addressQuery.data?.is_contract && addressQuery.data?.is_verified && config.UI.views.address.solidityscanEnabled &&