Add nomination (basic, initially single account) (#845)
This commit is contained in:
parent
c96b51b216
commit
fd104ccd45
@ -5,29 +5,30 @@
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Button, Input, Modal } from '@polkadot/ui-app';
|
||||
import { Button, Input, Modal, TxButton } from '@polkadot/ui-app';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
type Props = I18nProps & {
|
||||
accountId: string,
|
||||
isOpen: boolean,
|
||||
onClose: () => void,
|
||||
onNominate: (nominee: string) => void,
|
||||
intentions: Array<string>
|
||||
intentions: Array<string>,
|
||||
validators: Array<string>
|
||||
};
|
||||
|
||||
type State = {
|
||||
isNomineeValid: boolean,
|
||||
isAddressFormatValid: boolean,
|
||||
nominee: string
|
||||
nominees: Array<string>
|
||||
};
|
||||
|
||||
class Nominating extends React.PureComponent<Props, State> {
|
||||
state: State = {
|
||||
isNomineeValid: false,
|
||||
isAddressFormatValid: false,
|
||||
nominee: ''
|
||||
nominees: []
|
||||
};
|
||||
|
||||
render () {
|
||||
@ -51,8 +52,8 @@ class Nominating extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
renderButtons () {
|
||||
const { onClose, t } = this.props;
|
||||
const { isNomineeValid } = this.state;
|
||||
const { accountId, onClose, t } = this.props;
|
||||
const { isNomineeValid, nominees } = this.state;
|
||||
|
||||
return (
|
||||
<Modal.Actions>
|
||||
@ -63,11 +64,14 @@ class Nominating extends React.PureComponent<Props, State> {
|
||||
label={t('Cancel')}
|
||||
/>
|
||||
<Button.Or />
|
||||
<Button
|
||||
isDisabled={!isNomineeValid}
|
||||
<TxButton
|
||||
accountId={accountId}
|
||||
isDisabled={!isNomineeValid || !nominees.length}
|
||||
isPrimary
|
||||
onClick={this.nominate}
|
||||
onClick={onClose}
|
||||
params={[nominees]}
|
||||
label={t('Nominate')}
|
||||
tx='staking.nominate'
|
||||
/>
|
||||
</Button.Group>
|
||||
</Modal.Actions>
|
||||
@ -76,7 +80,7 @@ class Nominating extends React.PureComponent<Props, State> {
|
||||
|
||||
renderContent () {
|
||||
const { t } = this.props;
|
||||
const { isNomineeValid, nominee } = this.state;
|
||||
const { isNomineeValid, nominees } = this.state;
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -90,7 +94,7 @@ class Nominating extends React.PureComponent<Props, State> {
|
||||
isError={!isNomineeValid}
|
||||
label={t('nominate the following address (validator or intention)')}
|
||||
onChange={this.onChangeNominee}
|
||||
value={nominee}
|
||||
value={nominees[0]}
|
||||
/>
|
||||
{this.renderErrors()}
|
||||
</Modal.Content>
|
||||
@ -124,7 +128,7 @@ class Nominating extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
private onChangeNominee = (nominee: string) => {
|
||||
const { intentions } = this.props;
|
||||
const { intentions, validators } = this.props;
|
||||
|
||||
let isAddressFormatValid = false;
|
||||
|
||||
@ -137,22 +141,11 @@ class Nominating extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
this.setState({
|
||||
isNomineeValid: intentions.includes(nominee),
|
||||
isNomineeValid: validators.includes(nominee) || intentions.includes(nominee),
|
||||
isAddressFormatValid,
|
||||
nominee
|
||||
nominees: [nominee]
|
||||
});
|
||||
}
|
||||
|
||||
private nominate = () => {
|
||||
const { onClose, onNominate } = this.props;
|
||||
const { nominee } = this.state;
|
||||
|
||||
if (!nominee) {
|
||||
onClose();
|
||||
} else {
|
||||
onNominate(nominee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default translate(Nominating);
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
|
||||
import { DerivedBalancesMap } from '@polkadot/api-derive/types';
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { QueueTx$ExtrinsicAdd } from '@polkadot/ui-app/Status/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
|
||||
import React from 'react';
|
||||
@ -15,8 +14,7 @@ import { withCalls } from '@polkadot/ui-api';
|
||||
import Bonding from './Bonding';
|
||||
import Controller from './Controller';
|
||||
import Staking from './Staking';
|
||||
// import Nominating from './Nominating';
|
||||
// import UnnominateButton from './UnnominateButton';
|
||||
import Nominating from './Nominating';
|
||||
import translate from '../translate';
|
||||
|
||||
type Props = ApiProps & I18nProps & {
|
||||
@ -31,12 +29,13 @@ type Props = ApiProps & I18nProps & {
|
||||
staking_validators?: ValidatorPrefs,
|
||||
intentions: Array<string>,
|
||||
isValidator: boolean,
|
||||
queueExtrinsic: QueueTx$ExtrinsicAdd
|
||||
validators: Array<string>
|
||||
};
|
||||
|
||||
type State = {
|
||||
isBondingOpen: boolean,
|
||||
isControllerOpen: boolean,
|
||||
isNominateOpen: boolean,
|
||||
isStakingOpen: boolean,
|
||||
bondedId: AccountId | null,
|
||||
controllerId: AccountId | null,
|
||||
@ -47,6 +46,7 @@ class Account extends React.PureComponent<Props, State> {
|
||||
state: State = {
|
||||
isBondingOpen: false,
|
||||
isControllerOpen: false,
|
||||
isNominateOpen: false,
|
||||
isStakingOpen: false,
|
||||
bondedId: null,
|
||||
controllerId: null,
|
||||
@ -74,6 +74,7 @@ class Account extends React.PureComponent<Props, State> {
|
||||
<article className='staking--Account'>
|
||||
{this.renderBonding()}
|
||||
{this.renderController()}
|
||||
{this.renderNominating()}
|
||||
{this.renderStaking()}
|
||||
<AddressSummary
|
||||
balance={balanceArray(accountId)}
|
||||
@ -179,34 +180,20 @@ class Account extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
// private renderNominating () {
|
||||
// const { intentions } = this.props;
|
||||
// const { isNominateOpen } = this.state;
|
||||
private renderNominating () {
|
||||
const { accountId, intentions, validators } = this.props;
|
||||
const { isNominateOpen } = this.state;
|
||||
|
||||
// return (
|
||||
// <Nominating
|
||||
// isOpen={isNominateOpen}
|
||||
// onClose={this.toggleNominate}
|
||||
// onNominate={this.nominate}
|
||||
// intentions={intentions}
|
||||
// />
|
||||
// );
|
||||
// }
|
||||
|
||||
// private renderPrefs () {
|
||||
// const { accountId, staking_validatorPreferences } = this.props;
|
||||
// const { isPrefsOpen } = this.state;
|
||||
|
||||
// return (
|
||||
// <Preferences
|
||||
// accountId={accountId}
|
||||
// isOpen={isPrefsOpen}
|
||||
// onClose={this.togglePrefs}
|
||||
// onSetPrefs={this.setPrefs}
|
||||
// validatorPreferences={staking_validatorPreferences}
|
||||
// />
|
||||
// );
|
||||
// }
|
||||
return (
|
||||
<Nominating
|
||||
accountId={accountId}
|
||||
isOpen={isNominateOpen}
|
||||
onClose={this.toggleNominate}
|
||||
intentions={intentions}
|
||||
validators={validators}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
private renderButtons () {
|
||||
const { t } = this.props;
|
||||
@ -244,6 +231,15 @@ class Account extends React.PureComponent<Props, State> {
|
||||
label={t('Stake')}
|
||||
/>
|
||||
);
|
||||
buttons.push(<Button.Or key='nominate.or' />);
|
||||
buttons.push(
|
||||
<Button
|
||||
isPrimary
|
||||
key='nominate'
|
||||
onClick={this.toggleNominate}
|
||||
label={t('Nominate')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
@ -251,49 +247,8 @@ class Account extends React.PureComponent<Props, State> {
|
||||
{buttons}
|
||||
</Button.Group>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// private nominate = (nominee: string) => {
|
||||
// const { api } = this.props;
|
||||
|
||||
// this.send(api.tx.staking.nominate(nominee));
|
||||
|
||||
// this.toggleNominate();
|
||||
// }
|
||||
|
||||
// private unnominate = (index: number) => {
|
||||
// const { api } = this.props;
|
||||
|
||||
// this.send(api.tx.staking.unnominate(index));
|
||||
// }
|
||||
|
||||
// private setPrefs = (prefs: ValidatorPrefs) => {
|
||||
// const { api } = this.props;
|
||||
|
||||
// this.send(api.tx.staking.registerPreferences(this.getIntentionIndex(), prefs));
|
||||
|
||||
// this.togglePrefs();
|
||||
// }
|
||||
|
||||
// private stake = () => {
|
||||
// const { api } = this.props;
|
||||
|
||||
// this.send(api.tx.staking.stake());
|
||||
// }
|
||||
|
||||
// private unstake = () => {
|
||||
// const { api } = this.props;
|
||||
|
||||
// this.send(api.tx.staking.unstake(this.getIntentionIndex()));
|
||||
// }
|
||||
|
||||
// private getIntentionIndex (): number {
|
||||
// const { accountId, intentions } = this.props;
|
||||
|
||||
// return intentions.indexOf(accountId);
|
||||
// }
|
||||
|
||||
private toggleBonding = () => {
|
||||
this.setState(({ isBondingOpen }) => ({
|
||||
isBondingOpen: !isBondingOpen
|
||||
@ -306,23 +261,17 @@ class Account extends React.PureComponent<Props, State> {
|
||||
}));
|
||||
}
|
||||
|
||||
private toggleNominate = () => {
|
||||
this.setState(({ isNominateOpen }) => ({
|
||||
isNominateOpen: !isNominateOpen
|
||||
}));
|
||||
}
|
||||
|
||||
private toggleStaking = () => {
|
||||
this.setState(({ isStakingOpen }) => ({
|
||||
isStakingOpen: !isStakingOpen
|
||||
}));
|
||||
}
|
||||
|
||||
// private toggleNominate = () => {
|
||||
// this.setState(({ isNominateOpen }: State) => ({
|
||||
// isNominateOpen: !isNominateOpen
|
||||
// }));
|
||||
// }
|
||||
|
||||
// private togglePrefs = () => {
|
||||
// this.setState(({ isPrefsOpen }: State) => ({
|
||||
// isPrefsOpen: !isPrefsOpen
|
||||
// }));
|
||||
// }
|
||||
}
|
||||
|
||||
export default translate(
|
||||
|
||||
@ -3,12 +3,10 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { QueueProps } from '@polkadot/ui-app/Status/types';
|
||||
import { ComponentProps } from './types';
|
||||
|
||||
import React from 'react';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import { QueueConsumer } from '@polkadot/ui-app/Status/Context';
|
||||
|
||||
import Account from './Account';
|
||||
import translate from './translate';
|
||||
@ -20,29 +18,25 @@ class StakeList extends React.PureComponent<Props> {
|
||||
const { balances, balanceArray, intentions, validators } = this.props;
|
||||
|
||||
return (
|
||||
<QueueConsumer>
|
||||
{({ queueExtrinsic }: QueueProps) => (
|
||||
<div className='staking--StakeList'>
|
||||
{keyring.getAccounts().map((account) => {
|
||||
const address = account.address();
|
||||
const name = account.getMeta().name || '';
|
||||
<div className='staking--StakeList'>
|
||||
{keyring.getAccounts().map((account, index) => {
|
||||
const address = account.address();
|
||||
const name = account.getMeta().name || '';
|
||||
|
||||
return (
|
||||
<Account
|
||||
accountId={address}
|
||||
balances={balances}
|
||||
balanceArray={balanceArray}
|
||||
intentions={intentions}
|
||||
isValidator={validators.includes(address)}
|
||||
key={address}
|
||||
name={name}
|
||||
queueExtrinsic={queueExtrinsic}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</QueueConsumer>
|
||||
return (
|
||||
<Account
|
||||
accountId={address}
|
||||
balances={balances}
|
||||
balanceArray={balanceArray}
|
||||
intentions={intentions}
|
||||
isValidator={validators.includes(address)}
|
||||
key={address}
|
||||
name={name}
|
||||
validators={validators}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user