From bdceb5e2bd2bb23778ee269a1b219f8cf5c1a14d Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 16 Oct 2019 11:36:23 +0200 Subject: [PATCH] Set session key mismatch (#1730) * Set session key mismatch * Cleanup 0 render * 0 checks --- ...etSessionAccount.tsx => SetSessionKey.tsx} | 22 +++++++++++-------- .../app-staking/src/Actions/Account/index.tsx | 10 ++++----- .../src/InputAddress/index.tsx | 9 ++++---- 3 files changed, 23 insertions(+), 18 deletions(-) rename packages/app-staking/src/Actions/Account/{SetSessionAccount.tsx => SetSessionKey.tsx} (87%) diff --git a/packages/app-staking/src/Actions/Account/SetSessionAccount.tsx b/packages/app-staking/src/Actions/Account/SetSessionKey.tsx similarity index 87% rename from packages/app-staking/src/Actions/Account/SetSessionAccount.tsx rename to packages/app-staking/src/Actions/Account/SetSessionKey.tsx index fe918c0745..365be7bb9e 100644 --- a/packages/app-staking/src/Actions/Account/SetSessionAccount.tsx +++ b/packages/app-staking/src/Actions/Account/SetSessionKey.tsx @@ -23,9 +23,12 @@ const EMPTY_PROOF = new Uint8Array(); function SetSessionKey ({ controllerId, isOpen, onClose, sessionIds, stashId, t }: Props): React.ReactElement | null { const { isSubstrateV2 } = useContext(ApiContext); - const [ed25519, setEd25519] = useState(null); - const [ed25519Error, setEd25519Error] = useState(sessionIds[0] || controllerId); - const [keys, setKeys] = useState(null); + const [keysError, setKeysError] = useState(null); + const [keys, setKeys] = useState( + isSubstrateV2 + ? null + : sessionIds[0] || controllerId + ); if (!isOpen) { return null; @@ -33,7 +36,7 @@ function SetSessionKey ({ controllerId, isOpen, onClose, sessionIds, stashId, t const hasError = isSubstrateV2 ? !keys - : (!ed25519 || !!ed25519Error); + : (!keys || !!keysError); return ( @@ -100,7 +104,7 @@ function SetSessionKey ({ controllerId, isOpen, onClose, sessionIds, stashId, t params={ isSubstrateV2 ? [keys, EMPTY_PROOF] - : [ed25519] + : [keys] } tx={ isSubstrateV2 diff --git a/packages/app-staking/src/Actions/Account/index.tsx b/packages/app-staking/src/Actions/Account/index.tsx index cb032a6714..f984237ad4 100644 --- a/packages/app-staking/src/Actions/Account/index.tsx +++ b/packages/app-staking/src/Actions/Account/index.tsx @@ -20,7 +20,7 @@ import InjectKeys from './InjectKeys'; import Nominate from './Nominate'; import SetControllerAccount from './SetControllerAccount'; import SetRewardDestination from './SetRewardDestination'; -import SetSessionAccount from './SetSessionAccount'; +import SetSessionKey from './SetSessionKey'; import translate from '../../translate'; import Unbond from './Unbond'; import Validate from './Validate'; @@ -95,7 +95,7 @@ class Account extends React.PureComponent { } const { controllerId, nextSessionIds, nominators, online, offline, rewardDestination, sessionIds, stakers, stakingLedger, stashId, validatorPrefs } = staking_info; - const isStashNominating = nominators && nominators.length !== 0; + const isStashNominating = nominators && !!nominators.length; const _stashId = toIdString(stashId); const isStashValidating = !!allStashes && !!_stashId && allStashes.includes(_stashId); @@ -175,7 +175,7 @@ class Account extends React.PureComponent {
{this.renderControllerAccount()} - {!isSubstrateV2 && sessionIds.length && ( + {!isSubstrateV2 && !!sessionIds.length && (
{ withValidatorPrefs={isStashValidating} />
- {nominees && nominees.length !== 0 && ( + {nominees && !!nominees.length && (
{nominees.map((nomineeId, index): React.ReactNode => ( @@ -502,7 +502,7 @@ class Account extends React.PureComponent { } return ( - { value: Array.isArray(value) ? value.map(addressToAddress) : (addressToAddress(value) || undefined) - }; } catch (error) { return null; @@ -158,7 +159,7 @@ class InputAddress extends React.PureComponent { ? optionsAll[type] : [] ); - const _defaultValue = (isMultiple || value !== undefined) + const _defaultValue = (isMultiple || !isUndefined(value)) ? undefined : actualValue; @@ -188,7 +189,7 @@ class InputAddress extends React.PureComponent { style={style} value={ isMultiple && !value - ? [] + ? MULTI_DEFAULT : value } withEllipsis={withEllipsis}