From 58a969bb8f4d6a60d28139df48bac1fd6411ca90 Mon Sep 17 00:00:00 2001 From: adrianvrj Date: Thu, 7 Nov 2024 17:22:47 -0600 Subject: [PATCH] [feat] added tweet message --- frontend/README.md | 37 ++++++++++++++++++- frontend/gostarkme-web/app/app/page.tsx | 14 ++++--- .../components/dashboard/fundCard.tsx | 2 +- .../components/modules/Fund/Fund.tsx | 14 ++----- .../modules/confirmation/Confirmation.tsx | 17 ++++++--- .../confirmation/CreationConfirmation.tsx | 4 +- .../confirmation/DonationConfirmation.tsx | 4 +- .../modules/confirmation/VoteConfirmation.tsx | 4 +- .../components/modules/newfunding/Stages.tsx | 8 +++- .../gostarkme-web/components/ui/ShareOnX.tsx | 8 ++-- frontend/gostarkme-web/state/nFunds.ts | 7 +++- 11 files changed, 87 insertions(+), 32 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index 25a67a9..1d0c386 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -14,7 +14,42 @@ -- Comment the content of the file `frontend/gostarkme-web/next.config.mjs`. +- Comment the content of the file `frontend/gostarkme-web/next.config.mjs`. Adding only one element to the ```nextConfig``` object like this: + +``` +/** @type {import('next').NextConfig} */ +const nextConfig = { + /** + * Enable static exports for the App Router. + * + * @see https://nextjs.org/docs/app/building-your-application/deploying/static-exports + */ + // output: "export", + + /** + * Set base path. This is the slug of your GitHub repository. + * + * @see https://nextjs.org/docs/app/api-reference/next-config-js/basePath + */ + // basePath: "/gostarkme", + + // assetPrefix: 'https://web3wagers.github.io/gostarkme', + + /** + * Disable server-based image optimization. Next.js does not support + * dynamic features with static exports. + * + * @see https://nextjs.org/docs/app/api-reference/components/image#unoptimized + */ + // images: { + // unoptimized: true, + // }, + + reactStrictMode: false, + }; + + export default nextConfig; +``` ## Local Deployment diff --git a/frontend/gostarkme-web/app/app/page.tsx b/frontend/gostarkme-web/app/app/page.tsx index 90f7359..87a7f09 100644 --- a/frontend/gostarkme-web/app/app/page.tsx +++ b/frontend/gostarkme-web/app/app/page.tsx @@ -16,13 +16,12 @@ const Dashboard = () => { const wallet = useAtomValue(walletStarknetkitLatestAtom); - const [fundManagerContract, _setFundManagerContract] = useState(new Contract(fundManager, FUND_MANAGER_ADDR, wallet?.account)); - const [funds, setFunds] = useState([]); const [loading, setLoading] = useState(true); async function getFunds() { + const fundManagerContract = new Contract(fundManager, FUND_MANAGER_ADDR, wallet?.account); const id = await fundManagerContract.getCurrentId(); let fundings = []; for (let i = 1; i < id; i++) { @@ -63,15 +62,20 @@ const Dashboard = () => { href: "/" }} /> + {!wallet && +
+ Please connect your wallet to see funding dashboard. +
+ } - {loading &&
+ {loading && wallet &&
Loading funds...
} - {funds.length !== 0 && !loading && + {funds.length !== 0 && !loading && wallet &&
{funds.map((fund: { type: string; title: string; description: string; fund_id: string }, index: number) => ( @@ -79,7 +83,7 @@ const Dashboard = () => {
} - {funds.length === 0 && !loading && + {funds.length === 0 && !loading && wallet &&
There is no fundings to display. diff --git a/frontend/gostarkme-web/components/dashboard/fundCard.tsx b/frontend/gostarkme-web/components/dashboard/fundCard.tsx index 28b13a0..4b6cee2 100644 --- a/frontend/gostarkme-web/components/dashboard/fundCard.tsx +++ b/frontend/gostarkme-web/components/dashboard/fundCard.tsx @@ -22,7 +22,7 @@ const FundCards = ({ fund, index }: FundCardProps) => { const setClickedFund = useSetAtom(clickedFundState); function handleNav() { - setClickedFund(Number(fund.fund_id)); + setClickedFund({id: Number(fund.fund_id), name: fund.title}); } return ( diff --git a/frontend/gostarkme-web/components/modules/Fund/Fund.tsx b/frontend/gostarkme-web/components/modules/Fund/Fund.tsx index a963103..2407295 100644 --- a/frontend/gostarkme-web/components/modules/Fund/Fund.tsx +++ b/frontend/gostarkme-web/components/modules/Fund/Fund.tsx @@ -27,7 +27,7 @@ const Fund = () => { const clickedFund = useAtomValue(clickedFundState); async function getDetails() { - let addr = await fundManagerContract.getFund(clickedFund); + let addr = await fundManagerContract.getFund(clickedFund?.id); addr = "0x" + addr.toString(16); const fundContract = new Contract(fundAbi, addr, wallet?.account); @@ -51,16 +51,8 @@ const Fund = () => { let evidenceLink = await fundContract.get_evidence_link(); - if (evidenceLink.indexOf('https') <= 0) { - evidenceLink = "https://" + evidenceLink; - } - let contactHandle = await fundContract.get_contact_handle(); - if (contactHandle.indexOf('https') <= 0) { - contactHandle = "https://" + contactHandle; - } - setFund({ name: name, desc: desc, @@ -97,10 +89,10 @@ const Fund = () => {

{fund.desc}

Evidence

- {fund.evidenceLink} + {fund.evidenceLink}

Contact handle

- {fund.contactHandle} + {fund.contactHandle} {Number(fund.state) === 0 &&

Fund is currently innactive.

} {Number(fund.state) === 1 && } {Number(fund.state) === 2 && } diff --git a/frontend/gostarkme-web/components/modules/confirmation/Confirmation.tsx b/frontend/gostarkme-web/components/modules/confirmation/Confirmation.tsx index 5e5fcaa..edb75c4 100644 --- a/frontend/gostarkme-web/components/modules/confirmation/Confirmation.tsx +++ b/frontend/gostarkme-web/components/modules/confirmation/Confirmation.tsx @@ -1,15 +1,22 @@ 'use client'; -import React from "react"; +import React, { useEffect } from "react"; import CreationConfirmation from "./CreationConfirmation"; import VoteConfirmation from "./VoteConfirmation"; import DonationConfirmation from "./DonationConfirmation"; -import { useAtomValue } from "jotai"; +import { useAtom, useAtomValue } from "jotai"; import { latestTxAtom } from "@/state/latestTx"; import Navbar from "@/components/ui/Navbar"; import { navItems } from "@/constants"; +import { clickedFundState } from "@/state/nFunds"; +import { walletStarknetkitLatestAtom } from "@/state/connectedWallet"; const Confirmation = () => { const tx = useAtomValue(latestTxAtom); + const actualFund = useAtomValue(clickedFundState); + const voteMessage = ` ๐Ÿ—ณ๏ธ Just cast my vote for an amazing cause called ${actualFund?.name} on Go Stark Me! This fund needs more votes to start raising fundsโ€”every vote counts! Letโ€™s support projects that make a difference at https://web3wagers.github.io/gostarkme/ @web3_wagers ๐Ÿ™Œ๐Ÿ’ซ #GoStarkMe #Starknet #CommunityPower`; + const donationMessage = `๐Ÿ™Œ Proud to support ${actualFund?.name} on Go Stark Me! Donations make a difference. ๐Ÿ’ช Go ahead and donate at https://web3wagers.github.io/gostarkme/ @web3_wagers #Starknet #GoStarkMe #Web3Wagers`; + const newFundMessage = `๐Ÿš€ Just launched a new fund on Go Stark Me called ${actualFund?.name}! Iโ€™m raising support for an important cause, and every contribution makes a difference. Join me in making an impact at https://web3wagers.github.io/gostarkme/! ๐Ÿ’ช๐ŸŒ Check it out on @web3_wagers #GoStarkMe #Starknet #BlockchainForGood`; + return ( <> {

Success 🚀

{tx?.type === "newfund" && - + } {tx?.type === "vote" && - + } {tx?.type === "donation" && - + }
} diff --git a/frontend/gostarkme-web/components/modules/confirmation/CreationConfirmation.tsx b/frontend/gostarkme-web/components/modules/confirmation/CreationConfirmation.tsx index 975b5d7..fca5460 100644 --- a/frontend/gostarkme-web/components/modules/confirmation/CreationConfirmation.tsx +++ b/frontend/gostarkme-web/components/modules/confirmation/CreationConfirmation.tsx @@ -3,16 +3,18 @@ import React from "react"; interface CreationConfirmationProps { txHash: String; + message: String; } const CreationConfirmation: React.FC = ({ txHash, + message, }) => ( <>

Your funding was created, take a look at the transaction here.

Share your contribution via X to tell everyone how cool you are

- +
); diff --git a/frontend/gostarkme-web/components/modules/confirmation/DonationConfirmation.tsx b/frontend/gostarkme-web/components/modules/confirmation/DonationConfirmation.tsx index c0cb7ac..6641179 100644 --- a/frontend/gostarkme-web/components/modules/confirmation/DonationConfirmation.tsx +++ b/frontend/gostarkme-web/components/modules/confirmation/DonationConfirmation.tsx @@ -3,16 +3,18 @@ import React from "react"; interface DonationConfirmationProps { txHash: String; + message: String; } const DonationConfirmation: React.FC = ({ txHash, + message, }) => ( <>

Your donation was sent to the funding, take a look at the transaction here.

Share your contribution via X to tell everyone how cool you are

- +
); diff --git a/frontend/gostarkme-web/components/modules/confirmation/VoteConfirmation.tsx b/frontend/gostarkme-web/components/modules/confirmation/VoteConfirmation.tsx index 4f9d5be..2dfc05d 100644 --- a/frontend/gostarkme-web/components/modules/confirmation/VoteConfirmation.tsx +++ b/frontend/gostarkme-web/components/modules/confirmation/VoteConfirmation.tsx @@ -3,16 +3,18 @@ import React from "react"; interface VoteConfirmationProps { txHash: String; + message: String; } const VoteConfirmation: React.FC = ({ txHash, + message, }) => ( <>

Your vote was submitted, take a look at the transaction here.

Share your contribution via X to tell everyone how cool you are

- +
); diff --git a/frontend/gostarkme-web/components/modules/newfunding/Stages.tsx b/frontend/gostarkme-web/components/modules/newfunding/Stages.tsx index 2784624..1ea0929 100644 --- a/frontend/gostarkme-web/components/modules/newfunding/Stages.tsx +++ b/frontend/gostarkme-web/components/modules/newfunding/Stages.tsx @@ -5,10 +5,11 @@ import DescriptionStep from "./DescriptionStep"; import { Contract, wallet, InvokeFunctionResponse, shortString } from "starknet"; import { fundManager } from "@/contracts/abis/fundManager"; import { FUND_MANAGER_ADDR } from "@/constants"; -import { useAtom, useAtomValue } from "jotai"; +import { useAtom, useAtomValue, useSetAtom } from "jotai"; import { walletStarknetkitLatestAtom } from "@/state/connectedWallet"; import { latestTxAtom } from "@/state/latestTx"; import { useRouter } from "next/navigation"; +import { clickedFundState } from "@/state/nFunds"; const Stages = () => { const [currentStep, setCurrentStep] = useState(0); @@ -18,7 +19,9 @@ const Stages = () => { const [errors, setErrors] = useState({ fundingName: "", goal: "", evidenceLink: "", contactHandle: "" }); const [evidenceLink, setEvidenceLink] = useState(""); const [contactHandle, setContactHandle] = useState(""); - const [latestTx, setLatesTx] = useAtom(latestTxAtom); + const setLatesTx = useSetAtom(latestTxAtom); + const setActualFund = useSetAtom(clickedFundState); + const wallet = useAtomValue(walletStarknetkitLatestAtom); const router = useRouter(); @@ -66,6 +69,7 @@ const Stages = () => { fundManagerContract.newFund(fundingName, goal, evidenceLink, contactHandle, fundingDescription) .then(async (resp: InvokeFunctionResponse) => { setLatesTx({ txHash: resp.transaction_hash, type: "newfund" }); + setActualFund({id: 0, name: fundingName}); router.push("/app/confirmation"); }) .catch((e: any) => { console.log(e) }); diff --git a/frontend/gostarkme-web/components/ui/ShareOnX.tsx b/frontend/gostarkme-web/components/ui/ShareOnX.tsx index 0b4fae2..a3da1ae 100644 --- a/frontend/gostarkme-web/components/ui/ShareOnX.tsx +++ b/frontend/gostarkme-web/components/ui/ShareOnX.tsx @@ -2,14 +2,16 @@ import React from 'react'; interface ShareXButtonProps { - txHash: String; + message: String; } -const ShareXButton : React.FC = ({txHash}) => { +const ShareXButton : React.FC = ({message}) => { + const tweetText = encodeURIComponent(message.toString()); + const tweetUrl = `https://twitter.com/intent/tweet?text=${tweetText}`; return (