Fix council slash params (#3276)
This commit is contained in:
parent
49b3f41f1a
commit
a068d03db0
@ -22,6 +22,7 @@ interface HashState {
|
||||
hash?: string;
|
||||
isHashValid: boolean;
|
||||
}
|
||||
|
||||
interface ProposalState {
|
||||
proposal?: SubmittableExtrinsic<'promise'> | null;
|
||||
proposalLength: number;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { CallFunction } from '@polkadot/types/types';
|
||||
import { SubmittableExtrinsic } from '@polkadot/api/types';
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Button, Dropdown, Input, InputAddress, Modal, TxButton } from '@polkadot/react-components';
|
||||
@ -23,13 +23,18 @@ interface Option {
|
||||
value: number;
|
||||
}
|
||||
|
||||
interface ProposalState {
|
||||
proposal?: SubmittableExtrinsic<'promise'> | null;
|
||||
proposalLength: number;
|
||||
}
|
||||
|
||||
function Slashing ({ className = '', isMember, members }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const slashes = useAvailableSlashes();
|
||||
const [isVisible, toggleVisible] = useToggle();
|
||||
const [accountId, setAcountId] = useState<string | null>(null);
|
||||
const [proposal, setProposal] = useState<CallFunction | null>(null);
|
||||
const [{ proposal, proposalLength }, setProposal] = useState<ProposalState>({ proposal: null, proposalLength: 0 });
|
||||
const [eras, setEras] = useState<Option[]>([]);
|
||||
const [selectedEra, setSelectedEra] = useState(0);
|
||||
const threshold = Math.ceil((members.length || 0) * getThreshold(api));
|
||||
@ -50,12 +55,14 @@ function Slashing ({ className = '', isMember, members }: Props): React.ReactEle
|
||||
|
||||
useEffect((): void => {
|
||||
const actioned = selectedEra && slashes && slashes.find(([era]): boolean => era.eqn(selectedEra));
|
||||
const proposal = actioned
|
||||
? api.tx.staking.cancelDeferredSlash(actioned[0], actioned[1].map((_, index): number => index))
|
||||
: null;
|
||||
|
||||
setProposal((): any =>
|
||||
actioned
|
||||
? api.tx.staking.cancelDeferredSlash(actioned[0], actioned[1].map((_, index): number => index))
|
||||
: null
|
||||
);
|
||||
setProposal({
|
||||
proposal,
|
||||
proposalLength: proposal?.encodedLength || 0
|
||||
});
|
||||
}, [api, selectedEra, slashes]);
|
||||
|
||||
return (
|
||||
@ -121,7 +128,11 @@ function Slashing ({ className = '', isMember, members }: Props): React.ReactEle
|
||||
isDisabled={!threshold || !members.includes(accountId || '') || !proposal}
|
||||
label={t<string>('Revert')}
|
||||
onStart={toggleVisible}
|
||||
params={[threshold, proposal]}
|
||||
params={
|
||||
api.tx.council.propose.meta.args.length === 3
|
||||
? [threshold, proposal, proposalLength]
|
||||
: [threshold, proposal]
|
||||
}
|
||||
tx='council.propose'
|
||||
/>
|
||||
</Modal.Actions>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user