From fe987537e9862d6ea1b65b48a44784785e6d2e5a Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Thu, 7 Dec 2023 20:42:28 +0530 Subject: [PATCH] add check for cause?.data because it can cause can be undefined --- .../nextjs/components/scaffold-eth/Contract/utilsContract.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nextjs/components/scaffold-eth/Contract/utilsContract.tsx b/packages/nextjs/components/scaffold-eth/Contract/utilsContract.tsx index 0c7d662ad..9da4b1edd 100644 --- a/packages/nextjs/components/scaffold-eth/Contract/utilsContract.tsx +++ b/packages/nextjs/components/scaffold-eth/Contract/utilsContract.tsx @@ -25,9 +25,9 @@ const getParsedError = (e: any): string => { message = e.details; } else if (e.shortMessage) { message = e.shortMessage; - const cause = e.cause as { data?: DecodeErrorResultReturnType }; + const cause = e.cause as { data?: DecodeErrorResultReturnType } | undefined; // if its not generic error, append custom error name and its args to message - if (cause.data && cause.data?.abiItem?.name !== "Error") { + if (cause?.data && cause.data?.abiItem?.name !== "Error") { const customErrorArgs = cause.data.args?.toString() ?? ""; message = `${message.replace(/reverted\.$/, "reverted with following reason:")}\n${ cause.data.errorName