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

Removed extra check in donation validation #122

Merged
merged 4 commits into from
Oct 31, 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 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
Loading