Skip to content

Commit

Permalink
fix: update encoding and format for farcaster share URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
veganbeef committed Oct 15, 2024
1 parent 72157d0 commit 3c88cb5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
23 changes: 17 additions & 6 deletions packages/grant-explorer/src/features/common/ShareButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ export const ShareButtons = ({
}): JSX.Element => {
const twitterShareUrl = createTwitterAttestationShareUrl(attestationLink);

const farcasterShareUrl = createFarcasterShareUrl(attestationLink);
const farcasterShareText = getFarcasterAttestationShareText();
const farcasterShareUrl = createFarcasterShareUrl(farcasterShareText, [
attestationLink,
]);

return (
<div className="z-30">
Expand Down Expand Up @@ -78,13 +81,21 @@ export function createTwitterAttestationShareUrl(attestationLink: string) {
)}`;
}

export function createFarcasterAttestationShareText(attestationLink: string) {
return `Certified public goods supporter 🫡\n\nMy contribution is now onchain—check out the visual that represents my impact.\n\nHat tip to @gitcoin 💚\n\n&embeds[${attestationLink}]=https://farcaster.xyz"}`;
export function getFarcasterAttestationShareText() {
const encodedText1 = encodeURIComponent(
`Certified public goods supporter 🫡\n\nMy contribution is now onchain—check out the visual that represents my impact.\n\nHat tip to `
);
const encodedText2 = encodeURIComponent(` 💚\n`);
// NB: mentions should not be encoded
return `${encodedText1}@gitcoin${encodedText2}`;
}

export function createFarcasterShareUrl(attestationLink: string) {
const shareText = createFarcasterAttestationShareText(attestationLink);
return `https://warpcast.com/~/compose?text=${encodeURIComponent(shareText)}`;
export function createFarcasterShareUrl(
shareText: string,
embedLinks: string[]
) {
// NB: embed links should not be encoded
return `https://warpcast.com/~/compose?text=${shareText}${embedLinks.forEach((link) => `&embeds[]=${link}`)}`;
}

type TwitterButtonParams = {
Expand Down
11 changes: 6 additions & 5 deletions packages/grant-explorer/src/features/round/ViewRoundPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { Box, Tab, Tabs } from "@chakra-ui/react";
import GenericModal from "../common/GenericModal";
import RoundStartCountdownBadge from "./RoundStartCountdownBadge";
import ApplicationsCountdownBanner from "./ApplicationsCountdownBanner";
import { createFarcasterShareUrl } from "../common/ShareButtons";

export default function ViewRound() {
datadogLogs.logger.info("====> Route: /round/:chainId/:roundId");
Expand Down Expand Up @@ -1164,15 +1165,15 @@ const ShareButton = ({
📈 $${formatAmount(totalUSDCrowdfunded.toFixed(2))} funded so far
🤝 ${formatAmount(totalDonations, true)} donations
👀 Check out ${roundName}’s stats!
${window.location.href}`;
`;

const twitterShareUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(
shareText
shareText + window.location.href
)}`;

const farcasterShareUrl = `https://warpcast.com/~/compose?text=${encodeURIComponent(
shareText
)}`;
const farcasterShareUrl = createFarcasterShareUrl(shareText, [
window.location.href,
]);

return (
<>
Expand Down

0 comments on commit 3c88cb5

Please sign in to comment.