Skip to content

Commit

Permalink
Merge pull request #122 from GeneralMagicio/fix/round-matching
Browse files Browse the repository at this point in the history
Removed extra check in donation validation
  • Loading branch information
aminlatifi authored Oct 31, 2024
2 parents e7d08a3 + 0e27d3a commit 469715b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/services/donationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function syncDonationStatusWithBlockchainNetworkTestCases() {
assert.isOk(updateDonation);
assert.equal(updateDonation.id, donation.id);
assert.equal(updateDonation.status, DONATION_STATUS.VERIFIED);
assert.equal(updateDonation.earlyAccessRoundId, ea.id);
// assert.equal(updateDonation.earlyAccessRoundId, ea.id);
});

it('should associate donation to overlapping qf round after verification', async () => {
Expand Down Expand Up @@ -222,7 +222,7 @@ function syncDonationStatusWithBlockchainNetworkTestCases() {
assert.isOk(updateDonation);
assert.equal(updateDonation.id, donation.id);
assert.equal(updateDonation.status, DONATION_STATUS.VERIFIED);
assert.equal(updateDonation.qfRoundId, qf.id);
// assert.equal(updateDonation.qfRoundId, qf.id);
});
}

Expand Down
48 changes: 23 additions & 25 deletions src/services/donationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ import { CustomToken, getTokenPrice } from './priceService';
import { updateProjectStatistics } from './projectService';
import { updateOrCreateProjectRoundRecord } from '../repositories/projectRoundRecordRepository';
import { updateOrCreateProjectUserRecord } from '../repositories/projectUserRecordRepository';
import { findActiveEarlyAccessRound } from '../repositories/earlyAccessRoundRepository';
import { findActiveQfRound } from '../repositories/qfRoundRepository';
import { ProjectAddress } from '../entities/projectAddress';
import { processAnkrTransfers } from './ankrService';
import { User } from '../entities/user';
Expand All @@ -61,7 +59,6 @@ import {
QACC_DONATION_TOKEN_SYMBOL,
} from '../constants/qacc';
import { ApolloContext } from '../types/ApolloContext';
import qAccService from './qAccService';

export const TRANSAK_COMPLETED_STATUS = 'COMPLETED';

Expand Down Expand Up @@ -295,28 +292,28 @@ export const syncDonationStatusWithBlockchainNetwork = async (params: {
const transactionDate = new Date(transaction.timestamp * 1000);

// Only double check if the donation is not already assigned to a round
if (!donation.earlyAccessRoundId && !donation.qfRoundId) {
const cap = await qAccService.getQAccDonationCap({
userId: donation.userId,
projectId: donation.projectId,
donateTime: transactionDate,
});

logger.debug(
`the available cap at time ${transaction.timestamp} is ${cap}, and donation amount is ${donation.amount}`,
);
if (cap >= donation.amount) {
const [earlyAccessRound, qfRound] = await Promise.all([
findActiveEarlyAccessRound(transactionDate),
findActiveQfRound({ date: transactionDate }),
]);
donation.earlyAccessRound = earlyAccessRound;
donation.qfRound = qfRound;
} else {
donation.earlyAccessRound = null;
donation.qfRound = null;
}
}
// if (!donation.earlyAccessRoundId && !donation.qfRoundId) {
// const cap = await qAccService.getQAccDonationCap({
// userId: donation.userId,
// projectId: donation.projectId,
// donateTime: transactionDate,
// });

// logger.debug(
// `the available cap at time ${transaction.timestamp} is ${cap}, and donation amount is ${donation.amount}`,
// );
// if (cap >= donation.amount) {
// const [earlyAccessRound, qfRound] = await Promise.all([
// findActiveEarlyAccessRound(transactionDate),
// findActiveQfRound({ date: transactionDate }),
// ]);
// donation.earlyAccessRound = earlyAccessRound;
// donation.qfRound = qfRound;
// } else {
// donation.earlyAccessRound = null;
// donation.qfRound = null;
// }
// }
await donation.save();

// ONLY verified donations should be accumulated
Expand Down Expand Up @@ -721,6 +718,7 @@ const ankrTransferHandler = async (transfer: TokenTransfer) => {

await Donation.update(Number(donationId), {
origin: DONATION_ORIGINS.CHAIN,
status: DONATION_STATUS.VERIFIED,
});

logger.debug(
Expand Down

0 comments on commit 469715b

Please sign in to comment.