-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
140 additions
and
21 deletions.
There are no files selected for viewing
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
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,40 @@ | ||
"use client"; | ||
import React from "react"; | ||
import { useErrorReportingStore } from "../stores/useErrorReport"; | ||
import { Dialog, DialogContent } from "./ui/dialog"; | ||
import { Button } from "./ui/button"; | ||
import * as Sentry from "@sentry/nextjs"; | ||
|
||
export default function ErrorReportingDialog() { | ||
const { isOpen, setIsOpen, error, setError } = useErrorReportingStore(); | ||
async function handleError() { | ||
Sentry.captureException(error); | ||
// close dialog | ||
setError(null); | ||
setIsOpen(false); | ||
} | ||
return ( | ||
<Dialog | ||
open={isOpen} | ||
onOpenChange={(isOpen) => { | ||
setIsOpen(isOpen); | ||
!isOpen && setError(null); | ||
}} | ||
> | ||
<DialogContent className="fixed bottom-4 right-4 z-50 rounded-md bg-black "> | ||
<div className="flex flex-col items-center justify-center gap-4 p-6 text-sm text-white"> | ||
<span className="font-bold">Report this error?</span> | ||
<span> | ||
{error instanceof Error ? error.name : "Unknown error name"} | ||
</span> | ||
<p className="max-h-40 max-w-xl overflow-x-hidden overflow-y-scroll whitespace-break-spaces rounded-md bg-white/10 p-4 text-xs"> | ||
{error instanceof Error ? error.message : "Unknown error message"} | ||
</p> | ||
<Button onClick={handleError} variant={"secondary"}> | ||
Report | ||
</Button> | ||
</div> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} |
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,26 @@ | ||
import React from "react"; | ||
import * as DialogPrimitive from "@radix-ui/react-dialog"; | ||
|
||
export const DialogContent = React.forwardRef< | ||
React.ElementRef<typeof DialogPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> | ||
>(({ children, ...props }, forwardedRef) => ( | ||
<DialogPrimitive.Portal> | ||
<DialogPrimitive.Overlay className="fixed inset-0 z-30 bg-black/50" /> | ||
<DialogPrimitive.Content {...props} ref={forwardedRef}> | ||
<div className="mr-2 mt-2 flex justify-end"> | ||
<DialogPrimitive.Close | ||
aria-label="Close" | ||
className="flex size-6 items-center justify-center rounded-md bg-white" | ||
> | ||
<span className="text-xs">X</span> | ||
</DialogPrimitive.Close> | ||
</div> | ||
{children} | ||
</DialogPrimitive.Content> | ||
</DialogPrimitive.Portal> | ||
)); | ||
|
||
export const Dialog = DialogPrimitive.Root; | ||
export const DialogTrigger = DialogPrimitive.Trigger; | ||
DialogContent.displayName = DialogPrimitive.Content.displayName; |
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,41 @@ | ||
import { useWriteContract as baseUseWriteContract, Config } from "wagmi"; | ||
import { WriteContractMutateAsync } from "wagmi/query"; | ||
import { useErrorReportingStore } from "@/stores/useErrorReport"; | ||
|
||
type VariablesType<T> = T extends (variables: infer V, ...args: any[]) => void | ||
? V | ||
: never; | ||
|
||
export default function useWriteContract() { | ||
const { | ||
writeContractAsync: baseWriteContractAsync, | ||
writeContract, | ||
...props | ||
} = baseUseWriteContract(); | ||
const setIsOpen = useErrorReportingStore((s) => s.setIsOpen); | ||
const setError = useErrorReportingStore((s) => s.setError); | ||
|
||
function handleError(error: unknown) { | ||
if (error instanceof Error && error.message.includes("User rejected")) | ||
return; | ||
setError(error); | ||
setIsOpen(true); | ||
} | ||
|
||
async function writeContractAsync( | ||
props: VariablesType<WriteContractMutateAsync<Config>>, | ||
) { | ||
try { | ||
return await baseWriteContractAsync(props); | ||
} catch (error) { | ||
handleError(error); | ||
} | ||
} | ||
|
||
return { | ||
...props, | ||
// do not export a sync write to be able to handle error | ||
// writeContract, | ||
writeContractAsync, | ||
}; | ||
} |
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,15 @@ | ||
import { create } from "zustand"; | ||
|
||
interface ErrorReportingStore { | ||
isOpen: boolean; | ||
setIsOpen: (isOpen: boolean) => void; | ||
error: unknown | null; | ||
setError: (error: unknown) => void; | ||
} | ||
|
||
export const useErrorReportingStore = create<ErrorReportingStore>((set) => ({ | ||
isOpen: false, | ||
setIsOpen: (isOpen) => set({ isOpen }), | ||
error: null, | ||
setError: (error: unknown) => set({ error }), | ||
})); |