Skip to content

Commit

Permalink
Merge branch 'main' into transaction-status-context-modal-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
BrickheadJohnny committed Nov 12, 2024
2 parents 2e8f2a5 + 5df4963 commit fbbd684
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Open source interface for Guild.xyz -- a tool for platformless membership manage

1. `npm i`
2. `npm run dev`
3. If you don't have the secret environment variables, copy the `.env.examples` as `.env.local`.
3. If you don't have the secret environment variables, copy the `.env.example` as `.env.local`.

Open [http://localhost:3000](http://localhost:3000) in your browser to see the result.

Expand Down
Binary file added public/lego/GuildRamenAssembly.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion src/app/oauth-result/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const OauthResultPage = ({ searchParams }: { searchParams: OAuthResultParams })
<div className="flex h-[90vh] flex-col justify-center p-10 text-center">
<h1 className="mb-3 font-bold text-2xl">
{searchParams.status === "success"
? `${rewardConfig?.name} successfully conneted!`
? `${rewardConfig?.name} successfully connected!`
: searchParams.platform
? `${rewardConfig?.name} connection failed`
: "Connection unsuccessful"}
Expand Down
16 changes: 10 additions & 6 deletions src/rewards/Token/ClaimTokenButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ButtonProps, Tooltip, useDisclosure } from "@chakra-ui/react"
import { useRolePlatform } from "components/[guild]/RolePlatforms/components/RolePlatformProvider"
import dynamic from "next/dynamic"
import { claimTextButtonTooltipLabel } from "rewards/SecretText/TextCardButton"
import { RewardCardButton } from "rewards/components/RewardCardButton"
Expand All @@ -12,25 +11,30 @@ import {
GeogatedCountryPopover,
useIsFromGeogatedCountry,
} from "./GeogatedCountryAlert"
import { TokenRewardProvider } from "./TokenRewardContext"
import { TokenRewardProvider, useTokenRewardContext } from "./TokenRewardContext"

type Props = {
isDisabled?: boolean
rolePlatform: RolePlatform
rolePlatform: RolePlatform // TODO: decide if it should be a prop or we should get it from context!
} & ButtonProps

const DynamicClaimTokenModal = dynamic(() => import("./ClaimTokenModal"))

const ClaimTokenButton = ({ isDisabled, children, ...rest }: Props) => {
const rolePlatform = useRolePlatform()
const ClaimTokenButton = ({
isDisabled,
rolePlatform,
children,
...rest
}: Props) => {
const { guildPlatform } = useTokenRewardContext()

const { isOpen, onOpen, onClose } = useDisclosure()
const isFromGeogatedCountry = useIsFromGeogatedCountry()

const { isAvailable } = getRolePlatformTimeframeInfo(rolePlatform)

return (
<TokenRewardProvider guildPlatform={rolePlatform.guildPlatform}>
<TokenRewardProvider guildPlatform={guildPlatform}>
<GeogatedCountryPopover isDisabled={!isFromGeogatedCountry}>
<Tooltip
isDisabled={!isAvailable}
Expand Down
2 changes: 1 addition & 1 deletion src/rewards/Token/EditTokenModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ const EditTokenModal = ({
if (!!snapshotRequirement && changeSnapshot) {
await submitEditRequirement({
...snapshotRequirement,
...data.snapshotRequirement,
id: snapshotRequirement?.id!, // just to make TS happy...
data: data?.data?.guildPlatformId ? data.data : snapshotRequirement?.data,
})
}

Expand Down
83 changes: 83 additions & 0 deletions src/rewards/Token/PoolDetailsDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { Anchor } from "@/components/ui/Anchor"
import { Badge, badgeVariants } from "@/components/ui/Badge"
import { Button } from "@/components/ui/Button"
import {
Dialog,
DialogBody,
DialogCloseButton,
DialogContent,
DialogHeader,
DialogTitle,
} from "@/components/ui/Dialog"
import { useCopyToClipboard } from "@/hooks/useCopyToClipboard"
import { cn } from "@/lib/utils"
import { Check, Copy } from "@phosphor-icons/react/dist/ssr"
import { useRolePlatform } from "components/[guild]/RolePlatforms/components/RolePlatformProvider"
import { Dispatch, SetStateAction } from "react"
import shortenHex from "utils/shortenHex"
import { CHAIN_CONFIG, Chain } from "wagmiConfig/chains"

type Props = {
open: boolean
onOpenChange: Dispatch<SetStateAction<boolean>>
}

export const PoolDetailsDialog = ({ open, onOpenChange }: Props) => {
const { guildPlatform } = useRolePlatform()

const { chain, poolId, contractAddress } = guildPlatform.platformGuildData

const chainIcon = CHAIN_CONFIG[chain as Chain].iconUrl
const chainName = CHAIN_CONFIG[chain as Chain].name
const blockExplorerUrl = CHAIN_CONFIG[chain as Chain].blockExplorerUrl

const { hasCopied, copyToClipboard } = useCopyToClipboard()

return (
<Dialog open={open} onOpenChange={(open) => onOpenChange(open)}>
<DialogContent>
<DialogHeader>
<DialogTitle>Pool details</DialogTitle>
</DialogHeader>

<DialogBody>
<div className="flex h-8 items-center justify-between">
<span className="font-bold">Chain</span>
<Badge>
<img src={chainIcon} alt={chainName} className="size-4" />
<span>{chainName}</span>
</Badge>
</div>

<div className="flex h-8 items-center justify-between">
<span className="font-bold">Contract</span>
<Badge>
<Anchor
href={`${blockExplorerUrl}/address/${contractAddress}`}
className="hover:underline-offset-1"
target="_blank"
showExternal
>
{shortenHex(contractAddress)}
</Anchor>
</Badge>
</div>

<div className="flex h-8 items-center justify-between">
<span className="font-bold">Pool ID</span>
<Button
className={cn(badgeVariants({ className: "" }))}
size="sm"
leftIcon={hasCopied ? <Check weight="bold" /> : <Copy weight="bold" />}
onClick={() => copyToClipboard(poolId.toString())}
>
{`#${poolId}`}
</Button>
</div>
</DialogBody>

<DialogCloseButton />
</DialogContent>
</Dialog>
)
}
75 changes: 69 additions & 6 deletions src/rewards/Token/TokenRewardCardEditMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import { useDisclosure } from "@/hooks/useDisclosure"
import { MenuDivider, MenuItem, useColorModeValue } from "@chakra-ui/react"
import {
MenuDivider,
MenuItem,
useColorModeValue,
useDisclosure,
} from "@chakra-ui/react"
import { Coin, Pencil, TrashSimple, Wallet } from "@phosphor-icons/react"
ArrowSquareOut,
ArrowsLeftRight,
Coin,
Pencil,
TrashSimple,
Wallet,
} from "@phosphor-icons/react"
import EditRewardAvailabilityMenuItem from "components/[guild]/AccessHub/components/EditRewardAvailabilityMenuItem"
import PlatformCardMenu from "components/[guild]/RolePlatforms/components/PlatformCard/components/PlatformCardMenu"
import useToast from "hooks/useToast"
import dynamic from "next/dynamic"
import { useState } from "react"
import { GuildPlatform } from "types"
import { ERC20_SUPPORTED_CHAINS } from "utils/guildCheckout/constants"
import { useAccount } from "wagmi"
import EditTokenModal from "./EditTokenModal"
import FundPoolModal from "./FundPoolModal"
import { PoolDetailsDialog } from "./PoolDetailsDialog"
import RemoveTokenRewardConfirmation from "./RemoveTokenRewardConfirmation"
import WithdrawPoolModal from "./WithdrawPoolModal"
import usePool from "./hooks/usePool"

const DynamicTransferPoolOwnershipDialog = dynamic(() =>
import("./TransferPoolOwnershipDialog").then(
(module) => module.TransferPoolOwnershipDialog
)
)

const TokenRewardCardEditMenu = ({
guildPlatform,
Expand All @@ -37,6 +52,18 @@ const TokenRewardCardEditMenu = ({
onClose: editOnClose,
} = useDisclosure()

const {
onOpen: transferOwnershipOnOpen,
isOpen: transferOwnershipIsOpen,
setValue: transferOwnershipSetValue,
} = useDisclosure()

const {
onOpen: poolDetailsOnOpen,
isOpen: poolDetailsIsOpen,
setValue: poolDetailsSetValue,
} = useDisclosure()

const {
isOpen: deleteIsOpen,
onOpen: deleteOnOpen,
Expand All @@ -47,6 +74,18 @@ const TokenRewardCardEditMenu = ({

const removeColor = useColorModeValue("red.600", "red.300")

const { address } = useAccount()
const { data } = usePool(
// TODO: should we use `guildPlatform.platformGuildData.contractAddress` here instead?
guildPlatform.platformGuildData
?.chain as (typeof ERC20_SUPPORTED_CHAINS)[number],
BigInt(guildPlatform.platformGuildData?.poolId ?? "0") // We'll never use this fallback, since poolId is defined at this point
)

const isPoolOwner = data?.owner?.toLowerCase() === address?.toLowerCase()

const [shouldHideTransferButton, setShouldHideTransferButton] = useState(false)

return (
<>
<PlatformCardMenu>
Expand All @@ -63,6 +102,14 @@ const TokenRewardCardEditMenu = ({
<MenuItem icon={<Wallet />} onClick={withdrawOnOpen}>
Withdraw from pool
</MenuItem>
{isPoolOwner && !shouldHideTransferButton && (
<MenuItem icon={<ArrowsLeftRight />} onClick={transferOwnershipOnOpen}>
Transfer pool ownership
</MenuItem>
)}
<MenuItem icon={<ArrowSquareOut />} onClick={poolDetailsOnOpen}>
View pool details
</MenuItem>
<MenuDivider />
<MenuItem icon={<TrashSimple />} onClick={deleteOnOpen} color={removeColor}>
Remove reward
Expand Down Expand Up @@ -95,6 +142,22 @@ const TokenRewardCardEditMenu = ({
/>

<EditTokenModal onClose={editOnClose} isOpen={editIsOpen} />

{isPoolOwner && (
<DynamicTransferPoolOwnershipDialog
open={transferOwnershipIsOpen}
onOpenChange={transferOwnershipSetValue}
/**
* The proper way of doing this would be to wait for the TX receipt when transferring ownership, then mutate `usePool`'s data, but this will work too for now
*/
onSuccess={() => setShouldHideTransferButton(true)}
/>
)}

<PoolDetailsDialog
open={poolDetailsIsOpen}
onOpenChange={poolDetailsSetValue}
/>
</>
)
}
Expand Down
Loading

0 comments on commit fbbd684

Please sign in to comment.