Skip to content

Commit

Permalink
fix: proposal list data polling
Browse files Browse the repository at this point in the history
  • Loading branch information
Argeare5 committed Jan 20, 2025
1 parent 6f6edfe commit be5785d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/components/ProposalNextState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export function ProposalNextState({
expiryTimestamp={timestamp}
onExpire={async () => {
if (!isForHelpModal) {
await updateProposalsListActiveData([proposalId]);
await updateProposalsListActiveData({
activeIds: [proposalId],
rpcOnly: true,
});
}
}}
/>
Expand Down
5 changes: 4 additions & 1 deletion src/components/ProposalsList/ProposalsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ export function ProposalsList({
proposalsData.activeProposalsData.length ||
proposalsData.finishedProposalsData.length
) {
initializeProposalsListData(proposalsData, true);
initializeProposalsListData({
proposalsListData: proposalsData,
fromServer: true,
});
}
}, [
proposalsData.activeProposalsData.length,
Expand Down
75 changes: 53 additions & 22 deletions src/store/proposalsListSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ export interface IProposalsListSlice {
activeProposalsData: Record<number, ActiveProposalOnTheList>;
finishedProposalsData: Record<number, ProposalOnTheList>;
};
initializeProposalsListData: (
initializeProposalsListData: ({
proposalsListData,
fromServer,
fromPolling,
}: {
proposalsListData: {
activeProposalsData: ActiveProposalOnTheList[];
finishedProposalsData: ProposalOnTheList[];
},
fromServer?: boolean,
) => void;
};
fromServer?: boolean;
fromPolling?: boolean;
}) => void;
initializeLoading: boolean;

activeProposalsDataInterval: number | undefined;
Expand All @@ -48,11 +53,16 @@ export interface IProposalsListSlice {
startNewProposalsPolling: (activePage: number) => Promise<void>;
stopNewProposalsPolling: () => void;

updateProposalsListActiveData: (
activeIds: number[],
activePage?: number,
rpcOnly?: boolean,
) => Promise<void>;
updateProposalsListActiveData: ({
activeIds,
activePage,
rpcOnly,
}: {
activeIds: number[];
activePage?: number;
rpcOnly?: boolean;
polling?: boolean;
}) => Promise<void>;
updateUserDataOnTheList: (rpcOnly?: boolean) => Promise<void>;

updatedListDataLoading: Record<number, boolean>;
Expand Down Expand Up @@ -93,7 +103,11 @@ export const createProposalsListSlice: StoreSlice<
activeProposalsData: {},
finishedProposalsData: {},
},
initializeProposalsListData: (proposalsListData, fromServer) => {
initializeProposalsListData: ({
proposalsListData,
fromServer,
fromPolling,
}) => {
const activeProposalsData = get().proposalsListData.activeProposalsData;
const finishedProposalsData = get().proposalsListData.activeProposalsData;
if (
Expand Down Expand Up @@ -139,6 +153,13 @@ export const createProposalsListSlice: StoreSlice<
...finishedProposal,
isActive: true,
};
} else if (isForIPFS && fromPolling) {
draft.proposalsListData.finishedProposalsData[
proposal.proposalId
] = {
...finishedProposal,
isActive: true,
};
}
delete draft.proposalsListData.activeProposalsData[
proposal.proposalId
Expand All @@ -157,19 +178,21 @@ export const createProposalsListSlice: StoreSlice<
const currentInterval = get().activeProposalsDataInterval;
clearInterval(currentInterval);

const func = async (acP?: number, rpcOnly?: boolean) => {
const func = async () => {
const configs = get().configs;
const activeIds = selectProposalsForActivePage(
get(),
acP ?? 1,
activePage ?? 1,
).activeProposalsData.map((proposal) => proposal.proposalId);
if (configs && activeIds.length > 0) {
await get().updateProposalsListActiveData(activeIds, acP, rpcOnly);
await get().updateProposalsListActiveData({
activeIds,
activePage,
polling: true,
});
}
};

func(activePage, true);

const interval = setInterval(func, DATA_POLLING_TIME);
set({ activeProposalsDataInterval: Number(interval) });
},
Expand Down Expand Up @@ -210,11 +233,11 @@ export const createProposalsListSlice: StoreSlice<
1,
Number(totalProposalsCount) - currentProposalCount,
);
await get().updateProposalsListActiveData(
newIdsForFirstScreen,
undefined,
await get().updateProposalsListActiveData({
activeIds: newIdsForFirstScreen,
rpcOnly,
);
polling: true,
});
}
};
if (activePage === 1) {
Expand All @@ -231,7 +254,12 @@ export const createProposalsListSlice: StoreSlice<
}
},

updateProposalsListActiveData: async (activeIds, activePage, rpcOnly) => {
updateProposalsListActiveData: async ({
activeIds,
activePage,
rpcOnly,
polling,
}) => {
const configs = get().configs;
if (configs && activeIds.length > 0) {
if (
Expand All @@ -258,7 +286,10 @@ export const createProposalsListSlice: StoreSlice<
},
})
: api.proposalsList.getActive.query(input));
get().initializeProposalsListData(proposalsData);
get().initializeProposalsListData({
proposalsListData: proposalsData,
fromPolling: polling,
});
get().updateUserDataOnTheList(rpcOnly);
if (activePage) {
set((state) =>
Expand Down Expand Up @@ -453,7 +484,7 @@ export const createProposalsListSlice: StoreSlice<
draft.filters.activeIds = data.ids;
}),
);
get().initializeProposalsListData(data.data);
get().initializeProposalsListData({ proposalsListData: data.data });
set({
paginationCount: data.count ?? -1,
});
Expand Down

1 comment on commit be5785d

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