diff --git a/src/repositories/donationRepository.ts b/src/repositories/donationRepository.ts index caa7b3ae8..9bf2825fc 100644 --- a/src/repositories/donationRepository.ts +++ b/src/repositories/donationRepository.ts @@ -26,6 +26,19 @@ export const fillQfRoundDonationsUserScores = async (): Promise => { `); }; +export const addressHasDonated = async (address: string) => { + const projectAddress = await Donation.query( + ` + SELECT "id" + FROM donation + where lower("fromWalletAddress") = $1 + limit 1 + `, + [address.toLowerCase()], + ); + return projectAddress.length > 0; +}; + export const createDonation = async (data: { amount: number; project: Project; diff --git a/src/resolvers/userResolver.ts b/src/resolvers/userResolver.ts index a03f3906a..15ace1d8c 100644 --- a/src/resolvers/userResolver.ts +++ b/src/resolvers/userResolver.ts @@ -18,6 +18,8 @@ import { SegmentAnalyticsSingleton } from '../services/segment/segmentAnalyticsS import { AppDataSource } from '../orm'; import { getGitcoinAdapter } from '../adapters/adaptersFactory'; import { logger } from '../utils/logger'; +import { isWalletAddressInPurpleList } from '../repositories/projectAddressRepository'; +import { addressHasDonated } from '../repositories/donationRepository'; @Resolver(of => User) export class UserResolver { @@ -29,6 +31,14 @@ export class UserResolver { // return User.create(data).save(); } + @Query(returns => Boolean) + async walletAddressUsed(@Arg('address') address: string): Promise { + return ( + (await isWalletAddressInPurpleList(address)) || + (await addressHasDonated(address)) + ); + } + @Query(returns => UserByAddressResponse, { nullable: true }) async userByAddress( @Arg('address', type => String) address: string,