-
Notifications
You must be signed in to change notification settings - Fork 15
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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> | ||
); | ||
}; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { atom } from 'jotai'; | ||
import { ClientAsset } from '@/state/skipClient'; | ||
import { Wallet } from '@/components/RenderWalletList'; | ||
|
||
export type AssetAtom = Partial<ClientAsset> & { | ||
amount?: string; | ||
}; | ||
|
||
export const sourceAssetAtom = atom<AssetAtom>(); | ||
|
||
export const destinationAssetAtom = atom<AssetAtom>(); | ||
|
||
export const connectedWalletAtom = atom<Wallet>(); | ||
|
||
export const destinationWalletAtom = atom<Wallet>(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { atomWithReset } from 'jotai/utils'; | ||
|
||
export const errorAtom = atomWithReset< | ||
ExpectedErrorDetails | Error | undefined | ||
>(undefined); | ||
|
||
type ExpectedErrorDetails = {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { atom } from 'jotai'; | ||
|
||
export enum Routes { | ||
SwapPage, | ||
SwapExecutionPage, | ||
} | ||
|
||
export const currentPageAtom = atom<Routes>(Routes.SwapPage); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,11 @@ import type { Meta, StoryObj } from '@storybook/react'; | |
import { renderLightAndDarkTheme } from './renderLightAndDarkTheme'; | ||
import { SwapExecutionPage } from '@/pages/SwapExecutionPage/SwapExecutionPage'; | ||
import NiceModal from '@ebay/nice-modal-react'; | ||
import { destinationAssetAtom } from '@/state/swap'; | ||
import { destinationAssetAtom } from '@/state/swapPage'; | ||
import { useAtom } from 'jotai'; | ||
import operations from '@/pages/SwapExecutionPage/operations.json'; | ||
import { skipAssets } from '@/state/skip'; | ||
import { skipAssets } from '@/state/skipClient'; | ||
import { useEffect, useState } from 'react'; | ||
import { Operation } from '@/pages/SwapExecutionPage/SwapExecutionPageRouteDetailedRow'; | ||
|
||
const meta = { | ||
title: 'Pages/SwapExecutionPage', | ||
|
@@ -16,8 +15,8 @@ const meta = { | |
const [_destinationAsset, setDestinationAsset] = | ||
useAtom(destinationAssetAtom); | ||
const [shouldRender, setShouldRender] = useState(false); | ||
const firstOperation = props.operations[0]; | ||
const lastOperation = props.operations[props.operations.length - 1]; | ||
const firstOperation = operations[0]; | ||
const lastOperation = operations[operations.length - 1]; | ||
|
||
const [{ data: assets }] = useAtom(skipAssets); | ||
|
||
|
@@ -57,7 +56,5 @@ type Story = StoryObj<typeof meta>; | |
export default meta; | ||
|
||
export const SwapExecutionPageExample: Story = { | ||
args: { | ||
operations: operations as Operation[], | ||
}, | ||
args: {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason why you move it inside? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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> | ||
); | ||
} | ||
}; | ||
Comment on lines
+1
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
/* Aliases */ | ||
"baseUrl": ".", | ||
"paths": { | ||
"@*": ["src/*"] | ||
"@/*": ["src/*"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes auto imports / ide from suggesting |
||
} | ||
}, | ||
"include": ["src"] | ||
|
There was a problem hiding this comment.
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