interface icon indicating copy to clipboard operation
interface copied to clipboard

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

Open Jdecristi opened this issue 2 years ago • 6 comments

General Changes

Developer Notes

Implementing getStaticProps will run at build time rather than query. To handle redirection based on route parameters, redirect on static. This can be achieved by checking for the existence of a reserve based on the underlyingAsset during page mount. If the reserve exists, load the page. Otherwise, redirect to the 404 page.


Author Checklist

Please ensure you, the author, have gone through this checklist to ensure there is an efficient workflow for the reviewers.

  • [x] The base branch is set to main
  • [x] The title is using Conventional Commit formatting
  • [x] The Github issue has been linked to the PR in the Development section
  • [x] The General Changes section has been filled out
  • [x] Developer Notes have been added (optional)

If the PR is ready for review:

  • [x] The PR is in Open state and not in Draft mode
  • [x] The Ready for Dev Review label has been added

Reviewer Checklist

Please ensure you, as the reviewer(s), have gone through this checklist to ensure that the code changes are ready to ship safely and to help mitigate any downstream issues that may occur.

  • [ ] End-to-end tests are passing without any errors
  • [ ] Code style generally follows existing patterns
  • [ ] Code changes do not significantly increase the application bundle size
  • [ ] If there are new 3rd-party packages, they do not introduce potential security threats
  • [ ] If there are new environment variables being added, they have been added to the .env.example file as well as the pertinant .github/actions/* files
  • [ ] There are no CI changes, or they have been approved by the DevOps and Engineering team(s)
  • [ ] Code changes have been quality checked in the ephemeral URL
  • [ ] QA verification has been completed
  • [ ] There are two or more approvals from the core team
  • [ ] Squash and merge has been checked

Jdecristi avatar Apr 13 '23 22:04 Jdecristi

Link Height tasks by mentioning a task ID in the pull request title or commit messages, or description and comments with the keyword link (e.g. "Link T-123").

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

height[bot] avatar Apr 13 '23 22:04 height[bot]

@defispartan @grothem I fixed the issues you mentioned

  const { reserves, loading } = useAppDataContext();

  ...

  useEffect(() => {
    if (!mode) setMode('overview');

    if (loading && 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, loading, reserves.length]);

Jdecristi avatar May 06 '23 19:05 Jdecristi

The re-direct to 404 is working, but when I click an asset from the markets or dashboard page it just takes me to a blank reserve page and I have to refresh for the page to load. This happens in development and production mode

defispartan avatar May 17 '23 03:05 defispartan

@defispartan @grothem I figured out the issue, it was when I changed the if (router.isReady && reserves.length) to if (loading && reserves.length). Loading the page does check the reserves, but re-loading the page doesn't. I had to change it back to fix the issue.

Jdecristi avatar May 17 '23 05:05 Jdecristi

@Jdecristi if I visit the reserve page such as DAI. And then I change the query params to something like https://app.aave.com/reserve-overview/?underlyingAsset=213&marketName=proto_mainnet_v3 I still do not get a 404 page. Can you try and fix? Thank you for your contributions!!

foodaka avatar May 25 '23 17:05 foodaka

@foodaka I'm not able to reproduce your error. Would you mind going into more detail or showing through a screen recording?

Jdecristi avatar May 25 '23 20:05 Jdecristi