-
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.
Add approval page & fix split request accept thing (#267)
* add approval page * cleanup * fix
- Loading branch information
Showing
7 changed files
with
146 additions
and
4 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,103 @@ | ||
import type { NextPage } from 'next' | ||
import Layout from '../components/Layout' | ||
import SEO from '../components/SEO' | ||
import { | ||
useAnchorWallet, | ||
useConnection, | ||
useWallet, | ||
} from '@solana/wallet-adapter-react' | ||
import { | ||
PythBalance, | ||
StakeAccount, | ||
StakeConnection, | ||
STAKING_ADDRESS, | ||
} from '@pythnetwork/staking' | ||
import { useEffect, useState } from 'react' | ||
import { utils, Wallet } from '@project-serum/anchor' | ||
import toast from 'react-hot-toast' | ||
import { capitalizeFirstLetter } from '../utils/capitalizeFirstLetter' | ||
import { PublicKey } from '@solana/web3.js' | ||
import { useRouter } from 'next/router' | ||
|
||
const ApproveSplit: NextPage = () => { | ||
const { connection } = useConnection() | ||
const anchorWallet = useAnchorWallet() | ||
const { publicKey, connected } = useWallet() | ||
|
||
const [stakeConnection, setStakeConnection] = useState<StakeConnection>() | ||
|
||
const [stakeAccount, setStakeAccount] = useState<StakeAccount>() | ||
const [amount, setAmount] = useState<PythBalance>() | ||
const [recipient, setRecipient] = useState<PublicKey>() | ||
|
||
useEffect(() => { | ||
const initialize = async () => { | ||
try { | ||
const stakeConnection = await StakeConnection.createStakeConnection( | ||
connection, | ||
anchorWallet as Wallet, | ||
STAKING_ADDRESS | ||
) | ||
setStakeConnection(stakeConnection) | ||
} catch (e) { | ||
toast.error(capitalizeFirstLetter(e.message)) | ||
} | ||
} | ||
if (!connected) { | ||
setStakeConnection(undefined) | ||
} else { | ||
initialize() | ||
} | ||
}, [connected]) | ||
|
||
const router = useRouter() | ||
const { key } = router.query | ||
|
||
useEffect(() => { | ||
const helper = async () => { | ||
if (stakeConnection !== undefined) { | ||
const splitAccountOwner: PublicKey = new PublicKey(key!) | ||
const stakeAccount = (await stakeConnection!.getMainAccount( | ||
splitAccountOwner | ||
))! | ||
|
||
const { balance, recipient } = (await stakeConnection.getSplitRequest( | ||
stakeAccount | ||
))! | ||
|
||
setStakeAccount(stakeAccount) | ||
setAmount(balance) | ||
setRecipient(recipient) | ||
} | ||
} | ||
helper() | ||
}, [stakeConnection]) | ||
|
||
const approveSplit = async () => { | ||
await stakeConnection!.acceptSplit(stakeAccount!, amount!, recipient!) | ||
} | ||
|
||
return ( | ||
<Layout> | ||
<SEO title={'Approve Split'} /> | ||
<p className=" text-sm ">Approve a split request from {key}</p> | ||
<p> | ||
{stakeAccount != undefined | ||
? `stake account address: ${stakeAccount.address}` | ||
: 'no owner'} | ||
</p> | ||
<p>{amount != undefined ? `amount: ${amount}` : 'no amount'}</p> | ||
<p> | ||
{recipient != undefined ? `recipient: ${recipient}` : 'no recipient'} | ||
</p> | ||
<button | ||
className="rounded-full p-2 hover:bg-hoverGray" | ||
onClick={() => approveSplit()} | ||
> | ||
Click to approve | ||
</button> | ||
</Layout> | ||
) | ||
} | ||
|
||
export default ApproveSplit |
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
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
b59be91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
staking – ./
staking-rho-nine.vercel.app
staking-git-main-pyth-web.vercel.app
staking.pyth.network
staking-pyth-web.vercel.app
b59be91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
staking-devnet – ./
governance-nu.vercel.app
staking-devnet-pyth-web.vercel.app
staking-devnet-git-main-pyth-web.vercel.app