Skip to content

Commit

Permalink
update all useBlockNumber hook uses to specify chainId
Browse files Browse the repository at this point in the history
so that we don't mix mainChain & secondaryChain block numbers in our
calculations
  • Loading branch information
datadanne committed Oct 31, 2023
1 parent 252e0c1 commit cc572b6
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion garage/src/components/ProposalStatusBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";
import { useBlockNumber } from "wagmi";
import { Badge } from "@chakra-ui/react";
import { Proposal, ProposalStatus } from "~/types";
import { secondaryChain } from "~/env";

export const proposalStatus = (
blockNumber: bigint | undefined,
Expand All @@ -17,7 +18,7 @@ export const proposalStatus = (
};

export const ProposalStatusBadge = ({ proposal }: { proposal: Proposal }) => {
const { data: blockNumber } = useBlockNumber();
const { data: blockNumber } = useBlockNumber({ chainId: secondaryChain.id });
const status = proposalStatus(blockNumber, proposal);

return (
Expand Down
2 changes: 1 addition & 1 deletion garage/src/pages/Dashboard/modules/RigsInventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const isSelectable = (rig: Rig, selectable: Selectable): boolean => {
export const RigsInventory = (props: React.ComponentProps<typeof Box>) => {
const { actingAsAddress } = useAccount();
const { rigs, refresh } = useOwnedRigs(actingAsAddress);
const { data: currentBlockNumber } = useBlockNumber();
const { data: currentBlockNumber } = useBlockNumber({ chainId: mainChain.id });
const pilots = useMemo(() => {
if (!rigs) return;

Expand Down
2 changes: 1 addition & 1 deletion garage/src/pages/PilotDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export const PilotDetails = () => {
return !!address && address.toLowerCase() === owner?.toLowerCase();
}, [address, owner]);

const { data: currentBlockNumber } = useBlockNumber();
const { data: currentBlockNumber } = useBlockNumber({ chainId: mainChain.id });

return (
<Flex
Expand Down
7 changes: 3 additions & 4 deletions garage/src/pages/Proposal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const CastVote = ({

const { votingPower } = useAddressVotingPower(address, proposal.id);

const { data: blockNumber } = useBlockNumber();
const { data: blockNumber } = useBlockNumber({ chainId: secondaryChain.id });
const [votes, setVotes] = useState<VoteState>({});

const isEligible = (votingPower ?? 0) > 0;
Expand Down Expand Up @@ -468,7 +468,7 @@ const Votes = ({
};

const Results = ({ proposal, results, refresh, ...props }: ModuleProps) => {
const { data: blockNumber } = useBlockNumber();
const { data: blockNumber } = useBlockNumber({ chainId: secondaryChain.id });

const totalResults = results.reduce((acc, { result }) => acc + result, 0);

Expand Down Expand Up @@ -572,8 +572,7 @@ const Header = ({ proposal, results, refresh, ...props }: ModuleProps) => {

export const Proposal = () => {
const { id } = useParams();

const { data: blockNumber } = useBlockNumber();
const { data: blockNumber } = useBlockNumber({ chainId: secondaryChain.id });
const {
data: { proposal, votes, results },
refresh,
Expand Down
15 changes: 7 additions & 8 deletions garage/src/pages/Proposals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
proposalStatus,
ProposalStatusBadge,
} from "~/components/ProposalStatusBadge";
import { secondaryChain } from "~/env";

const GRID_GAP = 4;

Expand All @@ -34,12 +35,12 @@ type ModuleProps = React.ComponentProps<typeof Box> & {
};

const Information = ({ proposal, ...props }: ModuleProps) => {
const { data: blockNumber } = useBlockNumber();
const { data: blockNumber } = useBlockNumber({ chainId: secondaryChain.id });

const status = useMemo(() => proposalStatus(blockNumber, proposal), [
blockNumber,
proposal,
]);
const status = useMemo(
() => proposalStatus(blockNumber, proposal),
[blockNumber, proposal]
);

const startsIn = proposal.startBlock - Number(blockNumber ?? 0);
const endsIn = proposal.endBlock - Number(blockNumber ?? 0);
Expand Down Expand Up @@ -110,9 +111,7 @@ export const Proposals = () => {
{...MODULE_PROPS}
/>
))}
{proposals?.length === 0 && (
<Box {...MODULE_PROPS}>Coming soon.</Box>
)}
{proposals?.length === 0 && <Box {...MODULE_PROPS}>Coming soon.</Box>}
</VStack>
</Flex>
);
Expand Down
4 changes: 3 additions & 1 deletion garage/src/pages/RigDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ const FilecoinDealsModal = ({
export const RigDetails = () => {
const { id } = useParams();
const { actingAsAddress } = useAccount();
const { data: currentBlockNumber } = useBlockNumber();
const { data: currentBlockNumber } = useBlockNumber({
chainId: mainChain.id,
});
const { rig, refresh: refreshRig } = useRig(id || "");

const { data: contractData, refetch } = useContractReads({
Expand Down
2 changes: 1 addition & 1 deletion garage/src/pages/RigDetails/modules/Pilots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const Pilots = ({
p,
...props
}: PilotProps) => {
const { data: blockNumber, refetch } = useBlockNumber();
const { data: blockNumber, refetch } = useBlockNumber({ chainId: mainChain.id });
useEffect(() => {
refetch();
}, [rig, refetch]);
Expand Down

0 comments on commit cc572b6

Please sign in to comment.