generated from scaffold-eth/scaffold-eth
-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2968 from OlympusDAO/develop
Release: Delegate coolers & repay calc
- Loading branch information
Showing
6 changed files
with
208 additions
and
167 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useMutation } from "@tanstack/react-query"; | ||
import toast from "react-hot-toast"; | ||
import { Cooler__factory } from "src/typechain"; | ||
import { useSigner } from "wagmi"; | ||
|
||
export const useDelegateVoting = () => { | ||
const { data: signer } = useSigner(); | ||
|
||
return useMutation( | ||
async ({ coolerAddress, delegationAddress }: { coolerAddress: string; delegationAddress: string }) => { | ||
if (!signer) throw new Error(`Please connect a wallet`); | ||
const coolerContract = Cooler__factory.connect(coolerAddress, signer); | ||
const receipt = await coolerContract.delegateVoting(delegationAddress); | ||
return receipt; | ||
}, | ||
{ | ||
onError: (error: Error) => { | ||
toast.error(error.message); | ||
}, | ||
onSuccess: async tx => { | ||
toast(`Successfully Delegated Voting`); | ||
}, | ||
}, | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Box, SvgIcon } from "@mui/material"; | ||
import { Input, Modal, PrimaryButton } from "@olympusdao/component-library"; | ||
import { useState } from "react"; | ||
import { ReactComponent as lendAndBorrowIcon } from "src/assets/icons/lendAndBorrow.svg"; | ||
import { WalletConnectedGuard } from "src/components/WalletConnectedGuard"; | ||
import { useDelegateVoting } from "src/views/Lending/Cooler/hooks/useDelegateVoting"; | ||
|
||
export const DelegateVoting = ({ | ||
coolerAddress, | ||
open, | ||
setOpen, | ||
}: { | ||
coolerAddress?: string; | ||
open: boolean; | ||
setOpen: (open: boolean) => void; | ||
}) => { | ||
const [delegationAddress, setDelegationAddress] = useState(""); | ||
const delegateVoting = useDelegateVoting(); | ||
|
||
return ( | ||
<Modal | ||
maxWidth="476px" | ||
minHeight="200px" | ||
open={open} | ||
headerContent={ | ||
<Box display="flex" alignItems="center" gap="6px"> | ||
<SvgIcon component={lendAndBorrowIcon} /> <Box fontWeight="500">Delegate Voting</Box> | ||
</Box> | ||
} | ||
onClose={() => setOpen(false)} | ||
> | ||
{coolerAddress ? ( | ||
<> | ||
<Box display="flex" flexDirection="row" justifyContent="space-between" alignItems="center"></Box> | ||
<Box mt={"16px"} mb="16px"> | ||
<Input | ||
id="delegateAddress" | ||
placeholder="Address" | ||
value={delegationAddress} | ||
onChange={e => { | ||
setDelegationAddress(e.target.value); | ||
}} | ||
/> | ||
</Box> | ||
|
||
<WalletConnectedGuard fullWidth> | ||
<PrimaryButton | ||
fullWidth | ||
disabled={delegateVoting.isLoading} | ||
onClick={() => { | ||
delegateVoting.mutate( | ||
{ coolerAddress, delegationAddress }, | ||
{ | ||
onSuccess: () => { | ||
setOpen(false); | ||
}, | ||
}, | ||
); | ||
}} | ||
loading={delegateVoting.isLoading} | ||
> | ||
Delegate Voting | ||
</PrimaryButton> | ||
</WalletConnectedGuard> | ||
</> | ||
) : ( | ||
<></> | ||
)} | ||
</Modal> | ||
); | ||
}; |
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.