Skip to content

Commit

Permalink
Bump wagmi, viem and rainbowkit versions (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
technophile-04 committed May 20, 2024
1 parent 44110ed commit 6b9b4d0
Show file tree
Hide file tree
Showing 5 changed files with 437 additions and 733 deletions.
29 changes: 17 additions & 12 deletions packages/nextjs/hooks/scaffold-eth/useDeployedContractInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,28 @@ export const useDeployedContractInfo = <TContractName extends ContractName>(cont

useEffect(() => {
const checkContractDeployment = async () => {
if (!isMounted() || !publicClient) return;
try {
if (!isMounted() || !publicClient) return;

if (!deployedContract) {
setStatus(ContractCodeStatus.NOT_FOUND);
return;
}
if (!deployedContract) {
setStatus(ContractCodeStatus.NOT_FOUND);
return;
}

const code = await publicClient.getBytecode({
address: deployedContract.address,
});
const code = await publicClient.getBytecode({
address: deployedContract.address,
});

// If contract code is `0x` => no contract deployed on that address
if (code === "0x") {
// If contract code is `0x` => no contract deployed on that address
if (code === "0x") {
setStatus(ContractCodeStatus.NOT_FOUND);
return;
}
setStatus(ContractCodeStatus.DEPLOYED);
} catch (e) {
console.error(e);
setStatus(ContractCodeStatus.NOT_FOUND);
return;
}
setStatus(ContractCodeStatus.DEPLOYED);
};

checkContractDeployment();
Expand Down
8 changes: 4 additions & 4 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
},
"dependencies": {
"@heroicons/react": "^2.0.11",
"@rainbow-me/rainbowkit": "^2.0.2",
"@rainbow-me/rainbowkit": "2.1.0",
"@tanstack/react-query": "^5.28.6",
"@uniswap/sdk-core": "^4.0.1",
"@uniswap/v2-sdk": "^3.0.1",
"blo": "^1.0.1",
"burner-connector": "^0.0.6",
"burner-connector": "^0.0.7",
"daisyui": "4.5.0",
"next": "^14.0.4",
"next-themes": "^0.2.1",
Expand All @@ -32,8 +32,8 @@
"react-hot-toast": "^2.4.0",
"use-debounce": "^8.0.4",
"usehooks-ts": "^2.13.0",
"viem": "^2.8.16",
"wagmi": "^2.5.12",
"viem": "2.10.9",
"wagmi": "2.9.2",
"zustand": "^4.1.2"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/utils/scaffold-eth/getMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const getMetadata = ({
const imageUrl = `${baseUrl}${imageRelativePath}`;

return {
metadataBase: new URL(baseUrl),
title: {
default: title,
template: titleTemplate,
Expand Down
42 changes: 23 additions & 19 deletions packages/nextjs/utils/scaffold-eth/getParsedError.ts
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";
};
Loading

0 comments on commit 6b9b4d0

Please sign in to comment.