mirror of https://github.com/certusone/oyster.git
feat: remove register/vote workflow
This commit is contained in:
parent
f13b63b0b2
commit
6c75998abe
|
@ -1,106 +0,0 @@
|
||||||
import { ParsedAccount } from '@oyster/common';
|
|
||||||
import { Button, Col, Modal, Row, Slider } from 'antd';
|
|
||||||
import React, { useState } from 'react';
|
|
||||||
import {
|
|
||||||
TimelockConfig,
|
|
||||||
TimelockSet,
|
|
||||||
TimelockState,
|
|
||||||
TimelockStateStatus,
|
|
||||||
VotingEntryRule,
|
|
||||||
} from '../../models/timelock';
|
|
||||||
import { LABELS } from '../../constants';
|
|
||||||
import { depositSourceTokens } from '../../actions/depositSourceTokens';
|
|
||||||
import { contexts, hooks } from '@oyster/common';
|
|
||||||
import { ExclamationCircleOutlined } from '@ant-design/icons';
|
|
||||||
|
|
||||||
const { useWallet } = contexts.Wallet;
|
|
||||||
const { useConnection } = contexts.Connection;
|
|
||||||
const { useAccountByMint } = hooks;
|
|
||||||
|
|
||||||
const { confirm } = Modal;
|
|
||||||
export function RegisterToVote({
|
|
||||||
proposal,
|
|
||||||
state,
|
|
||||||
timelockConfig,
|
|
||||||
}: {
|
|
||||||
proposal: ParsedAccount<TimelockSet>;
|
|
||||||
state: ParsedAccount<TimelockState>;
|
|
||||||
timelockConfig: ParsedAccount<TimelockConfig>;
|
|
||||||
}) {
|
|
||||||
const wallet = useWallet();
|
|
||||||
const connection = useConnection();
|
|
||||||
const voteAccount = useAccountByMint(proposal.info.votingMint);
|
|
||||||
const yesVoteAccount = useAccountByMint(proposal.info.yesVotingMint);
|
|
||||||
const noVoteAccount = useAccountByMint(proposal.info.noVotingMint);
|
|
||||||
|
|
||||||
const userTokenAccount = useAccountByMint(proposal.info.sourceMint);
|
|
||||||
const alreadyHaveTokens =
|
|
||||||
(voteAccount && voteAccount.info.amount.toNumber() > 0) ||
|
|
||||||
(yesVoteAccount && yesVoteAccount.info.amount.toNumber() > 0) ||
|
|
||||||
(noVoteAccount && noVoteAccount.info.amount.toNumber() > 0);
|
|
||||||
|
|
||||||
const eligibleToView =
|
|
||||||
timelockConfig.info.votingEntryRule == VotingEntryRule.Anytime &&
|
|
||||||
[TimelockStateStatus.Draft, TimelockStateStatus.Voting].includes(
|
|
||||||
state.info.status,
|
|
||||||
);
|
|
||||||
|
|
||||||
const [_, setTokenAmount] = useState(1);
|
|
||||||
return eligibleToView ? (
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
onClick={() =>
|
|
||||||
confirm({
|
|
||||||
title: 'Confirm',
|
|
||||||
icon: <ExclamationCircleOutlined />,
|
|
||||||
content: (
|
|
||||||
<Row>
|
|
||||||
<Col span={24}>
|
|
||||||
<p>
|
|
||||||
You can convert up to{' '}
|
|
||||||
{userTokenAccount?.info.amount.toNumber() || 0} tokens to
|
|
||||||
voting tokens to vote on this proposal. You can refund these
|
|
||||||
at any time.
|
|
||||||
</p>
|
|
||||||
{userTokenAccount?.info.amount.toNumber() && (
|
|
||||||
<Slider
|
|
||||||
min={1}
|
|
||||||
max={userTokenAccount?.info.amount.toNumber() || 0}
|
|
||||||
onChange={setTokenAmount}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
),
|
|
||||||
okText: LABELS.CONFIRM,
|
|
||||||
cancelText: LABELS.CANCEL,
|
|
||||||
onOk: async () => {
|
|
||||||
if (userTokenAccount) {
|
|
||||||
// tokenAmount is out of date in this scope, so we use a trick to get it here.
|
|
||||||
const valueHolder = { value: 0 };
|
|
||||||
await setTokenAmount(amount => {
|
|
||||||
valueHolder.value = amount;
|
|
||||||
return amount;
|
|
||||||
});
|
|
||||||
|
|
||||||
await depositSourceTokens(
|
|
||||||
connection,
|
|
||||||
wallet.wallet,
|
|
||||||
proposal,
|
|
||||||
voteAccount?.pubkey,
|
|
||||||
yesVoteAccount?.pubkey,
|
|
||||||
noVoteAccount?.pubkey,
|
|
||||||
userTokenAccount.pubkey,
|
|
||||||
valueHolder.value,
|
|
||||||
);
|
|
||||||
// reset
|
|
||||||
setTokenAmount(1);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{alreadyHaveTokens ? LABELS.ADD_MORE_VOTES : LABELS.REGISTER_TO_VOTE}
|
|
||||||
</Button>
|
|
||||||
) : null;
|
|
||||||
}
|
|
|
@ -1,111 +0,0 @@
|
||||||
import { ParsedAccount } from '@oyster/common';
|
|
||||||
import { Button, Col, Modal, Row, Slider, Switch } from 'antd';
|
|
||||||
import React, { useState } from 'react';
|
|
||||||
import {
|
|
||||||
TimelockConfig,
|
|
||||||
TimelockSet,
|
|
||||||
TimelockState,
|
|
||||||
TimelockStateStatus,
|
|
||||||
} from '../../models/timelock';
|
|
||||||
import { LABELS } from '../../constants';
|
|
||||||
import { vote } from '../../actions/vote';
|
|
||||||
import { contexts, hooks } from '@oyster/common';
|
|
||||||
import {
|
|
||||||
CheckOutlined,
|
|
||||||
CloseOutlined,
|
|
||||||
ExclamationCircleOutlined,
|
|
||||||
} from '@ant-design/icons';
|
|
||||||
|
|
||||||
const { useWallet } = contexts.Wallet;
|
|
||||||
const { useConnection } = contexts.Connection;
|
|
||||||
const { useAccountByMint } = hooks;
|
|
||||||
|
|
||||||
const { confirm } = Modal;
|
|
||||||
export function Vote({
|
|
||||||
proposal,
|
|
||||||
state,
|
|
||||||
timelockConfig,
|
|
||||||
}: {
|
|
||||||
proposal: ParsedAccount<TimelockSet>;
|
|
||||||
state: ParsedAccount<TimelockState>;
|
|
||||||
timelockConfig: ParsedAccount<TimelockConfig>;
|
|
||||||
}) {
|
|
||||||
const wallet = useWallet();
|
|
||||||
const connection = useConnection();
|
|
||||||
const voteAccount = useAccountByMint(proposal.info.votingMint);
|
|
||||||
const yesVoteAccount = useAccountByMint(proposal.info.yesVotingMint);
|
|
||||||
const noVoteAccount = useAccountByMint(proposal.info.noVotingMint);
|
|
||||||
const [mode, setMode] = useState(true);
|
|
||||||
const [_, setTokenAmount] = useState(1);
|
|
||||||
const eligibleToView =
|
|
||||||
voteAccount &&
|
|
||||||
voteAccount.info.amount.toNumber() > 0 &&
|
|
||||||
state.info.status === TimelockStateStatus.Voting;
|
|
||||||
return eligibleToView ? (
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
onClick={() =>
|
|
||||||
confirm({
|
|
||||||
title: 'Confirm',
|
|
||||||
icon: <ExclamationCircleOutlined />,
|
|
||||||
content: (
|
|
||||||
<Row>
|
|
||||||
<Col span={24}>
|
|
||||||
<p>
|
|
||||||
Burning your {voteAccount?.info.amount.toNumber()} tokens is
|
|
||||||
an irreversible action. Choose how many to burn in favor OR
|
|
||||||
against this proposal. Use the switch to indicate preference.
|
|
||||||
</p>
|
|
||||||
<Slider
|
|
||||||
min={1}
|
|
||||||
max={voteAccount?.info.amount.toNumber()}
|
|
||||||
onChange={setTokenAmount}
|
|
||||||
/>
|
|
||||||
<Switch
|
|
||||||
checkedChildren={<CheckOutlined />}
|
|
||||||
unCheckedChildren={<CloseOutlined />}
|
|
||||||
defaultChecked
|
|
||||||
onChange={setMode}
|
|
||||||
/>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
),
|
|
||||||
okText: LABELS.CONFIRM,
|
|
||||||
cancelText: LABELS.CANCEL,
|
|
||||||
onOk: async () => {
|
|
||||||
if (voteAccount && yesVoteAccount && noVoteAccount) {
|
|
||||||
// tokenAmount and mode is out of date in this scope, so we use a trick to get it here.
|
|
||||||
const valueHolder = { value: 0, mode: true };
|
|
||||||
await setTokenAmount(amount => {
|
|
||||||
valueHolder.value = amount;
|
|
||||||
return amount;
|
|
||||||
});
|
|
||||||
await setMode(mode => {
|
|
||||||
valueHolder.mode = mode;
|
|
||||||
return mode;
|
|
||||||
});
|
|
||||||
const yesTokenAmount = valueHolder.mode ? valueHolder.value : 0;
|
|
||||||
const noTokenAmount = !valueHolder.mode ? valueHolder.value : 0;
|
|
||||||
await vote(
|
|
||||||
connection,
|
|
||||||
wallet.wallet,
|
|
||||||
proposal,
|
|
||||||
timelockConfig,
|
|
||||||
state,
|
|
||||||
voteAccount.pubkey,
|
|
||||||
yesVoteAccount.pubkey,
|
|
||||||
noVoteAccount.pubkey,
|
|
||||||
yesTokenAmount,
|
|
||||||
noTokenAmount,
|
|
||||||
);
|
|
||||||
// reset
|
|
||||||
setTokenAmount(1);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{LABELS.VOTE}
|
|
||||||
</Button>
|
|
||||||
) : null;
|
|
||||||
}
|
|
|
@ -68,11 +68,9 @@ export const LABELS = {
|
||||||
EXECUTED: 'Executed.',
|
EXECUTED: 'Executed.',
|
||||||
WITHDRAWING_VOTING_TOKENS: 'Refunding voting tokens as Source Tokens',
|
WITHDRAWING_VOTING_TOKENS: 'Refunding voting tokens as Source Tokens',
|
||||||
TOKENS_WITHDRAWN: 'Voting tokens refunded as Source Tokens',
|
TOKENS_WITHDRAWN: 'Voting tokens refunded as Source Tokens',
|
||||||
REGISTER_TO_VOTE: 'Register to Vote',
|
|
||||||
QUICK_VOTE: 'Quick Vote',
|
QUICK_VOTE: 'Quick Vote',
|
||||||
CONFIRM: 'Confirm',
|
CONFIRM: 'Confirm',
|
||||||
CANCEL: 'Cancel',
|
CANCEL: 'Cancel',
|
||||||
ADD_MORE_VOTES: 'Add More Votes',
|
|
||||||
REFUND_TOKENS: 'Refund My Tokens',
|
REFUND_TOKENS: 'Refund My Tokens',
|
||||||
REGISTER_GOVERNANCE: 'Register',
|
REGISTER_GOVERNANCE: 'Register',
|
||||||
PROGRAM: 'Program ID',
|
PROGRAM: 'Program ID',
|
||||||
|
|
|
@ -23,8 +23,6 @@ import { NewInstructionCard } from '../../components/Proposal/NewInstructionCard
|
||||||
import SignButton from '../../components/Proposal/SignButton';
|
import SignButton from '../../components/Proposal/SignButton';
|
||||||
import AddSigners from '../../components/Proposal/AddSigners';
|
import AddSigners from '../../components/Proposal/AddSigners';
|
||||||
import MintSourceTokens from '../../components/Proposal/MintSourceTokens';
|
import MintSourceTokens from '../../components/Proposal/MintSourceTokens';
|
||||||
import { Vote } from '../../components/Proposal/Vote';
|
|
||||||
import { RegisterToVote } from '../../components/Proposal/RegisterToVote';
|
|
||||||
import { QuickVote } from '../../components/Proposal/QuickVote';
|
import { QuickVote } from '../../components/Proposal/QuickVote';
|
||||||
import { WithdrawTokens } from '../../components/Proposal/WithdrawTokens';
|
import { WithdrawTokens } from '../../components/Proposal/WithdrawTokens';
|
||||||
import './style.less';
|
import './style.less';
|
||||||
|
@ -297,11 +295,6 @@ function InnerProposalView({
|
||||||
timelockConfig.info.governanceMint.toBase58()
|
timelockConfig.info.governanceMint.toBase58()
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<RegisterToVote
|
|
||||||
timelockConfig={timelockConfig}
|
|
||||||
proposal={proposal}
|
|
||||||
state={timelockState}
|
|
||||||
/>
|
|
||||||
<WithdrawTokens
|
<WithdrawTokens
|
||||||
timelockConfig={timelockConfig}
|
timelockConfig={timelockConfig}
|
||||||
proposal={proposal}
|
proposal={proposal}
|
||||||
|
@ -312,11 +305,6 @@ function InnerProposalView({
|
||||||
proposal={proposal}
|
proposal={proposal}
|
||||||
state={timelockState}
|
state={timelockState}
|
||||||
/>
|
/>
|
||||||
<Vote
|
|
||||||
proposal={proposal}
|
|
||||||
timelockConfig={timelockConfig}
|
|
||||||
state={timelockState}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
Loading…
Reference in New Issue