Skip to content

Commit

Permalink
feat: clear projects from expired rounds from cart
Browse files Browse the repository at this point in the history
  • Loading branch information
vacekj committed Dec 19, 2023
1 parent 39ce901 commit 8748a3b
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ export function SummaryContainer() {
const { data: walletClient } = useWalletClient();
const navigate = useNavigate();
const { address, isConnected } = useAccount();
const { projects, getVotingTokenForChain, chainToVotingToken } =
useCartStorage();
const {
projects,
getVotingTokenForChain,
chainToVotingToken,
remove: removeProjectFromCart,
} = useCartStorage();
const { checkout, voteStatus, chainsToCheckout } = useCheckoutStore();
const dataLayer = useDataLayer();

Expand Down Expand Up @@ -128,6 +132,25 @@ export function SummaryContainer() {
);
});

/** useEffect to clear projects from expired rounds (no longer accepting donations) */
useEffect(() => {
if (!rounds) {
return;
}
/*get rounds that have expired */
const expiredRounds = rounds
.filter((round) => round.roundEndTime.getTime() < Date.now())
.map((round) => round.id)
.filter((id): id is string => id !== undefined);

const expiredProjects = projects.filter((project) =>
expiredRounds.includes(project.roundId)
);
expiredProjects.forEach((project) => {
removeProjectFromCart(project.grantApplicationId);
});
}, [projects, removeProjectFromCart, rounds]);

const [clickedSubmit, setClickedSubmit] = useState(false);

useEffect(() => {
Expand Down

0 comments on commit 8748a3b

Please sign in to comment.