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

Add Router, errorAtom, renderLogic #181

Merged
merged 1 commit into from
Aug 21, 2024
Merged

Add Router, errorAtom, renderLogic #181

merged 1 commit into from
Aug 21, 2024

Conversation

toddkao
Copy link
Collaborator

@toddkao toddkao commented Aug 20, 2024

No description provided.

Copy link

vercel bot commented Aug 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
widget-nextjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 20, 2024 7:38pm

Copy link

changeset-bot bot commented Aug 20, 2024

⚠️ No Changeset found

Latest commit: 3acbd26

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -26,7 +26,7 @@
/* Aliases */
"baseUrl": ".",
"paths": {
"@*": ["src/*"]
"@/*": ["src/*"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes auto imports / ide from suggesting @components instead of @/components which isn't valid with this config

Comment on lines +1 to +31
import { ErrorPage } from '@/pages/ErrorPage/ErrorPage';
import { SwapExecutionPage } from '@/pages/SwapExecutionPage/SwapExecutionPage';
import { SwapPage } from '@/pages/SwapPage/SwapPage';
import { errorAtom } from '@/state/errorPage';
import { Routes, currentPageAtom } from '@/state/router';
import { useAtom } from 'jotai';
import { ErrorBoundary } from 'react-error-boundary';

export const Router = () => {
const [currentPage] = useAtom(currentPageAtom);
const [error, setError] = useAtom(errorAtom);

if (error) {
return <ErrorPage />;
}

switch (currentPage) {
case Routes.SwapPage:
return (
<ErrorBoundary fallback={null} onError={(error) => setError(error)}>
<SwapPage />
</ErrorBoundary>
);
case Routes.SwapExecutionPage:
return (
<ErrorBoundary fallback={null} onError={(error) => setError(error)}>
<SwapExecutionPage />
</ErrorBoundary>
);
}
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested manually throwing an error within SwapPage and it successfully sets errorAtom state and renders ErrorPage

Copy link
Collaborator Author

@toddkao toddkao Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also tested and can confirm that these error boundaries will not catch any errors thrown within a modal, we will need to handle those separately

Comment on lines +1 to +13
import { errorAtom } from '@/state/errorPage';
import { useResetAtom } from 'jotai/utils';

export const ErrorPage = () => {
const resetError = useResetAtom(errorAtom);

return (
<div>
error page
<button onClick={() => resetError()}>reset</button>
</div>
);
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is temp, i created a ticket to actually create the ErrorPage properly

Copy link
Member

@codingki codingki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

args: {
operations: operations as Operation[],
},
args: {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why you move it inside?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codingki yeah I figure that eventually this data will exist in an atom, so we won't be passing it into the component as a prop, so I decided to just move it inside for now (the usage of the component is more similar to how it'll be when we have the data in an atom)

@toddkao toddkao merged commit a475965 into main Aug 21, 2024
5 checks passed
@toddkao toddkao deleted the FRE-930 branch August 21, 2024 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants