Skip to content

fixes attestation store #3721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions packages/grant-explorer/src/attestationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,45 @@ import { persist } from "zustand/middleware";
import { Hex } from "viem";

interface AttestationState {
checkedOutTransactions: Hex[];
addCheckedOutTransaction: (tx: Hex) => void;
getCheckedOutTransactions: () => Hex[];
checkedOutTransactions: Record<Hex, Hex[]>;
addCheckedOutTransaction: (tx: Hex, address?: Hex) => void;
getCheckedOutTransactions: (address?: Hex) => Hex[];
cleanCheckedOutTransactions: () => void;
}

export const useAttestationStore = create<AttestationState>()(
persist(
devtools((set, get) => ({
checkedOutTransactions: [],
addCheckedOutTransaction: (tx: Hex) => {
checkedOutTransactions: {},
addCheckedOutTransaction: (tx: Hex, address?: Hex) => {
if (!address) {
return;
}
set((oldState) => ({
checkedOutTransactions: [...oldState.checkedOutTransactions, tx],
checkedOutTransactions: {
...oldState.checkedOutTransactions,
[address]: [
...(oldState.checkedOutTransactions[address] || []),
tx,
],
},
}));
},
getCheckedOutTransactions: () => {
return get().checkedOutTransactions;
getCheckedOutTransactions: (address?: Hex) => {
if (!address) {
return [];
}
return get().checkedOutTransactions[address] || [];
},
cleanCheckedOutTransactions: () => {
set({
checkedOutTransactions: [],
checkedOutTransactions: {},
});
},
})),
{
name: "attestation-store",
version: 1,
version: 1.01,
}
)
);
3 changes: 2 additions & 1 deletion packages/grant-explorer/src/checkoutStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const useCheckoutStore = create<CheckoutState>()(
walletClient: WalletClient,
connector: Connector
) => {
const userAddress = walletClient.account?.address;
const chainIdsToCheckOut = chainsToCheckout.map((chain) => chain.chainId);
get().setChainsToCheckout(
uniq([...get().chainsToCheckout, ...chainIdsToCheckOut])
Expand Down Expand Up @@ -325,7 +326,7 @@ export const useCheckoutStore = create<CheckoutState>()(
});
useAttestationStore
.getState()
.addCheckedOutTransaction(receipt.transactionHash);
.addCheckedOutTransaction(receipt.transactionHash, userAddress);
} catch (error) {
let context: Record<string, unknown> = {
chainId,
Expand Down
13 changes: 6 additions & 7 deletions packages/grant-explorer/src/features/round/ThankYou.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default function ThankYou() {
}, [minted]);

const transactions = useAttestationStore((state) =>
state.getCheckedOutTransactions()
state.getCheckedOutTransactions(address)
);

const handleSelectBackground = (option: string) => {
Expand Down Expand Up @@ -169,7 +169,6 @@ export default function ThankYou() {
? false
: balance.value < attestationFee + (gasEstimation ?? 0n);


return (
<>
<Navbar />
Expand Down Expand Up @@ -201,13 +200,13 @@ export default function ThankYou() {
Mint your Impact
</h1>
<p className="mt-1 text-lg font-modern-era-regular">
Capture your contribution onchain with an
attestation and receive a unique visual that
symbolizes your donation.
Capture your contribution onchain with an attestation
and receive a unique visual that symbolizes your
donation.
</p>
<p className="my-2 text-lg font-modern-era-regular">
This visual reflects your onchain attestation,
marking your support in a meaningful way.
This visual reflects your onchain attestation, marking
your support in a meaningful way.
</p>
</div>
<PreviewFrame
Expand Down