Skip to content

Commit

Permalink
fix missing chain ids
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetson committed Dec 4, 2023
1 parent feb913c commit 23c2f02
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 21 deletions.
5 changes: 4 additions & 1 deletion packages/nextjs/hooks/scaffold-eth/useScaffoldContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export const useScaffoldContract = <
contractName: TContractName;
walletClient?: TWalletClient | null;
}) => {
const { data: deployedContractData, isLoading: deployedContractLoading } = useDeployedContractInfo(contractName);
const { data: deployedContractData, isLoading: deployedContractLoading } = useDeployedContractInfo(
contractName,
walletClient?.chain.id as number,
);
const publicClient = usePublicClient();

let contract = undefined;
Expand Down
5 changes: 2 additions & 3 deletions packages/nextjs/hooks/scaffold-eth/useScaffoldContractRead.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ExtractAbiFunctionNames } from "abitype";
import { useContractRead } from "wagmi";
import { useDeployedContractInfo } from "~~/hooks/scaffold-eth";
import { getTargetNetworks } from "~~/utils/scaffold-eth";
import {
AbiFunctionReturnType,
ContractAbi,
Expand All @@ -26,10 +25,10 @@ export const useScaffoldContractRead = <
args,
...readConfig
}: UseScaffoldReadConfig<TContractName, TFunctionName>) => {
const { data: deployedContract } = useDeployedContractInfo(contractName);
const { data: deployedContract } = useDeployedContractInfo(contractName, readConfig.chainId as number);

return useContractRead({
chainId: getTargetNetworks()[0].id,
chainId: readConfig.chainId as number,
functionName,
address: deployedContract?.address,
abi: deployedContract?.abi,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Abi, ExtractAbiFunctionNames } from "abitype";
import { useContractWrite, useNetwork } from "wagmi";
import { getParsedError } from "~~/components/scaffold-eth";
import { useDeployedContractInfo, useTransactor } from "~~/hooks/scaffold-eth";
import { getTargetNetworks, notification } from "~~/utils/scaffold-eth";
import { getTargetById, notification } from "~~/utils/scaffold-eth";
import { ContractAbi, ContractName, UseScaffoldWriteConfig } from "~~/utils/scaffold-eth/contract";

type UpdatedArgs = Parameters<ReturnType<typeof useContractWrite<Abi, string, undefined>>["writeAsync"]>[0];
Expand All @@ -29,11 +29,11 @@ export const useScaffoldContractWrite = <
blockConfirmations,
...writeConfig
}: UseScaffoldWriteConfig<TContractName, TFunctionName>) => {
const { data: deployedContractData } = useDeployedContractInfo(contractName);
const { data: deployedContractData } = useDeployedContractInfo(contractName, writeConfig.chainId as number);
const { chain } = useNetwork();
const writeTx = useTransactor();
const [isMining, setIsMining] = useState(false);
const configuredNetwork = getTargetNetworks()[0];
const configuredNetwork = getTargetById(writeConfig.chainId as number);

const wagmiContractWrite = useContractWrite({
address: deployedContractData?.address,
Expand Down
11 changes: 8 additions & 3 deletions packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as chains from "viem/chains";
import { usePublicClient } from "wagmi";
import { useDeployedContractInfo } from "~~/hooks/scaffold-eth";
import scaffoldConfig from "~~/scaffold.config";
import { getTargetNetworks } from "~~/utils/scaffold-eth";
import { getTargetById } from "~~/utils/scaffold-eth";
import { replacer } from "~~/utils/scaffold-eth/common";
import {
ContractAbi,
Expand All @@ -27,6 +27,7 @@ import {
* @param config.receiptData - if set to true it will return the receipt data for each event (default: false)
* @param config.watch - if set to true, the events will be updated every pollingInterval milliseconds set at scaffoldConfig (default: false)
* @param config.enabled - set this to false to disable the hook from running (default: true)
* @param config.chainId - a chain where contract is deployed
*/
export const useScaffoldEventHistory = <
TContractName extends ContractName,
Expand All @@ -44,15 +45,19 @@ export const useScaffoldEventHistory = <
receiptData,
watch,
enabled = true,
chainId,
}: UseScaffoldEventHistoryConfig<TContractName, TEventName, TBlockData, TTransactionData, TReceiptData>) => {
const [events, setEvents] = useState<any[]>();
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string>();
const [fromBlockUpdated, setFromBlockUpdated] = useState<bigint>(fromBlock);

const { data: deployedContractData, isLoading: deployedContractLoading } = useDeployedContractInfo(contractName);
const { data: deployedContractData, isLoading: deployedContractLoading } = useDeployedContractInfo(
contractName,
chainId,
);
const publicClient = usePublicClient();
const configuredNetwork = getTargetNetworks()[0];
const configuredNetwork = getTargetById(chainId);

const readEvents = async (fromBlock?: bigint) => {
setIsLoading(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Abi, ExtractAbiEventNames } from "abitype";
import { Log } from "viem";
import { useContractEvent } from "wagmi";
import { addIndexedArgsToEvent, useDeployedContractInfo } from "~~/hooks/scaffold-eth";
import { getTargetNetworks } from "~~/utils/scaffold-eth";
import { ContractAbi, ContractName, UseScaffoldEventConfig } from "~~/utils/scaffold-eth/contract";

/**
Expand All @@ -20,8 +19,9 @@ export const useScaffoldEventSubscriber = <
contractName,
eventName,
listener,
chainId,
}: UseScaffoldEventConfig<TContractName, TEventName>) => {
const { data: deployedContractData } = useDeployedContractInfo(contractName);
const { data: deployedContractData } = useDeployedContractInfo(contractName, chainId as number);

const addInexedArgsToLogs = (logs: Log[]) => logs.map(addIndexedArgsToEvent);
const listenerWithIndexedArgs = (logs: Log[]) =>
Expand All @@ -30,7 +30,7 @@ export const useScaffoldEventSubscriber = <
return useContractEvent({
address: deployedContractData?.address,
abi: deployedContractData?.abi as Abi,
chainId: getTargetNetworks()[0].id,
chainId: chainId,
listener: listenerWithIndexedArgs,
eventName,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/pages/approve.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ContractName } from "~~/utils/scaffold-eth/contract";
import { getContractNames } from "~~/utils/scaffold-eth/contractNames";

const selectedContractStorageKey = "scaffoldEth2.selectedContract";
const contractNames = getContractNames();
const contractNames = getContractNames(11155111);

const Approve: NextPage = () => {
const [selectedContract, setSelectedContract] = useLocalStorage<ContractName>(
Expand All @@ -15,7 +15,7 @@ const Approve: NextPage = () => {
);

useEffect(() => {
if (!contractNames.includes(selectedContract)) {
if (!contractNames.includes(selectedContract as string)) {
setSelectedContract(contractNames[0]);
}
}, [selectedContract, setSelectedContract]);
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/pages/bridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ContractName } from "~~/utils/scaffold-eth/contract";
import { getContractNames } from "~~/utils/scaffold-eth/contractNames";

const selectedContractStorageKey = "scaffoldEth2.selectedContract";
const contractNames = getContractNames();
const contractNames = getContractNames(11155111);

const Bridge: NextPage = () => {
const [selectedContract, setSelectedContract] = useLocalStorage<ContractName>(
Expand All @@ -16,7 +16,7 @@ const Bridge: NextPage = () => {
);

useEffect(() => {
if (!contractNames.includes(selectedContract)) {
if (!contractNames.includes(selectedContract as string)) {
setSelectedContract(contractNames[0]);
}
}, [selectedContract, setSelectedContract]);
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/pages/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ContractName } from "~~/utils/scaffold-eth/contract";
import { getContractNames } from "~~/utils/scaffold-eth/contractNames";

const selectedContractStorageKey = "scaffoldEth2.selectedContract";
const contractNames = getContractNames();
const contractNames = getContractNames(11155111);

const Register: NextPage = () => {
const [selectedContract, setSelectedContract] = useLocalStorage<ContractName>(
Expand All @@ -15,7 +15,7 @@ const Register: NextPage = () => {
);

useEffect(() => {
if (!contractNames.includes(selectedContract)) {
if (!contractNames.includes(selectedContract as string)) {
setSelectedContract(contractNames[0]);
}
}, [selectedContract, setSelectedContract]);
Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/pages/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ContractName } from "~~/utils/scaffold-eth/contract";
import { getContractNames } from "~~/utils/scaffold-eth/contractNames";

const selectedContractStorageKey = "scaffoldEth2.selectedContract";
const contractNames = getContractNames();
const contractNames = getContractNames(11155111);

const Setup: NextPage = () => {
const [selectedContract, setSelectedContract] = useLocalStorage<ContractName>(
Expand All @@ -16,7 +16,7 @@ const Setup: NextPage = () => {
);

useEffect(() => {
if (!contractNames.includes(selectedContract)) {
if (!contractNames.includes(selectedContract as string)) {
setSelectedContract(contractNames[0]);
}
}, [selectedContract, setSelectedContract]);
Expand Down
1 change: 1 addition & 0 deletions packages/nextjs/utils/scaffold-eth/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export type UseScaffoldEventHistoryConfig<
receiptData?: TReceiptData;
watch?: boolean;
enabled?: boolean;
chainId: number;
};

export type UseScaffoldEventHistoryData<
Expand Down

0 comments on commit 23c2f02

Please sign in to comment.