Skip to content

Commit

Permalink
added polling when checking if a user is donating to a collective (#137)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
krisbitney authored Feb 1, 2024
1 parent 30a3bce commit 1435336
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/app/src/components/ViewCollective.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions packages/app/src/hooks/useDonorCollectiveByAddresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions packages/app/src/models/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
4 changes: 3 additions & 1 deletion packages/app/src/subgraph/useSubgraphDonorCollective.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1435336

Please sign in to comment.