explicitly handle user reject error

This commit is contained in:
Tony D'Addeo 2024-12-04 17:37:34 -06:00 committed by lucas-neynar
parent e5a55c463b
commit 561878eac0
No known key found for this signature in database

View File

@ -21,6 +21,7 @@ import { config } from "~/components/providers/WagmiProvider";
import { Button } from "~/components/ui/Button"; import { Button } from "~/components/ui/Button";
import { truncateAddress } from "~/lib/truncateAddress"; import { truncateAddress } from "~/lib/truncateAddress";
import { base, optimism } from "wagmi/chains"; import { base, optimism } from "wagmi/chains";
import { BaseError, UserRejectedRequestError } from "viem";
export default function Demo( export default function Demo(
{ title }: { title?: string } = { title: "Frames v2 Demo" } { title }: { title?: string } = { title: "Frames v2 Demo" }
@ -183,11 +184,6 @@ export default function Demo(
setIsContextOpen((prev) => !prev); setIsContextOpen((prev) => !prev);
}, []); }, []);
const renderError = (error: Error | null) => {
if (!error) return null;
return <div className="text-red-500 text-xs mt-1">{error.message}</div>;
};
if (!isSDKLoaded) { if (!isSDKLoaded) {
return <div>Loading...</div>; return <div>Loading...</div>;
} }
@ -464,5 +460,14 @@ function SendEth() {
const renderError = (error: Error | null) => { const renderError = (error: Error | null) => {
if (!error) return null; if (!error) return null;
if (error instanceof BaseError) {
const isUserRejection = error.walk((e) => e instanceof UserRejectedRequestError)
if (isUserRejection) {
return <div className="text-red-500 text-xs mt-1">Rejected by user.</div>;
}
}
return <div className="text-red-500 text-xs mt-1">{error.message}</div>; return <div className="text-red-500 text-xs mt-1">{error.message}</div>;
}; };