No indices lookups anywhere, only on address book (#3531)

* No indices lookups anywhere, only on address book

* Linting
This commit is contained in:
Jaco Greeff 2020-08-26 19:37:10 +02:00 committed by GitHub
parent 6fed928f6c
commit 4c007e29ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 17 deletions

View File

@ -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) {

View File

@ -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;
}