From ddebd6b3c28c84cfd08f4498b88f83f6f412cc0a Mon Sep 17 00:00:00 2001 From: Massimiliano Mirra Date: Wed, 3 Jan 2024 19:26:44 +0000 Subject: [PATCH] fix: copy correct url when clicking "share profile" (#2750) --- .../features/contributors/DonationsTable.tsx | 200 +++++++++--------- .../contributors/ViewContributionHistory.tsx | 4 +- .../ViewContributionHistory.test.tsx | 11 +- 3 files changed, 113 insertions(+), 102 deletions(-) diff --git a/packages/grant-explorer/src/features/contributors/DonationsTable.tsx b/packages/grant-explorer/src/features/contributors/DonationsTable.tsx index 7126706636..2691d14d16 100644 --- a/packages/grant-explorer/src/features/contributors/DonationsTable.tsx +++ b/packages/grant-explorer/src/features/contributors/DonationsTable.tsx @@ -22,116 +22,118 @@ export function DonationsTable(props: { className="border-collapse w-full" data-testid="donation-history-table" > - - Project - -
Donation
-
- - -

- The displayed amount in USD reflects
- the value at the time of your donation. -

-
-
- - - Transaction Information - - - {props.contributions.length > 0 && - props.contributions - .map((contributions) => { - return contributions.data.map((contribution) => ({ - ...contribution, - chainId: contributions.chainId, - })); - }) - .flat() - .sort((a, b) => Number(b.timestamp - a.timestamp)) - .map((contribution) => { - const tokenId = - contribution.token.toLowerCase() + "-" + contribution.chainId; - const token = props.tokens[tokenId]; + + + Project + +
Donation
+
+ + +

+ The displayed amount in USD reflects
+ the value at the time of your donation. +

+
+
+ + + Transaction Information + + + {props.contributions.length > 0 && + props.contributions + .map((contributions) => { + return contributions.data.map((contribution) => ({ + ...contribution, + chainId: contributions.chainId, + })); + }) + .flat() + .sort((a, b) => Number(b.timestamp - a.timestamp)) + .map((contribution) => { + const tokenId = + contribution.token.toLowerCase() + "-" + contribution.chainId; + const token = props.tokens[tokenId]; - let formattedAmount = "N/A"; + let formattedAmount = "N/A"; - if (token) { - formattedAmount = `${formatUnits( - BigInt(contribution.amount), - token.decimal - )} ${token.name}`; - } + if (token) { + formattedAmount = `${formatUnits( + BigInt(contribution.amount), + token.decimal + )} ${token.name}`; + } - return ( - - -
-
-
- Round Chain Logo + return ( + + +
+
+
+ Round Chain Logo + + {contribution.roundName} + + +
- {contribution.roundName} + {contribution.projectTitle} -
- - {contribution.projectTitle} -
-
- {/* Todo: display contribution timestamp */} - {/*
4 mins ago
*/} - - - {formattedAmount} -
- ${contribution.amountUSD.toFixed(2)} -
- - -
- -
- - - ); - })} + {/* Todo: display contribution timestamp */} + {/*
4 mins ago
*/} + + + {formattedAmount} +
+ ${contribution.amountUSD.toFixed(2)} +
+ + +
+ +
+ + + ); + })} + {props.contributions.length === 0 && (
diff --git a/packages/grant-explorer/src/features/contributors/ViewContributionHistory.tsx b/packages/grant-explorer/src/features/contributors/ViewContributionHistory.tsx index 242d12dcd7..5e3ad99306 100644 --- a/packages/grant-explorer/src/features/contributors/ViewContributionHistory.tsx +++ b/packages/grant-explorer/src/features/contributors/ViewContributionHistory.tsx @@ -221,7 +221,7 @@ export function ViewContributionHistory(props: {
@@ -307,7 +307,7 @@ export function ViewContributionHistoryWithoutDonations(props: {
diff --git a/packages/grant-explorer/src/features/contributors/__tests__/ViewContributionHistory.test.tsx b/packages/grant-explorer/src/features/contributors/__tests__/ViewContributionHistory.test.tsx index 906acdae62..42c5d547a9 100644 --- a/packages/grant-explorer/src/features/contributors/__tests__/ViewContributionHistory.test.tsx +++ b/packages/grant-explorer/src/features/contributors/__tests__/ViewContributionHistory.test.tsx @@ -1,4 +1,4 @@ -import { render, screen, waitFor } from "@testing-library/react"; +import { fireEvent, render, screen, waitFor } from "@testing-library/react"; import { faker } from "@faker-js/faker"; import { ViewContributionHistory, @@ -125,6 +125,10 @@ vi.mock("wagmi", async () => { }; }); +Object.assign(navigator, { + clipboard: { writeText: vi.fn() }, +}); + describe("", () => { beforeEach(() => { vi.clearAllMocks(); @@ -191,5 +195,10 @@ describe("", () => { screen.getByText(mockAddress.slice(0, 6) + "..." + mockAddress.slice(-6)) ).toBeInTheDocument(); expect(screen.getByText("Share Profile")).toBeInTheDocument(); + + fireEvent.click(screen.getByText("Share Profile")); + expect(navigator.clipboard.writeText).toHaveBeenCalledWith( + expect.stringMatching("http://localhost:3000/#/contributors/") + ); }); });