-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from MakerXStudio/handle-transaction-errors
chore: handle errors in transactions
- Loading branch information
Showing
18 changed files
with
252 additions
and
175 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { asError } from '@/utils/error' | ||
import { Loadable } from 'jotai/vanilla/utils/loadable' | ||
import { Loader2 as Loader } from 'lucide-react' | ||
|
||
type RenderLoadableProps<T> = { | ||
loadable: Loadable<T> | ||
children: (data: Awaited<T>) => React.ReactNode | ||
fallback?: React.ReactNode | ||
transformError?: (error: Error) => Error | undefined | ||
} | ||
|
||
export function RenderLoadable<T>({ loadable, children, fallback, transformError }: RenderLoadableProps<T>) { | ||
if (loadable.state === 'hasData') { | ||
return <>{children(loadable.data)}</> | ||
} else if (loadable.state === 'loading') { | ||
return <>{fallback ?? <Loader className="size-10 animate-spin" />}</> | ||
} | ||
|
||
const error = transformError ? transformError(asError(loadable.error)) : asError(loadable.error) | ||
if (error) { | ||
throw error | ||
} | ||
|
||
return <></> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { cn } from '@/features/common/utils' | ||
import { asError } from '@/utils/error' | ||
import { useRouteError } from 'react-router-dom' | ||
|
||
type ErrorPageProps = { | ||
title?: string | ||
} | ||
|
||
export function ErrorPage({ title }: ErrorPageProps) { | ||
const error = asError(useRouteError()) | ||
|
||
return ( | ||
<div> | ||
<h1 className={cn('text-2xl text-primary font-bold')}>{title ?? 'Error'}</h1> | ||
<p>Error: {error.message}</p> | ||
</div> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.