Fix unnominate (Option causing issues) (#827)
* Fix unnominate (Option causing issues) * Merge master
This commit is contained in:
parent
f23ac1cea4
commit
0bc26e2078
@ -33,22 +33,22 @@ type Props = ApiProps & I18nProps & {
|
||||
|
||||
type State = {
|
||||
isNominateOpen: boolean,
|
||||
isNominating: boolean,
|
||||
isPrefsOpen: boolean
|
||||
isPrefsOpen: boolean,
|
||||
nominee: AccountId | null
|
||||
};
|
||||
|
||||
class Account extends React.PureComponent<Props, State> {
|
||||
state: State = {
|
||||
isNominateOpen: false,
|
||||
isNominating: false,
|
||||
isPrefsOpen: false
|
||||
isPrefsOpen: false,
|
||||
nominee: null
|
||||
};
|
||||
|
||||
static getDerivedStateFromProps ({ staking_nominating }: Props) {
|
||||
const isNominating = !!staking_nominating && !staking_nominating.isEmpty;
|
||||
|
||||
static getDerivedStateFromProps ({ staking_nominating }: Props): Partial<State> {
|
||||
return {
|
||||
isNominating
|
||||
nominee: staking_nominating
|
||||
? staking_nominating.unwrapOr(null)
|
||||
: null
|
||||
};
|
||||
}
|
||||
|
||||
@ -76,19 +76,17 @@ class Account extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
private renderNominee () {
|
||||
const { staking_nominating, balanceArray } = this.props;
|
||||
const { isNominating } = this.state;
|
||||
const { balanceArray } = this.props;
|
||||
const { nominee } = this.state;
|
||||
|
||||
if (!isNominating || !staking_nominating || staking_nominating.isNone) {
|
||||
if (!nominee) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const nominating = staking_nominating.unwrap();
|
||||
|
||||
return (
|
||||
<AddressMini
|
||||
balance={balanceArray(nominating)}
|
||||
value={nominating}
|
||||
balance={balanceArray(nominee)}
|
||||
value={nominee}
|
||||
withBalance
|
||||
/>
|
||||
);
|
||||
@ -153,10 +151,10 @@ class Account extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
private renderButtons () {
|
||||
const { accountId, intentions, staking_nominating, t } = this.props;
|
||||
const { isNominating } = this.state;
|
||||
const { accountId, intentions, t } = this.props;
|
||||
const { nominee } = this.state;
|
||||
const isIntending = intentions.includes(accountId);
|
||||
const canStake = !isIntending && !isNominating;
|
||||
const canStake = !isIntending && !nominee;
|
||||
|
||||
if (canStake) {
|
||||
return (
|
||||
@ -176,12 +174,12 @@ class Account extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
if (isNominating) {
|
||||
if (nominee) {
|
||||
return (
|
||||
<Button.Group>
|
||||
<UnnominateButton
|
||||
accountId={accountId || ''}
|
||||
nominating={staking_nominating || ''}
|
||||
nominating={nominee}
|
||||
onClick={this.unnominate}
|
||||
/>
|
||||
</Button.Group>
|
||||
|
||||
@ -7,13 +7,14 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import React from 'react';
|
||||
import { Button } from '@polkadot/ui-app';
|
||||
import { withCall, withMulti } from '@polkadot/ui-api';
|
||||
import { AccountId, Vector } from '@polkadot/types';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
type Props = I18nProps & {
|
||||
accountId: string,
|
||||
nominating: string,
|
||||
staking_nominatorsFor: Array<string>,
|
||||
nominating: AccountId,
|
||||
staking_nominatorsFor: Vector<AccountId>,
|
||||
onClick: (index: number) => void
|
||||
};
|
||||
|
||||
@ -41,9 +42,7 @@ class UnnominateButton extends React.Component<Props> {
|
||||
|
||||
onClick(
|
||||
staking_nominatorsFor
|
||||
.map((accountId) =>
|
||||
accountId.toString()
|
||||
)
|
||||
.map((accountId) => accountId.toString())
|
||||
.indexOf(accountId));
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
import { ApiProps, CallState, Subtract } from '../types';
|
||||
import { Options } from './types';
|
||||
|
||||
import memoize from 'memoizee';
|
||||
import React from 'react';
|
||||
import { assert, isNull, isUndefined } from '@polkadot/util';
|
||||
|
||||
@ -159,7 +158,7 @@ export default function withCall<P extends ApiProps> (endpoint: string, { at, at
|
||||
await this.unsubscribe();
|
||||
|
||||
if (isSubscription) {
|
||||
this.destroy = await memoize(apiMethod)(...params, (value?: any) =>
|
||||
this.destroy = await apiMethod(...params, (value?: any) =>
|
||||
this.triggerUpdate(this.props, value)
|
||||
);
|
||||
} else {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user