From 1435336905668ec40838e81f2d23cd7b6814c50f Mon Sep 17 00:00:00 2001 From: Kris Bitney Date: Thu, 1 Feb 2024 16:52:00 +0500 Subject: [PATCH] added polling when checking if a user is donating to a collective (#137) * added polling to subgraph when checking if a user is donating to a collective * changed poll interval for supporter check to env var with default 30 sec * fixed merge conflicts --- packages/app/src/components/ViewCollective.tsx | 4 ++-- packages/app/src/hooks/useDonorCollectiveByAddresses.ts | 5 +++-- packages/app/src/models/constants.ts | 2 ++ packages/app/src/subgraph/useSubgraphDonorCollective.ts | 4 +++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/app/src/components/ViewCollective.tsx b/packages/app/src/components/ViewCollective.tsx index 72f0fb20..7052813c 100644 --- a/packages/app/src/components/ViewCollective.tsx +++ b/packages/app/src/components/ViewCollective.tsx @@ -34,7 +34,7 @@ import FlowingDonationsRowItem from './FlowingDonationsRowItem'; import { useDeleteFlow } from '../hooks/useContractCalls/useDeleteFlow'; import ErrorModal from './modals/ErrorModal'; import FlowingCurrentPoolRowItem from './FlowingCurrentPoolRowItem'; -import { defaultInfoLabel } from '../models/constants'; +import { defaultInfoLabel, IS_DONATING_POLL_INTERVAL } from '../models/constants'; interface ViewCollectiveProps { collective: Collective; @@ -63,7 +63,7 @@ function ViewCollective({ collective }: ViewCollectiveProps) { const infoLabel = collective.ipfs.infoLabel ?? defaultInfoLabel; const { address } = useAccount(); - const maybeDonorCollective = useDonorCollectiveByAddresses(address ?? '', poolAddress); + const maybeDonorCollective = useDonorCollectiveByAddresses(address ?? '', poolAddress, IS_DONATING_POLL_INTERVAL); const isDonating = maybeDonorCollective && maybeDonorCollective.flowRate !== '0'; const [stopDonationModalVisible, setStopDonationModalVisible] = useState(false); diff --git a/packages/app/src/hooks/useDonorCollectiveByAddresses.ts b/packages/app/src/hooks/useDonorCollectiveByAddresses.ts index c17cdc9b..f635d935 100644 --- a/packages/app/src/hooks/useDonorCollectiveByAddresses.ts +++ b/packages/app/src/hooks/useDonorCollectiveByAddresses.ts @@ -4,9 +4,10 @@ import { subgraphDonorCollectiveToModel } from '../models/transforms'; export function useDonorCollectiveByAddresses( donorAddress: string, - collectiveAddress: string + collectiveAddress: string, + pollInterval?: number ): DonorCollective | undefined { - const subgraphDonorCollective = useSubgraphDonorCollective(donorAddress, collectiveAddress); + const subgraphDonorCollective = useSubgraphDonorCollective(donorAddress, collectiveAddress, pollInterval); if (!subgraphDonorCollective) return undefined; return subgraphDonorCollectiveToModel(subgraphDonorCollective); } diff --git a/packages/app/src/models/constants.ts b/packages/app/src/models/constants.ts index 5a07e521..8e5840c2 100644 --- a/packages/app/src/models/constants.ts +++ b/packages/app/src/models/constants.ts @@ -38,3 +38,5 @@ export const frequencyOptions: { value: Frequency; label: Frequency }[] = Object })); export const defaultInfoLabel = 'Please see the smart contract for information regarding payment logic.'; + +export const IS_DONATING_POLL_INTERVAL = parseInt(process.env.IS_DONATING_POLL_INTERVAL ?? '30000', 10); diff --git a/packages/app/src/subgraph/useSubgraphDonorCollective.ts b/packages/app/src/subgraph/useSubgraphDonorCollective.ts index 15fae5db..8e93965d 100644 --- a/packages/app/src/subgraph/useSubgraphDonorCollective.ts +++ b/packages/app/src/subgraph/useSubgraphDonorCollective.ts @@ -21,13 +21,15 @@ const donorCollectiveByEntities = gql` export function useSubgraphDonorCollective( donorAddress: string, - collectiveAddress: string + collectiveAddress: string, + pollInterval?: number ): SubgraphDonorCollective | undefined { const response = useSubgraphData(donorCollectiveByEntities, { variables: { donor: donorAddress.toLowerCase(), collective: collectiveAddress.toLowerCase(), }, + pollInterval, }); const data = (response as DonorCollectiveSubgraphResponse).donorCollectives; if (!data || data.length === 0) {