generated from scaffold-eth/scaffold-eth
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cancel rewards functionality (#2321)
* feat: add cancel rewards functionality * feat: check for rewards status in rewards info as well * feat: add switchChain fn to cancel rewards * feat: add toasts and one more messsage in cancel rewards modal
- Loading branch information
Showing
7 changed files
with
284 additions
and
47 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...amp/components/_pages/Contest/Rewards/components/CancelRewards/components/Modal/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import DialogModalV4 from "@components/UI/DialogModalV4"; | ||
import Image from "next/image"; | ||
import { FC } from "react"; | ||
|
||
interface CancelRewardsModalProps { | ||
isCancelRewardsModalOpen: boolean; | ||
setIsCancelRewardsModalOpen: (isOpen: boolean) => void; | ||
cancelRewardsHandler: () => void; | ||
} | ||
|
||
const CancelRewardsModal: FC<CancelRewardsModalProps> = ({ | ||
isCancelRewardsModalOpen, | ||
setIsCancelRewardsModalOpen, | ||
cancelRewardsHandler, | ||
}) => { | ||
return ( | ||
<DialogModalV4 isOpen={isCancelRewardsModalOpen} onClose={setIsCancelRewardsModalOpen}> | ||
<div className="flex flex-col gap-8 py-6 md:py-16 pl-8 md:pl-32 pr-4 md:pr-16"> | ||
<div className="flex justify-between items-center"> | ||
<p className="text-[24px] text-neutral-11 font-bold">cancel rewards?? 😬</p> | ||
<Image | ||
src="/modal/modal_close.svg" | ||
width={39} | ||
height={33} | ||
alt="close" | ||
className="hidden md:block cursor-pointer" | ||
onClick={() => setIsCancelRewardsModalOpen(false)} | ||
/> | ||
</div> | ||
<div className="flex flex-col gap-4 text-neutral-11 text-[16px]"> | ||
<p>if you proceed, you will cancel rewards for this contest.</p> | ||
<p className="font-bold">🚨 players will not be able to receive rewards.</p> | ||
<p>🚨 after you cancel rewards, you can withdraw any funds on the rewards page.</p> | ||
<p>🚨 you will not be able to deploy another rewards pool for this contest.</p> | ||
<p>are you really, really, really sure you want to proceed?</p> | ||
</div> | ||
<button | ||
className="mt-4 bg-negative-11 rounded-[40px] w-80 h-10 text-center text-true-black text-[16px] font-bold hover:opacity-80 transition-opacity duration-300 ease-in-out" | ||
onClick={cancelRewardsHandler} | ||
> | ||
cancel rewards 😈 | ||
</button> | ||
</div> | ||
</DialogModalV4> | ||
); | ||
}; | ||
|
||
export default CancelRewardsModal; |
48 changes: 48 additions & 0 deletions
48
...ges/react-app-revamp/components/_pages/Contest/Rewards/components/CancelRewards/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useCancelRewards } from "@hooks/useCancelRewards"; | ||
import { FC, useState } from "react"; | ||
import CancelRewardsModal from "./components/Modal"; | ||
import { TrashIcon } from "@heroicons/react/24/outline"; | ||
import { Abi } from "viem"; | ||
import { switchChain } from "@wagmi/core"; | ||
import { useAccount } from "wagmi"; | ||
import { config } from "@config/wagmi"; | ||
|
||
interface CancelRewardsProps { | ||
rewardsAddress: `0x${string}`; | ||
abi: Abi; | ||
chainId: number; | ||
version: string; | ||
} | ||
|
||
const CancelRewards: FC<CancelRewardsProps> = ({ rewardsAddress, abi, chainId, version }) => { | ||
const { cancelRewards, isLoading } = useCancelRewards({ rewardsAddress, abi, chainId, version }); | ||
const [isCancelRewardsModalOpen, setIsCancelRewardsModalOpen] = useState(false); | ||
const { chainId: accountChainId } = useAccount(); | ||
const isUserOnCorrectChain = accountChainId === chainId; | ||
const handleOpenModal = () => setIsCancelRewardsModalOpen(true); | ||
|
||
const handleCancelRewards = async () => { | ||
if (!isUserOnCorrectChain) { | ||
await switchChain(config, { chainId }); | ||
} | ||
|
||
cancelRewards(); | ||
setIsCancelRewardsModalOpen(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<button disabled={isLoading} onClick={handleOpenModal}> | ||
<TrashIcon className="w-6 h-6 text-negative-11 hover:text-negative-10 transition-colors duration-300 ease-in-out" /> | ||
</button> | ||
|
||
<CancelRewardsModal | ||
isCancelRewardsModalOpen={isCancelRewardsModalOpen} | ||
setIsCancelRewardsModalOpen={setIsCancelRewardsModalOpen} | ||
cancelRewardsHandler={handleCancelRewards} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default CancelRewards; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.