Skip to content

Commit

Permalink
free mint when totalAttestation < threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Oct 10, 2024
1 parent 96ba477 commit daf0a26
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
10 changes: 4 additions & 6 deletions packages/data-layer/src/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,13 +1008,11 @@ export class DataLayer {
});
}

async getAttestationCountByRecipientId({
recipientId,
async getAttestationCount({
attestationChainIds,
}: {
recipientId: string;
attestationChainIds: number[]
}): Promise<number> {
return this.attestationService.getAttestationCountByRecipientId({
recipientId,
});
return this.attestationService.getAttestationCount({attestationChainIds});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,26 @@ export class AttestationService {
return response.attestationTxns;
}

async getAttestationCountByRecipientId({
recipientId,
async getAttestationCount({
attestationChainIds
}: {
recipientId: string;
}): Promise<number> {
attestationChainIds: number[];
}) : Promise<number> {
const query = gql`
query getAttestationCountByRecipientId(
$recipientId: String!
query getAttestationCount(
$attestationChainIds: [Int!]!
) {
attestations(filter: {recipient: { equalTo: $recipientId}}) {
attestations(filter: {
chainId: { in: $attestationChainIds }
}) {
uid
}
}
`;

const response: { attestations: any[] } =
await request(this.gsIndexerEndpoint, query, {
recipientId,
attestationChainIds,
});

return response.attestations.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export const PreviewFrame = ({
></div>
<div className="flex flex-wrap gap-3 items-center mt-3 p-2">
<div className="flex flex-col items-center">
<div className="flex flex-wrap items-center space-x-2 z-30">
<div className="flex flex-wrap items-center space-x-2 z-30 my-3">
<div className="text-2xl font-modern-era-regular">
Pick your color
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const ShareButtons = (): JSX.Element => {
return (
<div className="z-30">
<div className="flex flex-col items-center justify-center gap-2 relative">
<span className="font-mona font-semibold">Share</span>
<span className="font-mona font-semibold py-1">Share Your Impact</span>
<div className="flex items-center justify-center gap-2 relative">
<div className="flex w-9 h-9 items-center justify-center gap-2 p-2 relative rounded-3xl border border-solid border-color-primitives-neutral-100 cursor-pointer">
<img className="relative w-9 h-9" alt="Frame" src={Link} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMemo } from "react";
import { useAccount } from "wagmi";
import { MintingAttestationIdsData, useDataLayer } from "data-layer";
import { useQuery, UseQueryResult } from "@tanstack/react-query";
import { AttestationFee, FeeExemptAttestationsLimit } from "../../attestations/utils/constants";
import { AttestationChainId, AttestationFee, FeeExemptAttestationsLimit } from "../../attestations/utils/constants";

export type MintingAttestationsResponse = Omit<
UseQueryResult<MintingAttestationIdsData[], Error>,
Expand Down Expand Up @@ -58,22 +58,20 @@ export const useMintingAttestations = (

export const useAttestationFee = () => {

const { address } = useAccount();
const dataLayer = useDataLayer();

const exisitingAttestations = useQuery({
queryKey :[address],
queryKey :[],
queryFn: async () => {
const response = await dataLayer.getAttestationCountByRecipientId({
recipientId: address!.toLowerCase(),
const response = await dataLayer.getAttestationCount({
attestationChainIds: [AttestationChainId]
});
return response;
},
})

const fee = useMemo<bigint>(() => {
if (
!address ||
!exisitingAttestations.data ||
exisitingAttestations.data >= FeeExemptAttestationsLimit
) return AttestationFee;
Expand Down

0 comments on commit daf0a26

Please sign in to comment.