From 484306db36c68882ff0a9504a940102240a7dbe4 Mon Sep 17 00:00:00 2001 From: csillag Date: Wed, 21 Sep 2022 12:42:34 +0200 Subject: [PATCH] Avoid app crash when invalid address is provided. Fixes #940. --- src/app/pages/AccountPage/index.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/app/pages/AccountPage/index.tsx b/src/app/pages/AccountPage/index.tsx index 5d439430e1..09fa09fa1d 100644 --- a/src/app/pages/AccountPage/index.tsx +++ b/src/app/pages/AccountPage/index.tsx @@ -35,6 +35,7 @@ import { mobileHeaderZIndex } from '../../components/Sidebar' import { ValidatorList } from '../StakingPage/Features/ValidatorList' import { AccountDetails } from './Features/AccountDetails' import { AccountSummary } from './Features/AccountSummary' +import { isValidAddress } from '../../lib/helpers' const StyledNavItem = styled(NavLink)` display: flex; @@ -84,13 +85,13 @@ const NavItem = ({ counter, label, route }: NavItemProps) => { ) } -interface Props {} +interface AccountPageProps {} interface AccountPageParams { address: string } -export function AccountPage(props: Props) { +function AccountPageInternal(props: AccountPageProps) { const { t } = useTranslation() const isMobile = React.useContext(ResponsiveContext) === 'small' const { address } = useParams() @@ -217,3 +218,16 @@ export function AccountPage(props: Props) { ) } + +export function AccountPage(props: AccountPageProps) { + const { t } = useTranslation() + const { address } = useParams() + if (!isValidAddress(address!)) { + return ( + + {t('errors.invalidAddress', 'Invalid address')} + + ) + } + return +}