Disable stash operations (when not own) (#1901)
This commit is contained in:
parent
f71c9fd5cd
commit
ae6b453f0d
@ -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}>
|
||||
|
||||
@ -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}
|
||||
/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user