-
Notifications
You must be signed in to change notification settings - Fork 809
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump wagmi, viem and rainbowkit versions (#849)
- Loading branch information
1 parent
44110ed
commit 6b9b4d0
Showing
5 changed files
with
437 additions
and
733 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
import { BaseError as BaseViemError, DecodeErrorResultReturnType } from "viem"; | ||
import { BaseError as BaseViemError, ContractFunctionRevertedError } from "viem"; | ||
|
||
/** | ||
* Parses an viem/wagmi error to get a displayable string | ||
* @param e - error object | ||
* @returns parsed error string | ||
*/ | ||
export const getParsedError = (e: any): string => { | ||
let message: string = e.message ?? "An unknown error occurred"; | ||
if (e instanceof BaseViemError) { | ||
if (e.details) { | ||
message = e.details; | ||
} else if (e.shortMessage) { | ||
message = e.shortMessage; | ||
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?.errorName !== "Error") { | ||
const customErrorArgs = cause.data.args?.toString() ?? ""; | ||
message = `${message.replace(/reverted\.$/, "reverted with following reason:")}\n${ | ||
cause.data.errorName | ||
export const getParsedError = (error: any): string => { | ||
const parsedError = error?.walk ? error.walk() : error; | ||
|
||
if (parsedError instanceof BaseViemError) { | ||
if (parsedError.details) { | ||
return parsedError.details; | ||
} | ||
|
||
if (parsedError.shortMessage) { | ||
if ( | ||
parsedError instanceof ContractFunctionRevertedError && | ||
parsedError.data && | ||
parsedError.data.errorName !== "Error" | ||
) { | ||
const customErrorArgs = parsedError.data.args?.toString() ?? ""; | ||
return `${parsedError.shortMessage.replace(/reverted\.$/, "reverted with the following reason:")}\n${ | ||
parsedError.data.errorName | ||
}(${customErrorArgs})`; | ||
} | ||
} else if (e.message) { | ||
message = e.message; | ||
} else if (e.name) { | ||
message = e.name; | ||
|
||
return parsedError.shortMessage; | ||
} | ||
|
||
return parsedError.message ?? parsedError.name ?? "An unknown error occurred"; | ||
} | ||
|
||
return message; | ||
return parsedError?.message ?? "An unknown error occurred"; | ||
}; |
Oops, something went wrong.