From debe26a3769259a86bc4cd6c485b7a7a648bac50 Mon Sep 17 00:00:00 2001 From: BrickheadJohnny Date: Thu, 24 Oct 2024 16:07:07 +0200 Subject: [PATCH] cleanup: remove the unused `PAYMENT` requirement --- .../components/GuildCheckout/BuyPass.tsx | 152 ------------ .../GuildCheckout/components/BuyTotal.tsx | 113 --------- .../components/PaymentFeeCurrency.tsx | 223 ------------------ .../PaymentTransactionStatusModal.tsx | 56 ----- .../GuildCheckout/components/TOSCheckbox.tsx | 37 --- .../components/buttons/BuyAllowanceButton.tsx | 116 --------- .../components/buttons/BuyButton.tsx | 120 ---------- .../GuildCheckout/hooks/usePayFee.ts | 129 ---------- .../components/SetHiddenRoleRequirements.tsx | 1 - .../Requirements/EditRequirements.tsx | 5 +- .../Requirements/SetRequirements.tsx | 2 +- .../components/AddRequirement.tsx | 43 ++-- src/requirements/Payment/PaymentForm.tsx | 119 ---------- .../Payment/PaymentRequirement.tsx | 127 ---------- .../RegisterVaultForm/RegisterVaultForm.tsx | 193 --------------- .../RegisterVaultForm/hooks/useCoinById.ts | 20 -- .../RegisterVaultForm/hooks/useFeeInUSD.ts | 17 -- .../hooks/useRegisterVault.ts | 84 ------- .../components/RegisterVaultForm/index.ts | 4 - .../WithdrawButton/WithdrawButton.tsx | 88 ------- .../WithdrawButton/hooks/useWithdraw.ts | 50 ---- .../components/WithdrawButton/index.ts | 3 - src/requirements/Payment/hooks/useHasPaid.ts | 25 -- src/requirements/Payment/hooks/useVault.ts | 46 ---- .../requirementDisplayComponents.ts | 3 - src/requirements/requirementFormComponents.ts | 3 - src/requirements/requirements.ts | 6 - src/utils/guildCheckout/constants.ts | 10 - 28 files changed, 23 insertions(+), 1772 deletions(-) delete mode 100644 src/components/[guild]/Requirements/components/GuildCheckout/BuyPass.tsx delete mode 100644 src/components/[guild]/Requirements/components/GuildCheckout/components/BuyTotal.tsx delete mode 100644 src/components/[guild]/Requirements/components/GuildCheckout/components/PaymentFeeCurrency.tsx delete mode 100644 src/components/[guild]/Requirements/components/GuildCheckout/components/PaymentTransactionStatusModal.tsx delete mode 100644 src/components/[guild]/Requirements/components/GuildCheckout/components/TOSCheckbox.tsx delete mode 100644 src/components/[guild]/Requirements/components/GuildCheckout/components/buttons/BuyAllowanceButton.tsx delete mode 100644 src/components/[guild]/Requirements/components/GuildCheckout/components/buttons/BuyButton.tsx delete mode 100644 src/components/[guild]/Requirements/components/GuildCheckout/hooks/usePayFee.ts delete mode 100644 src/requirements/Payment/PaymentForm.tsx delete mode 100644 src/requirements/Payment/PaymentRequirement.tsx delete mode 100644 src/requirements/Payment/components/RegisterVaultForm/RegisterVaultForm.tsx delete mode 100644 src/requirements/Payment/components/RegisterVaultForm/hooks/useCoinById.ts delete mode 100644 src/requirements/Payment/components/RegisterVaultForm/hooks/useFeeInUSD.ts delete mode 100644 src/requirements/Payment/components/RegisterVaultForm/hooks/useRegisterVault.ts delete mode 100644 src/requirements/Payment/components/RegisterVaultForm/index.ts delete mode 100644 src/requirements/Payment/components/WithdrawButton/WithdrawButton.tsx delete mode 100644 src/requirements/Payment/components/WithdrawButton/hooks/useWithdraw.ts delete mode 100644 src/requirements/Payment/components/WithdrawButton/index.ts delete mode 100644 src/requirements/Payment/hooks/useHasPaid.ts delete mode 100644 src/requirements/Payment/hooks/useVault.ts diff --git a/src/components/[guild]/Requirements/components/GuildCheckout/BuyPass.tsx b/src/components/[guild]/Requirements/components/GuildCheckout/BuyPass.tsx deleted file mode 100644 index 3c78bb6468..0000000000 --- a/src/components/[guild]/Requirements/components/GuildCheckout/BuyPass.tsx +++ /dev/null @@ -1,152 +0,0 @@ -import { usePostHogContext } from "@/components/Providers/PostHogProvider" -import { useWeb3ConnectionManager } from "@/components/Web3ConnectionManager/hooks/useWeb3ConnectionManager" -import { - Alert, - AlertDescription, - AlertIcon, - Collapse, - Icon, - ModalBody, - ModalCloseButton, - ModalContent, - ModalFooter, - ModalHeader, - ModalOverlay, - Stack, -} from "@chakra-ui/react" -import { Coin } from "@phosphor-icons/react" -import useGuild from "components/[guild]/hooks/useGuild" -import Button from "components/common/Button" -import { Modal } from "components/common/Modal" -import { useRoleMembership } from "components/explorer/hooks/useMembership" -import { paymentSupportedChains } from "utils/guildCheckout/constants" -import { useChainId } from "wagmi" -import { Chains } from "wagmiConfig/chains" -import { useRequirementContext } from "../RequirementContext" -import BuyTotal from "./components/BuyTotal" -import { useGuildCheckoutContext } from "./components/GuildCheckoutContext" -import PaymentFeeCurrency from "./components/PaymentFeeCurrency" -import { UnlockingRewards } from "./components/PaymentTransactionStatusModal" -import TOSCheckbox from "./components/TOSCheckbox" -import BuyAllowanceButton from "./components/buttons/BuyAllowanceButton" -import BuyButton from "./components/buttons/BuyButton" -import DisconnectFuelButton from "./components/buttons/DisconnectFuelButton" -import SwitchNetworkButton from "./components/buttons/SwitchNetworkButton" - -const BuyPass = () => { - const { captureEvent } = usePostHogContext() - - const { isWeb3Connected, type } = useWeb3ConnectionManager() - const chainId = useChainId() - const requirement = useRequirementContext() - const { isOpen, onOpen, onClose } = useGuildCheckoutContext() - const { urlName, name, roles } = useGuild() - const role = roles?.find((r) => r.id === requirement?.roleId) - - const { isLoading: isMembershipLoading, reqAccesses } = useRoleMembership(role?.id) - - const userSatisfiesOtherRequirements = reqAccesses - ?.filter((r) => r.requirementId !== requirement?.id) - ?.every((r) => r.access) - - const onClick = () => { - onOpen() - captureEvent("Click: Buy (Requirement)", { - guild: urlName, - }) - } - - if ( - !isWeb3Connected || - isMembershipLoading || - requirement?.type !== "PAYMENT" || - !paymentSupportedChains.find((c) => c === requirement.chain) - ) - return null - - return ( - <> - - - - - - - {`Buy ${name} pass`} - - - - - {userSatisfiesOtherRequirements === false && role?.logic === "AND" && ( - - - - - There're other requirements you don't satisfy, so the pass alone - won't grant you access - - - - )} - - - - - - - - - - - {type === "EVM" ? ( - <> - - - - - I understand that if the owner changes the requirements, I - could lose access. - - - - - - - ) : ( - Buy pass - )} - - - - - - - ) -} - -export default BuyPass diff --git a/src/components/[guild]/Requirements/components/GuildCheckout/components/BuyTotal.tsx b/src/components/[guild]/Requirements/components/GuildCheckout/components/BuyTotal.tsx deleted file mode 100644 index f1fd48d5af..0000000000 --- a/src/components/[guild]/Requirements/components/GuildCheckout/components/BuyTotal.tsx +++ /dev/null @@ -1,113 +0,0 @@ -import { HStack, Skeleton, Td, Text, Tr } from "@chakra-ui/react" -import useTokenData from "hooks/useTokenData" -import useVault from "requirements/Payment/hooks/useVault" -import { NULL_ADDRESS } from "utils/guildCheckout/constants" -import { formatUnits } from "viem" -import { CHAIN_CONFIG, Chain } from "wagmiConfig/chains" -import { useRequirementContext } from "../../RequirementContext" -import usePayFee from "../hooks/usePayFee" -import FeesTable from "./FeesTable" -import { useGuildCheckoutContext } from "./GuildCheckoutContext" -import PriceFallback from "./PriceFallback" - -const BuyTotal = (): JSX.Element => { - const requirement = useRequirementContext() - const { pickedCurrency } = useGuildCheckoutContext() - - // TODO: we could remove the cast once we'll have schemas for "ERC..." requirements - const requirementChain = requirement.chain as Chain - const requirementAddress = requirement.address as `0x${string}` - - const { token, fee, isLoading, error } = useVault( - requirementAddress, - requirement.data.id, - requirementChain - ) - - const { data: tokenData } = useTokenData(requirementChain, token) - - const isNativeCurrency = pickedCurrency === NULL_ADDRESS - - const { isPreparing, estimatedGas } = usePayFee() - - const estimatedGasInFloat = - typeof estimatedGas === "bigint" - ? parseFloat( - formatUnits( - estimatedGas, - CHAIN_CONFIG[requirementChain].nativeCurrency.decimals - ) - ) - : null - - const priceInSellToken = fee - ? isNativeCurrency - ? Number( - formatUnits(fee, CHAIN_CONFIG[requirementChain].nativeCurrency.decimals) - ) - : tokenData?.decimals - ? Number(formatUnits(fee, tokenData.decimals)) + - (isNativeCurrency ? (estimatedGasInFloat ?? 0) : 0) - : 0 - : 0 - - const isTooSmallPrice = priceInSellToken < 0.001 - - return ( - - - Total with fees: - - - - - - - {priceInSellToken - ? `${ - isTooSmallPrice - ? "< 0.001" - : Number(priceInSellToken.toFixed(3)) - } ` - : "0.00 "} - {tokenData?.symbol} - - {!isNativeCurrency && ( - - {` + Gas`} - - )} - - - - - } - > - - Price - - {priceInSellToken - ? `${isTooSmallPrice ? "< 0.001" : Number(priceInSellToken.toFixed(3))} ` - : "0.00 "} - {tokenData?.symbol} - - - - Gas fee - - - {!estimatedGasInFloat - ? "Couldn't estimate" - : `${Number(estimatedGasInFloat.toFixed(8))} ${ - CHAIN_CONFIG[requirementChain].nativeCurrency.symbol - }`} - - - - - ) -} - -export default BuyTotal diff --git a/src/components/[guild]/Requirements/components/GuildCheckout/components/PaymentFeeCurrency.tsx b/src/components/[guild]/Requirements/components/GuildCheckout/components/PaymentFeeCurrency.tsx deleted file mode 100644 index 1f67c58404..0000000000 --- a/src/components/[guild]/Requirements/components/GuildCheckout/components/PaymentFeeCurrency.tsx +++ /dev/null @@ -1,223 +0,0 @@ -import { - Box, - Circle, - HStack, - Img, - MenuItem, - Skeleton, - SkeletonCircle, - Stack, - Text, - useColorModeValue, -} from "@chakra-ui/react" -import useToken from "hooks/useToken" -import useTokenBalance from "hooks/useTokenBalance" -import { useEffect } from "react" -import { Fragment } from "react" -import useVault from "requirements/Payment/hooks/useVault" -import { Rest } from "types" -import { NULL_ADDRESS } from "utils/guildCheckout/constants" -import { formatUnits } from "viem" -import { useAccount, useBalance } from "wagmi" -import { CHAIN_CONFIG, Chains } from "wagmiConfig/chains" -import { useRequirementContext } from "../../RequirementContext" -import { useGuildCheckoutContext } from "./GuildCheckoutContext" - -const PaymentFeeCurrency = (): JSX.Element => { - const lightShade = useColorModeValue("white", "gray.700") - const borderWidth = useColorModeValue(1, 0) - - const requirement = useRequirementContext<"PAYMENT">() - const { pickedCurrency, setPickedCurrency } = useGuildCheckoutContext() - - const { token, fee, error, isLoading } = useVault( - requirement?.address as `0x${string}`, - requirement?.data?.id, - requirement?.chain - ) - - const isNativeCurrency = token === NULL_ADDRESS - - const { data: tokenData } = useToken({ - address: token, - chainId: Chains[requirement.chain], - shouldFetch: Boolean(!isNativeCurrency && Chains[requirement.chain]), - }) - - const convertedFee = fee - ? isNativeCurrency - ? formatUnits(fee, CHAIN_CONFIG[requirement.chain].nativeCurrency.decimals) - : tokenData?.decimals - ? formatUnits(fee, tokenData.decimals) - : undefined - : undefined - - useEffect(() => { - if (!token) return - setPickedCurrency(token) - }, [token, setPickedCurrency]) - - return ( - - - Payment currency - - - - - - - ) -} - -const TokenInfo = ({ - chainId, - address: tokenAddress, - asMenuItem, - isLoading, - error, - requiredAmount, - ...rest -}: { - chainId: number - address: `0x${string}` - isLoading?: boolean - error?: any - requiredAmount: number - asMenuItem?: boolean -} & Rest): JSX.Element => { - const circleBgColor = useColorModeValue("blackAlpha.100", "blackAlpha.300") - - const isTooSmallRequiredAmount = requiredAmount - ? parseFloat(requiredAmount.toFixed(3)) <= 0.0 - : undefined - - const isNativeCurrency = tokenAddress === NULL_ADDRESS - - const logoURI = isNativeCurrency - ? CHAIN_CONFIG[Chains[chainId]].iconUrl - : undefined - - const { address } = useAccount() - const { data: coinBalanceData, isLoading: isCoinBalanceLoading } = useBalance({ - address, - chainId, - }) - - const { - data: tokenBalanceData, - isLoading: isTokenBalanceLoading, - isError: isTokenBalanceError, - } = useTokenBalance({ - token: tokenAddress, - chainId, - shouldFetch: tokenAddress !== NULL_ADDRESS, - }) - - const symbol = isNativeCurrency - ? CHAIN_CONFIG[Chains[chainId]].nativeCurrency.symbol - : tokenBalanceData?.symbol - - const isBalanceLoading = isCoinBalanceLoading || isTokenBalanceLoading - - const formattedBalance = Number( - Number( - tokenAddress === NULL_ADDRESS && coinBalanceData?.value - ? formatUnits(coinBalanceData.value, coinBalanceData.decimals) - : tokenBalanceData?.value - ? formatUnits(tokenBalanceData.value, tokenBalanceData.decimals) - : 0 - ).toFixed(3) - ) - - const Wrapper = asMenuItem ? MenuItem : Fragment - - return ( - - - - - {logoURI ? ( - {symbol} - ) : ( - - {symbol} - - )} - - - - - - - {isTokenBalanceError - ? "Couldn't fetch token data" - : error - ? `[?] ${symbol}` - : `${ - isTooSmallRequiredAmount - ? "< 0.001" - : Number(requiredAmount?.toFixed(3)) - } ${symbol}`} - - {` (${CHAIN_CONFIG[Chains[chainId]].name})`} - - - - - - {address ? ( - <> - {`Balance: `} - - {`${formattedBalance ?? "0.00"} ${symbol ?? "currency"}`} - - - ) : ( - "Connect wallet to check balance" - )} - - - - - ) -} - -export default PaymentFeeCurrency diff --git a/src/components/[guild]/Requirements/components/GuildCheckout/components/PaymentTransactionStatusModal.tsx b/src/components/[guild]/Requirements/components/GuildCheckout/components/PaymentTransactionStatusModal.tsx deleted file mode 100644 index bbf60791dc..0000000000 --- a/src/components/[guild]/Requirements/components/GuildCheckout/components/PaymentTransactionStatusModal.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import { Text } from "@chakra-ui/react" -import NoReward from "components/[guild]/Requirements/components/GuildCheckout/components/NoReward" -import TransactionStatusModal from "components/[guild]/Requirements/components/GuildCheckout/components/TransactionStatusModal" -import { useRequirementContext } from "components/[guild]/Requirements/components/RequirementContext" -import Reward from "components/[guild]/RoleCard/components/Reward" -import useGuild from "components/[guild]/hooks/useGuild" - -const PaymentTransactionStatusModal = () => { - const { name, roleId } = useRequirementContext() - - return ( - - - Unlocking rewards... - - - - } - successComponent={ - <> - - Unlocked rewards: - - - - } - errorComponent={{`Couldn't buy pass`}} - /> - ) -} - -export const UnlockingRewards = ({ roleId }: { roleId: number }) => { - const { roles, guildPlatforms } = useGuild() - const role = roles.find((r) => r.id === roleId) - - if (!role.rolePlatforms?.length) return - - return role.rolePlatforms.map((rp) => { - const guildPlatform = guildPlatforms.find((gp) => gp.id === rp.guildPlatformId) - - return ( - - ) - }) -} - -export default PaymentTransactionStatusModal diff --git a/src/components/[guild]/Requirements/components/GuildCheckout/components/TOSCheckbox.tsx b/src/components/[guild]/Requirements/components/GuildCheckout/components/TOSCheckbox.tsx deleted file mode 100644 index a5cf0d593d..0000000000 --- a/src/components/[guild]/Requirements/components/GuildCheckout/components/TOSCheckbox.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import { Checkbox, useColorModeValue } from "@chakra-ui/react" -import { PropsWithChildren } from "react" -import { useGuildCheckoutContext } from "./GuildCheckoutContext" - -const TOSCheckbox = ({ children }: PropsWithChildren): JSX.Element => { - const borderColor = useColorModeValue("gray.300", "inherit") - const { agreeWithTOS, setAgreeWithTOS } = useGuildCheckoutContext() - - return ( - .chakra-checkbox__control": { - marginTop: 1, - borderWidth: 1, - borderColor, - }, - }} - _checked={{ - "> .chakra-checkbox__control[data-checked]": { - bgColor: "blue.500", - borderColor: "blue.500", - color: "white", - }, - }} - pb={4} - isChecked={agreeWithTOS} - onChange={(e) => setAgreeWithTOS(e.target.checked)} - size="sm" - > - {children} - - ) -} - -export default TOSCheckbox diff --git a/src/components/[guild]/Requirements/components/GuildCheckout/components/buttons/BuyAllowanceButton.tsx b/src/components/[guild]/Requirements/components/GuildCheckout/components/buttons/BuyAllowanceButton.tsx deleted file mode 100644 index 93823960a4..0000000000 --- a/src/components/[guild]/Requirements/components/GuildCheckout/components/buttons/BuyAllowanceButton.tsx +++ /dev/null @@ -1,116 +0,0 @@ -import { usePostHogContext } from "@/components/Providers/PostHogProvider" -import { Collapse, Icon, Tooltip } from "@chakra-ui/react" -import { Check, Question, Warning } from "@phosphor-icons/react" -import useGuild from "components/[guild]/hooks/useGuild" -import Button from "components/common/Button" -import useToken from "hooks/useToken" -import useVault from "requirements/Payment/hooks/useVault" -import { NULL_ADDRESS } from "utils/guildCheckout/constants" -import { useChainId } from "wagmi" -import { CHAIN_CONFIG, Chains } from "wagmiConfig/chains" -import { useRequirementContext } from "../../../RequirementContext" -import useAllowance from "../../hooks/useAllowance" -import { useGuildCheckoutContext } from "../GuildCheckoutContext" - -const BuyAllowanceButton = (): JSX.Element => { - const { captureEvent } = usePostHogContext() - const { urlName } = useGuild() - - const requirement = useRequirementContext<"PAYMENT">() - const requirementAddress = requirement.address as `0x${string}` - - const requirementChainId = Chains[requirement.chain] - const { pickedCurrency } = useGuildCheckoutContext() - - const chainId = useChainId() - const isNativeCurrencyPicked = pickedCurrency === NULL_ADDRESS - - const { data: tokenData } = useToken({ - address: pickedCurrency, - chainId: Chains[requirement.chain], - shouldFetch: Boolean(!isNativeCurrencyPicked && Chains[requirement.chain]), - }) - - const nativeCurrency = CHAIN_CONFIG[requirement.chain].nativeCurrency - - const tokenSymbol = isNativeCurrencyPicked - ? nativeCurrency.symbol - : tokenData?.symbol - const tokenName = isNativeCurrencyPicked ? nativeCurrency.name : name - - const { fee, isLoading: isVaultLoading } = useVault( - requirementAddress, - requirement.data.id, - requirement.chain - ) - - const { - allowance, - isAllowanceLoading, - isAllowing, - allowanceError, - allowSpendingTokens, - } = useAllowance(pickedCurrency, requirementAddress) - - const isEnoughAllowance = - typeof fee === "bigint" && typeof allowance === "bigint" - ? fee <= allowance - : false - - const onClick = () => { - allowSpendingTokens() - captureEvent("Click: BuyAllowanceButton (GuildCheckout)", { - guild: urlName, - }) - } - - return ( - - - - ) -} - -export default BuyAllowanceButton diff --git a/src/components/[guild]/Requirements/components/GuildCheckout/components/buttons/BuyButton.tsx b/src/components/[guild]/Requirements/components/GuildCheckout/components/buttons/BuyButton.tsx deleted file mode 100644 index f4419ddd5e..0000000000 --- a/src/components/[guild]/Requirements/components/GuildCheckout/components/buttons/BuyButton.tsx +++ /dev/null @@ -1,120 +0,0 @@ -import { usePostHogContext } from "@/components/Providers/PostHogProvider" -import useGuild from "components/[guild]/hooks/useGuild" -import Button from "components/common/Button" -import useTokenBalance from "hooks/useTokenBalance" -import useHasPaid from "requirements/Payment/hooks/useHasPaid" -import useVault from "requirements/Payment/hooks/useVault" -import { NULL_ADDRESS } from "utils/guildCheckout/constants" -import { useAccount, useBalance } from "wagmi" -import { Chains } from "wagmiConfig/chains" -import { useRequirementContext } from "../../../RequirementContext" -import useAllowance from "../../hooks/useAllowance" -import usePayFee from "../../hooks/usePayFee" -import { useGuildCheckoutContext } from "../GuildCheckoutContext" - -const BuyButton = (): JSX.Element => { - const { captureEvent } = usePostHogContext() - const { urlName } = useGuild() - - const { address, chainId } = useAccount() - - const requirement = useRequirementContext<"PAYMENT">() - const requirementAddress = requirement.address as `0x${string}` - - const { pickedCurrency, agreeWithTOS } = useGuildCheckoutContext() - - const { - fee, - multiplePayments, - isLoading: isVaultLoading, - error, - } = useVault(requirementAddress, requirement.data.id, requirement.chain) - - const { data: hasPaid, isLoading: isHasPaidLoading } = useHasPaid( - requirementAddress, - +requirement.data.id, - requirement.chain - ) - - const { allowance, isAllowanceLoading, allowanceError } = useAllowance( - pickedCurrency, - requirementAddress - ) - - const { - error: payFeeError, - isPreparing, - estimatedGas, - payFee, - isLoading, - } = usePayFee() - - const handleSubmit = async () => { - payFee() - captureEvent("Click: BuyButton (GuildCheckout)", { - guild: urlName, - }) - } - - const isSufficientAllowance = - typeof fee === "bigint" && typeof allowance === "bigint" - ? fee <= allowance - : false - - const { data: coinBalanceData, isLoading: isCoinBalanceLoading } = useBalance({ - address, - chainId, - }) - const { data: tokenBalanceData, isLoading: isTokenBalanceLoading } = - useTokenBalance({ - token: pickedCurrency, - chainId, - shouldFetch: pickedCurrency !== NULL_ADDRESS, - }) - - const isBalanceLoading = isCoinBalanceLoading || isTokenBalanceLoading - - const pickedCurrencyIsNative = pickedCurrency === NULL_ADDRESS - - const isSufficientBalance = - fee && - (coinBalanceData?.value || tokenBalanceData?.value) && - (pickedCurrencyIsNative - ? coinBalanceData?.value >= fee - : tokenBalanceData?.value >= fee) - - const isDisabled = - !payFee || - error || - payFeeError || - !agreeWithTOS || - Chains[chainId] !== requirement.chain || - (!isVaultLoading && !isHasPaidLoading && !multiplePayments && hasPaid) || - (!pickedCurrencyIsNative && - (isAllowanceLoading || allowanceError || !isSufficientAllowance)) || - isBalanceLoading || - !isSufficientBalance - - const errorMsg = - (!multiplePayments && hasPaid && "Already paid") || - (!isSufficientBalance && "Insufficient balance") || - (error && "Couldn't calculate price") || - (!isPreparing && !estimatedGas && "Couldn't estimate gas") - - return ( - - ) -} - -export default BuyButton diff --git a/src/components/[guild]/Requirements/components/GuildCheckout/hooks/usePayFee.ts b/src/components/[guild]/Requirements/components/GuildCheckout/hooks/usePayFee.ts deleted file mode 100644 index 1b034fe806..0000000000 --- a/src/components/[guild]/Requirements/components/GuildCheckout/hooks/usePayFee.ts +++ /dev/null @@ -1,129 +0,0 @@ -import { usePostHogContext } from "@/components/Providers/PostHogProvider" -import { useMembershipUpdate } from "components/[guild]/JoinModal/hooks/useMembershipUpdate" -import useGuild from "components/[guild]/hooks/useGuild" -import useShowErrorToast from "hooks/useShowErrorToast" -import useSubmitTransaction from "hooks/useSubmitTransaction" -import useToast from "hooks/useToast" -import useTokenBalance from "hooks/useTokenBalance" -import useHasPaid from "requirements/Payment/hooks/useHasPaid" -import useVault from "requirements/Payment/hooks/useVault" -import feeCollectorAbi from "static/abis/feeCollector" -import { NULL_ADDRESS } from "utils/guildCheckout/constants" -import { useAccount, useBalance } from "wagmi" -import { Chains } from "wagmiConfig/chains" -import { useRequirementContext } from "../../RequirementContext" -import { useGuildCheckoutContext } from "../components/GuildCheckoutContext" -import useAllowance from "./useAllowance" - -const usePayFee = () => { - const { captureEvent } = usePostHogContext() - const { urlName } = useGuild() - const postHogOptions = { guild: urlName } - - const { address, chainId } = useAccount() - - const requirement = useRequirementContext<"PAYMENT">() - const requirementAddress = requirement.address as `0x${string}` - - const { pickedCurrency, onClose } = useGuildCheckoutContext() - - const showErrorToast = useShowErrorToast() - const toast = useToast() - - const { - fee, - multiplePayments, - isLoading: isVaultLoading, - refetch: refetchVault, - } = useVault(requirementAddress, requirement.data.id, requirement.chain) - - const { data: hasPaid, isLoading: isHasPaidLoading } = useHasPaid( - requirementAddress, - +requirement.data.id, - requirement.chain - ) - - const pickedCurrencyIsNative = pickedCurrency === NULL_ADDRESS - - const { data: coinBalanceData } = useBalance({ - address, - chainId: Chains[requirement.chain], - }) - const { data: tokenBalanceData } = useTokenBalance({ - token: pickedCurrency as `0x${string}`, - chainId: Chains[requirement.chain], - shouldFetch: !pickedCurrencyIsNative, - }) - - const isSufficientBalance = - fee && - (coinBalanceData || tokenBalanceData) && - (pickedCurrencyIsNative - ? coinBalanceData?.value >= fee - : tokenBalanceData?.value >= fee) - - const { allowance } = useAllowance(pickedCurrency, requirementAddress) - - const enabled = - requirement?.chain === Chains[chainId] && - !isVaultLoading && - !isHasPaidLoading && - (multiplePayments || !hasPaid) && - typeof fee === "bigint" && - isSufficientBalance && - (!pickedCurrencyIsNative - ? typeof allowance === "bigint" && fee <= allowance - : fee < coinBalanceData?.value) - - const contractCallParams = { - abi: feeCollectorAbi, - address: requirement.address, - functionName: "payFee", - args: [BigInt(requirement.data.id)], - value: pickedCurrencyIsNative ? fee : undefined, - chainId: Chains[requirement.chain], - query: { - enabled, - }, - } as const - - const { triggerMembershipUpdate } = useMembershipUpdate() - - const { error, isPreparing, isLoading, estimatedGas, onSubmitTransaction } = - useSubmitTransaction(contractCallParams, { - customErrorsMap: { - VaultDoesNotExist: "Vault doesn't exist", - TransferFailed: "Transfer failed", - AlreadyPaid: "You've already paid to this vault", - }, - onError: (errorMessage, rawError) => { - showErrorToast(errorMessage ?? "Unknown error") - captureEvent("Buy pass error (GuildCheckout)", { - ...postHogOptions, - error: rawError, - }) - }, - onSuccess: () => { - captureEvent("Bought pass (GuildCheckout)", postHogOptions) - toast({ - status: "success", - title: "Successful payment", - }) - - onClose() - - refetchVault() - triggerMembershipUpdate({ roleIds: [requirement.roleId] }) - }, - }) - - return { - isPreparing, - error, - estimatedGas, - payFee: onSubmitTransaction, - isLoading, - } -} - -export default usePayFee diff --git a/src/components/[guild]/crm/FilterByRoles/components/SetHiddenRoleRequirements.tsx b/src/components/[guild]/crm/FilterByRoles/components/SetHiddenRoleRequirements.tsx index 843dfe53bc..34baaf8703 100644 --- a/src/components/[guild]/crm/FilterByRoles/components/SetHiddenRoleRequirements.tsx +++ b/src/components/[guild]/crm/FilterByRoles/components/SetHiddenRoleRequirements.tsx @@ -58,7 +58,6 @@ const SetHiddenRoleRequirements = (): JSX.Element => { index={i} removeRequirement={removeReq} updateRequirement={update} - isEditDisabled={type === "PAYMENT"} /> diff --git a/src/components/create-guild/Requirements/EditRequirements.tsx b/src/components/create-guild/Requirements/EditRequirements.tsx index e869a0a734..c58fc7cce0 100644 --- a/src/components/create-guild/Requirements/EditRequirements.tsx +++ b/src/components/create-guild/Requirements/EditRequirements.tsx @@ -44,10 +44,7 @@ const EditRequirements = ({ roleId }: Props) => { diff --git a/src/components/create-guild/Requirements/SetRequirements.tsx b/src/components/create-guild/Requirements/SetRequirements.tsx index 54f333c631..5622cd4788 100644 --- a/src/components/create-guild/Requirements/SetRequirements.tsx +++ b/src/components/create-guild/Requirements/SetRequirements.tsx @@ -86,7 +86,7 @@ const SetRequirements = ({ titleSize = undefined }: Props): JSX.Element => { remove(idx) }} updateRequirement={update} - isEditDisabled={type === "PAYMENT" || type === "GUILD_SNAPSHOT"} + isEditDisabled={type === "GUILD_SNAPSHOT"} /> diff --git a/src/components/create-guild/Requirements/components/AddRequirement.tsx b/src/components/create-guild/Requirements/components/AddRequirement.tsx index 8b8d8f4015..294a9dcdf9 100644 --- a/src/components/create-guild/Requirements/components/AddRequirement.tsx +++ b/src/components/create-guild/Requirements/components/AddRequirement.tsx @@ -298,34 +298,33 @@ const AddRequirementForm = forwardRef( )} - {selectedType !== "PAYMENT" && ( - - - - - )} + + + + + ) } ) -const DISABLED_REQUIREMENTS: RequirementType[] = ["GUILD_SNAPSHOT", "PAYMENT"] +const DISABLED_REQUIREMENTS: RequirementType[] = ["GUILD_SNAPSHOT"] const AddRequirementHome = forwardRef( ({ setSelectedType, providerTypesOnly }: any, ref: any) => { const { featureFlags } = useGuild() diff --git a/src/requirements/Payment/PaymentForm.tsx b/src/requirements/Payment/PaymentForm.tsx deleted file mode 100644 index f6c3666400..0000000000 --- a/src/requirements/Payment/PaymentForm.tsx +++ /dev/null @@ -1,119 +0,0 @@ -import { HStack, Icon, Stack, Tooltip } from "@chakra-ui/react" -import { Check, Question } from "@phosphor-icons/react" -import Button from "components/common/Button" -import useTriggerNetworkChange from "hooks/useTriggerNetworkChange" -import { useEffect } from "react" -import { FormProvider, useForm, useFormContext, useWatch } from "react-hook-form" -import { RequirementFormProps } from "requirements/types" -import { FEE_COLLECTOR_CONTRACT } from "utils/guildCheckout/constants" -import { useAccount } from "wagmi" -import { Chains } from "wagmiConfig/chains" -import RegisterVaultForm, { - RegisterVaultFormType, -} from "./components/RegisterVaultForm" -import useRegisterVault from "./components/RegisterVaultForm/hooks/useRegisterVault" - -const PaymentForm = ({ - baseFieldPath, - addRequirement, - setOnCloseAttemptToast, -}: RequirementFormProps): JSX.Element => { - const { address, chainId } = useAccount() - const { requestNetworkChange } = useTriggerNetworkChange() - - const { setValue } = useFormContext() - - useEffect(() => { - if (!chainId) return - setValue(`${baseFieldPath}.address`, FEE_COLLECTOR_CONTRACT[Chains[chainId]]) - }, [chainId, setValue, baseFieldPath]) - - const vaultId = useWatch({ name: `${baseFieldPath}.data.id` }) - - const registerVaultFormMethods = useForm({ - mode: "all", - defaultValues: { owner: address }, - }) - const { - control: registerVaultFormControl, - formState: { errors: registerVaultFormErrors }, - handleSubmit: registerVaultFormHandleSubmit, - } = registerVaultFormMethods - - const chain = useWatch({ control: registerVaultFormControl, name: "chain" }) - - useEffect( - () => setValue(`${baseFieldPath}.chain`, chain), - [chain, setValue, baseFieldPath] - ) - - const isOnCorrectChain = chainId === Chains[chain] - - const token = useWatch({ control: registerVaultFormControl, name: "token" }) - const fee = useWatch({ control: registerVaultFormControl, name: "fee" }) - const owner = useWatch({ control: registerVaultFormControl, name: "owner" }) - - const { onSubmitTransaction, isLoading } = useRegisterVault({ - chain, - token, - fee, - owner, - onSuccess: (registeredVaultId) => { - setValue(`${baseFieldPath}.data.id`, registeredVaultId) - addRequirement() - }, - }) - - useEffect(() => { - if (isLoading) - setOnCloseAttemptToast( - "You can't close the modal until the transaction finishes" - ) - else setOnCloseAttemptToast(false) - }, [isLoading, setOnCloseAttemptToast]) - - return ( - - - - - - - {isOnCorrectChain ? ( - - ) : ( - - )} - - - ) -} - -export default PaymentForm diff --git a/src/requirements/Payment/PaymentRequirement.tsx b/src/requirements/Payment/PaymentRequirement.tsx deleted file mode 100644 index c6be61876f..0000000000 --- a/src/requirements/Payment/PaymentRequirement.tsx +++ /dev/null @@ -1,127 +0,0 @@ -import { Icon, Text } from "@chakra-ui/react" -import { Coins } from "@phosphor-icons/react" -import { BlockExplorerUrl } from "components/[guild]/Requirements/components/BlockExplorerUrl" -import BuyPass from "components/[guild]/Requirements/components/GuildCheckout/BuyPass" -import { GuildCheckoutProvider } from "components/[guild]/Requirements/components/GuildCheckout/components/GuildCheckoutContext" -import { - Requirement, - RequirementProps, -} from "components/[guild]/Requirements/components/Requirement" -import { useRequirementContext } from "components/[guild]/Requirements/components/RequirementContext" -import { RequirementWarningIcon } from "components/[guild]/Requirements/components/RequirementDisplayComponent" -import useGuildPermission from "components/[guild]/hooks/useGuildPermission" -import { DataBlock } from "components/common/DataBlock" -import { useRoleMembership } from "components/explorer/hooks/useMembership" -import useToken from "hooks/useToken" -import { NULL_ADDRESS } from "utils/guildCheckout/constants" -import { formatUnits } from "viem" -import { CHAIN_CONFIG, Chains } from "wagmiConfig/chains" -import PaymentTransactionStatusModal from "../../components/[guild]/Requirements/components/GuildCheckout/components/PaymentTransactionStatusModal" -import WithdrawButton from "./components/WithdrawButton" -import useVault from "./hooks/useVault" - -const OriginalPaymentRequirement = (props: RequirementProps): JSX.Element => { - const { isAdmin } = useGuildPermission() - - const { - id, - roleId, - chain, - address, - data: requirementData, - } = useRequirementContext<"PAYMENT">() - const { - token, - fee, - multiplePayments, - isLoading: isVaultLoading, - error: vaultError, - } = useVault(address as `0x${string}`, requirementData?.id, chain) - - const isNativeCurrency = token === NULL_ADDRESS - - const { - data: tokenData, - error: tokenError, - isLoading: isTokenDataLoading, - } = useToken({ - address: token, - chainId: Chains[chain], - shouldFetch: Boolean(!isNativeCurrency && chain), - }) - - const convertedFee = fee - ? isNativeCurrency - ? formatUnits(fee, CHAIN_CONFIG[chain].nativeCurrency.decimals) - : tokenData?.decimals - ? formatUnits(fee, tokenData.decimals) - : undefined - : undefined - - const symbol = isNativeCurrency - ? CHAIN_CONFIG[chain].nativeCurrency.symbol - : tokenData?.symbol - - const { reqAccesses } = useRoleMembership(roleId ?? 0) - - const satisfiesRequirement = reqAccesses?.find( - (req) => req.requirementId === id - )?.access - - return ( - } - {...props} - rightElement={ - props?.rightElement ? ( - - {satisfiesRequirement && !multiplePayments ? ( - props?.rightElement - ) : ( - - )} - - - ) : null - } - footer={ - <> - {isAdmin ? ( - - ) : token ? ( - - ) : null} - - } - > - <> - {"Pay "} - - {convertedFee && symbol ? `${convertedFee} ${symbol}` : "-"} - - {` on ${CHAIN_CONFIG[chain].name}`} - - - ) -} - -const PaymentRequirement = (props: RequirementProps) => { - const { type } = useRequirementContext() - return ( - }> - {`Unsupported requirement type: `} - {type} - - ) -} - -export default PaymentRequirement diff --git a/src/requirements/Payment/components/RegisterVaultForm/RegisterVaultForm.tsx b/src/requirements/Payment/components/RegisterVaultForm/RegisterVaultForm.tsx deleted file mode 100644 index 7b73dc58ea..0000000000 --- a/src/requirements/Payment/components/RegisterVaultForm/RegisterVaultForm.tsx +++ /dev/null @@ -1,193 +0,0 @@ -import { - FormControl, - FormHelperText, - FormLabel, - Input, - InputGroup, - InputRightAddon, - NumberDecrementStepper, - NumberIncrementStepper, - NumberInput, - NumberInputField, - NumberInputStepper, - Stack, - Text, -} from "@chakra-ui/react" -import FormErrorMessage from "components/common/FormErrorMessage" -import useToken from "hooks/useToken" -import { useController, useFormContext, useWatch } from "react-hook-form" -import useFeeInUSD from "requirements/Payment/components/RegisterVaultForm/hooks/useFeeInUSD" -import ChainPicker from "requirements/common/ChainPicker" -import TokenPicker from "requirements/common/TokenPicker" -import { - ADDRESS_REGEX, - NULL_ADDRESS, - paymentSupportedChains, -} from "utils/guildCheckout/constants" -import { useChainId } from "wagmi" -import { CHAIN_CONFIG, Chain, Chains } from "wagmiConfig/chains" - -const coingeckoCoinIds: Partial> = { - ETHEREUM: "ethereum", - POLYGON: "matic-network", - GOERLI: "ethereum", -} - -export type RegisterVaultFormType = { - chain: Chain - token: `0x${string}` - fee: string - owner: `0x${string}` -} - -type Props = { - isDisabled?: boolean -} - -const RegisterVaultForm = ({ isDisabled }: Props): JSX.Element => { - const { - control, - register, - setValue, - formState: { errors }, - } = useFormContext() - const chain = useWatch({ control, name: "chain" }) - const token = useWatch({ control, name: "token" }) - - const { data: tokenData } = useToken({ - address: token, - chainId: Chains[chain], - shouldFetch: Boolean(token !== NULL_ADDRESS && chain), - }) - const chainId = useChainId() - - const validateFee = (value: string): boolean | string => { - const tokenDecimals = - token === NULL_ADDRESS - ? CHAIN_CONFIG[Chains[chainId] as Chain].nativeCurrency.decimals - : tokenData?.decimals - const lastDotIndex = value.lastIndexOf(".") - const decimalPrecision = value.slice(lastDotIndex + 1).length - if (decimalPrecision > tokenDecimals) { - return `Decimal places must not exceed ${tokenDecimals} digits.` - } - - return true - } - - const { - field: { - ref: feeFieldRef, - value: feeFieldValue, - onChange: feeFieldOnChange, - onBlur: feeFieldOnBlur, - }, - fieldState: { error: feeFieldError }, - } = useController({ - name: "fee", - rules: { - required: "This field is required.", - min: { - value: 0, - message: "Amount must be positive", - }, - validate: validateFee, - }, - }) - - const handleFeeChange = (valueAsString: string) => { - const legalChars = "0123456789." - const filteredInput = [...valueAsString] - .filter((char) => legalChars.includes(char)) - .join("") - - feeFieldOnChange(filteredInput) - } - - const { feeInUSD } = useFeeInUSD( - feeFieldValue, - token === NULL_ADDRESS ? coingeckoCoinIds[chain] : undefined - ) - - return ( - - setValue("token", null)} - isDisabled={isDisabled} - /> - - - - - Price - - - handleFeeChange(valueAsString)} - onBlur={feeFieldOnBlur} - sx={ - feeInUSD > 0 && { - "> input": { - borderRightRadius: 0, - }, - "div div:first-of-type": { - borderTopRightRadius: 0, - }, - "div div:last-of-type": { - borderBottomRightRadius: 0, - }, - } - } - > - - - - - - - - {feeInUSD > 0 && ( - - {`$${feeInUSD.toFixed(2)}`} - - )} - - - Creators keep 90% of their revenue - - {feeFieldError?.message} - - - - Address to receive payments to - - - {errors?.owner?.message} - - - You need to register a vault in Guild's Payment contract in order to receive - payments. You'll be able to collect funds from it anytime. - - - ) -} - -export default RegisterVaultForm diff --git a/src/requirements/Payment/components/RegisterVaultForm/hooks/useCoinById.ts b/src/requirements/Payment/components/RegisterVaultForm/hooks/useCoinById.ts deleted file mode 100644 index 7c0f696342..0000000000 --- a/src/requirements/Payment/components/RegisterVaultForm/hooks/useCoinById.ts +++ /dev/null @@ -1,20 +0,0 @@ -import useSWRImmutable from "swr/immutable" -import fetcher from "utils/fetcher" - -const fetchCoin = (id: string) => - fetcher( - `https://api.coingecko.com/api/v3/coins/${id}?localization=false&tickers=true&market_data=true&community_data=false&developer_data=false&sparkline=false` - ) - -const useCoinById = ( - id: string -): { coinData: Record; isCoinDataLoading: boolean } => { - const { data: coinData, isValidating: isCoinDataLoading } = useSWRImmutable( - id, - fetchCoin - ) - - return { coinData, isCoinDataLoading } -} - -export default useCoinById diff --git a/src/requirements/Payment/components/RegisterVaultForm/hooks/useFeeInUSD.ts b/src/requirements/Payment/components/RegisterVaultForm/hooks/useFeeInUSD.ts deleted file mode 100644 index 0623081f82..0000000000 --- a/src/requirements/Payment/components/RegisterVaultForm/hooks/useFeeInUSD.ts +++ /dev/null @@ -1,17 +0,0 @@ -import useCoinById from "./useCoinById" - -const useFeeInUSD = ( - fee: number, - coingeckoId: string -): { feeInUSD: number; isFeeInUSDLoading: boolean } => { - const { coinData, isCoinDataLoading } = useCoinById(coingeckoId) - - const coinUSDPrice = coinData?.market_data?.current_price?.usd - - return { - feeInUSD: fee && coinUSDPrice ? fee * coinUSDPrice : undefined, - isFeeInUSDLoading: isCoinDataLoading, - } -} - -export default useFeeInUSD diff --git a/src/requirements/Payment/components/RegisterVaultForm/hooks/useRegisterVault.ts b/src/requirements/Payment/components/RegisterVaultForm/hooks/useRegisterVault.ts deleted file mode 100644 index 11f7a626ca..0000000000 --- a/src/requirements/Payment/components/RegisterVaultForm/hooks/useRegisterVault.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { usePostHogContext } from "@/components/Providers/PostHogProvider" -import useShowErrorToast from "hooks/useShowErrorToast" -import useSubmitTransaction from "hooks/useSubmitTransaction" -import useToken from "hooks/useToken" -import feeCollectorAbi from "static/abis/feeCollector" -import { findEvent } from "utils/findEventInTxResponse" -import { FEE_COLLECTOR_CONTRACT, NULL_ADDRESS } from "utils/guildCheckout/constants" -import { parseUnits } from "viem" -import { useChainId } from "wagmi" -import { CHAIN_CONFIG, Chain, Chains } from "wagmiConfig/chains" - -type RegisterVaultParams = { - owner: `0x${string}` - token: `0x${string}` - fee: string - chain: Chain -} - -const useRegisterVault = ({ - chain, - token, - fee, - owner, - onSuccess, -}: RegisterVaultParams & { onSuccess: (registeredVaultId: string) => void }) => { - const { captureEvent } = usePostHogContext() - const chainId = useChainId() - - const showErrorToast = useShowErrorToast() - - const { data: tokenData } = useToken({ - address: token, - chainId: Chains[chain], - shouldFetch: Boolean(token !== NULL_ADDRESS && chain), - }) - const tokenDecimals = - token === NULL_ADDRESS - ? CHAIN_CONFIG[Chains[chainId] as Chain].nativeCurrency.decimals - : tokenData?.decimals - - const feeInWei = fee && tokenDecimals ? parseUnits(fee, tokenDecimals) : undefined - - const registerVaultParams = [owner, token, false, BigInt(feeInWei ?? 0)] as const - - return useSubmitTransaction( - { - abi: feeCollectorAbi, - address: - FEE_COLLECTOR_CONTRACT[ - Chains[chainId] as keyof typeof FEE_COLLECTOR_CONTRACT - ], - functionName: "registerVault", - args: registerVaultParams, - chainId: Chains[chain], - query: { - enabled: Boolean(feeInWei && chainId === Chains[chain]), - }, - }, - { - setContext: false, - onError: (errorMessage, error) => { - showErrorToast(errorMessage) - captureEvent("Register vault error", { - error, - }) - }, - onSuccess: (_, events) => { - const vaultRegisteredEvent = findEvent< - typeof feeCollectorAbi, - "VaultRegistered" - >(events as [], "VaultRegistered") - - if (!vaultRegisteredEvent) { - showErrorToast("Couldn't find 'VaultRegistered' event") - return - } - - onSuccess(vaultRegisteredEvent.args.vaultId.toString()) - }, - } - ) -} - -export default useRegisterVault diff --git a/src/requirements/Payment/components/RegisterVaultForm/index.ts b/src/requirements/Payment/components/RegisterVaultForm/index.ts deleted file mode 100644 index cf9cfd8997..0000000000 --- a/src/requirements/Payment/components/RegisterVaultForm/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -import RegisterVaultForm, { RegisterVaultFormType } from "./RegisterVaultForm" - -export default RegisterVaultForm -export type { RegisterVaultFormType } diff --git a/src/requirements/Payment/components/WithdrawButton/WithdrawButton.tsx b/src/requirements/Payment/components/WithdrawButton/WithdrawButton.tsx deleted file mode 100644 index 1383585ed6..0000000000 --- a/src/requirements/Payment/components/WithdrawButton/WithdrawButton.tsx +++ /dev/null @@ -1,88 +0,0 @@ -import { Icon, Spinner, Tooltip } from "@chakra-ui/react" -import { LinkBreak, Wallet } from "@phosphor-icons/react" -import { useRequirementContext } from "components/[guild]/Requirements/components/RequirementContext" -import Button from "components/common/Button" -import useTokenData from "hooks/useTokenData" -import useTriggerNetworkChange from "hooks/useTriggerNetworkChange" -import useVault from "requirements/Payment/hooks/useVault" -import shortenHex from "utils/shortenHex" -import { formatUnits } from "viem" -import { useAccount } from "wagmi" -import { CHAIN_CONFIG, Chains } from "wagmiConfig/chains" -import useWithdraw from "./hooks/useWithdraw" - -const WithdrawButton = (): JSX.Element => { - const { - address: vaultAddressAsString, - chain, - data, - } = useRequirementContext<"PAYMENT">() - const vaultAddress = vaultAddressAsString as `0x${string}` - const { owner, token, balance } = useVault(vaultAddress, data?.id, chain) - const { - data: { symbol, decimals }, - } = useTokenData(chain, token) - - const { address, chainId } = useAccount() - const { requestNetworkChange } = useTriggerNetworkChange() - - const isOnVaultsChain = Chains[chain] === chainId - - const formattedWithdrawableAmount = - balance && decimals && Number(formatUnits(balance, decimals)) * 0.9 - - const { onSubmitTransaction, isPreparing, isLoading, error } = useWithdraw( - vaultAddress, - +data.id, - chain - ) - - const isDisabledLabel = - balance === BigInt(0) - ? "Withdrawable amount is 0" - : owner && owner !== address - ? `Only the requirement's original creator can withdraw (${shortenHex(owner)})` - : isOnVaultsChain && error - - return ( - - - - ) -} - -export default WithdrawButton diff --git a/src/requirements/Payment/components/WithdrawButton/hooks/useWithdraw.ts b/src/requirements/Payment/components/WithdrawButton/hooks/useWithdraw.ts deleted file mode 100644 index d17fe10ca4..0000000000 --- a/src/requirements/Payment/components/WithdrawButton/hooks/useWithdraw.ts +++ /dev/null @@ -1,50 +0,0 @@ -import useShowErrorToast from "hooks/useShowErrorToast" -import useSubmitTransaction from "hooks/useSubmitTransaction" -import useToast from "hooks/useToast" -import useVault from "requirements/Payment/hooks/useVault" -import feeCollectorAbi from "static/abis/feeCollector" -import { useChainId } from "wagmi" -import { Chain, Chains } from "wagmiConfig/chains" - -const useWithdraw = ( - contractAddress: `0x${string}`, - vaultId: number, - chain: Chain -) => { - const showErrorToast = useShowErrorToast() - const toast = useToast() - - const chainId = useChainId() - - const isOnVaultsChain = Chains[chain] === chainId - - const { refetch } = useVault(contractAddress, vaultId, chain) - - return useSubmitTransaction( - { - abi: feeCollectorAbi, - address: contractAddress, - functionName: "withdraw", - args: [BigInt(vaultId), "guild"], - query: { - enabled: isOnVaultsChain, - }, - }, - { - setContext: false, - customErrorsMap: { - TransferFailed: "Transfer failed", - }, - onError: (error) => showErrorToast(error), - onSuccess: () => { - toast({ - title: "Successful withdraw", - status: "success", - }) - refetch() - }, - } - ) -} - -export default useWithdraw diff --git a/src/requirements/Payment/components/WithdrawButton/index.ts b/src/requirements/Payment/components/WithdrawButton/index.ts deleted file mode 100644 index 0131322e3b..0000000000 --- a/src/requirements/Payment/components/WithdrawButton/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import WithdrawButton from "./WithdrawButton" - -export default WithdrawButton diff --git a/src/requirements/Payment/hooks/useHasPaid.ts b/src/requirements/Payment/hooks/useHasPaid.ts deleted file mode 100644 index c44ef9ea5a..0000000000 --- a/src/requirements/Payment/hooks/useHasPaid.ts +++ /dev/null @@ -1,25 +0,0 @@ -import feeCollectorAbi from "static/abis/feeCollector" -import { useAccount, useReadContract } from "wagmi" -import { Chain, Chains } from "wagmiConfig/chains" - -const useHasPaid = ( - contractAddress: `0x${string}`, - vaultId: number, - chain?: Chain -) => { - const { address } = useAccount() - const enabled = Boolean(contractAddress && address && vaultId) - - return useReadContract({ - abi: feeCollectorAbi, - address: contractAddress, - functionName: "hasPaid", - args: [BigInt(vaultId ?? 0), address], - chainId: Chains[chain], - query: { - enabled, - }, - }) -} - -export default useHasPaid diff --git a/src/requirements/Payment/hooks/useVault.ts b/src/requirements/Payment/hooks/useVault.ts deleted file mode 100644 index 9bdd35bf6f..0000000000 --- a/src/requirements/Payment/hooks/useVault.ts +++ /dev/null @@ -1,46 +0,0 @@ -import feeCollectorAbi from "static/abis/feeCollector" -import { useReadContract } from "wagmi" -import { Chain, Chains } from "wagmiConfig/chains" - -type GetVaultResponse = { - owner: `0x${string}` - token: `0x${string}` - multiplePayments: boolean - fee: bigint - balance: bigint - error: Error - isLoading: boolean - refetch: () => void -} - -const useVault = ( - contractAddress: `0x${string}`, - vaultId: number | string, - chain: Chain -): GetVaultResponse => { - const { data, error, isLoading, refetch } = useReadContract({ - address: contractAddress, - abi: feeCollectorAbi, - chainId: Chains[chain], - functionName: "getVault", - args: [BigInt(vaultId ?? 0)], - query: { - enabled: Boolean(contractAddress && vaultId && chain), - }, - }) - - const [owner, token, multiplePayments, fee, balance] = data ?? [] - - return { - owner, - token, - multiplePayments, - fee, - balance, - error, - isLoading, - refetch, - } -} - -export default useVault diff --git a/src/requirements/requirementDisplayComponents.ts b/src/requirements/requirementDisplayComponents.ts index 898cfa9e2e..360d0f2067 100644 --- a/src/requirements/requirementDisplayComponents.ts +++ b/src/requirements/requirementDisplayComponents.ts @@ -25,9 +25,6 @@ export const REQUIREMENT_DISPLAY_COMPONENTS = { GUILD_SNAPSHOT: dynamic( () => import("requirements/Airdrop/AirdropRequirement") ), - PAYMENT: dynamic( - () => import("requirements/Payment/PaymentRequirement") - ), CONTRACT: dynamic( () => import("requirements/ContractState/ContractStateRequirement") ), diff --git a/src/requirements/requirementFormComponents.ts b/src/requirements/requirementFormComponents.ts index 021937b55e..86bdca7926 100644 --- a/src/requirements/requirementFormComponents.ts +++ b/src/requirements/requirementFormComponents.ts @@ -15,9 +15,6 @@ export const REQUIREMENT_FORM_COMPONENTS = { () => import("requirements/Allowlist/AllowlistForm") ), GUILD_SNAPSHOT: null, - PAYMENT: dynamic( - () => import("requirements/Payment/PaymentForm") - ), CONTRACT: dynamic( () => import("requirements/ContractState/ContractStateForm") ), diff --git a/src/requirements/requirements.ts b/src/requirements/requirements.ts index 299e9beaed..728e447614 100644 --- a/src/requirements/requirements.ts +++ b/src/requirements/requirements.ts @@ -1,5 +1,4 @@ import { - Coins, CurrencyCircleDollar, ImageSquare, Link, @@ -46,11 +45,6 @@ export const REQUIREMENTS_DATA = [ types: ["GUILD_SNAPSHOT"], isNegatable: true, }, - { - icon: Coins, - name: "Payment", - types: ["PAYMENT"], - }, { icon: Wrench, name: "Contract query", diff --git a/src/utils/guildCheckout/constants.ts b/src/utils/guildCheckout/constants.ts index 35acc6fbb7..8b096fb670 100644 --- a/src/utils/guildCheckout/constants.ts +++ b/src/utils/guildCheckout/constants.ts @@ -22,16 +22,6 @@ export const ERC20_SUPPORTED_CHAINS = Object.keys( ERC20_CONTRACTS ) as (keyof typeof ERC20_CONTRACTS)[] -export const FEE_COLLECTOR_CONTRACT = { - ETHEREUM: "0xe4b4c6a7c6b6396032096c12adf46b7f14a70f4d", - OPTIMISM: "0xf7c2baa81feb6dd7bda0b3a03afbc1e13f955da5", - POLYGON: "0xe4b4c6a7c6b6396032096c12adf46b7f14a70f4d", - SEPOLIA: "0xc3563655d35397b77228c07a7f5301b0e0fa417d", -} as const satisfies Partial> -export const paymentSupportedChains = Object.keys( - FEE_COLLECTOR_CONTRACT -) as (keyof typeof FEE_COLLECTOR_CONTRACT)[] - export type GuildPinsSupportedChain = keyof typeof consts.PinContractAddresses export const openseaBaseUrl: Partial> = {