Skip to content

Commit 59dcdc1

Browse files
authored
feat: update twitter message, add tests (gitcoinco#2328)
1 parent c8a5cfe commit 59dcdc1

11 files changed

Lines changed: 294 additions & 72 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {
2+
Chain,
3+
fantom,
4+
fantomTestnet,
5+
goerli,
6+
mainnet,
7+
optimism,
8+
} from "wagmi/chains";
9+
import { arbitrum, arbitrumGoerli } from "viem/chains";
10+
import { pgnTestnet, pgn } from "common/src/chains";
11+
12+
const testnetChains = () => {
13+
return [
14+
goerli,
15+
{ ...fantomTestnet, iconUrl: "/logos/fantom-logo.svg" },
16+
pgnTestnet,
17+
arbitrumGoerli,
18+
];
19+
};
20+
21+
const mainnetChains = () => {
22+
return [
23+
mainnet,
24+
optimism,
25+
pgn,
26+
arbitrum,
27+
{ ...fantom, iconUrl: "/logos/fantom-logo.svg" },
28+
];
29+
};
30+
31+
export const allChains: Chain[] =
32+
process.env.REACT_APP_ENV === "development"
33+
? [...testnetChains(), ...mainnetChains()]
34+
: [...mainnetChains()];

packages/grant-explorer/src/app/wagmi.ts

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,10 @@ import {
1010
walletConnectWallet,
1111
metaMaskWallet,
1212
} from "@rainbow-me/rainbowkit/wallets";
13-
import {
14-
mainnet,
15-
goerli,
16-
fantom,
17-
fantomTestnet,
18-
optimism,
19-
Chain,
20-
} from "wagmi/chains";
2113
import { configureChains, createConfig } from "wagmi";
22-
23-
import { pgnTestnet, pgn } from "common/src/chains";
2414
import { publicProvider } from "wagmi/providers/public";
2515
import { infuraProvider } from "wagmi/providers/infura";
26-
import { arbitrumGoerli, arbitrum } from "viem/chains";
27-
28-
const testnetChains = () => {
29-
return [
30-
goerli,
31-
{ ...fantomTestnet, iconUrl: "/logos/fantom-logo.svg" },
32-
pgnTestnet,
33-
arbitrumGoerli,
34-
];
35-
};
36-
37-
const mainnetChains = () => {
38-
return [
39-
mainnet,
40-
optimism,
41-
pgn,
42-
arbitrum,
43-
{ ...fantom, iconUrl: "/logos/fantom-logo.svg" },
44-
];
45-
};
46-
47-
export const allChains: Chain[] =
48-
process.env.REACT_APP_ENV === "development"
49-
? [...testnetChains(), ...mainnetChains()]
50-
: [...mainnetChains()];
16+
import { allChains } from "./chainConfig";
5117

5218
export const { chains, publicClient, webSocketPublicClient } = configureChains(
5319
allChains,

packages/grant-explorer/src/checkoutStore.test.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useCheckoutStore } from "./checkoutStore";
2-
import { ProgressStatus } from "./features/api/types";
2+
import { CartProject, ProgressStatus } from "./features/api/types";
33
import { ChainId } from "common";
44
import { beforeEach } from "vitest";
5+
import { makeApprovedProjectData } from "./test-utils";
56

67
const store = useCheckoutStore;
78
const initialState = store.getState();
@@ -67,4 +68,17 @@ describe("Checkout Store", () => {
6768
ChainId.GOERLI_CHAIN_ID,
6869
]);
6970
});
71+
72+
it("chainsToCheckout manipulation", async () => {
73+
const projects: CartProject[] = [
74+
makeApprovedProjectData(),
75+
makeApprovedProjectData(),
76+
makeApprovedProjectData(),
77+
];
78+
expect(store.getState().checkedOutProjects).toEqual([]);
79+
80+
store.getState().setCheckedOutProjects(projects);
81+
expect(store.getState().checkedOutProjects).toStrictEqual(projects);
82+
expect(store.getState().getCheckedOutProjects()).toStrictEqual(projects);
83+
});
7084
});

packages/grant-explorer/src/checkoutStore.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
import { MRC_CONTRACTS } from "./features/api/contracts";
2525
import { groupBy, uniq } from "lodash-es";
2626
import { datadogLogs } from "@datadog/browser-logs";
27-
import { allChains } from "./app/wagmi";
27+
import { allChains } from "./app/chainConfig";
2828
import { WalletClient } from "wagmi";
2929
import { getContract, getWalletClient, PublicClient } from "@wagmi/core";
3030

@@ -54,6 +54,9 @@ interface CheckoutState {
5454
walletClient: WalletClient,
5555
publicClient: PublicClient
5656
) => Promise<void>;
57+
getCheckedOutProjects: () => CartProject[];
58+
checkedOutProjects: CartProject[];
59+
setCheckedOutProjects: (newArray: CartProject[]) => void;
5760
}
5861

5962
const defaultProgressStatusForAllChains = Object.fromEntries(
@@ -289,6 +292,9 @@ export const useCheckoutStore = create<CheckoutState>()(
289292
[chainId]: ProgressStatus.IS_SUCCESS,
290293
},
291294
}));
295+
set({
296+
checkedOutProjects: [...get().checkedOutProjects, ...donations],
297+
});
292298
} catch (error) {
293299
datadogLogs.logger.error(
294300
`error: vote - ${error}. Data - ${donations.toString()}`
@@ -305,6 +311,15 @@ export const useCheckoutStore = create<CheckoutState>()(
305311
}
306312
/* End main chain loop*/
307313
},
314+
checkedOutProjects: [],
315+
getCheckedOutProjects: () => {
316+
return get().checkedOutProjects;
317+
},
318+
setCheckedOutProjects: (newArray: CartProject[]) => {
319+
set({
320+
checkedOutProjects: newArray,
321+
});
322+
},
308323
}))
309324
);
310325

packages/grant-explorer/src/features/api/voting.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import mrcAbi from "./abi/multiRoundCheckout";
1414
import { ChainId } from "common";
1515
import { WalletClient } from "wagmi";
1616
import { getContract, getPublicClient } from "@wagmi/core";
17-
import { allChains } from "../../app/wagmi";
17+
import { allChains } from "../../app/chainConfig";
1818

1919
export type PermitSignature = {
2020
v: number;

packages/grant-explorer/src/features/discovery/RoundCard.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ChainId, renderToPlainText, truncateDescription } from "common";
22
import { RoundOverview } from "../api/rounds";
3-
import { getDaysLeft } from "../api/utils";
3+
import { getDaysLeft, payoutTokens } from "../api/utils";
44
import {
55
BasicCard,
66
CardContent,
@@ -19,13 +19,23 @@ type RoundCardProps = {
1919

2020
const RoundCard = (props: RoundCardProps) => {
2121
const daysLeft = getDaysLeft(Number(props.round.roundEndTime));
22+
const chainIdEnumValue = ChainId[props.round.chainId as keyof typeof ChainId];
2223

23-
const { data: tokenData } = useToken({
24+
const { data } = useToken({
2425
address: getAddress(props.round.token),
2526
chainId: Number(props.round.chainId),
2627
});
2728

28-
const chainIdEnumValue = ChainId[props.round.chainId as keyof typeof ChainId];
29+
const nativePayoutToken = payoutTokens.find(
30+
(t) =>
31+
t.chainId === chainIdEnumValue &&
32+
t.address === getAddress(props.round.token)
33+
);
34+
35+
const tokenData = data ?? {
36+
...nativePayoutToken,
37+
symbol: nativePayoutToken?.name ?? "ETH",
38+
};
2939

3040
const approvedApplicationsCount = props.round.projects?.length ?? 0;
3141

packages/grant-explorer/src/features/round/ThankYou.ignored.tsx

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { fireEvent, screen } from "@testing-library/react";
2+
import ThankYou, {
3+
createTwitterShareText,
4+
createTwitterShareUrl,
5+
TwitterButton,
6+
} from "./ThankYou";
7+
import { renderWithContext } from "../../test-utils";
8+
import { zeroAddress } from "viem";
9+
import { expect } from "vitest";
10+
11+
vi.mock("wagmi", async () => {
12+
const actual = await vi.importActual<typeof import("wagmi")>("wagmi");
13+
return {
14+
...actual,
15+
useAccount: () => ({
16+
address: "",
17+
}),
18+
};
19+
});
20+
21+
describe("<TwitterButton />", () => {
22+
it("Should render text inside button", async () => {
23+
renderWithContext(
24+
<TwitterButton address={zeroAddress} isMrc={true} roundName={"Round"} />
25+
);
26+
27+
expect(screen.getByText("Share on Twitter")).toBeInTheDocument();
28+
});
29+
30+
it("Should redirect to twitter with correct text", async () => {
31+
const openSpy = vi.spyOn(window, "open").mockImplementation(() => {
32+
return null;
33+
});
34+
35+
renderWithContext(
36+
<TwitterButton address={zeroAddress} isMrc={true} roundName={"Round"} />
37+
);
38+
39+
fireEvent.click(screen.getByText("Share on Twitter"));
40+
expect(openSpy).toHaveBeenCalledOnce();
41+
expect(openSpy).toHaveBeenCalledWith(
42+
"https://twitter.com/share?text=I%20just%20donated%20to%20Round%20and%20more%20on%20%40gitcoin.%20Join%20me%20in%20making%20a%20difference%20by%20donating%20today%2C%20and%20check%20out%20the%20projects%20I%20supported%20on%20my%20Donation%20History%20page!%0A%0Ahttps%3A%2F%2Fexplorer.gitcoin.co%2F%23%2Fcontributors%2F0x0000000000000000000000000000000000000000",
43+
"_blank"
44+
);
45+
});
46+
});
47+
48+
describe("createTwitterShareUrl", () => {
49+
it("encodes the url properly", function () {
50+
expect(
51+
createTwitterShareUrl({
52+
address: zeroAddress,
53+
isMrc: false,
54+
})
55+
).toEqual(
56+
"https://twitter.com/share?text=I%20just%20donated%20to%20a%20round%20on%20%40gitcoin.%20Join%20me%20in%20making%20a%20difference%20by%20donating%20today%2C%20and%20check%20out%20the%20projects%20I%20supported%20on%20my%20Donation%20History%20page!%0A%0Ahttps%3A%2F%2Fexplorer.gitcoin.co%2F%23%2Fcontributors%2F0x0000000000000000000000000000000000000000"
57+
);
58+
});
59+
});
60+
61+
describe("createTwiterShareText", () => {
62+
it("handles no round name", function () {
63+
expect(
64+
createTwitterShareText({
65+
address: zeroAddress,
66+
isMrc: false,
67+
})
68+
).toEqual(
69+
`I just donated to a round on @gitcoin. Join me in making a difference by donating today, and check out the projects I supported on my Donation History page!
70+
71+
https://explorer.gitcoin.co/#/contributors/0x0000000000000000000000000000000000000000`
72+
);
73+
});
74+
75+
it("handles no round name", function () {
76+
expect(
77+
createTwitterShareText({
78+
address: zeroAddress,
79+
isMrc: false,
80+
})
81+
).toEqual(
82+
`I just donated to a round on @gitcoin. Join me in making a difference by donating today, and check out the projects I supported on my Donation History page!
83+
84+
https://explorer.gitcoin.co/#/contributors/0x0000000000000000000000000000000000000000`
85+
);
86+
});
87+
88+
it("handles one round, no mrc", function () {
89+
expect(
90+
createTwitterShareText({
91+
address: zeroAddress,
92+
isMrc: false,
93+
roundName: "Round",
94+
})
95+
).toEqual(
96+
`I just donated to Round on @gitcoin. Join me in making a difference by donating today, and check out the projects I supported on my Donation History page!
97+
98+
https://explorer.gitcoin.co/#/contributors/0x0000000000000000000000000000000000000000`
99+
);
100+
});
101+
102+
it("handles one round plus mrc", function () {
103+
expect(
104+
createTwitterShareText({
105+
address: zeroAddress,
106+
isMrc: true,
107+
roundName: "Round",
108+
})
109+
).toEqual(
110+
`I just donated to Round and more on @gitcoin. Join me in making a difference by donating today, and check out the projects I supported on my Donation History page!
111+
112+
https://explorer.gitcoin.co/#/contributors/0x0000000000000000000000000000000000000000`
113+
);
114+
});
115+
});
116+
117+
describe.skip("<ThankYou/>", () => {
118+
it("Should show twitter, go back home, view your trasaction button", async () => {
119+
renderWithContext(<ThankYou />);
120+
121+
expect(screen.queryByTestId("view-tx-button")).toBeInTheDocument();
122+
expect(screen.queryByTestId("twitter-button")).toBeInTheDocument();
123+
expect(screen.queryByTestId("home-button")).toBeInTheDocument();
124+
});
125+
});

0 commit comments

Comments
 (0)