Skip to content

Commit

Permalink
Merge pull request #19 from lxdao-official/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
KieSun authored Nov 4, 2024
2 parents 218c929 + 7b562e9 commit 7128c5c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/controller/contribution.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,10 @@ export class ContributionController {
const data = await this.contributionService.syncUnClaimed(chainId);
return CoreApiResponse.success(data);
}

@Get('allUnClaimedList')
async allUnClaimedList(@Query() query: ContributionListQuery) {
const data = await this.contributionService.getAllUnClaimedList(query);
return CoreApiResponse.success(data);
}
}
34 changes: 32 additions & 2 deletions src/core/service/contribution.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class ContributionService {
const where = {
deleted: false,
projectId,
status: {
in: [Status.READY, Status.CLAIM],
},
};
if (endDateTo && endDateFrom) {
where['endDate'] = {
Expand Down Expand Up @@ -360,8 +363,17 @@ export class ContributionService {
}

async syncUnClaimed(chainId: number) {
const ids = await this.easService.getEASList(chainId);
const data = await this.prisma.contribution.findMany({
let data = await this.prisma.contribution.findMany({
where: {
status: Status.READY,
},
});
const unClaimedIds = data.map((item) => item.uId);
const id_in = unClaimedIds.reduce((pre, cur) => {
return pre + `${pre ? '\n' : ''}` + `"${cur}"`;
}, '');
const ids = await this.easService.getEASList(chainId, id_in);
data = await this.prisma.contribution.findMany({
where: {
id: {
in: ids,
Expand All @@ -385,4 +397,22 @@ export class ContributionService {
}
return unClaimed;
}

async getAllUnClaimedList(query: ContributionListQuery) {
const { projectId, endDateFrom, endDateTo } = query;
const where = {
deleted: false,
projectId,
status: Status.READY,
};
if (endDateTo && endDateFrom) {
where['endDate'] = {
gte: new Date(endDateFrom),
lte: new Date(endDateTo),
};
}
return this.prisma.contribution.findMany({
where,
});
}
}
31 changes: 29 additions & 2 deletions src/core/service/eas.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ export class EasService {
return signerWallet.signMessage(ethers.getBytes(hash));
}

async getEASList(chainId?: number) {
async getEASList(chainId?: number, uIds?: string) {
const easMap = chainId === 10 ? MainEasSchemaMap : SepoliaEasSchemaMap;
const query = `
const query = uIds
? `
query Attestations {
attestations(
take: 100,
Expand All @@ -75,6 +76,32 @@ export class EasService {
revoked
}
}
`
: `
query Attestations {
attestations(
where: {
id: {
in: [
${uIds}
]
},
schemaId: {
equals: "${easMap.claim}"
}
}
) {
id
refUID
ipfsHash
recipient
decodedDataJson
data
attester
revocable
revoked
}
}
`;
const { data } = await axios.post<{
data: { attestations: EasAttestation<EasSchemaVoteKey>[] };
Expand Down

0 comments on commit 7128c5c

Please sign in to comment.