Fix ChainProperties JSON decoding
This commit is contained in:
@@ -12,15 +12,11 @@ describe('ChainProperties', (): void => {
|
||||
).toEqual(['ss58Format', 'tokenDecimals', 'tokenSymbol']);
|
||||
});
|
||||
|
||||
it('decodes from an actual object', (): void => {
|
||||
const { ss58Format, tokenDecimals, tokenSymbol } = registry.createType('ChainProperties', {
|
||||
ss58Format: 2,
|
||||
tokenDecimals: 15,
|
||||
tokenSymbol: 'KSM'
|
||||
});
|
||||
it('decodes from an actual JSON', (): void => {
|
||||
const { ss58Format, tokenDecimals, tokenSymbol } = registry.createType('ChainProperties', JSON.parse('{"ss58Format":2,"tokenDecimals":12,"tokenSymbol":"KSM"}'));
|
||||
|
||||
expect(ss58Format.unwrap().eq(2)).toBe(true);
|
||||
expect(tokenDecimals.unwrap().eq([15])).toBe(true);
|
||||
expect(tokenDecimals.unwrap().eq([12])).toBe(true);
|
||||
expect(tokenSymbol.unwrap().eq(['KSM'])).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@ import { Vec } from '../codec/Vec';
|
||||
import { Text } from '../primitive/Text';
|
||||
import { u32 } from '../primitive/U32';
|
||||
|
||||
function createValue (registry: Registry, type: string, value: unknown, asArray = true): Codec {
|
||||
function createValue (registry: Registry, type: string, value: unknown, asArray = true): Option<Codec> {
|
||||
// We detect codec here as well - when found, generally this is constructed from itself
|
||||
if (isFunction((value as Codec).toHuman) && (isFunction((value as Option<Codec>).unwrapOrDefault) || (!asArray || Array.isArray(value)))) {
|
||||
return value as Codec;
|
||||
if (isFunction((value as Option<Codec>).unwrapOrDefault)) {
|
||||
return value as Option<Codec>;
|
||||
}
|
||||
|
||||
return registry.createType(
|
||||
|
||||
Reference in New Issue
Block a user