Skip to content

Commit

Permalink
add query for knowing if wallet was used
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 committed Sep 16, 2023
1 parent ed3025a commit ae9f96a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/repositories/donationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ export const fillQfRoundDonationsUserScores = async (): Promise<void> => {
`);
};

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;
Expand Down
10 changes: 10 additions & 0 deletions src/resolvers/userResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -29,6 +31,14 @@ export class UserResolver {
// return User.create(data).save();
}

@Query(returns => Boolean)
async walletAddressUsed(@Arg('address') address: string): Promise<Boolean> {
return (
(await isWalletAddressInPurpleList(address)) ||
(await addressHasDonated(address))
);
}

@Query(returns => UserByAddressResponse, { nullable: true })
async userByAddress(
@Arg('address', type => String) address: string,
Expand Down

0 comments on commit ae9f96a

Please sign in to comment.