Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Redirect to 404 page if reserve details asset is invalid #1551

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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