diff --git a/.eslintrc.json b/.eslintrc.json index 8d79a925..0304b37b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -56,9 +56,7 @@ "allowSeparatedGroups": true } ], - // turn on errors for missing imports "import/no-unresolved": "error", - // "import/no-named-as-default-member": "off", "import/order": [ "error", { @@ -92,6 +90,9 @@ } } ], + "import/no-default-export": [ + "warn" + ], "no-unused-vars": "off", "@typescript-eslint/no-unused-vars": [ "warn", @@ -100,5 +101,23 @@ "varsIgnorePattern": "^_" } ] - } + }, + "overrides": [ + { + "files": [ + "src/pages/**/*" + ], + "rules": { + "import/no-default-export": "off" + } + }, + { + "files": [ + "src/app/**/{page,layout,not-found}.tsx" + ], + "rules": { + "import/no-default-export": "off" + } + } + ] } \ No newline at end of file diff --git a/src/modules/pot/components/TimeLeft.tsx b/src/common/ui/components/_legacy/TimeLeft.tsx similarity index 94% rename from src/modules/pot/components/TimeLeft.tsx rename to src/common/ui/components/_legacy/TimeLeft.tsx index 77463032..e8715905 100644 --- a/src/modules/pot/components/TimeLeft.tsx +++ b/src/common/ui/components/_legacy/TimeLeft.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from "react"; -const TimeLeft = ({ daysLeft }: { daysLeft: number }) => { +export const TimeLeft = ({ daysLeft }: { daysLeft: number }) => { const [timeLeft, setTimeLeft] = useState("-"); function formatTimeLeft(targetTimestamp: number) { @@ -43,4 +43,3 @@ const TimeLeft = ({ daysLeft }: { daysLeft: number }) => { return timeLeft; }; -export default TimeLeft; diff --git a/src/modules/pot/components/ActivePots.tsx b/src/modules/pot/components/ActivePots.tsx index e38ba2f5..e1efa2e4 100644 --- a/src/modules/pot/components/ActivePots.tsx +++ b/src/modules/pot/components/ActivePots.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useMemo, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import Big from "big.js"; @@ -10,7 +10,7 @@ import { POT_SORT_OPTIONS, POT_STATUSES } from "../constants"; import { useFilteredPots } from "../hooks"; import { filters } from "../utils/filters"; -const ActivePots = () => { +export const ActivePots = () => { const [categoryFilter, setCategoryFilter] = useState(null); // Fetch Pots @@ -119,4 +119,3 @@ const ActivePots = () => { ); }; -export default ActivePots; diff --git a/src/modules/pot/components/Banner.tsx b/src/modules/pot/components/Banner.tsx deleted file mode 100644 index 56094188..00000000 --- a/src/modules/pot/components/Banner.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import { useEffect, useState } from "react"; - -import Link from "next/link"; - -import { potFactoryClient } from "@/common/contracts/core"; -import { Button } from "@/common/ui/components"; -import { useWallet } from "@/modules/auth"; -import routesPath from "@/modules/core/routes"; - -const Banner = () => { - const { wallet } = useWallet(); - - const [isPotDeploymentAvailable, updatePotDeploymentAvailability] = useState(false); - - useEffect(() => { - if (wallet?.accountId) { - potFactoryClient - .isDeploymentAvailable({ - accountId: wallet.accountId, - }) - .then(updatePotDeploymentAvailability); - } - }, [wallet?.accountId]); - - return ( -
-
-

Explore Pots

-

- Donate to Matching Rounds
to Get Your Contributions - Amplified. -

-
- {isPotDeploymentAvailable && ( - - )} - - - -
-
-
- ); -}; - -export default Banner; diff --git a/src/modules/pot/components/ChallengeModal.tsx b/src/modules/pot/components/ChallengeModal.tsx index 8a804afc..b3a52ac9 100644 --- a/src/modules/pot/components/ChallengeModal.tsx +++ b/src/modules/pot/components/ChallengeModal.tsx @@ -23,7 +23,7 @@ type Props = { previousChallenge?: Challenge; }; -const ChallengeModal = ({ open, onCloseClick, potDetail, previousChallenge }: Props) => { +export const ChallengeModal = ({ open, onCloseClick, potDetail, previousChallenge }: Props) => { const { actAsDao, accountId } = useTypedSelector((state) => state.nav); // AccountID (Address) @@ -79,5 +79,3 @@ const ChallengeModal = ({ open, onCloseClick, potDetail, previousChallenge }: Pr ); }; - -export default ChallengeModal; diff --git a/src/modules/pot/components/PoolAllocationTable/index.tsx b/src/modules/pot/components/PoolAllocationTable/index.tsx deleted file mode 100644 index 4b40ced0..00000000 --- a/src/modules/pot/components/PoolAllocationTable/index.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { Pot } from "@/common/api/indexer"; - -import Table from "./Table"; -import { useOrderedDonations } from "../../hooks"; - -export const PoolAllocationTable = ({ potDetail }: { potDetail: Pot }) => { - const { - orderedPayouts, - totalAmountNearPayouts, - orderedDonations, - uniqueDonationDonors, - totalAmountNearDonations, - } = useOrderedDonations(potDetail.account); - - const { public_donations_count } = potDetail; - - if (public_donations_count > 0 && orderedPayouts.length > 0) { - return ( - - ); - } else if (orderedDonations.length > 0) { - return ( -
- ); - } -}; - -export default PoolAllocationTable; diff --git a/src/modules/pot/components/PotCard.tsx b/src/modules/pot/components/PotCard.tsx index 95bdbc3a..abf8b92b 100644 --- a/src/modules/pot/components/PotCard.tsx +++ b/src/modules/pot/components/PotCard.tsx @@ -4,15 +4,15 @@ import { Pot } from "@/common/api/indexer"; import routesPath from "@/modules/core/routes"; import Indicator from "./Indicator"; -import Tag from "./Tag"; +import { PotTag } from "./PotTag"; import useNearAndUsdByPot from "../hooks/useNearAndUsdByPot"; import getPotTags from "../utils/getPotTags"; -type Props = { +export type PotCardProps = { pot: Pot; }; -export const PotCard = ({ pot }: Props) => { +export const PotCard: React.FC = ({ pot }) => { const { amountNear, amountUsd } = useNearAndUsdByPot({ pot }); const preLoadingText = `Pot ${pot.account} not found.`; @@ -60,7 +60,7 @@ export const PotCard = ({ pot }: Props) => { {tags.map( (tag) => tag.visibility && ( - { ); }; - -export default PotCard; diff --git a/src/modules/pot/components/PotHero.tsx b/src/modules/pot/components/PotHero.tsx index 46245861..7df7636c 100644 --- a/src/modules/pot/components/PotHero.tsx +++ b/src/modules/pot/components/PotHero.tsx @@ -16,11 +16,11 @@ import { DonateToPotProjects } from "@/modules/donation"; import { TokenTotalValue } from "@/modules/token"; import { useTypedSelector } from "@/store"; -import ChallengeModal from "./ChallengeModal"; +import { ChallengeModal } from "./ChallengeModal"; import FundMatchingPoolModal from "./FundMatchingPoolModal"; import NewApplicationModal from "./NewApplicationModal"; -import { PoolAllocationTable } from "./PoolAllocationTable"; import { PotApplicationRequirements } from "./PotApplicationRequirements"; +import { PotStats } from "./PotStats"; import { PotTimeline } from "./PotTimeline"; import { usePotUserPermissions } from "../hooks/permissions"; import { isPotVotingBased } from "../utils/voting"; @@ -145,7 +145,7 @@ export const PotHero: React.FC = ({ potId }) => { {isVotingBasedPot ? ( ) : ( - pot && + pot && )} {isSignedIn && ( diff --git a/src/modules/pot/components/PoolAllocationTable/Table/index.tsx b/src/modules/pot/components/PotStats.tsx similarity index 72% rename from src/modules/pot/components/PoolAllocationTable/Table/index.tsx rename to src/modules/pot/components/PotStats.tsx index 5447016f..4820b963 100644 --- a/src/modules/pot/components/PoolAllocationTable/Table/index.tsx +++ b/src/modules/pot/components/PotStats.tsx @@ -3,14 +3,15 @@ import { useState } from "react"; import Link from "next/link"; import { coingecko } from "@/common/api/coingecko"; +import { Pot } from "@/common/api/indexer"; import { Toggle } from "@/common/assets/svgs"; import { truncate } from "@/common/lib"; import { AccountProfilePicture } from "@/modules/core"; import routesPath from "@/modules/core/routes"; -import { JoinDonation } from "@/modules/pot/hooks"; +import { JoinDonation, useOrderedDonations } from "@/modules/pot/hooks"; import { useProfileData } from "@/modules/profile"; -import { Container, Row } from "./styles"; +import { Container, Row } from "./styled"; const Table = ({ donations, @@ -101,4 +102,34 @@ const Donation = ({ donorId, nearAmount, index, usdToggle }: DonationProps) => { ); }; -export default Table; +export const PotStats = ({ potDetail }: { potDetail: Pot }) => { + const { + orderedPayouts, + totalAmountNearPayouts, + orderedDonations, + uniqueDonationDonors, + totalAmountNearDonations, + } = useOrderedDonations(potDetail.account); + + const { public_donations_count } = potDetail; + + if (public_donations_count > 0 && orderedPayouts.length > 0) { + return ( +
+ ); + } else if (orderedDonations.length > 0) { + return ( +
+ ); + } +}; diff --git a/src/modules/pot/components/PotTag.tsx b/src/modules/pot/components/PotTag.tsx new file mode 100644 index 00000000..7192c041 --- /dev/null +++ b/src/modules/pot/components/PotTag.tsx @@ -0,0 +1,35 @@ +export type PotTagProps = { + backgroundColor?: string; + borderColor?: string; + textColor?: string; + text: string; + preElements?: React.ReactNode; +}; + +export const PotTag: React.FC = ({ + backgroundColor, + borderColor, + textColor, + text, + preElements, +}) => ( +
+ {preElements} + +

+ {text} +

+
+); diff --git a/src/modules/pot/components/PotTimeline.tsx b/src/modules/pot/components/PotTimeline.tsx index 67d391b4..e3eef69b 100644 --- a/src/modules/pot/components/PotTimeline.tsx +++ b/src/modules/pot/components/PotTimeline.tsx @@ -6,7 +6,7 @@ import { ByPotId } from "@/common/api/indexer"; import { cn } from "@/common/ui/utils"; import { PotTimelineFragment } from "./PotTimelineFragment"; -import TimeLeft from "./TimeLeft"; +import { TimeLeft } from "@/common/ui/components/_legacy/TimeLeft"; import { usePotLifecycle } from "../hooks/lifecycle"; /** diff --git a/src/modules/pot/components/Tag.tsx b/src/modules/pot/components/Tag.tsx deleted file mode 100644 index cc4b4b5c..00000000 --- a/src/modules/pot/components/Tag.tsx +++ /dev/null @@ -1,33 +0,0 @@ -type Props = { - backgroundColor?: string; - borderColor?: string; - textColor?: string; - textStyle?: any; - text: string; - preElements?: any; -}; - -const Tag = ({ backgroundColor, borderColor, textColor, text, preElements }: Props) => { - return ( -
- {preElements} -

- {text} -

-
- ); -}; - -export default Tag; diff --git a/src/modules/pot/components/index.ts b/src/modules/pot/components/index.ts index 7e500767..e4afa5be 100644 --- a/src/modules/pot/components/index.ts +++ b/src/modules/pot/components/index.ts @@ -1,8 +1,4 @@ export { default as Indicator } from "./Indicator"; -export { default as PotCard } from "./PotCard"; -export * from "./PotLayout"; -export { default as Tag } from "./Tag"; -export { default as TimeLeft } from "./TimeLeft"; export { default as DonationsTable } from "./DonationsTable"; export { default as SponsorsBoard } from "./SponsorsBoard/SponsorsBoard"; export { default as SponsorsTable } from "./SponsorsTable/SponsorsTable"; diff --git a/src/modules/pot/components/PoolAllocationTable/Table/styles.ts b/src/modules/pot/components/styled.ts similarity index 100% rename from src/modules/pot/components/PoolAllocationTable/Table/styles.ts rename to src/modules/pot/components/styled.ts diff --git a/src/modules/pot/index.ts b/src/modules/pot/index.ts index ff69e5f3..0d92fffb 100644 --- a/src/modules/pot/index.ts +++ b/src/modules/pot/index.ts @@ -1,4 +1,7 @@ export * from "./components"; +export * from "./components/ActivePots"; +export * from "./components/PotCard"; +export * from "./components/PotLayout"; export * from "./constants"; export * from "./hooks"; export { type PotInputs, potSchema } from "./models"; diff --git a/src/pages/pots.tsx b/src/pages/pots.tsx index b90b51c6..f1156238 100644 --- a/src/pages/pots.tsx +++ b/src/pages/pots.tsx @@ -1,6 +1,56 @@ import { PageWithBanner } from "@/common/ui/components"; -import ActivePots from "@/modules/pot/components/ActivePots"; -import Banner from "@/modules/pot/components/Banner"; +import {ActivePots} from "@/modules/pot"; +import { useEffect, useState } from "react"; + +import Link from "next/link"; + +import { potFactoryClient } from "@/common/contracts/core"; +import { Button } from "@/common/ui/components"; +import { useWallet } from "@/modules/auth"; +import {hrefByRouteName} from "@/modules/core"; + +const Banner = () => { + const { wallet } = useWallet(); + + const [isPotDeploymentAvailable, updatePotDeploymentAvailability] = useState(false); + + useEffect(() => { + if (wallet?.accountId) { + potFactoryClient + .isDeploymentAvailable({ + accountId: wallet.accountId, + }) + .then(updatePotDeploymentAvailability); + } + }, [wallet?.accountId]); + + return ( +
+
+

Explore Pots

+

+ Donate to Matching Rounds
to Get Your Contributions + Amplified. +

+
+ {isPotDeploymentAvailable && ( + + )} + + + +
+
+
+ ); +}; export default function PotsPage() { return (