From bf8e2b15bae1342e9c50a3ec0049284d934e1573 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 27 Feb 2019 15:04:03 +0100 Subject: [PATCH] Check instanceof to determine param (numbers only) (#764) --- packages/ui-params/src/Param/findComponent.ts | 14 ++++++++++++-- packages/ui-params/src/initValue.ts | 11 +++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/ui-params/src/Param/findComponent.ts b/packages/ui-params/src/Param/findComponent.ts index 5d7be0d928..7fc3f9ef4d 100644 --- a/packages/ui-params/src/Param/findComponent.ts +++ b/packages/ui-params/src/Param/findComponent.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 { TypeDef, TypeDefInfo } from '@polkadot/types'; +import { TypeDef, TypeDefInfo, UInt, createType } from '@polkadot/types'; import { Props, ComponentMap } from '../types'; import Account from './Account'; @@ -72,5 +72,15 @@ export default function findComponent (def: TypeDef, overrides: ComponentMap = { } })(def); - return overrides[type] || components[type] || Unknown; + let Component = overrides[type] || components[type]; + + if (!Component) { + const instance = createType(type); + + if (instance instanceof UInt) { + return Amount; + } + } + + return Component || Unknown; } diff --git a/packages/ui-params/src/initValue.ts b/packages/ui-params/src/initValue.ts index 8e021b569f..7a79c6ebb5 100644 --- a/packages/ui-params/src/initValue.ts +++ b/packages/ui-params/src/initValue.ts @@ -5,7 +5,7 @@ import { RawParam$Value } from './types'; import BN from 'bn.js'; -import { Bytes, Hash, TypeDef, TypeDefInfo } from '@polkadot/types'; +import { Bytes, Hash, TypeDef, TypeDefInfo, UInt, createType } from '@polkadot/types'; export default function getInitValue (def: TypeDef): RawParam$Value | Array { if (def.info === TypeDefInfo.Vector) { @@ -78,8 +78,15 @@ export default function getInitValue (def: TypeDef): RawParam$Value | Array