From ae9f96a4a1b59051bdab82790bd118a7c8529747 Mon Sep 17 00:00:00 2001 From: Carlos Date: Sat, 16 Sep 2023 15:16:13 -0500 Subject: [PATCH] add query for knowing if wallet was used --- src/repositories/donationRepository.ts | 13 +++++++++++++ src/resolvers/userResolver.ts | 10 ++++++++++ 2 files changed, 23 insertions(+) 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,