Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using batch provider now #10

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions frontend/components/Admin/AdminPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ export default function AdminPanel() {
Promise.all([
fetchEvents(setEvents, networkId),
fetchGrants(setGrant, networkId),
]).finally(() => {
setLoadingData(false);
});
])
.catch((error) => console.error(error))
.finally(() => {
setLoadingData(false);
});
}, [networkId]);

return loadingData ? (
Expand Down
4 changes: 2 additions & 2 deletions frontend/lib/store/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ export const fetchEvents = async (setEvents, networkId) => {
throw Error("Invalid network id:" + networkId);
}
// Always use infura for fetching events, provider from wallet can be really slow
const provider = new ethers.providers.JsonRpcProvider(
const provider = new ethers.providers.JsonRpcBatchProvider(
`https://${infuraName}.infura.io/v3/8abb2592d8d344daafc5362ddd33efd1`
);

const vesterContract = new ethers.Contract(
process.env.NEXT_PUBLIC_VESTER_CONTRACT_ADDRESS,
vesterAbi.abi,
provider
); // should be provider.getSigner() ?
);

let newEvents = {};
// TODO: Make below more abstract, just gather all events
Expand Down
8 changes: 4 additions & 4 deletions frontend/lib/store/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const grantsState = atom({
export const getGrants = selectorFamily({
key: "getGrants",
get:
(address) =>
(_) =>
({ get }) => {
return Object.values(get(grantsState));
},
Expand Down Expand Up @@ -77,7 +77,7 @@ export const fetchGrant = async (setGrant, tokenId, networkId) => {
throw Error("Invalid network id:" + networkId);
}
// Always use infura for fetching events, provider from wallet can be really slow
const provider = new ethers.providers.JsonRpcProvider({
const provider = new ethers.providers.JsonRpcBatchProvider({
url: `https://${infuraName}.infura.io/v3/8abb2592d8d344daafc5362ddd33efd1`,
skipFetchSetup: true,
});
Expand Down Expand Up @@ -162,7 +162,7 @@ export const fetchGrants = async (setGrant, networkId) => {
throw Error("Invalid network id:" + networkId);
}
// Always use infura for fetching events, provider from wallet can be really slow
const provider = new ethers.providers.JsonRpcProvider(
const provider = new ethers.providers.JsonRpcBatchProvider(
`https://${infuraName}.infura.io/v3/8c6bfe963db94518b16b17114e29e628`
);
const vesterContract = new ethers.Contract(
Expand Down Expand Up @@ -190,7 +190,7 @@ export const fetchGrantsByUser = async (setGrant, owner, networkId) => {
throw Error("Invalid network id:" + networkId);
}
// Always use infura for fetching events, provider from wallet can be really slow
const provider = new ethers.providers.JsonRpcProvider({
const provider = new ethers.providers.JsonRpcBatchProvider({
url: `https://${infuraName}.infura.io/v3/8abb2592d8d344daafc5362ddd33efd1`,
skipFetchSetup: true,
});
Expand Down
15 changes: 8 additions & 7 deletions frontend/pages/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,27 @@ import { useAccount } from "wagmi";
import vesterAbi from "../abis/Vester.json";
import { useState, useEffect } from "react";
import { ethers } from "ethers";
import { useEthersSigner } from "../utils/ethers";

export default function Admin() {
const { address } = useAccount();

const [_, setOwner] = useState(null);
const { address, chain } = useAccount();
const signer = useEthersSigner({ chainId: chain?.id || "10" });
const [owner, setOwner] = useState(null);
useEffect(() => {
async function getOwner() {
const provider = new ethers.providers.Web3Provider(window?.ethereum);
if (!signer) return;
const vesterContract = new ethers.Contract(
process.env.NEXT_PUBLIC_VESTER_CONTRACT_ADDRESS,
vesterAbi.abi,
provider
signer
); // should be provider.getSigner() ?
const owner = await vesterContract.owner();
setOwner(owner);
}
getOwner();
}, []);
}, [signer]);

const shouldRender = address; // && address == owner;
const shouldRender = address;

return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/utils/ethers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export function clientToSigner(client) {

/** Hook to convert a Viem Client to an ethers.js Signer. */
export function useEthersSigner({ chainId } = {}) {
const { data: client } = useConnectorClient < Config > { chainId };
const { data: client } = useConnectorClient({ chainId });
return useMemo(() => (client ? clientToSigner(client) : undefined), [client]);
}
Loading