InputAddress should handle defaultValue of U8a (#1136)

* InputAddress should handle defaultValue of U8a

* Linting, my old friend
This commit is contained in:
Jaco Greeff 2019-05-10 18:28:56 +02:00 committed by GitHub
parent 5c21396c33
commit c970ecbc35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 46 deletions

View File

@ -93,7 +93,6 @@ class Account extends React.PureComponent<Props, State> {
{this.renderStashId()}
{this.renderSessionId()}
{this.renderNominee()}
{this.renderNominators()}
</div>
</div>
</AddressSummary>
@ -198,30 +197,6 @@ class Account extends React.PureComponent<Props, State> {
);
}
private renderNominators () {
// const { staking_nominatorsFor } = this.props;
// if (!staking_nominatorsFor) {
// return null;
// }
// return (
// <div className='staking--Account-detail'>
// <label className='staking--label'>nominators</label>
// <div className='ui--Nominators'>
// {staking_nominatorsFor.map((nominator) => (
// <AddressMini
// isPadded={false}
// key={nominator}
// value={nominator}
// withBalance
// />
// ))}
// </div>
// </div>
// );
}
private renderControllerId () {
const { controllerId, recentlyOffline, t } = this.props;

View File

@ -44,18 +44,22 @@ type State = {
const STORAGE_KEY = 'options:InputAddress';
const DEFAULT_TYPE = 'all';
const transformToAddress = (value: string | Uint8Array): string | null => {
try {
return addressToAddress(value) || null;
} catch (error) {
console.error('Unable to transform address', value);
}
return null;
};
const transformToAccountId = (value: string): string | null => {
if (!value) {
return null;
}
let accountId;
try {
accountId = addressToAddress(value);
} catch (error) {
console.error('Unable to transform address', value);
}
const accountId = transformToAddress(value);
return !accountId
? null
@ -127,12 +131,21 @@ class InputAddress extends React.PureComponent<Props, State> {
const lastValue = InputAddress.getLastValue(type);
const lastOption = this.getLastOptionValue();
const actualValue = isDisabled || (defaultValue && this.hasValue(defaultValue))
? defaultValue
const actualValue = transformToAddress(
isDisabled || (defaultValue && this.hasValue(defaultValue))
? defaultValue
: (
this.hasValue(lastValue)
? lastValue
: (lastOption && lastOption.value)
)
);
const actualOptions = options
? options
: (
this.hasValue(lastValue)
? lastValue
: (lastOption && lastOption.value)
isDisabled && actualValue
? [createOption(actualValue)]
: (optionsAll ? optionsAll[type] : [])
);
return (
@ -154,15 +167,7 @@ class InputAddress extends React.PureComponent<Props, State> {
: this.onChange
}
onSearch={this.onSearch}
options={
options
? options
: (
isDisabled && actualValue
? [createOption(actualValue)]
: (optionsAll ? optionsAll[type] : [])
)
}
options={actualOptions}
placeholder={placeholder}
renderLabel={
isMultiple