Skip to content

Commit

Permalink
fix: proposal history data
Browse files Browse the repository at this point in the history
  • Loading branch information
Argeare5 committed Dec 17, 2024
1 parent 00441c3 commit 929f141
Show file tree
Hide file tree
Showing 21 changed files with 143 additions and 133 deletions.
17 changes: 3 additions & 14 deletions src/components/ProposalsDetails/History/ProposalHistoryModal.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import React, { useEffect } from 'react';

import { useStore } from '../../../providers/ZustandStoreProvider';
import {
DetailedProposalData,
HistoryItemType,
ProposalHistoryItem as IProposalHistoryItem,
TxInfo,
} from '../../../types';
import { DetailedProposalData, HistoryItemType, TxInfo } from '../../../types';
import { DetailsModalWrapper } from './DetailsModalWrapper';
import { getHistoryId } from './helpers';
import { ProposalHistoryItem } from './ProposalHistoryItem';
Expand Down Expand Up @@ -90,7 +85,6 @@ const getHistoryLinkFunc = (

interface ProposalHistoryModalProps {
proposal: DetailedProposalData;
eventsData?: Record<string, IProposalHistoryItem>;
isOpen: boolean;
setIsOpen: (value: boolean) => void;
}
Expand Down Expand Up @@ -179,19 +173,14 @@ function ProposalHistoryModalInit({

export function ProposalHistoryModal({
proposal,
eventsData,
isOpen,
setIsOpen,
}: ProposalHistoryModalProps) {
const initProposalHistory = useStore((store) => store.initProposalHistory);

useEffect(() => {
initProposalHistory(proposal, eventsData);
}, [
isOpen,
proposal.proposalData.id,
Object.values(eventsData ?? {}).length,
]);
initProposalHistory(proposal);
}, [isOpen, proposal.proposalData.id]);

return (
<ProposalHistoryModalInit
Expand Down
1 change: 0 additions & 1 deletion src/components/ProposalsDetails/ProposalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ export function ProposalPage({
proposal={data}
isOpen={isProposalHistoryModalOpen}
setIsOpen={setIsProposalHistoryOpen}
eventsData={{}} // TODO
/>
)}

Expand Down
5 changes: 3 additions & 2 deletions src/components/Web3/creationFee/CreationFeesModalItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { TransactionUnion, TxType } from '../../../store/transactionsSlice';
import { CreationFee, CreationFeeState } from '../../../types';
import { BoxWith3D } from '../../BoxWith3D';
import { Link } from '../../Link';
import { ProposalState } from '../../ProposalState';
import { SmallButton } from '../../SmallButton';

interface CreationFeesModalItemProps {
Expand Down Expand Up @@ -95,7 +96,7 @@ export function CreationFeesModalItem({
mr: 0,
},
}}>
{/*<ProposalStatus status={proposalStatus} />*/}
<ProposalState state={proposalStatus} />
</Box>
</Box>

Expand All @@ -113,7 +114,7 @@ export function CreationFeesModalItem({
typography: 'descriptorAccent',
},
}}>
{/*<ProposalStatus status={proposalStatus} />*/}
<ProposalState state={proposalStatus} />
</Box>

<Box
Expand Down
3 changes: 2 additions & 1 deletion src/requests/fetchActiveProposalsDataForList.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ClientsRecord } from '@bgd-labs/frontend-web3-utils';
import { Client } from 'viem';
import { mainnet } from 'viem/chains';

Expand All @@ -24,7 +25,7 @@ export type FetchProposalsDataForListParams = Pick<
'precisionDivider' | 'expirationTime' | 'cooldownPeriod'
> & {
votingConfigs: VotingConfig[];
clients: Record<number, Client>;
clients: ClientsRecord;
activeIds: number[];
};

Expand Down
19 changes: 18 additions & 1 deletion src/requests/fetchCreationFeesByCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CreationFeeState,
FeesDataAPI,
InitialProposalState,
ProposalState,
} from '../types';

export type FetchCreationFeesParams = {
Expand Down Expand Up @@ -42,9 +43,25 @@ export async function fetchCreationFeesByCreator({
status = CreationFeeState.RETURNED;
}

let proposalStatus = ProposalState.Created;
if (data.state === InitialProposalState.Active) {
proposalStatus = ProposalState.Voting;
} else if (data.state === InitialProposalState.Queued) {
proposalStatus = ProposalState.Succeed;
} else if (data.state === InitialProposalState.Executed) {
proposalStatus = ProposalState.Executed;
} else if (
data.state === InitialProposalState.Failed ||
data.state === InitialProposalState.Expired
) {
proposalStatus = ProposalState.Failed;
} else if (data.state === InitialProposalState.Cancelled) {
proposalStatus = ProposalState.Canceled;
}

return {
proposalId: data.proposalId,
proposalStatus: data.state,
proposalStatus,
ipfsHash: data.ipfsHash,
title: data.title ?? `Proposal ${index}`,
status,
Expand Down
3 changes: 2 additions & 1 deletion src/requests/fetchDataForCreateOverview.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ClientsRecord } from '@bgd-labs/frontend-web3-utils';
import { Client } from 'viem';

import { PayloadParams } from '../components/pages/ProposalCreateOverviewPage';
Expand All @@ -11,7 +12,7 @@ import { getPayloadsDataRPC } from './utils/getPayloadsDataRPC';
export type FetchDataForCreateOverviewScreen = {
ipfsHash: string;
payloads: PayloadParams[];
clients: Record<number, Client>;
clients: ClientsRecord;
};

export async function fetchDataForCreateOverviewScreen({
Expand Down
3 changes: 2 additions & 1 deletion src/requests/fetchDataForCreateProposalScreen.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ClientsRecord } from '@bgd-labs/frontend-web3-utils';
import { Client } from 'viem';

import { getPayloadsCountsRPC } from './utils/getPayloadsCountsRPC';
import { getProposalsDataRPC } from './utils/getProposalsDataRPC';

export type FetchDataForCreateProposalScreen = {
proposalsCount: bigint;
clients: Record<number, Client>;
clients: ClientsRecord;
};

export async function fetchDataForCreateProposalScreen({
Expand Down
2 changes: 2 additions & 0 deletions src/requests/fetchFilteredDataForList.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ClientsRecord } from '@bgd-labs/frontend-web3-utils';
import { mainnet } from 'viem/chains';

import { appConfig } from '../configs/appConfig';
Expand All @@ -15,6 +16,7 @@ export type FetchFilteredDataForListParams = Pick<
'precisionDivider' | 'expirationTime' | 'cooldownPeriod'
> & {
votingConfigs: VotingConfig[];
clients: ClientsRecord;
activePage?: number;
title?: string | null;
state?: ProposalStateForFilters | null;
Expand Down
16 changes: 14 additions & 2 deletions src/requests/fetchProposalDataForDetails.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IVotingPortal_ABI } from '@bgd-labs/aave-address-book/abis';
import { ClientsRecord } from '@bgd-labs/frontend-web3-utils';
import { Client } from 'viem';
import { readContract } from 'viem/actions';

Expand Down Expand Up @@ -28,7 +29,7 @@ export type FetchProposalsDataForDetailsParams = Pick<
> & {
proposalId: number;
votingConfigs: VotingConfig[];
clients: Record<number, Client>;
clients: ClientsRecord;
};

export async function fetchProposalDataForDetails({
Expand Down Expand Up @@ -77,7 +78,10 @@ export async function fetchProposalDataForDetails({

const proposalData = getProposalFormattedData(formatData);
const payloadsData = getProposalPayloadsFormattedData(formatData);
const votingData = getProposalVotingFormattedData(formatData);
const votingData = await getProposalVotingFormattedData(
formatData,
input.clients,
);

const formattedData = formatDataForDetails({
differential: config.differential,
Expand Down Expand Up @@ -108,6 +112,14 @@ export async function fetchProposalDataForDetails({
},
formattedData,
ipfsError,
eventsHashes: {
createdTxHash: formatData.createdTxHash,
executedTxHash: formatData.executedTxHash,
cancelledTxHash: formatData.cancelledTxHash,
queuedTxHash: formatData.queuedTxHash,
failedTxHash: formatData.failedTxHash,
votingActivatedTxHash: formatData.votingActivatedTxHash,
},
};
} catch (e) {
console.error(
Expand Down
4 changes: 2 additions & 2 deletions src/requests/utils/chains.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client } from 'viem';
import { ClientsRecord } from '@bgd-labs/frontend-web3-utils';

import { env } from '../../env';
import { createViemClient } from '../../utils/createClient';
Expand All @@ -19,7 +19,7 @@ const initialRpcUrls = getInitialRpcUrls({
zkSyncRPC: env.RPC_ZKSYNC,
});
const serverChains = getChains({ initialRpcUrls });
export const serverClients: Record<number, Client> = {};
export const serverClients: ClientsRecord = {};
Object.values(serverChains).forEach((chain) => {
serverClients[chain.id] = createViemClient({
chain: chain,
Expand Down
61 changes: 49 additions & 12 deletions src/requests/utils/formatDataFromAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import {
IGovernanceCore_ABI,
IVotingPortal_ABI,
} from '@bgd-labs/aave-address-book/abis';
import { ClientsRecord } from '@bgd-labs/frontend-web3-utils';
import { zeroAddress, zeroHash } from 'viem';
import { readContract } from 'viem/actions';

import { appConfig } from '../../configs/appConfig';
import { ipfsGateway } from '../../configs/configs';
Expand All @@ -10,6 +16,7 @@ import {
InitialPayloadState,
InitialProposalState,
} from '../../types';
import { IBaseVotingStrategy_ABI } from '../abis/IBaseVotingStrategy';
import { FetchProposalsDataForListParams } from '../fetchProposalsDataForList';
import { getDataForList, getProposalsWithPayloads } from './getDataForList';

Expand Down Expand Up @@ -89,15 +96,46 @@ export function getProposalPayloadsFormattedData(
executedAt: payload.executedAt ?? 0,
cancelledAt: payload.cancelledAt ?? 0,
queuedAt: payload.queuedAt ?? 0,
actions: [],
actions: [], // TODO
},
};
});
}

export function getProposalVotingFormattedData(
export async function getProposalVotingFormattedData(
proposal: GetProposalInitialResponse,
clients: ClientsRecord,
) {
let votingChainId = proposal.votingChainId;
// TODO: should be always from API request
if (!votingChainId) {
votingChainId = Number(
await readContract(clients[appConfig.govCoreChainId], {
abi: IVotingPortal_ABI,
address: proposal.votingPortal,
functionName: 'VOTING_MACHINE_CHAIN_ID',
args: [],
}),
);
}

// TODO: should be always from API request
const votingStrategyAddress = await readContract(
clients[appConfig.govCoreChainId],
{
abi: IGovernanceCore_ABI,
address: appConfig.govCoreConfig.contractAddress,
functionName: 'getPowerStrategy',
args: [],
},
);
const assets = await readContract(clients[appConfig.govCoreChainId], {
abi: IBaseVotingStrategy_ABI,
address: votingStrategyAddress,
functionName: 'getVotingAssetList',
args: [],
});

return {
proposalData: {
id: BigInt(proposal.proposalId),
Expand All @@ -113,16 +151,12 @@ export function getProposalVotingFormattedData(
),
},
hasRequiredRoots: proposal.hasRequiredRoots ?? false,
votingChainId: proposal.votingChainId,
votingChainId,
state: proposal.votingProposalState ?? 0,
strategy: votingStrategyAddress,
votingAssets: assets,
// TODO:
strategy: zeroAddress,
dataWarehouse: zeroAddress,
votingAssets: [
appConfig.additional.aaveAddress,
appConfig.additional.aAaveAddress,
appConfig.additional.stkAAVEAddress,
],
//
votedInfo: {
support: false,
Expand All @@ -136,7 +170,7 @@ export function getProposalVotingFormattedData(
}

export async function formatListData(
input: Omit<FetchProposalsDataForListParams, 'clients'>,
input: FetchProposalsDataForListParams,
data: Omit<GetGovernanceProposalsResponse, 'totalProposalsCount'>,
) {
const proposalsData = await Promise.all(
Expand All @@ -151,8 +185,11 @@ export async function formatListData(
proposalsData,
payloadsData,
});
const voting = data.proposals.map((proposal) =>
getProposalVotingFormattedData(proposal),
const voting = await Promise.all(
data.proposals.map(
async (proposal) =>
await getProposalVotingFormattedData(proposal, input.clients),
),
);

return getDataForList({
Expand Down
4 changes: 2 additions & 2 deletions src/requests/utils/getPayloadsCountsRPC.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPayloadsControllerCore_ABI } from '@bgd-labs/aave-address-book/abis';
import { Client } from 'viem';
import { ClientsRecord } from '@bgd-labs/frontend-web3-utils';
import { readContract } from 'viem/actions';

import { appConfig } from '../../configs/appConfig';
Expand All @@ -11,7 +11,7 @@ export async function getPayloadsCountsRPC({
proposalsCount,
proposalsData,
}: {
clients: Record<number, Client>;
clients: ClientsRecord;
proposalsCount: bigint;
proposalsData: ProposalInitialStruct[];
}) {
Expand Down
4 changes: 2 additions & 2 deletions src/requests/utils/getPayloadsDataRPC.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IPayloadsControllerDataHelper_ABI } from '@bgd-labs/aave-address-book/abis';
import { Client } from 'viem';
import { ClientsRecord } from '@bgd-labs/frontend-web3-utils';
import { readContract } from 'viem/actions';

import { appConfig } from '../../configs/appConfig';
Expand All @@ -9,7 +9,7 @@ export async function getPayloadsDataRPC({
chainId,
payloadsIds,
clients,
}: GetPayloadsData & { clients: Record<number, Client> }) {
}: GetPayloadsData & { clients: ClientsRecord }) {
const payloadsConfig = appConfig.payloadsControllerConfig[chainId];
const payloadsData = await readContract(clients[chainId], {
abi: IPayloadsControllerDataHelper_ABI,
Expand Down
4 changes: 2 additions & 2 deletions src/requests/utils/getProposalsDataRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
IGovernanceCore_ABI,
IGovernanceDataHelper_ABI,
} from '@bgd-labs/aave-address-book/abis';
import { Client } from 'viem';
import { ClientsRecord } from '@bgd-labs/frontend-web3-utils';
import { readContract } from 'viem/actions';

import { appConfig } from '../../configs/appConfig';
Expand All @@ -13,7 +13,7 @@ export async function getProposalsDataRPC({
proposalsCount,
proposalsIds,
clients,
}: GetProposalsData & { clients: Record<number, Client> }) {
}: GetProposalsData & { clients: ClientsRecord }) {
const ids = proposalsCount
? [...Array(Number(proposalsCount)).keys()]
: (proposalsIds ?? []);
Expand Down
Loading

1 comment on commit 929f141

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit was deployed on ipfs

Please sign in to comment.