-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create election's governance (#388)
* CHeckpoint * Continue * Continue * Cleanup * Bump program version * Cleanup * Continue * Continue * add comment
- Loading branch information
Showing
2 changed files
with
116 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { NextPage } from 'next' | ||
import Layout from '../components/Layout' | ||
import SEO from '../components/SEO' | ||
import { StakeAccount } from '@pythnetwork/staking' | ||
import { useEffect, useState } from 'react' | ||
import toast from 'react-hot-toast' | ||
import { capitalizeFirstLetter } from 'utils/capitalizeFirstLetter' | ||
import { useStakeConnection } from 'hooks/useStakeConnection' | ||
import { useStakeAccounts } from 'hooks/useStakeAccounts' | ||
|
||
const CreateElectionGovernance: NextPage = () => { | ||
const { data: stakeConnection } = useStakeConnection() | ||
const { data: stakeAccounts } = useStakeAccounts() | ||
const [selectedStakeAccount, setSelectStakeAccount] = useState<StakeAccount>() | ||
|
||
useEffect(() => { | ||
if (stakeAccounts && stakeAccounts.length > 0) | ||
setSelectStakeAccount(stakeAccounts[0]) | ||
}, [stakeAccounts]) | ||
|
||
const createElectionGovernance = async () => { | ||
if (stakeConnection && selectedStakeAccount) | ||
try { | ||
await stakeConnection.createElectionGovernance(selectedStakeAccount) | ||
toast.success('Successfully created election governance') | ||
} catch (err) { | ||
toast.error(capitalizeFirstLetter(err.message)) | ||
} | ||
} | ||
|
||
return ( | ||
<Layout> | ||
<SEO title={'Create election governance'} /> | ||
{stakeConnection ? ( | ||
<p> | ||
<button | ||
className="rounded-full p-2 hover:bg-hoverGray" | ||
onClick={() => createElectionGovernance()} | ||
> | ||
Click to approve | ||
</button> | ||
</p> | ||
) : ( | ||
<p className="p-2 hover:bg-hoverGray"> Please connect wallet</p> | ||
)} | ||
</Layout> | ||
) | ||
} | ||
|
||
export default CreateElectionGovernance |
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