diff --git a/config/example.env b/config/example.env index 8ca1f1f40..2610c1a28 100644 --- a/config/example.env +++ b/config/example.env @@ -310,5 +310,5 @@ MONGO_DB_REPORT_DB_NAME= GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE= # 1 day GITCOIN_PASSPORT_EXPIRATION_PERIOD_MS=86400000 -MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY= +MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_IN_USD= ACTIVATE_GITCOIN_SCORE_CHECK= diff --git a/src/constants/gitcoin.ts b/src/constants/gitcoin.ts index f4a4ef7e5..34c4cdce5 100644 --- a/src/constants/gitcoin.ts +++ b/src/constants/gitcoin.ts @@ -4,6 +4,7 @@ export const GITCOIN_PASSPORT_EXPIRATION_PERIOD_MS = (+config.get('GITCOIN_PASSPORT_EXPIRATION_PERIOD_MS') as number) || 86400000; // 1 day export const GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE = (+config.get('GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE') as number) || 50; -export const MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY = - (+config.get('MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY') as number) || - 1000; +export const MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_IN_USD = + (+config.get( + 'MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_IN_USD', + ) as number) || 1000; diff --git a/src/resolvers/qAccResolver.ts b/src/resolvers/qAccResolver.ts index c961d6751..8411af51a 100644 --- a/src/resolvers/qAccResolver.ts +++ b/src/resolvers/qAccResolver.ts @@ -12,7 +12,7 @@ import { getProjectUserRecordAmount } from '../repositories/projectUserRecordRep import qAccService from '../services/qAccService'; import { ApolloContext } from '../types/ApolloContext'; import { i18n, translationErrorMessagesKeys } from '../utils/errorMessages'; -import { getUserById } from '../services/userService'; +import { findUserById } from '../repositories/userRepository'; @ObjectType() class ProjectUserRecordAmounts { @@ -85,7 +85,10 @@ export class QAccResolver { i18n.__(translationErrorMessagesKeys.AUTHENTICATION_REQUIRED), ); - const dbUser = await getUserById(user.userId); + const dbUser = await findUserById(user.userId); + if (!dbUser) { + throw new Error(`user not found with id ${user.userId}`); + } const qAccCap = await qAccService.getQAccDonationCap({ projectId, diff --git a/src/services/qAccService.ts b/src/services/qAccService.ts index 65402d4a9..729a63a4d 100644 --- a/src/services/qAccService.ts +++ b/src/services/qAccService.ts @@ -12,7 +12,7 @@ import { updateUserGitcoinAnalysisScore } from './userService'; import { GITCOIN_PASSPORT_EXPIRATION_PERIOD_MS, GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE, - MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY, + MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_IN_USD, } from '../constants/gitcoin'; const getEaProjectRoundRecord = async ({ @@ -226,8 +226,16 @@ const getUserRemainedCapBasedOnGitcoinScore = async ({ projectId, userId: user.id, }); + const activeQfRound = await findActiveQfRound(); const qfTotalDonationAmount = userRecord.qfTotalDonationAmount; - return MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY - qfTotalDonationAmount; + if (!activeQfRound?.tokenPrice) { + throw new Error('active qf round does not have token price!'); + } + return ( + MAX_CONTRIBUTION_WITH_GITCOIN_PASSPORT_ONLY_IN_USD / + activeQfRound?.tokenPrice - + qfTotalDonationAmount + ); }; const validDonationAmountBasedOnKYCAndScore = async ({ diff --git a/src/services/userService.ts b/src/services/userService.ts index b3ab2586a..b4994def1 100644 --- a/src/services/userService.ts +++ b/src/services/userService.ts @@ -1,10 +1,7 @@ import { User } from '../entities/user'; import { Donation } from '../entities/donation'; import { logger } from '../utils/logger'; -import { - findAdminUserByEmail, - findUserById, -} from '../repositories/userRepository'; +import { findAdminUserByEmail } from '../repositories/userRepository'; import { getGitcoinAdapter } from '../adapters/adaptersFactory'; // eslint-disable-next-line @typescript-eslint/no-var-requires const bcrypt = require('bcrypt'); @@ -102,11 +99,3 @@ export const updateUserGitcoinAnalysisScore = async (user: User) => { user.passportScoreUpdateTimestamp = new Date(); await user.save(); }; - -export const getUserById = async (userId: number) => { - const foundedUser = await findUserById(userId); - if (foundedUser) { - return foundedUser; - } - throw new Error(`user not found with id ${userId}`); -};