From 561878eac095cb9a04ac9245dbdce6e376130b6d Mon Sep 17 00:00:00 2001 From: Tony D'Addeo Date: Wed, 4 Dec 2024 17:37:34 -0600 Subject: [PATCH] explicitly handle user reject error --- src/components/Demo.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/Demo.tsx b/src/components/Demo.tsx index 1f406d4..eec3387 100644 --- a/src/components/Demo.tsx +++ b/src/components/Demo.tsx @@ -21,6 +21,7 @@ import { config } from "~/components/providers/WagmiProvider"; import { Button } from "~/components/ui/Button"; import { truncateAddress } from "~/lib/truncateAddress"; import { base, optimism } from "wagmi/chains"; +import { BaseError, UserRejectedRequestError } from "viem"; export default function Demo( { title }: { title?: string } = { title: "Frames v2 Demo" } @@ -183,11 +184,6 @@ export default function Demo( setIsContextOpen((prev) => !prev); }, []); - const renderError = (error: Error | null) => { - if (!error) return null; - return
{error.message}
; - }; - if (!isSDKLoaded) { return
Loading...
; } @@ -464,5 +460,14 @@ function SendEth() { const renderError = (error: Error | null) => { if (!error) return null; + if (error instanceof BaseError) { + const isUserRejection = error.walk((e) => e instanceof UserRejectedRequestError) + + if (isUserRejection) { + return
Rejected by user.
; + } + } + return
{error.message}
; }; +