Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal data caching #453

Merged
merged 25 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f112197
WIP cache proposal data
jdville03 Jul 28, 2021
5a609f8
WIP use queryClient
jdville03 Jul 28, 2021
060efba
WIP refactor with useQuery hooks
jdville03 Jul 29, 2021
8a53164
apply caching strategy to governance proposals
jdville03 Aug 2, 2021
676fdc2
apply proposal data caching to individual proposal details
jdville03 Aug 3, 2021
dd12b94
Revert "apply proposal data caching to individual proposal details"
jdville03 Aug 3, 2021
c5cd5f0
Revert "Revert "apply proposal data caching to individual proposal de…
jdville03 Aug 3, 2021
45cd00c
WIP refetch for proposal actions updates
jdville03 Aug 3, 2021
f12fb4a
fix proposal action transitions
jdville03 Aug 6, 2021
995b03d
format comment
jdville03 Aug 7, 2021
6219f89
fix proposal action transitions
jdville03 Aug 10, 2021
c632919
format comments
jdville03 Aug 10, 2021
4d207a4
WIP update tests
jdville03 Aug 10, 2021
e5ee5e4
clean up hook after caching update
jdville03 Aug 10, 2021
f483493
update useProposals unit tests
jdville03 Aug 10, 2021
02698a9
update useGovernanceProposals unit tests
jdville03 Aug 10, 2021
4d54a70
update useDaoProposals unit test
jdville03 Aug 11, 2021
377b58a
update comment
jdville03 Aug 11, 2021
506f2cc
WIP fix last of failing tests
jdville03 Aug 12, 2021
628fafc
remove react query dev tools
jdville03 Aug 12, 2021
944ee78
update queryClient import in setupTests
jdville03 Aug 12, 2021
b9c8273
update testing clear cache
jdville03 Aug 13, 2021
59bfd4c
fixes outdated env vars being set
jtrein Aug 13, 2021
73189fd
fixes useProposalsVotes tests and makes slight improvements to code
jtrein Aug 13, 2021
e3ff95b
improve use of react queries
jdville03 Aug 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"react-lines-ellipsis": "^0.15.0",
"react-media": "^1.10.0",
"react-modal": "^3.13.1",
"react-query": "^3.19.1",
"react-redux": "^7.2.4",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
Expand Down
33 changes: 26 additions & 7 deletions src/components/governance/hooks/useGovernanceProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SnapshotProposalResponse,
SnapshotType,
} from '@openlaw/snapshot-js-erc712';
import {useQuery} from 'react-query';

import {AsyncStatus} from '../../../util/types';
import {BURN_ADDRESS} from '../../../util/constants';
Expand Down Expand Up @@ -48,13 +49,29 @@ export function useGovernanceProposals({

const {isMountedRef} = useIsMounted();

/**
* React Query
*/

const {
data: snapshotProposalEntriesData,
error: snapshotProposalEntriesError,
} = useQuery(
['snapshotProposalEntries', actionId],
async () => await getSnapshotProposalsByActionId(actionId),
{
enabled: !!actionId,
}
);

/**
* Cached callbacks
*/

const handleGetProposalsCached = useCallback(handleGetProposals, [
actionId,
isMountedRef,
snapshotProposalEntriesData,
snapshotProposalEntriesError,
]);

/**
Expand Down Expand Up @@ -119,14 +136,16 @@ export function useGovernanceProposals({
try {
setGovernanceProposalsStatus(AsyncStatus.PENDING);

const snapshotProposalEntries = await getSnapshotProposalsByActionId(
actionId
);
if (snapshotProposalEntriesError) {
throw snapshotProposalEntriesError;
}

if (!isMountedRef.current) return;
if (snapshotProposalEntriesData) {
if (!isMountedRef.current) return;

setGovernanceProposalsStatus(AsyncStatus.FULFILLED);
setGovernanceProposals(snapshotProposalEntries);
setGovernanceProposalsStatus(AsyncStatus.FULFILLED);
setGovernanceProposals(snapshotProposalEntriesData);
}
} catch (error) {
if (!isMountedRef.current) return;

Expand Down
Loading