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