Disable stash operations (when not own) (#1901)

This commit is contained in:
Jaco Greeff 2019-11-17 11:45:23 +01:00 committed by GitHub
parent f71c9fd5cd
commit ae6b453f0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 10 deletions

View File

@ -30,6 +30,7 @@ interface Props extends ApiProps, I18nProps {
allStashes?: string[];
balances_all?: DerivedBalances;
className?: string;
ownStash: boolean;
recentlyOnline?: DerivedHeartbeats;
staking_info?: DerivedStaking;
stashOptions: KeyringSectionOption[];
@ -345,7 +346,7 @@ class Account extends React.PureComponent<Props, State> {
key='settings'
onClose={this.toggleSettingPopup}
open={isSettingPopupOpen}
position='bottom left'
position='bottom right'
trigger={
<Button
icon='setting'
@ -368,7 +369,7 @@ class Account extends React.PureComponent<Props, State> {
}
private renderPopupMenu (): React.ReactNode {
const { balances_all, isSubstrateV2, t } = this.props;
const { balances_all, isSubstrateV2, ownStash, t } = this.props;
const { hexSessionId, isStashNominating, isStashValidating, sessionIds } = this.state;
// only show a "Bond Additional" button if this stash account actually doesn't bond everything already
@ -382,14 +383,20 @@ class Account extends React.PureComponent<Props, State> {
onClick={this.toggleSettingPopup}
>
{canBondExtra &&
<Menu.Item onClick={this.toggleBondExtra}>
<Menu.Item
disabled={!ownStash}
onClick={this.toggleBondExtra}
>
{t('Bond more funds')}
</Menu.Item>
}
<Menu.Item onClick={this.toggleUnbond}>
{t('Unbond funds')}
</Menu.Item>
<Menu.Item onClick={this.toggleSetControllerAccount}>
<Menu.Item
disabled={!ownStash}
onClick={this.toggleSetControllerAccount}
>
{t('Change controller account')}
</Menu.Item>
<Menu.Item onClick={this.toggleSetRewardDestination}>

View File

@ -22,22 +22,22 @@ import translate from '../translate';
interface Props extends I18nProps, ComponentProps {
}
function getMyStashes (allAccounts: string[], queryBonded?: Option<AccountId>[], queryLedger?: Option<StakingLedger>[]): string[] | null {
const result: string[] = [];
function getStashes (allAccounts: string[], queryBonded?: Option<AccountId>[], queryLedger?: Option<StakingLedger>[]): [string, boolean][] | null {
const result: [string, boolean][] = [];
if (!queryBonded || !queryLedger) {
return null;
}
queryBonded.forEach((value, index): void => {
value.isSome && result.push(allAccounts[index]);
value.isSome && result.push([allAccounts[index], true]);
});
queryLedger.forEach((ledger): void => {
if (ledger.isSome) {
const stashId = ledger.unwrap().stash.toString();
!result.includes(stashId) && result.push(stashId);
!result.some(([accountId]): boolean => accountId === stashId) && result.push([stashId, false]);
}
});
@ -49,7 +49,7 @@ function Accounts ({ allAccounts, allStashes, className, recentlyOnline, t }: Pr
const queryBonded = trackStream<Option<AccountId>[]>(api.query.staking.bonded.multi as any, [allAccounts]);
const queryLedger = trackStream<Option<StakingLedger>[]>(api.query.staking.ledger.multi as any, [allAccounts]);
const [isNewStakeOpen, setIsNewStateOpen] = useState(false);
const foundStashes = getMyStashes(allAccounts, queryBonded, queryLedger);
const foundStashes = getStashes(allAccounts, queryBonded, queryLedger);
const stashOptions = allStashes.map((stashId): KeyringSectionOption =>
createOption(stashId, (<AccountName params={stashId} />) as any)
);
@ -75,12 +75,13 @@ function Accounts ({ allAccounts, allStashes, className, recentlyOnline, t }: Pr
{isNewStakeOpen && (
<StartStaking onClose={_toggleNewStake} />
)}
{foundStashes && foundStashes.map((address, index): React.ReactNode => (
{foundStashes && foundStashes.map(([address, ownStash], index): React.ReactNode => (
address && (
<Account
allStashes={allStashes}
accountId={address}
key={index}
ownStash={ownStash}
recentlyOnline={recentlyOnline}
stashOptions={stashOptions}
/>