fix iteration over governance proposal
Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
parent
eef0031a4a
commit
76432be4b1
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ghost-dao-interface",
|
||||
"private": true,
|
||||
"version": "0.5.43",
|
||||
"version": "0.5.44",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { useMemo } from "react";
|
||||
import { useReadContract, useReadContracts } from "wagmi";
|
||||
import { simulateContract, writeContract, waitForTransactionReceipt } from "@wagmi/core";
|
||||
import toast from "react-hot-toast";
|
||||
@ -342,20 +343,20 @@ export const useProposals = (chainId, depth, searchedIndexes) => {
|
||||
});
|
||||
|
||||
const { data: proposalDetails } = useReadContracts({
|
||||
contracts: searchedIndexes?.map(index => {
|
||||
contracts: searchedIndexes?.map(proposalId => {
|
||||
return {
|
||||
abi: GovernorStorageAbi,
|
||||
address: GHOST_GOVERNANCE_ADDRESSES[chainId],
|
||||
functionName: "proposalDetails",
|
||||
args: [index],
|
||||
scopeKey: `proposalDetails-${chainId}-${index}`,
|
||||
args: [proposalId],
|
||||
scopeKey: `proposalDetails-${chainId}-${proposalId}`,
|
||||
chainId: chainId,
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const { data: proposalDeadlines } = useReadContracts({
|
||||
contracts: indexes?.map(index => {
|
||||
contracts: indexes?.map((_, index) => {
|
||||
const proposalId = searchedIndexes
|
||||
? searchedIndexes?.at(index)
|
||||
: proposalsDetailsAt?.at(index)?.result?.at(0);
|
||||
@ -372,7 +373,7 @@ export const useProposals = (chainId, depth, searchedIndexes) => {
|
||||
});
|
||||
|
||||
const { data: proposalVotes } = useReadContracts({
|
||||
contracts: indexes?.map(index => {
|
||||
contracts: indexes?.map((_, index) => {
|
||||
const proposalId = searchedIndexes
|
||||
? searchedIndexes?.at(index)
|
||||
: proposalsDetailsAt?.at(index)?.result?.at(0);
|
||||
@ -389,7 +390,7 @@ export const useProposals = (chainId, depth, searchedIndexes) => {
|
||||
});
|
||||
|
||||
const { data: proposalStates } = useReadContracts({
|
||||
contracts: indexes?.map(index => {
|
||||
contracts: indexes?.map((_, index) => {
|
||||
const proposalId = searchedIndexes
|
||||
? searchedIndexes?.at(index)
|
||||
: proposalsDetailsAt?.at(index)?.result?.at(0);
|
||||
@ -406,7 +407,7 @@ export const useProposals = (chainId, depth, searchedIndexes) => {
|
||||
});
|
||||
|
||||
const { data: proposalSnapshots } = useReadContracts({
|
||||
contracts: indexes?.map(index => {
|
||||
contracts: indexes?.map((_, index) => {
|
||||
const proposalId = searchedIndexes
|
||||
? searchedIndexes?.at(index)
|
||||
: proposalsDetailsAt?.at(index)?.result?.at(0);
|
||||
@ -451,7 +452,7 @@ export const useProposals = (chainId, depth, searchedIndexes) => {
|
||||
});
|
||||
|
||||
const { data: proposalProposer } = useReadContracts({
|
||||
contracts: indexes?.map(index => {
|
||||
contracts: indexes?.map((_, index) => {
|
||||
const proposalId = searchedIndexes
|
||||
? searchedIndexes?.at(index)
|
||||
: proposalsDetailsAt?.at(index)?.result?.at(0);
|
||||
@ -467,43 +468,61 @@ export const useProposals = (chainId, depth, searchedIndexes) => {
|
||||
})
|
||||
});
|
||||
|
||||
const hashes = indexes?.map(index => {
|
||||
let result = { short: index + 1, full: undefined };
|
||||
const proposalId = searchedIndexes
|
||||
? searchedIndexes?.at(index)
|
||||
: proposalsDetailsAt?.at(index)?.result?.at(0);
|
||||
const hashes = useMemo(() => {
|
||||
return indexes?.map((_, index) => {
|
||||
let result = { short: index + 1, full: undefined };
|
||||
const proposalId = searchedIndexes
|
||||
? searchedIndexes?.at(index)
|
||||
: proposalsDetailsAt?.at(index)?.result?.at(0);
|
||||
|
||||
if (proposalId) {
|
||||
const hash = "0x" + proposalId.toString(16);
|
||||
result.short = hash.slice(-5);
|
||||
result.full = hash;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
if (proposalId) {
|
||||
const hash = "0x" + proposalId.toString(16);
|
||||
result.short = hash.slice(-5);
|
||||
result.full = hash;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}, [indexes, searchedIndexes, proposalsDetailsAt]);
|
||||
|
||||
const voteValues = indexes?.map(idx => {
|
||||
const index = indexes.length - idx - 1;
|
||||
const againstVotes = proposalVotes?.at(index)?.result?.at(0) ?? 0n
|
||||
const forVotes = proposalVotes?.at(index)?.result?.at(1) ?? 0n;
|
||||
const voteValues = useMemo(() => {
|
||||
return indexes?.map((_, idx) => {
|
||||
const index = indexes.length - idx - 1;
|
||||
const againstVotes = proposalVotes?.at(index)?.result?.at(0) ?? 0n
|
||||
const forVotes = proposalVotes?.at(index)?.result?.at(1) ?? 0n;
|
||||
|
||||
const totalVotes = againstVotes + forVotes;
|
||||
return getVoteValue(forVotes, totalVotes);
|
||||
});
|
||||
const totalVotes = againstVotes + forVotes;
|
||||
return getVoteValue(forVotes, totalVotes);
|
||||
}) ?? [];
|
||||
}, [indexes, proposalVotes]);
|
||||
|
||||
const voteTargets = indexes?.map(idx => {
|
||||
const index = indexes.length - idx - 1;
|
||||
const againstVotes = proposalVotes?.at(index)?.result?.at(0) ?? 0n
|
||||
const forVotes = proposalVotes?.at(index)?.result?.at(1) ?? 0n;
|
||||
const totalSupply = pastTotalSupplies?.at(index)?.result ?? 0n;
|
||||
const voteTargets = useMemo(() => {
|
||||
return indexes?.map((_, idx) => {
|
||||
const index = indexes.length - idx - 1;
|
||||
const againstVotes = proposalVotes?.at(index)?.result?.at(0) ?? 0n
|
||||
const forVotes = proposalVotes?.at(index)?.result?.at(1) ?? 0n;
|
||||
const totalSupply = pastTotalSupplies?.at(index)?.result ?? 0n;
|
||||
|
||||
const totalVotes = againstVotes + forVotes;
|
||||
return getVoteTarget(totalVotes, totalSupply);
|
||||
});
|
||||
const totalVotes = againstVotes + forVotes;
|
||||
return getVoteTarget(totalVotes, totalSupply);
|
||||
}) ?? [];
|
||||
}, [indexes, proposalVotes, pastTotalSupplies]);
|
||||
|
||||
const proposals = indexes?.map(index => ({
|
||||
hashes: hashes?.at(index),
|
||||
const proposalDetailsPrepared = useMemo(() => {
|
||||
if (!searchedIndexes) return proposalsDetailsAt;
|
||||
return proposalDetails?.map((obj, index) => {
|
||||
if (!obj?.result) return obj;
|
||||
const proposalId = searchedIndexes.at(index);
|
||||
return {
|
||||
...obj,
|
||||
result: [proposalId, ...obj.result],
|
||||
};
|
||||
}) ?? [];
|
||||
}, [searchedIndexes, proposalsDetailsAt, proposalDetails]);
|
||||
|
||||
const proposals = indexes?.map((_, index) => ({
|
||||
hashes: hashes?.at(index) ?? { short: "", full: "" },
|
||||
proposer: proposalProposer?.at(index)?.result,
|
||||
details: proposalsDetailsAt?.at(index)?.result,
|
||||
details: proposalDetailsPrepared?.at(index)?.result,
|
||||
deadline: proposalDeadlines?.at(index)?.result ?? 0n,
|
||||
snapshot: proposalSnapshots?.at(index)?.result ?? 0n,
|
||||
state: proposalStates?.at(index)?.result ?? 0,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user