Skip to content

Commit

Permalink
resolve circular deps (#1357)
Browse files Browse the repository at this point in the history
* fix(Token): resolve circular deps

* fix(Reward): resolve circular deps
  • Loading branch information
dominik-stumpf authored Jul 8, 2024
1 parent 604e9a3 commit 4b24470
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { env } from "env"
import { Img, Text } from "@chakra-ui/react"
import useGuild from "components/[guild]/hooks/useGuild"
import { RewardDisplay } from "components/[guild]/RoleCard/components/Reward"
import { GuildAction, useMintGuildPinContext } from "../MintGuildPinContext"
import { RewardDisplay } from "components/[guild]/RoleCard/components/RewardDisplay"

const GuildPinReward = (): JSX.Element => {
const { pinType, pinImage } = useMintGuildPinContext()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Center, useColorModeValue } from "@chakra-ui/react"
import { Question } from "@phosphor-icons/react"
import { RewardDisplay } from "./Reward"
import { RewardDisplay } from "./RewardDisplay"

const HiddenRewards = () => {
const rewardImageBgColor = useColorModeValue("blackAlpha.100", "blackAlpha.300")
Expand Down
56 changes: 6 additions & 50 deletions src/components/[guild]/RoleCard/components/Reward.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import {
ChakraProps,
Circle,
HStack,
Icon,
Img,
Spinner,
Stack,
Text,
Tooltip,
Wrap,
useColorModeValue,
} from "@chakra-ui/react"
import { ArrowSquareOut, LockSimple } from "@phosphor-icons/react"
Expand All @@ -21,21 +17,15 @@ import Button from "components/common/Button"
import useMembership, {
useRoleMembership,
} from "components/explorer/hooks/useMembership"
import { Transition, motion } from "framer-motion"
import { PropsWithChildren, ReactNode, useMemo, useState } from "react"
import { motion } from "framer-motion"
import { useMemo, useState } from "react"
import rewards from "rewards"
import rewardComponents from "rewards/components"
import GoogleCardWarning from "rewards/Google/GoogleCardWarning"
import { GuildPlatform, PlatformType, Role, RolePlatform } from "types"
import { PlatformType, RolePlatform } from "types"
import capitalize from "utils/capitalize"

export type RewardProps = {
role: Role // should change to just roleId when we won't need memberCount anymore
platform: RolePlatform
withLink?: boolean
withMotionImg?: boolean
isLinkColorful?: boolean
}
import { RewardDisplay } from "./RewardDisplay"
import { RewardIconProps, RewardProps } from "./types"

const getRewardLabel = (platform: RolePlatform) => {
switch (platform.guildPlatform.platformId) {
Expand Down Expand Up @@ -158,40 +148,6 @@ const Reward = ({
)
}

const RewardDisplay = ({
icon,
label,
rightElement,
children,
...chakraProps
}: PropsWithChildren<
{
icon?: ReactNode
label: ReactNode
rightElement?: ReactNode
} & ChakraProps
>) => (
<HStack pt="3" spacing={2} alignItems={"flex-start"} {...chakraProps}>
{icon}

<Stack w="full" spacing={0.5}>
<Wrap spacingY={0.5}>
<Text maxW="calc(100% - var(--chakra-sizes-12))">{label}</Text>
{rightElement}
</Wrap>

{children}
</Stack>
</HStack>
)

export type RewardIconProps = {
rolePlatformId: number
guildPlatform: GuildPlatform
withMotionImg?: boolean
transition?: Transition
}

const MotionImg = motion(Img)
const MotionCircle = motion(Circle)

Expand Down Expand Up @@ -281,5 +237,5 @@ const RewardWrapper = ({ platform, ...props }: RewardProps) => {
)
}

export { Reward, RewardDisplay, RewardIcon, getRewardLabel }
export { Reward, RewardIcon, getRewardLabel }
export default RewardWrapper
29 changes: 29 additions & 0 deletions src/components/[guild]/RoleCard/components/RewardDisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ChakraProps, HStack, Stack, Wrap, Text } from "@chakra-ui/react"
import { PropsWithChildren, ReactNode } from "react"

export const RewardDisplay = ({
icon,
label,
rightElement,
children,
...chakraProps
}: PropsWithChildren<
{
icon?: ReactNode
label: ReactNode
rightElement?: ReactNode
} & ChakraProps
>) => (
<HStack pt="3" spacing={2} alignItems={"flex-start"} {...chakraProps}>
{icon}

<Stack w="full" spacing={0.5}>
<Wrap spacingY={0.5}>
<Text maxW="calc(100% - var(--chakra-sizes-12))">{label}</Text>
{rightElement}
</Wrap>

{children}
</Stack>
</HStack>
)
17 changes: 17 additions & 0 deletions src/components/[guild]/RoleCard/components/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Transition } from "framer-motion"
import { GuildPlatform, Role, RolePlatform } from "types"

export type RewardProps = {
role: Role // should change to just roleId when we won't need memberCount anymore
platform: RolePlatform
withLink?: boolean
withMotionImg?: boolean
isLinkColorful?: boolean
}

export type RewardIconProps = {
rolePlatformId: number
guildPlatform: GuildPlatform
withMotionImg?: boolean
transition?: Transition
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import DynamicTypeForm from "rewards/Token/DynamicTypeForm"
import Token from "static/icons/token.svg"
import ConversionInput from "./ConversionInput"

export enum SnapshotOption {
GUILD_POINTS = "GUILD_POINTS",
CUSTOM = "CUSTOM",
}

const DynamicAmount = () => {
const pointsPlatformId = useWatch({ name: "data.guildPlatformId" })
const chain = useWatch({ name: `chain` })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum SnapshotOption {
GUILD_POINTS = "GUILD_POINTS",
CUSTOM = "CUSTOM",
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import {
} from "components/[guild]/Requirements/components/GuildCheckout/components/TransactionStatusContext"
import TransactionStatusModal from "components/[guild]/Requirements/components/GuildCheckout/components/TransactionStatusModal"
import OpenseaLink from "components/[guild]/Requirements/components/GuildCheckout/components/TransactionStatusModal/components/OpenseaLink"
import {
RewardDisplay,
RewardIcon,
} from "components/[guild]/RoleCard/components/Reward"
import { RewardIcon } from "components/[guild]/RoleCard/components/Reward"
import { ContractCallFunction } from "components/[guild]/RolePlatforms/components/AddRoleRewardModal/components/AddContractCallPanel/components/CreateNftForm/hooks/useCreateNft"
import { PropsWithChildren, createContext, useContext, useEffect } from "react"
import { FormProvider, useForm, useWatch } from "react-hook-form"
import { GuildPlatform } from "types"
import { Chain, Chains } from "wagmiConfig/chains"
import useGuildRewardNftBalanceByUserId from "../hooks/useGuildRewardNftBalanceByUserId"
import useNftDetails from "../hooks/useNftDetails"
import { RewardDisplay } from "components/[guild]/RoleCard/components/RewardDisplay"

type Props = {
roleId: number
Expand Down
5 changes: 2 additions & 3 deletions src/rewards/ContractCall/ContractCallReward.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import useGuild from "components/[guild]/hooks/useGuild"
import Button from "components/common/Button"
import { motion } from "framer-motion"
import {
RewardDisplay,
RewardIconProps,
RewardProps,
} from "../../components/[guild]/RoleCard/components/Reward"

} from "../../components/[guild]/RoleCard/components/types"
import { usePostHogContext } from "components/_app/PostHogProvider"
import Link from "next/link"
import { forwardRef } from "react"
import NftAvailabilityTags from "./components/NftAvailabilityTags"
import { RewardDisplay } from "components/[guild]/RoleCard/components/RewardDisplay"

const ContractCallReward = ({
platform,
Expand Down
2 changes: 1 addition & 1 deletion src/rewards/Token/DynamicTypeForm.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Circle, FormControl, Icon, useColorModeValue } from "@chakra-ui/react"
import { ListNumbers } from "@phosphor-icons/react"
import CustomSnapshotForm from "components/[guild]/RolePlatforms/components/AddRoleRewardModal/components/AddTokenPanel/components/CustomSnapshotForm"
import { SnapshotOption } from "components/[guild]/RolePlatforms/components/AddRoleRewardModal/components/AddTokenPanel/components/DynamicAmount"
import GuildPointsSnapshotForm from "components/[guild]/RolePlatforms/components/AddRoleRewardModal/components/AddTokenPanel/components/GuildPointsSnapshotForm"
import { SnapshotOption } from "components/[guild]/RolePlatforms/components/AddRoleRewardModal/components/AddTokenPanel/components/types"
import RadioSelect from "components/common/RadioSelect"
import { Option } from "components/common/RadioSelect/RadioSelect"
import { useController, useFormContext } from "react-hook-form"
Expand Down
8 changes: 3 additions & 5 deletions src/rewards/components/FormReward.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Skeleton, Tooltip } from "@chakra-ui/react"
import { ArrowRight } from "@phosphor-icons/react"
import {
RewardDisplay,
RewardIcon,
RewardProps,
} from "components/[guild]/RoleCard/components/Reward"
import { RewardIcon } from "components/[guild]/RoleCard/components/Reward"
import { RewardDisplay } from "components/[guild]/RoleCard/components/RewardDisplay"
import { RewardProps } from "components/[guild]/RoleCard/components/types"
import useGuild from "components/[guild]/hooks/useGuild"
import { useGuildForm } from "components/[guild]/hooks/useGuildForms"
import Button from "components/common/Button"
Expand Down
8 changes: 3 additions & 5 deletions src/rewards/components/GatherReward.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Icon, Spinner, Text, Tooltip } from "@chakra-ui/react"
import { ArrowSquareOut, LockSimple } from "@phosphor-icons/react"
import { useOpenJoinModal } from "components/[guild]/JoinModal/JoinModalProvider"
import {
RewardDisplay,
RewardIcon,
RewardProps,
} from "components/[guild]/RoleCard/components/Reward"
import { RewardIcon } from "components/[guild]/RoleCard/components/Reward"
import { RewardDisplay } from "components/[guild]/RoleCard/components/RewardDisplay"
import { RewardProps } from "components/[guild]/RoleCard/components/types"
import AvailabilityTags from "components/[guild]/RolePlatforms/components/PlatformCard/components/AvailabilityTags"
import useGuild from "components/[guild]/hooks/useGuild"
import Button from "components/common/Button"
Expand Down
8 changes: 3 additions & 5 deletions src/rewards/components/PoapReward.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Tooltip } from "@chakra-ui/react"
import { ArrowRight } from "@phosphor-icons/react"
import {
RewardDisplay,
RewardIcon,
RewardProps,
} from "components/[guild]/RoleCard/components/Reward"
import { RewardIcon } from "components/[guild]/RoleCard/components/Reward"
import { RewardDisplay } from "components/[guild]/RoleCard/components/RewardDisplay"
import { RewardProps } from "components/[guild]/RoleCard/components/types"
import AvailabilityTags from "components/[guild]/RolePlatforms/components/PlatformCard/components/AvailabilityTags"
import useGuild from "components/[guild]/hooks/useGuild"
import Button from "components/common/Button"
Expand Down
8 changes: 3 additions & 5 deletions src/rewards/components/PointsReward.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { Link } from "@chakra-ui/next-js"
import { Icon, Tooltip, useColorModeValue } from "@chakra-ui/react"
import { ArrowRight, Check } from "@phosphor-icons/react"
import DynamicTag from "components/[guild]/RoleCard/components/DynamicReward/DynamicTag"
import {
RewardDisplay,
RewardIcon,
RewardProps,
} from "components/[guild]/RoleCard/components/Reward"
import { RewardIcon } from "components/[guild]/RoleCard/components/Reward"
import { RewardDisplay } from "components/[guild]/RoleCard/components/RewardDisplay"
import { RewardProps } from "components/[guild]/RoleCard/components/types"
import useGuild from "components/[guild]/hooks/useGuild"
import { useRoleMembership } from "components/explorer/hooks/useMembership"
import useDynamicRewardUserAmount from "rewards/Token/hooks/useDynamicRewardUserAmount"
Expand Down
8 changes: 3 additions & 5 deletions src/rewards/components/PolygonIDReward.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { Icon, Spinner, Tooltip } from "@chakra-ui/react"
import { ArrowSquareIn, LockSimple } from "@phosphor-icons/react"
import { useOpenJoinModal } from "components/[guild]/JoinModal/JoinModalProvider"
import {
RewardDisplay,
RewardIcon,
RewardProps,
} from "components/[guild]/RoleCard/components/Reward"
import { RewardIcon } from "components/[guild]/RoleCard/components/Reward"
import { RewardDisplay } from "components/[guild]/RoleCard/components/RewardDisplay"
import { RewardProps } from "components/[guild]/RoleCard/components/types"
import useGuild from "components/[guild]/hooks/useGuild"
import Button from "components/common/Button"
import useMembership, {
Expand Down
8 changes: 3 additions & 5 deletions src/rewards/components/TextReward.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { Icon, Spinner, Text, Tooltip } from "@chakra-ui/react"
import { ArrowSquareIn, LockSimple } from "@phosphor-icons/react"
import { useOpenJoinModal } from "components/[guild]/JoinModal/JoinModalProvider"
import {
RewardDisplay,
RewardIcon,
RewardProps,
} from "components/[guild]/RoleCard/components/Reward"
import { RewardIcon } from "components/[guild]/RoleCard/components/Reward"
import AvailabilityTags from "components/[guild]/RolePlatforms/components/PlatformCard/components/AvailabilityTags"
import useGuild from "components/[guild]/hooks/useGuild"
import Button from "components/common/Button"
Expand All @@ -22,6 +18,8 @@ import {
getRolePlatformTimeframeInfo,
} from "utils/rolePlatformHelpers"
import { useClaimedReward } from "../../hooks/useClaimedReward"
import { RewardProps } from "components/[guild]/RoleCard/components/types"
import { RewardDisplay } from "components/[guild]/RoleCard/components/RewardDisplay"

const SecretTextReward = ({ platform, withMotionImg }: RewardProps) => {
const { platformId, platformGuildData } = platform.guildPlatform
Expand Down
8 changes: 3 additions & 5 deletions src/rewards/components/TokenReward.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { Icon, Spinner, Tooltip } from "@chakra-ui/react"
import { ArrowSquareIn, LockSimple } from "@phosphor-icons/react"
import { useOpenJoinModal } from "components/[guild]/JoinModal/JoinModalProvider"
import DynamicTag from "components/[guild]/RoleCard/components/DynamicReward/DynamicTag"
import {
RewardDisplay,
RewardIcon,
RewardProps,
} from "components/[guild]/RoleCard/components/Reward"
import { RewardIcon } from "components/[guild]/RoleCard/components/Reward"
import AvailabilityTags from "components/[guild]/RolePlatforms/components/PlatformCard/components/AvailabilityTags"
import useGuildPermission from "components/[guild]/hooks/useGuildPermission"
import Button from "components/common/Button"
Expand All @@ -28,6 +24,8 @@ import {
getRolePlatformStatus,
getRolePlatformTimeframeInfo,
} from "utils/rolePlatformHelpers"
import { RewardProps } from "components/[guild]/RoleCard/components/types"
import { RewardDisplay } from "components/[guild]/RoleCard/components/RewardDisplay"

const TokenReward = ({ rolePlatform }: { rolePlatform: RolePlatform }) => {
const { token } = useTokenRewardContext()
Expand Down
2 changes: 1 addition & 1 deletion src/rewards/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ThemingProps } from "@chakra-ui/react"
import type { IconProps } from "@phosphor-icons/react"
import type { RewardProps } from "components/[guild]/RoleCard/components/Reward"
import type { RewardProps } from "components/[guild]/RoleCard/components/types"
import type {
ComponentType,
ForwardRefExoticComponent,
Expand Down

0 comments on commit 4b24470

Please sign in to comment.