Render MultiAddress.Id via Address component (#8424)

* Render MultiAddress.Id via Address component

* Remove stray log
This commit is contained in:
Jaco 2022-11-25 17:35:56 +02:00 committed by GitHub
parent bdf8c39d10
commit 7ef38f0c50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -1,6 +1,7 @@
// Copyright 2017-2022 @polkadot/react-params authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { MultiAddress } from '@polkadot/types/interfaces';
import type { Props } from '../types';
import React, { useCallback, useState } from 'react';
@ -9,6 +10,7 @@ import { InputAddress } from '@polkadot/react-components';
import { keyring } from '@polkadot/ui-keyring';
import Bare from './Bare';
import Enum from './Enum';
function isValidAddress (value?: string | null): boolean {
if (value) {
@ -24,7 +26,8 @@ function isValidAddress (value?: string | null): boolean {
return false;
}
function Account ({ className = '', defaultValue: { value }, isDisabled, isError, isInOption, label, onChange, withLabel }: Props): React.ReactElement<Props> {
function Account (props: Props): React.ReactElement<Props> {
const { className = '', defaultValue: { value }, isDisabled, isError, isInOption, label, onChange, type, withLabel } = props;
const [defaultValue] = useState(() => (value as string)?.toString());
const _onChange = useCallback(
@ -36,6 +39,13 @@ function Account ({ className = '', defaultValue: { value }, isDisabled, isError
[onChange]
);
// special handling for MultiAddress
if (type.type === 'MultiAddress') {
if (!isDisabled || !value || (value as MultiAddress).type !== 'Id') {
return <Enum {...props} />;
}
}
return (
<Bare className={className}>
<InputAddress

View File

@ -48,7 +48,7 @@ const SPECIAL_TYPES = ['AccountId', 'AccountId32', 'AccountIndex', 'Address', 'B
const DISPATCH_ERROR = ['DispatchError', 'SpRuntimeDispatchError'];
const componentDef: TypeToComponent[] = [
{ c: Account, t: ['AccountId', 'AccountId32', 'Address', 'LookupSource'] },
{ c: Account, t: ['AccountId', 'AccountId32', 'Address', 'LookupSource', 'MultiAddress'] },
{ c: Amount, t: ['AccountIndex', 'i8', 'i16', 'i32', 'i64', 'i128', 'u8', 'u16', 'u32', 'u64', 'u128', 'u256'] },
{ c: Balance, t: ['Amount', 'Balance', 'BalanceOf'] },
{ c: Bool, t: ['bool'] },