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

Contribution Count Shows Different Numbers - fixed #443 #460

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
56 changes: 36 additions & 20 deletions app/src/utils/data/contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,43 @@ export async function getContributions(
if (SUBGRAPH_URL) {
try {
// make the request
const res = await fetch(SUBGRAPH_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: `{
grantDonations(where: {lastUpdatedBlockNumber_gte: ${fromBlock}, lastUpdatedBlockNumber_lte: ${blockNumber}}) {
grantId
tokenIn
donationAmount
from
hash
rounds
lastUpdatedBlockNumber
}
}`,
}),
});
// resolve the json
const json = await res.json();

const limit = 100;

const fetchUntilAll = async (SUBGRAPH_URL: string, before = [], skip = 0): Promise<any[]> => {
const res = await fetch(SUBGRAPH_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: `{
grantDonations(first: ${limit}, skip: ${
skip * limit
}, where: {lastUpdatedBlockNumber_gte: ${fromBlock}, lastUpdatedBlockNumber_lte: ${blockNumber}}) {
grantId
tokenIn
donationAmount
from
hash
rounds
lastUpdatedBlockNumber
}
}`,
}),
});
// resolve the json
const json = await res.json();

if (json.data.grantDonations.length) {
return await fetchUntilAll(SUBGRAPH_URL, before, skip + 1);
Copy link
Collaborator

@apbendi apbendi Oct 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes needed:

  • merge json response with before before recursive call
  • increment indexdb number to bust cache

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's where to increment the version

// we can bump this version number to bust the users cache
version: 1,

} else {
return [...before];
}
};

const donationData = await fetchUntilAll(SUBGRAPH_URL);

// update each of the grants
json.data.grantDonations.forEach((contribution: ContributionSubgraph) => {
donationData.forEach((contribution: ContributionSubgraph) => {
// update to most recent block collected
fromBlock = Math.max(fromBlock, contribution.lastUpdatedBlockNumber);
const grantId = BigNumber.from(contribution.grantId).toNumber();
Expand Down