From e8030005b71a2fa5070cff00e12c9b3689e742aa Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 3 Jul 2020 07:18:50 +0200 Subject: [PATCH] Fix InputAddress lastValue (#3112) --- .../src/InputAddress/index.tsx | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/packages/react-components/src/InputAddress/index.tsx b/packages/react-components/src/InputAddress/index.tsx index f9ac07b495..72ad4b20b6 100644 --- a/packages/react-components/src/InputAddress/index.tsx +++ b/packages/react-components/src/InputAddress/index.tsx @@ -120,9 +120,10 @@ function setLastValue (type: KeyringOption$Type = DEFAULT_TYPE, value: string): class InputAddress extends React.PureComponent { public state: State = {}; - public static getDerivedStateFromProps ({ value }: Props): Pick | null { + public static getDerivedStateFromProps ({ type, value }: Props, { lastValue }: State): Pick | null { try { return { + lastValue: lastValue || getLastValue(type), value: Array.isArray(value) ? value.map(addressToAddress) : (addressToAddress(value) || undefined) @@ -134,14 +135,13 @@ class InputAddress extends React.PureComponent { public render (): React.ReactNode { const { className = '', defaultValue, help, hideAddress = false, isDisabled = false, isError, isMultiple, label, labelExtra, options, optionsAll, placeholder, type = DEFAULT_TYPE, withEllipsis, withLabel } = this.props; - const { value } = this.state; + const { lastValue, value } = this.state; const hasOptions = (options && options.length !== 0) || (optionsAll && Object.keys(optionsAll[type]).length !== 0); if (!hasOptions && !isDisabled) { return null; } - const lastValue = this.getLastValue(); const lastOption = this.getLastOptionValue(); const actualValue = transformToAddress( isDisabled || (defaultValue && this.hasValue(defaultValue)) @@ -241,21 +241,6 @@ class InputAddress extends React.PureComponent { } } - private getLastValue (): string { - const { type } = this.props; - const { lastValue: stateLast } = this.state; - - if (stateLast) { - return stateLast; - } - - const lastValue = getLastValue(type); - - this.setState(() => ({ lastValue })); - - return lastValue; - } - private onSearch = (filteredOptions: KeyringSectionOptions, _query: string): KeyringSectionOptions => { const { isInput = true } = this.props; const query = _query.trim();