Skip to content

Commit

Permalink
resolve circular deps inside rewards (#1348)
Browse files Browse the repository at this point in the history
* fix(SecretText): resolve circular dependency inside rewards

* fix(PolygonID): resolve circular dependency inside rewards
  • Loading branch information
dominik-stumpf authored Jul 3, 2024
1 parent 12fcefd commit 6331876
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { Tab, TabList, TabPanel, TabPanels, Tabs } from "@chakra-ui/react"
import { useAddRewardDiscardAlert } from "components/[guild]/AddRewardButton/hooks/useAddRewardDiscardAlert"
import useUser from "components/[guild]/hooks/useUser"
import Button from "components/common/Button"
import SecretTextDataForm, {
SecretTextRewardForm,
} from "rewards/SecretText/SecretTextDataForm/SecretTextDataForm"
import SecretTextDataForm from "rewards/SecretText/SecretTextDataForm/SecretTextDataForm"
import UniqueTextDataForm, {
UniqueTextRewardForm,
} from "rewards/UniqueText/UniqueTextDataForm"
Expand All @@ -13,6 +11,7 @@ import { useState } from "react"
import { FormProvider, useForm, useWatch } from "react-hook-form"
import { PlatformGuildData, PlatformName, PlatformType } from "types"
import DefaultAddRewardPanelWrapper from "../DefaultAddRewardPanelWrapper"
import { SecretTextRewardForm } from "rewards/SecretText/SecretTextDataForm/types"

enum TextPlatformName {
TEXT,
Expand Down
11 changes: 6 additions & 5 deletions src/rewards/PolygonID/components/ConnectDIDModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ import { useEffect } from "react"
import useSWR from "swr"
import useSWRImmutable from "swr/immutable"
import useConnectedDID from "../hooks/useConnectedDID"
import { useMintPolygonIDProofContext } from "./MintPolygonIDProofProvider"

type Props = {
isOpen: boolean
onClose: () => void
onMintPolygonIDProofModalOpen: () => void
}

const ConnectDIDModal = ({ isOpen, onClose }: Props) => {
const ConnectDIDModal = ({
isOpen,
onClose,
onMintPolygonIDProofModalOpen,
}: Props) => {
const { id: userId } = useUser()

const { onMintPolygonIDProofModalOpen } = useMintPolygonIDProofContext()

const toast = useToast()

const fetcherWithSign = useFetcherWithSign()
Expand Down
11 changes: 8 additions & 3 deletions src/rewards/PolygonID/components/MintPolygonIDProofProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ const DynamicMintPolygonIDProofModal = dynamic(
() => import("./MintPolygonIDProofModal")
)

const MintPolygonIDProofContext = createContext<{
interface MintPolygonIDProofContextType {
isConnectDIDModalOpen: boolean
onConnectDIDModalOpen: () => void
onConnectDIDModalClose: () => void
isMintPolygonIDProofModalOpen: boolean
onMintPolygonIDProofModalOpen: () => void
onMintPolygonIDProofModalClose: () => void
}>(undefined)
}

const MintPolygonIDProofContext = createContext<MintPolygonIDProofContextType>(
{} as MintPolygonIDProofContextType
)

const MintPolygonIDProofProvider = ({ children }: PropsWithChildren<unknown>) => {
const { guildPlatforms } = useGuild()
Expand Down Expand Up @@ -44,11 +48,12 @@ const MintPolygonIDProofProvider = ({ children }: PropsWithChildren<unknown>) =>
>
{children}

{guildPlatforms.find((gp) => gp.platformId === PlatformType.POLYGON_ID) && (
{guildPlatforms?.find((gp) => gp.platformId === PlatformType.POLYGON_ID) && (
<>
<DynamicConnectDIDModal
isOpen={isConnectDIDModalOpen}
onClose={onConnectDIDModalClose}
onMintPolygonIDProofModalOpen={onMintPolygonIDProofModalOpen}
/>
<DynamicMintPolygonIDProofModal
isOpen={isMintPolygonIDProofModalOpen}
Expand Down
5 changes: 2 additions & 3 deletions src/rewards/SecretText/EditSecretTextModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import { Modal } from "components/common/Modal"
import useToast from "hooks/useToast"
import { FormProvider, useForm } from "react-hook-form"
import { GuildPlatform } from "types"
import SecretTextDataForm, {
SecretTextRewardForm,
} from "./SecretTextDataForm/SecretTextDataForm"
import SecretTextDataForm from "./SecretTextDataForm/SecretTextDataForm"
import { SecretTextRewardForm } from "./SecretTextDataForm/types"

type Props = {
isOpen: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { PropsWithChildren } from "react"
import { useController, useFormContext, useWatch } from "react-hook-form"
import BoxIcon from "static/icons/box.svg"
import PublicRewardDataForm from "./components/PublicRewardDataForm"

export type SecretTextRewardForm = {
name: string
imageUrl?: string
text: string
}
import { SecretTextRewardForm } from "./types"

type Props = {
shouldValidate?: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Box, FormControl, FormLabel, HStack, Input } from "@chakra-ui/react"
import FormErrorMessage from "components/common/FormErrorMessage"
import { UniqueTextRewardForm } from "rewards/UniqueText/UniqueTextDataForm"
import { useFormContext } from "react-hook-form"
import { SecretTextRewardForm } from "../SecretTextDataForm"
import RewardImagePicker from "./RewardImagePicker"
import { SecretTextRewardForm } from "../types"

const PublicRewardDataForm = ({ defaultIcon }) => {
const {
Expand Down
3 changes: 2 additions & 1 deletion src/rewards/SecretText/SecretTextDataForm/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SecretTextDataForm, { SecretTextRewardForm } from "./SecretTextDataForm"
import SecretTextDataForm from "./SecretTextDataForm"
import { SecretTextRewardForm } from "./types"

export default SecretTextDataForm
export type { SecretTextRewardForm }
5 changes: 5 additions & 0 deletions src/rewards/SecretText/SecretTextDataForm/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type SecretTextRewardForm = {
name: string
imageUrl?: string
text: string
}

0 comments on commit 6331876

Please sign in to comment.