Convert assert to if + throw (remaining occurences) (#1622)

* Convert assert to if + throw (remaining occurences)

* Adjust for readability

* CHANGELOG
This commit is contained in:
Jaco
2022-08-04 10:45:10 +03:00
committed by GitHub
parent 2d4509c32a
commit c08c947abf
19 changed files with 128 additions and 71 deletions
+6 -3
View File
@@ -5,7 +5,7 @@ import type { HexString } from '@polkadot/util/types';
import type { Prefix } from './types';
// Original implementation: https://github.com/paritytech/polka-ui/blob/4858c094684769080f5811f32b081dd7780b0880/src/polkadot.js#L34
import { assert, u8aConcat } from '@polkadot/util';
import { u8aConcat } from '@polkadot/util';
import { base58Encode } from '../base58';
import { decodeAddress } from './decode';
@@ -16,8 +16,11 @@ export function encodeAddress (key: HexString | Uint8Array | string, ss58Format:
// decode it, this means we can re-encode an address
const u8a = decodeAddress(key);
assert(ss58Format >= 0 && ss58Format <= 16383 && ![46, 47].includes(ss58Format), 'Out of range ss58Format specified');
assert(defaults.allowedDecodedLengths.includes(u8a.length), () => `Expected a valid key to convert, with length ${defaults.allowedDecodedLengths.join(', ')}`);
if ((ss58Format < 0) || (ss58Format > 16383) || [46, 47].includes(ss58Format)) {
throw new Error('Out of range ss58Format specified');
} else if (!defaults.allowedDecodedLengths.includes(u8a.length)) {
throw new Error(`Expected a valid key to convert, with length ${defaults.allowedDecodedLengths.join(', ')}`);
}
const input = u8aConcat(
ss58Format < 64