Skip to content

Commit

Permalink
Merge pull request #1004 from oasisprotocol/csillag/handle-invalid-ad…
Browse files Browse the repository at this point in the history
…dress-in-url

Handle invalid address in url
  • Loading branch information
csillag authored Sep 29, 2022
2 parents 76c1316 + 484306d commit f74d793
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/app/pages/AccountPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<keyof AccountPageParams>()
Expand Down Expand Up @@ -217,3 +218,16 @@ export function AccountPage(props: Props) {
</Box>
)
}

export function AccountPage(props: AccountPageProps) {
const { t } = useTranslation()
const { address } = useParams<keyof AccountPageParams>()
if (!isValidAddress(address!)) {
return (
<Box pad={'small'}>
<AlertBox color={'status-error'}>{t('errors.invalidAddress', 'Invalid address')}</AlertBox>
</Box>
)
}
return <AccountPageInternal {...props} />
}

0 comments on commit f74d793

Please sign in to comment.