Skip to content

Commit

Permalink
add zero fee attestation
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Oct 10, 2024
1 parent 5e17f6b commit 96ba477
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 25 deletions.
10 changes: 10 additions & 0 deletions packages/data-layer/src/data-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,4 +1007,14 @@ export class DataLayer {
transactionHashes,
});
}

async getAttestationCountByRecipientId({
recipientId,
}: {
recipientId: string;
}): Promise<number> {
return this.attestationService.getAttestationCountByRecipientId({
recipientId,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,27 @@ export class AttestationService {

return response.attestationTxns;
}

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

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

return response.attestations.length;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "./MintYourImpactComponents";
import { AttestationChainId } from "./utils/constants";
import { MintingProcessContent } from "./components/index";
import { useAttestationFee } from "../contributors/hooks/useMintingAttestations";

type MintProgressModalBodyProps = {
handleSwitchChain: () => Promise<void>;
Expand All @@ -23,6 +24,7 @@ type MintProgressModalBodyProps = {
isTransactionHistoryPage?: boolean;
previewBackground?: string;
selectedColor?: string;
attestationFee: bigint;
};

// MintProgressModalBodyThankYou component
Expand All @@ -44,6 +46,7 @@ export function MintProgressModalBodyThankYou(
chainId: AttestationChainId,
address,
});
const { data: attestationFee } = useAttestationFee();

return (
<div className="min-w-full min-h-full">
Expand All @@ -54,6 +57,7 @@ export function MintProgressModalBodyThankYou(
isLoadingEstimation={isLoadingEstimation}
gasEstimation={gasEstimation}
isConnected={isConnected}
attestationFee={attestationFee}
handleSwitchChain={handleSwitchChain}
handleAttest={handleAttest}
isLoading={isLoading}
Expand All @@ -67,6 +71,7 @@ export function MintProgressModalBodyHistory(
props: MintProgressModalBodyProps
) {
const {
attestationFee,
handleSwitchChain,
status,
gasEstimation,
Expand Down Expand Up @@ -115,6 +120,7 @@ export function MintProgressModalBodyHistory(
handleSwitchChain={handleSwitchChain}
handleAttest={handleAttest}
isLoading={isLoading}
attestationFee={attestationFee}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ProgressStatus } from "../../../hooks/attestations/config";
import { AttestationFee } from "../utils/constants";
import {
ErrorMessage,
BalanceDisplay,
Expand All @@ -18,6 +17,7 @@ export const MintingProcessContent = ({
handleSwitchChain,
handleAttest,
isLoading,
attestationFee,
}: {
status: ProgressStatus;
balance: bigint | undefined;
Expand All @@ -28,6 +28,7 @@ export const MintingProcessContent = ({
handleSwitchChain: () => Promise<void>;
handleAttest: () => Promise<void>;
isLoading: boolean;
attestationFee: bigint;
}) => (
<div className="flex flex-col items-start justify-center">
{status === ProgressStatus.IS_ERROR && <ErrorMessage />}
Expand All @@ -36,7 +37,7 @@ export const MintingProcessContent = ({

<CostDetails
isLoading={isLoadingEstimation}
attestationFee={AttestationFee}
attestationFee={attestationFee}
estimatedGas={gasEstimation}
/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const AttestationChainId = 11155111;
export const AttestationFee = BigInt(0.001 * 10 ** 18);
export const FeeExemptAttestationsLimit = 20;
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import { useEstimateGas } from "../../../../hooks/attestations/useEstimateGas";

import {
AttestationChainId,
AttestationFee,
} from "../../../attestations/utils/constants";
import { ethers } from "ethers";
import { useAttestationFee } from "../../hooks/useMintingAttestations";

interface MintDonationImpactActionProps {
toggleModal: () => void;
Expand Down Expand Up @@ -90,9 +90,12 @@ export function MintDonationImpactAction({
address: address,
});

const { data: attestationFee } = useAttestationFee();
console.log("====> A1", attestationFee)

const notEnoughFunds =
balance?.value && gasEstimation
? balance.value <= AttestationFee + gasEstimation
? balance.value <= attestationFee + gasEstimation
: false;

const title =
Expand Down Expand Up @@ -120,6 +123,7 @@ export function MintDonationImpactAction({
subheading={subheading}
body={
<MintProgressModalBodyHistory
attestationFee={attestationFee}
handleSwitchChain={handleSwitchChain}
status={status}
gasEstimation={gasEstimation}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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";

export type MintingAttestationsResponse = Omit<
UseQueryResult<MintingAttestationIdsData[], Error>,
Expand Down Expand Up @@ -53,3 +55,31 @@ export const useMintingAttestations = (
data: attestations,
};
};

export const useAttestationFee = () => {

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

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

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

return BigInt(0);
}, [exisitingAttestations.data]);

return { data: fee };
};
9 changes: 6 additions & 3 deletions packages/grant-explorer/src/features/round/ThankYou.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import { useGetImages } from "../../hooks/attestations/useGetImages";
import { useEstimateGas } from "../../hooks/attestations/useEstimateGas";
import {
AttestationChainId,
AttestationFee,
} from "../attestations/utils/constants";
import { ethers } from "ethers";
import { useAttestationFee } from "../contributors/hooks/useMintingAttestations";

export default function ThankYou() {
datadogLogs.logger.info(
Expand All @@ -39,6 +39,7 @@ export default function ThankYou() {

const cart = useCartStorage();
const checkoutStore = useCheckoutStore();
const { address } = useAccount();

/** Fetch round data for tweet */
const checkedOutProjects = useCheckoutStore((state) =>
Expand Down Expand Up @@ -165,7 +166,6 @@ export default function ThankYou() {

const flex = width <= 1280;

const { address } = useAccount();
const { data: name, isLoading: isLoadingENS } = useResolveENS(address);

const { data: imagesBase64, isLoading: isLoadingImages } = useGetImages(
Expand Down Expand Up @@ -206,9 +206,11 @@ export default function ThankYou() {
address,
});

const { data: attestationFee } = useAttestationFee();

const notEnoughFunds =
balance?.value && gasEstimation
? balance.value <= AttestationFee + gasEstimation
? balance.value <= attestationFee + gasEstimation
: false;

return (
Expand Down Expand Up @@ -309,6 +311,7 @@ export default function ThankYou() {
subheading="Your unique donation graphic will be generated after you mint."
body={
<MintProgressModalBodyThankYou
attestationFee={attestationFee}
handleSwitchChain={handleSwitchChain}
status={status}
gasEstimation={gasEstimation}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useState } from 'react';

export type SwapParams = {
fromChainId: string;
toChainId: string;
Expand All @@ -15,14 +13,6 @@ const SquidWidget = ({
toTokenAddress,
}: SwapParams) => {

console.log('fromChainId', fromChainId);
console.log('toChainId', toChainId);
console.log('fromTokenAddress', fromTokenAddress);
console.log('toTokenAddress', toTokenAddress);

// State to manage loading
const [loading, setLoading] = useState(true);

// Construct the config object
const config = {
integratorId: "squid-swap-widget",
Expand All @@ -46,19 +36,13 @@ const SquidWidget = ({
// Construct the iframe URL
const iframeUrl = `https://studio.squidrouter.com/iframe?config=${configString}`;

// Handler for when iframe loads
const handleIframeLoad = () => {
setLoading(false);
};

return (
<div style={{ position: "relative", width: "500", height: "684px" }}>
<iframe
title="squid_widget"
width="500"
height="684"
src={iframeUrl}
onLoad={handleIframeLoad}
style={{ display: "block" }}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ export const useEASAttestation = (
};

return { status, handleSwitchChain, handleAttest };
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ export const useGetAttestationData = (
}
},
});
};
};

0 comments on commit 96ba477

Please sign in to comment.