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

added polling when checking if a user is donating to a collective #137

Merged
merged 4 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading