No indices lookups anywhere, only on address book (#3531)
* No indices lookups anywhere, only on address book * Linting
This commit is contained in:
parent
6fed928f6c
commit
4c007e29ef
@ -125,7 +125,7 @@ class InputAddress extends React.PureComponent<Props, State> {
|
||||
return {
|
||||
lastValue: lastValue || getLastValue(type),
|
||||
value: Array.isArray(value)
|
||||
? value.map(addressToAddress)
|
||||
? value.map((v) => addressToAddress(v))
|
||||
: (addressToAddress(value) || undefined)
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
@ -3,24 +3,22 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import { hexToU8a, isHex } from '@polkadot/util';
|
||||
import { hexToU8a, isHex, assert } from '@polkadot/util';
|
||||
|
||||
export default function toAddress (value?: string | Uint8Array | null): string | undefined {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
let address: string | undefined;
|
||||
|
||||
try {
|
||||
address = keyring.encodeAddress(
|
||||
isHex(value)
|
||||
export default function toAddress (value?: string | Uint8Array | null, allowIndices = false): string | undefined {
|
||||
if (value) {
|
||||
try {
|
||||
const u8a = isHex(value)
|
||||
? hexToU8a(value)
|
||||
: keyring.decodeAddress(value)
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Unable to encode address', value);
|
||||
: keyring.decodeAddress(value);
|
||||
|
||||
assert(allowIndices || u8a.length === 32, 'AccountIndex values not allowed');
|
||||
|
||||
return keyring.encodeAddress(u8a);
|
||||
} catch (error) {
|
||||
console.error('Unable to encode address', (error as Error).message, value);
|
||||
}
|
||||
}
|
||||
|
||||
return address;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user