Skip to content

Commit 6ad987f

Browse files
committed
chore: split up summarybox
1 parent 7965591 commit 6ad987f

File tree

2 files changed

+52
-36
lines changed

2 files changed

+52
-36
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { BigNumber, ethers } from "ethers";
2+
import React from "react";
3+
import { PayoutToken } from "../../api/types";
4+
type SummaryBoxProps = {
5+
payoutTokenPrice: number | undefined;
6+
totalDonation: BigNumber;
7+
selectedPayoutToken: PayoutToken;
8+
};
9+
export function Summary({
10+
payoutTokenPrice,
11+
totalDonation,
12+
selectedPayoutToken,
13+
}: SummaryBoxProps) {
14+
const totalDonationInUSD =
15+
payoutTokenPrice &&
16+
Number(
17+
ethers.utils.formatUnits(totalDonation, selectedPayoutToken.decimal)
18+
) * Number(payoutTokenPrice.toFixed(2));
19+
20+
return (
21+
<div className="shrink mb-5 block px-[16px] py-4 rounded-lg shadow-lg bg-white border border-violet-400 font-semibold">
22+
<h2 className="text-xl border-b-2 pb-2">Summary</h2>
23+
<div className="flex justify-between mt-4">
24+
<p>Your Contribution</p>
25+
<p>
26+
<span data-testid={"totalDonation"} className="mr-2">
27+
{ethers.utils.formatUnits(
28+
totalDonation,
29+
selectedPayoutToken.decimal
30+
)}
31+
</span>
32+
<span data-testid={"summaryPayoutToken"}>
33+
{selectedPayoutToken.name}
34+
</span>
35+
</p>
36+
</div>
37+
{payoutTokenPrice && (
38+
<div className="flex flex-row-reverse mt-2">
39+
<p className="text-[14px] text-grey-400">
40+
$ {totalDonationInUSD?.toFixed(2)}
41+
</p>
42+
</div>
43+
)}
44+
</div>
45+
);
46+
}

packages/grant-explorer/src/features/round/ViewCartPage/ViewCartPage.tsx

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { ConfirmationModalBody } from "./ConfirmationModalBody";
4343
import { InfoModalBody } from "./InfoModalBody";
4444
import { Header } from "./Header";
4545
import { ApplyTooltip } from "./ApplyTooltip";
46+
import { Summary } from "./SummaryBox";
4647

4748
export default function ViewCart() {
4849
const { chainId, roundId } = useParams();
@@ -313,7 +314,11 @@ export default function ViewCart() {
313314
return (
314315
<div className="order-first md:order-last">
315316
<div>
316-
<Summary />
317+
<Summary
318+
payoutTokenPrice={payoutTokenPrice}
319+
selectedPayoutToken={selectedPayoutToken}
320+
totalDonation={totalDonation}
321+
/>
317322
<Button
318323
$variant="solid"
319324
data-testid="handle-confirmation"
@@ -564,41 +569,6 @@ export default function ViewCart() {
564569
);
565570
}
566571

567-
function Summary() {
568-
const totalDonationInUSD =
569-
payoutTokenPrice &&
570-
Number(
571-
ethers.utils.formatUnits(totalDonation, selectedPayoutToken.decimal)
572-
) * Number(payoutTokenPrice.toFixed(2));
573-
574-
return (
575-
<div className="shrink mb-5 block px-[16px] py-4 rounded-lg shadow-lg bg-white border border-violet-400 font-semibold">
576-
<h2 className="text-xl border-b-2 pb-2">Summary</h2>
577-
<div className="flex justify-between mt-4">
578-
<p>Your Contribution</p>
579-
<p>
580-
<span data-testid={"totalDonation"} className="mr-2">
581-
{ethers.utils.formatUnits(
582-
totalDonation,
583-
selectedPayoutToken.decimal
584-
)}
585-
</span>
586-
<span data-testid={"summaryPayoutToken"}>
587-
{selectedPayoutToken.name}
588-
</span>
589-
</p>
590-
</div>
591-
{payoutTokenPrice && (
592-
<div className="flex flex-row-reverse mt-2">
593-
<p className="text-[14px] text-grey-400">
594-
$ {totalDonationInUSD?.toFixed(2)}
595-
</p>
596-
</div>
597-
)}
598-
</div>
599-
);
600-
}
601-
602572
function updateDonations(
603573
projectRegistryId: string,
604574
amount: string,

0 commit comments

Comments
 (0)