Skip to content

Commit

Permalink
fix: redirect to 404 if token address is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh DeCristi authored and Josh DeCristi committed May 17, 2023
1 parent 4b461bd commit ea84935
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pages/reserve-overview.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,30 @@ import { ContentContainer } from '../src/components/ContentContainer';
export default function ReserveOverview() {
const router = useRouter();
const { reserves } = useAppDataContext();
const underlyingAsset = router.query.underlyingAsset as string;
const { breakpoints } = useTheme();
const lg = useMediaQuery(breakpoints.up('lg'));

const [reserve, setReserve] = useState<ComputedReserveData>();
const [mode, setMode] = useState<'overview' | 'actions' | ''>('');

const underlyingAsset = router.query.underlyingAsset as string;

useEffect(() => {
if (!mode) setMode('overview');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [lg]);

const reserve = reserves.find(
(reserve) => reserve.underlyingAsset === underlyingAsset
) as ComputedReserveData;
if (router.isReady && reserves.length) {
const reserveFound = reserves.find((reserve) => reserve.underlyingAsset === underlyingAsset);

if (reserveFound) setReserve(reserveFound);
else router.replace('/404');
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [lg, router.isReady, reserves.length]);

const isOverview = mode === 'overview';

return (
return reserve ? (
<AssetCapsProvider asset={reserve}>
<ReserveTopDetails underlyingAsset={underlyingAsset} />

Expand Down Expand Up @@ -92,7 +98,7 @@ export default function ReserveOverview() {
</Box>
</ContentContainer>
</AssetCapsProvider>
);
) : null;
}

ReserveOverview.getLayout = function getLayout(page: React.ReactElement) {
Expand Down

0 comments on commit ea84935

Please sign in to comment.