-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
292 additions
and
168 deletions.
There are no files selected for viewing
41 changes: 23 additions & 18 deletions
41
frontend/components/Admin/AdminPanel/Grants/CancelButton.js
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 |
---|---|---|
@@ -1,42 +1,47 @@ | ||
import { ethers } from 'ethers' | ||
import { useToast } from '@chakra-ui/react' | ||
import { DeleteIcon } from '@chakra-ui/icons' | ||
import vesterAbi from '../../../../abis/Vester.json' | ||
import { useSigner } from 'wagmi' | ||
import { ethers } from "ethers"; | ||
import { useToast } from "@chakra-ui/react"; | ||
import { DeleteIcon } from "@chakra-ui/icons"; | ||
import vesterAbi from "../../../../abis/Vester.json"; | ||
import { useEthersSigner } from "../../../../utils/ethers"; | ||
import { useAccount } from "wagmi"; | ||
|
||
export default function CancelButton({ tokenId }) { | ||
const toast = useToast(); | ||
const { data: signer } = useSigner() | ||
const { chain } = useAccount(); | ||
const signer = useEthersSigner({ chainId: chain.id }); | ||
|
||
const executeCancel = async () => { | ||
const vesterContract = new ethers.Contract(process.env.NEXT_PUBLIC_VESTER_CONTRACT_ADDRESS, vesterAbi.abi, signer); | ||
const vesterContract = new ethers.Contract( | ||
process.env.NEXT_PUBLIC_VESTER_CONTRACT_ADDRESS, | ||
vesterAbi.abi, | ||
signer | ||
); | ||
|
||
try { | ||
await vesterContract.cancelGrant(tokenId) | ||
await vesterContract.cancelGrant(tokenId); | ||
} catch (err) { | ||
console.log(err) | ||
console.log(err); | ||
toast({ | ||
title: "Error", | ||
description: err?.data?.message || err?.error?.data?.message, | ||
status: "error", | ||
isClosable: true, | ||
}); | ||
return | ||
return; | ||
} | ||
|
||
toast({ | ||
title: 'Transaction Submitted', | ||
title: "Transaction Submitted", | ||
description: | ||
'Refer to your wallet for the latest status of this transaction. Refresh the page for an updated list of grants.', | ||
status: 'info', | ||
position: 'top', | ||
"Refer to your wallet for the latest status of this transaction. Refresh the page for an updated list of grants.", | ||
status: "info", | ||
position: "top", | ||
duration: 10000, | ||
isClosable: true, | ||
}) | ||
|
||
} | ||
}); | ||
}; | ||
|
||
return ( | ||
<DeleteIcon onClick={() => executeCancel()} cursor="pointer" boxSize={4} /> | ||
) | ||
); | ||
} |
Oops, something went wrong.