Disable staking actions in elections (#2516)
This commit is contained in:
parent
35868cbb2d
commit
286944cc9d
@ -362,9 +362,8 @@ function Account ({ address, className, filter, isFavorite, toggleFavorite }: Pr
|
||||
/>
|
||||
<Popup
|
||||
className='theme--default'
|
||||
isOpen={isSettingsOpen}
|
||||
onClose={toggleSettings}
|
||||
open={isSettingsOpen}
|
||||
position='bottom right'
|
||||
trigger={
|
||||
<Button
|
||||
icon='setting'
|
||||
|
||||
@ -264,9 +264,8 @@ function Address ({ address, className, filter, isFavorite, toggleFavorite }: Pr
|
||||
/>
|
||||
<Popup
|
||||
className='theme--default'
|
||||
isOpen={isSettingPopupOpen}
|
||||
onClose={_toggleSettingPopup}
|
||||
open={isSettingPopupOpen}
|
||||
position='bottom right'
|
||||
trigger={
|
||||
<Button
|
||||
icon='setting'
|
||||
|
||||
@ -70,10 +70,9 @@ function Parachain ({ basePath, className, isMine, paraInfoRef, sudoKey }: Props
|
||||
>
|
||||
{(sudoKey && isMine) && (
|
||||
<Popup
|
||||
isOpen={isMenuOpen}
|
||||
key='settings'
|
||||
onClose={toggleMenu}
|
||||
open={isMenuOpen}
|
||||
position='bottom right'
|
||||
trigger={
|
||||
<Button
|
||||
className='menu-button'
|
||||
|
||||
@ -35,8 +35,8 @@ interface Props {
|
||||
activeEra?: EraIndex;
|
||||
allStashes?: string[];
|
||||
className?: string;
|
||||
isInElection?: boolean;
|
||||
isOwnStash: boolean;
|
||||
isVisible: boolean;
|
||||
next?: string[];
|
||||
onUpdateType: (stashId: string, type: 'validator' | 'nominator' | 'started' | 'other') => void;
|
||||
rewards?: DeriveStakerReward[];
|
||||
@ -111,7 +111,7 @@ function createPayout (api: ApiPromise, payoutRewards: DeriveStakerReward[]): Su
|
||||
);
|
||||
}
|
||||
|
||||
function Account ({ allStashes, className, isOwnStash, next, onUpdateType, rewards, stakingOverview, stashId }: Props): React.ReactElement<Props> {
|
||||
function Account ({ allStashes, className, isInElection, isOwnStash, next, onUpdateType, rewards, stakingOverview, stashId }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { queueExtrinsic } = useContext(StatusContext);
|
||||
const { api } = useApi();
|
||||
@ -215,13 +215,6 @@ function Account ({ allStashes, className, isOwnStash, next, onUpdateType, rewar
|
||||
stashId={stashId}
|
||||
validatorPrefs={validatorPrefs}
|
||||
/>
|
||||
{/* {isPayoutOpen && controllerId && (
|
||||
<ClaimRewards
|
||||
controllerId={controllerId}
|
||||
onClose={togglePayout}
|
||||
payoutRewards={payoutRewards}
|
||||
/>
|
||||
)} */}
|
||||
{isInjectOpen && (
|
||||
<InjectKeys onClose={toggleInject} />
|
||||
)}
|
||||
@ -321,7 +314,7 @@ function Account ({ allStashes, className, isOwnStash, next, onUpdateType, rewar
|
||||
<TxButton
|
||||
accountId={controllerId}
|
||||
icon='stop'
|
||||
isDisabled={!isOwnController}
|
||||
isDisabled={!isOwnController || isInElection}
|
||||
isPrimary={false}
|
||||
key='stop'
|
||||
label={t('Stop')}
|
||||
@ -334,7 +327,7 @@ function Account ({ allStashes, className, isOwnStash, next, onUpdateType, rewar
|
||||
? (
|
||||
<Button
|
||||
icon='sign-in'
|
||||
isDisabled={!isOwnController}
|
||||
isDisabled={!isOwnController || isInElection}
|
||||
key='set'
|
||||
label={t('Session Key')}
|
||||
onClick={toggleSetSession}
|
||||
@ -343,7 +336,7 @@ function Account ({ allStashes, className, isOwnStash, next, onUpdateType, rewar
|
||||
: (
|
||||
<Button
|
||||
icon='check circle outline'
|
||||
isDisabled={!isOwnController}
|
||||
isDisabled={!isOwnController || isInElection}
|
||||
key='validate'
|
||||
label={t('Validate')}
|
||||
onClick={toggleValidate}
|
||||
@ -353,7 +346,7 @@ function Account ({ allStashes, className, isOwnStash, next, onUpdateType, rewar
|
||||
<Button.Or key='nominate.or' />
|
||||
<Button
|
||||
icon='hand paper outline'
|
||||
isDisabled={!isOwnController}
|
||||
isDisabled={!isOwnController || isInElection}
|
||||
key='nominate'
|
||||
label={t('Nominate')}
|
||||
onClick={toggleNominate}
|
||||
@ -362,13 +355,13 @@ function Account ({ allStashes, className, isOwnStash, next, onUpdateType, rewar
|
||||
)
|
||||
}
|
||||
<Popup
|
||||
isOpen={isSettingsOpen}
|
||||
key='settings'
|
||||
onClose={toggleSettings}
|
||||
open={isSettingsOpen}
|
||||
position='bottom right'
|
||||
trigger={
|
||||
<Button
|
||||
icon='setting'
|
||||
isDisabled={isInElection}
|
||||
onClick={toggleSettings}
|
||||
/>
|
||||
}
|
||||
|
||||
@ -16,9 +16,10 @@ import { rewardDestinationOptions } from './constants';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
isInElection?: boolean;
|
||||
}
|
||||
|
||||
function NewStake ({ className }: Props): React.ReactElement<Props> {
|
||||
function NewStake ({ className, isInElection }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const [isVisible, toggleVisible] = useToggle();
|
||||
@ -46,6 +47,7 @@ function NewStake ({ className }: Props): React.ReactElement<Props> {
|
||||
<Button.Group>
|
||||
<Button
|
||||
icon='add'
|
||||
isDisabled={isInElection}
|
||||
key='new-stake'
|
||||
label={t('New stake')}
|
||||
onClick={toggleVisible}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { DeriveStakingOverview, DeriveStakerReward } from '@polkadot/api-derive/types';
|
||||
import { ActiveEraInfo, EraIndex } from '@polkadot/types/interfaces';
|
||||
import { ActiveEraInfo, ElectionStatus, EraIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { Table } from '@polkadot/react-components';
|
||||
@ -27,10 +27,10 @@ function Actions ({ allRewards, allStashes, className, isVisible, next, stakingO
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const activeEra = useCall<EraIndex | undefined>(api.query.staking?.activeEra, [], {
|
||||
transform: (activeEra: Option<ActiveEraInfo>): EraIndex | undefined =>
|
||||
activeEra.isSome
|
||||
? activeEra.unwrap().index
|
||||
: undefined
|
||||
transform: (activeEra: Option<ActiveEraInfo>) => activeEra.unwrapOr({ index: undefined }).index
|
||||
});
|
||||
const isInElection = useCall<boolean>(api.query.staking?.eraElectionStatus, [], {
|
||||
transform: (status: ElectionStatus) => status.isOpen
|
||||
});
|
||||
const ownStashes = useOwnStashes();
|
||||
const [foundStashes, setFoundStashes] = useState<[string, boolean][] | null>(null);
|
||||
@ -59,7 +59,12 @@ function Actions ({ allRewards, allStashes, className, isVisible, next, stakingO
|
||||
|
||||
return (
|
||||
<div className={`${className} ${!isVisible && 'staking--hidden'}`}>
|
||||
<NewStake />
|
||||
<NewStake isInElection={isInElection} />
|
||||
{isInElection && (
|
||||
<article className='warning nomargin'>
|
||||
{t('There is currently an ongoing election for new validator candidates. As such staking operations are not permitted.')}
|
||||
</article>
|
||||
)}
|
||||
<Table
|
||||
empty={t('No funds staked yet. Bond funds to validate or nominate a validator')}
|
||||
header={[
|
||||
@ -74,8 +79,8 @@ function Actions ({ allRewards, allStashes, className, isVisible, next, stakingO
|
||||
<Account
|
||||
activeEra={activeEra}
|
||||
allStashes={allStashes}
|
||||
isInElection={isInElection}
|
||||
isOwnStash={isOwnStash}
|
||||
isVisible={isVisible}
|
||||
key={stashId}
|
||||
next={next}
|
||||
onUpdateType={_onUpdateType}
|
||||
|
||||
@ -2,6 +2,29 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Popup } from 'semantic-ui-react';
|
||||
import React from 'react';
|
||||
import { Popup as SUIPopup } from 'semantic-ui-react';
|
||||
|
||||
export default Popup;
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
isOpen?: boolean;
|
||||
onClose?: () => void;
|
||||
trigger?: React.ReactNode;
|
||||
}
|
||||
|
||||
function Popup ({ children, className, isOpen, onClose, trigger }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<SUIPopup
|
||||
className={className}
|
||||
onClose={onClose}
|
||||
open={isOpen}
|
||||
position='bottom right'
|
||||
trigger={trigger}
|
||||
>
|
||||
{children}
|
||||
</SUIPopup>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(Popup);
|
||||
|
||||
@ -143,6 +143,10 @@ export default createGlobalStyle<Props>`
|
||||
margin-left: 2.25rem;
|
||||
}
|
||||
|
||||
&.nomargin {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
&.error {
|
||||
background: #fff6f6;
|
||||
border-color: #e0b4b4;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user