From ba8d55c1f162f5e0f136aa7df0b3b495eddd1ed5 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 27 Sep 2019 10:15:57 +0200 Subject: [PATCH] Fix nomination selection (multi) (#1671) --- packages/app-staking/src/Actions/Accounts.tsx | 5 ++-- .../src/InputAddress/index.tsx | 30 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/packages/app-staking/src/Actions/Accounts.tsx b/packages/app-staking/src/Actions/Accounts.tsx index 2efcc14009..88967165b1 100644 --- a/packages/app-staking/src/Actions/Accounts.tsx +++ b/packages/app-staking/src/Actions/Accounts.tsx @@ -11,7 +11,7 @@ import { withCalls, withMulti } from '@polkadot/react-api/with'; import React, { useState } from 'react'; import styled from 'styled-components'; -import { Button, CardGrid } from '@polkadot/react-components'; +import { Button, CardGrid, InputAddress } from '@polkadot/react-components'; import createOption from '@polkadot/ui-keyring/options/item'; import { getAddressName } from '@polkadot/react-components/util'; @@ -43,7 +43,8 @@ function Accounts ({ allAccounts, allStashes, className, myControllers, recently const [isNewStakeOpen, setIsNewStateOpen] = useState(false); const myStashes = getMyStashes(myControllers, allAccounts); const stashOptions = allStashes.map((stashId): KeyringSectionOption => - createOption(stashId, getAddressName(stashId, 'account')) + // FIXME The static setting here just does screwy + (InputAddress as any).createOption(createOption(stashId, getAddressName(stashId, 'account'))) ); const isEmpty = !isNewStakeOpen && (!myStashes || myStashes.length === 0); diff --git a/packages/react-components/src/InputAddress/index.tsx b/packages/react-components/src/InputAddress/index.tsx index 440b4ecbf5..5d6a02f15b 100644 --- a/packages/react-components/src/InputAddress/index.tsx +++ b/packages/react-components/src/InputAddress/index.tsx @@ -48,7 +48,7 @@ interface State { const STORAGE_KEY = 'options:InputAddress'; const DEFAULT_TYPE = 'all'; -const transformToAddress = (value: string | Uint8Array): string | null => { +function transformToAddress (value: string | Uint8Array): string | null { try { return addressToAddress(value) || null; } catch (error) { @@ -56,9 +56,9 @@ const transformToAddress = (value: string | Uint8Array): string | null => { } return null; -}; +} -const transformToAccountId = (value: string): string | null => { +function transformToAccountId (value: string): string | null { if (!value) { return null; } @@ -68,9 +68,9 @@ const transformToAccountId = (value: string): string | null => { return !accountId ? null : accountId; -}; +} -const createOption = (address: string): KeyringSectionOption => { +function createOption (address: string): KeyringSectionOption { let isRecent: boolean | undefined; const pair = keyring.getAccount(address); let name: string | undefined; @@ -89,7 +89,7 @@ const createOption = (address: string): KeyringSectionOption => { } return createItem(createKeyringItem(address, name), !isRecent); -}; +} class InputAddress extends React.PureComponent { public state: State = {}; @@ -151,15 +151,9 @@ class InputAddress extends React.PureComponent { ? optionsAll[type] : [] ); - let _defaultValue; - - if (value !== undefined) { - _defaultValue = undefined; - } else if (isMultiple) { - _defaultValue = undefined; - } else { - _defaultValue = actualValue; - } + const _defaultValue = (isMultiple || value !== undefined) + ? undefined + : actualValue; return ( { export { InputAddress }; -export default withMulti( +const InputAddressExported = withMulti( styled(InputAddress)` .ui.dropdown .text { width: 100%; @@ -327,3 +321,7 @@ export default withMulti( }, {}) }) ); + +(InputAddressExported as any).createOption = createItem; + +export default InputAddressExported;