Skip to content

Commit

Permalink
fix full page reload when network name + select methods
Browse files Browse the repository at this point in the history
  • Loading branch information
technophile-04 committed Feb 19, 2024
1 parent dbc67fe commit a82f670
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useReducer, useState } from "react";
import router from "next/router";
import { useRouter } from "next/router";
import { ContractReadMethods } from "./ContractReadMethods";
import { ContractVariables } from "./ContractVariables";
import { ContractWriteMethods } from "./ContractWriteMethods";
Expand Down Expand Up @@ -28,6 +28,8 @@ export const ContractUI = ({ className = "", initialContractData }: ContractUIPr
const mainChainId = useAbiNinjaState(state => state.mainChainId);
const mainNetwork = mainNetworks.find(network => network.id === mainChainId);
const networkColor = useNetworkColor(mainNetwork);
const router = useRouter();
const { network } = router.query as { network?: string };

const updateUrlWithSelectedMethods = (selectedMethods: string[]) => {
const currentQuery = new URLSearchParams(window.location.search);
Expand All @@ -36,7 +38,7 @@ export const ContractUI = ({ className = "", initialContractData }: ContractUIPr
} else {
currentQuery.delete("methods");
}
const newPath = `/${initialContractData.address}/${mainChainId}`;
const newPath = `/${initialContractData.address}/${network}`;

router.push({ pathname: newPath, query: currentQuery.toString() }, undefined, { shallow: true });
};
Expand Down Expand Up @@ -83,7 +85,7 @@ export const ContractUI = ({ className = "", initialContractData }: ContractUIPr
method => method.type === "function" && "name" in method && selectedMethodNames.includes(method.name),
) as AbiFunction[]; // Cast it to AbiFunction[]
setAbi(selectedMethods);
}, [initialContractData.abi]);
}, [initialContractData.abi, router?.query?.methods]);

const { data: contractNameData, isLoading: isContractNameLoading } = useContractRead({
address: initialContractData.address,
Expand Down

0 comments on commit a82f670

Please sign in to comment.