Skip to content

Commit

Permalink
feat: clear projects from expired rounds from cart (#2754)
Browse files Browse the repository at this point in the history
* feat: clear projects from expired rounds from cart

* chore: use isPresent instead of manual type assertion
  • Loading branch information
vacekj authored Dec 20, 2023
1 parent 96fc1f7 commit a39f457
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ import { MatchingEstimateTooltip } from "../../common/MatchingEstimateTooltip";
import { parseChainId } from "common/src/chains";
import { useDataLayer } from "data-layer";
import { fetchBalance } from "@wagmi/core";
import { isPresent } from "ts-is-present";

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 +133,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(isPresent);

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

5 comments on commit a39f457

@vercel
Copy link

@vercel vercel bot commented on a39f457 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

manager – ./packages/round-manager

manager-grants-stack.vercel.app
grants-stack-round-manager.vercel.app
manager-git-main-grants-stack.vercel.app
manager.gitcoin.co

@vercel
Copy link

@vercel vercel bot commented on a39f457 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

manager-staging – ./packages/round-manager

grants-stack-manager-staging.vercel.app
manager-staging-grants-stack.vercel.app
manager-staging-git-main-grants-stack.vercel.app

@vercel
Copy link

@vercel vercel bot commented on a39f457 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

explorer-staging – ./packages/grant-explorer

explorer-staging-git-main-grants-stack.vercel.app
grants-stack-explorer-staging.vercel.app
explorer-staging-grants-stack.vercel.app

@vercel
Copy link

@vercel vercel bot commented on a39f457 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-staging – ./packages/builder

grants-stack-builder-staging.vercel.app
builder-staging-grants-stack.vercel.app
builder-staging-git-main-grants-stack.vercel.app

@vercel
Copy link

@vercel vercel bot commented on a39f457 Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder – ./packages/builder

builder-grants-stack.vercel.app
builder-kappa-one.vercel.app
builder-git-main-grants-stack.vercel.app
builder.gitcoin.co

Please sign in to comment.