From 30f5baa9062b2286756c37f925a84271a2d98372 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 18 Feb 2020 21:08:18 +0100 Subject: [PATCH] ExtrinsicEra & Vote toHuman (#1893) --- packages/types/src/codec/Raw.ts | 4 ++-- .../types/src/primitive/Extrinsic/ExtrinsicEra.ts | 8 +++++--- packages/types/src/primitive/Generic/Vote.ts | 12 +++++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/types/src/codec/Raw.ts b/packages/types/src/codec/Raw.ts index 572073f4de..f0c823c3a7 100644 --- a/packages/types/src/codec/Raw.ts +++ b/packages/types/src/codec/Raw.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { H256 } from '../interfaces/runtime'; -import { AnyU8a, IU8a, Registry } from '../types'; +import { AnyJson, AnyU8a, IU8a, Registry } from '../types'; import { isU8a, isUndefined, u8aToHex, u8aToU8a } from '@polkadot/util'; import { blake2AsU8a } from '@polkadot/util-crypto'; @@ -102,7 +102,7 @@ export default class Raw extends Uint8Array implements IU8a { /** * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ - public toHuman (): string { + public toHuman (): AnyJson { return this.toJSON(); } diff --git a/packages/types/src/primitive/Extrinsic/ExtrinsicEra.ts b/packages/types/src/primitive/Extrinsic/ExtrinsicEra.ts index 604c168f7a..5b23d756dd 100644 --- a/packages/types/src/primitive/Extrinsic/ExtrinsicEra.ts +++ b/packages/types/src/primitive/Extrinsic/ExtrinsicEra.ts @@ -5,7 +5,7 @@ import { AnyU8a, IExtrinsicEra, Registry } from '../../types'; import BN from 'bn.js'; -import { assert, bnToBn, hexToU8a, isHex, isU8a, isObject, u8aToBn } from '@polkadot/util'; +import { assert, bnToBn, formatNumber, hexToU8a, isHex, isU8a, isObject, u8aToBn } from '@polkadot/util'; import Enum from '../../codec/Enum'; import Tuple from '../../codec/Tuple'; @@ -127,8 +127,10 @@ export class MortalEra extends Tuple { * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information */ public toHuman (): any { - // FIXME we need proper expansion here - return this.toJSON(); + return { + period: formatNumber(this.period), + phase: formatNumber(this.phase) + }; } /** diff --git a/packages/types/src/primitive/Generic/Vote.ts b/packages/types/src/primitive/Generic/Vote.ts index 7cc6819c72..333fa7b53a 100644 --- a/packages/types/src/primitive/Generic/Vote.ts +++ b/packages/types/src/primitive/Generic/Vote.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { ArrayElementType, Registry } from '../../types'; +import { AnyJsonObject, ArrayElementType, Registry } from '../../types'; import democracyDef from '../../interfaces/democracy/definitions'; import { Conviction } from '../../interfaces/democracy'; @@ -101,6 +101,16 @@ export default class Vote extends U8aFixed { return !this.isAye; } + /** + * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information + */ + public toHuman (isExpanded?: boolean): AnyJsonObject { + return { + vote: this.isAye ? 'Aye' : 'Nay', + conviction: this.conviction.toHuman(isExpanded) + }; + } + /** * @description Returns the base runtime type name for this instance */