Skip to content

Commit

Permalink
fix: fix polling time and small bugs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Argeare5 committed Jan 11, 2025
1 parent 19d3488 commit 219eee7
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useSWR from 'swr';
import { BasicModal } from '../../../../../components/BasicModal';
import { PayloadDetailsContent } from '../../../../../components/PayloadsExplorer/PayloadDetailsContent';
import { PayloadExploreItemLoading } from '../../../../../components/PayloadsExplorer/PayloadExploreItemLoading';
import { DATA_POLLING_TIME } from '../../../../../configs/configs';
import { useStore } from '../../../../../providers/ZustandStoreProvider';
import { payloadByIdFetcher } from '../../../../../requests/fetchers/payloadByIdFetcher';
import { selectAppClients } from '../../../../../store/selectors/rpcSwitcherSelectors';
Expand All @@ -32,7 +33,7 @@ export default function Page({
},
payloadByIdFetcher,
{
refreshInterval: 30_000,
refreshInterval: DATA_POLLING_TIME,
},
);

Expand Down
26 changes: 26 additions & 0 deletions src/app/payloads-explorer/[payloadController]/loading.appPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use client';

import { useEffect } from 'react';

import { PayloadsExplorerPageLoading } from '../../../components/PayloadsExplorer/PayloadsExplorerPageLoading';
import { appConfig } from '../../../configs/appConfig';

export default function LoadingPage() {
useEffect(() => {
window.scroll(0, 0);
}, []);
const chainWithController = `${appConfig.govCoreChainId}_${appConfig.payloadsControllerConfig[appConfig.govCoreChainId].contractAddresses[0]}`;
return (
<PayloadsExplorerPageLoading
activePage={0}
chainWithController={
typeof window !== 'undefined'
? window.location.pathname.split('/')[
window.location.pathname.split('/').length - 1
]
: chainWithController
}
count={0}
/>
);
}
5 changes: 4 additions & 1 deletion src/components/PayloadsExplorer/PayloadDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useRouter } from 'nextjs-toploader/app';
import React from 'react';
import useSWR from 'swr';

import { DATA_POLLING_TIME } from '../../configs/configs';
import { ROUTES } from '../../configs/routes';
import { useStore } from '../../providers/ZustandStoreProvider';
import { payloadByIdFetcher } from '../../requests/fetchers/payloadByIdFetcher';
Expand Down Expand Up @@ -32,7 +33,9 @@ export function PayloadDetails({ payload }: { payload: PayloadWithHashes }) {
payloadByIdFetcher,
{
refreshInterval:
payload.data.state >= InitialPayloadState.Executed ? 0 : 10_000,
payload.data.state >= InitialPayloadState.Executed
? 0
: DATA_POLLING_TIME,
},
);

Expand Down
3 changes: 2 additions & 1 deletion src/components/PayloadsExplorer/PayloadsExplorerPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useSWR from 'swr';
import ColumnsIcon from '../../assets/icons/columnsIcon.svg';
import RowIcon from '../../assets/icons/rowIcon.svg';
import { appConfig, appUsedNetworks } from '../../configs/appConfig';
import { DATA_POLLING_TIME } from '../../configs/configs';
import {
getLocalStoragePayloadsExplorerView,
setLocalStoragePayloadsExplorerView,
Expand Down Expand Up @@ -113,7 +114,7 @@ export function PayloadsExplorerPage({
},
filteredPayloadsDataFetcher,
{
refreshInterval: 30_000,
refreshInterval: DATA_POLLING_TIME,
},
);

Expand Down
3 changes: 2 additions & 1 deletion src/components/ProposalsDetails/ProposalPayloads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Hex, zeroHash } from 'viem';
import ArrowToBottom from '../../assets/icons/arrowToBottom.svg';
import ArrowToTop from '../../assets/icons/arrowToTop.svg';
import LinkIcon from '../../assets/icons/linkIcon.svg';
import { isForIPFS } from '../../configs/appConfig';
import {
formatPayloadData,
generateSeatbeltLink,
Expand Down Expand Up @@ -282,7 +283,7 @@ function PayloadItem({
</Box>
<CopyAndExternalIconsSet
iconSize={12}
externalLink={`${window.location.origin}/payloads-explorer/payload/${Number(payload.id)}_${Number(payload.chain)}_${payload.payloadsController}`}
externalLink={`${isForIPFS ? 'https://vote.onaave.com' : window.location.origin}/payloads-explorer/payload/${Number(payload.id)}_${Number(payload.chain)}_${payload.payloadsController}`}
sx={{ '.CopyAndExternalIconsSet__link': { ml: 4 } }}
/>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProposalsList/ProposalsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function ProposalsList({
]);
useEffect(() => {
startActiveProposalsDataPolling(activePage);
startNewProposalsPolling();
startNewProposalsPolling(activePage);
return () => {
stopActiveProposalsDataPolling();
stopNewProposalsPolling();
Expand Down
3 changes: 3 additions & 0 deletions src/configs/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ export const DECIMALS = 18;

// for API Requests
export const INITIAL_API_URL = `https://api.onaave.com/gov`;

// for data polling time
export const DATA_POLLING_TIME = 60_000;
6 changes: 3 additions & 3 deletions src/helpers/getProposalMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ export async function getProposalMetadata(
const ipfsResponse = await fetch(ipfsPath);
if (!ipfsResponse.ok) throw Error(`IPFS: error fetching ${ipfsPath}`);
const clone = ipfsResponse.clone();

try {
const response = await ipfsResponse.json();
const { content, data } = matter(response.description);
return {
...response,
ipfsHash,
description: String(JSON.parse(JSON.stringify(content))),
description: content,
...data,
};
} catch (e) {
console.error(e);
const { content, data } = matter(await clone.text());
return {
...ipfsResponse,
ipfsHash,
description: String(JSON.parse(JSON.stringify(content))),
description: content,
...(data as { title: string; discussions: string; author: string }),
};
}
Expand Down
91 changes: 41 additions & 50 deletions src/requests/fetchDataForCreateOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,60 +21,51 @@ export async function fetchDataForCreateOverviewScreen({
}) {
const { clients, ipfsHash, payloads } = input;

let ipfsData: ProposalMetadata | undefined = undefined;
let ipfsError = '';
try {
// TODO: get data from API
throw new Error('TODO: API not implemented');
ipfsData = await getProposalMetadata(ipfsHash, ipfsGateway);
} catch (e) {
console.error(
'Error getting data for create overview screen from API, using RPC fallback',
e,
);
let ipfsData: ProposalMetadata | undefined = undefined;
let ipfsError = '';
try {
ipfsData = await getProposalMetadata(ipfsHash, ipfsGateway);
} catch (e) {
ipfsError = texts.other.fetchFromIpfsError;
console.error('Error getting ipfs data', e);
}
ipfsError = texts.other.fetchFromIpfsError;
console.error('Error getting ipfs data', e);
}

const payloadsChainsWithIds: Record<number, number[]> = {};
const payloadsChains = payloads
.map((payload) => payload.chainId)
const payloadsChainsWithIds: Record<number, number[]> = {};
const payloadsChains = payloads
.map((payload) => payload.chainId)
.filter((value, index, self) => self.indexOf(value) === index);
payloadsChains.forEach((chainId) => {
payloadsChainsWithIds[Number(chainId)] = payloads
.filter((payload) => Number(payload.chainId) === Number(chainId))
.map((payload) => payload.payloadId)
.filter((value, index, self) => self.indexOf(value) === index);
payloadsChains.forEach((chainId) => {
payloadsChainsWithIds[Number(chainId)] = payloads
.filter((payload) => Number(payload.chainId) === Number(chainId))
.map((payload) => payload.payloadId)
.filter((value, index, self) => self.indexOf(value) === index);
});
const payloadsData = (
await Promise.all(
Object.entries(payloadsChainsWithIds).map(
async ([chainId, payloadsIds]) =>
await getPayloadsDataRPC({
chainId: Number(chainId),
payloadsIds,
clients,
}),
),
)
).flat();
});
const payloadsData = (
await Promise.all(
Object.entries(payloadsChainsWithIds).map(
async ([chainId, payloadsIds]) =>
await getPayloadsDataRPC({
chainId: Number(chainId),
payloadsIds,
clients,
}),
),
)
).flat();

const formattedPayloads: PayloadWithHashes[] = await Promise.all(
payloadsData.map(async (payload) => {
const seatbeltMD = await fetch(generateSeatbeltLink(payload));
return {
...payload,
seatbeltMD: seatbeltMD.ok ? await seatbeltMD.text() : undefined,
};
}),
);
const formattedPayloads: PayloadWithHashes[] = await Promise.all(
payloadsData.map(async (payload) => {
const seatbeltMD = await fetch(generateSeatbeltLink(payload));
return {
...payload,
seatbeltMD: seatbeltMD.ok ? await seatbeltMD.text() : undefined,
};
}),
);

return {
ipfsData,
payloads: formattedPayloads,
ipfsError,
};
}
return {
ipfsData,
payloads: formattedPayloads,
ipfsError,
};
}
36 changes: 14 additions & 22 deletions src/requests/fetchDataForCreateProposalScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@ export async function fetchDataForCreateProposalScreen({
input: FetchDataForCreateProposalScreen;
}) {
const { clients, proposalsCount } = input;

try {
// TODO: get data from API
throw new Error('TODO: API not implemented');
} catch (e) {
console.error(
'Error getting data for create screen from API, using RPC fallback',
e,
);
const proposalsData = await getProposalsDataRPC({
clients,
proposalsCount: Number(proposalsCount),
});
const { payloadsAvailableIds, payloadsCounts } = await getPayloadsCountsRPC(
{ proposalsCount, clients, proposalsData },
);
return {
payloadsCounts,
payloadsAvailableIds,
proposalsData,
};
}
const proposalsData = await getProposalsDataRPC({
clients,
proposalsCount: Number(proposalsCount),
});
const { payloadsAvailableIds, payloadsCounts } = await getPayloadsCountsRPC({
proposalsCount,
clients,
proposalsData,
});
return {
payloadsCounts,
payloadsAvailableIds,
proposalsData,
};
}
8 changes: 6 additions & 2 deletions src/store/proposalSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Draft, produce } from 'immer';
import { Hex, zeroHash } from 'viem';

import { appConfig, isForIPFS } from '../configs/appConfig';
import { DATA_POLLING_TIME } from '../configs/configs';
import { generateSeatbeltLink } from '../helpers/formatPayloadData';
import { fetchCreatorPropositionPower } from '../requests/fetchCreatorPropositionPower';
import { fetchProposalDataForDetails } from '../requests/fetchProposalDataForDetails';
Expand Down Expand Up @@ -153,7 +154,10 @@ export const createProposalSlice: StoreSlice<
startActiveProposalDetailsPolling: async (id) => {
const currentInterval = get().activeProposalDetailsInterval;
clearInterval(currentInterval);
const interval = setInterval(() => get().getProposalDetails(id), 30000);
const interval = setInterval(
() => get().getProposalDetails(id),
DATA_POLLING_TIME,
);
set({ activeProposalDetailsInterval: Number(interval) });
},
stopActiveProposalDetailsPolling: () => {
Expand Down Expand Up @@ -407,7 +411,7 @@ export const createProposalSlice: StoreSlice<
endBlockNumber,
lastBlockNumber,
});
}, 60000);
}, DATA_POLLING_TIME);
set({ getVotersInterval: Number(interval) });
},
stopVotersPolling: () => {
Expand Down
Loading

1 comment on commit 219eee7

@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.