Check instanceof to determine param (numbers only) (#764)

This commit is contained in:
Jaco Greeff 2019-02-27 15:04:03 +01:00 committed by GitHub
parent 9294dc895a
commit bf8e2b15ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View File

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

View File

@ -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<RawParam$Value> {
if (def.info === TypeDefInfo.Vector) {
@ -78,8 +78,15 @@ export default function getInitValue (def: TypeDef): RawParam$Value | Array<RawP
case 'Signature':
return void 0;
default:
default: {
const instance = createType(type);
if (instance instanceof UInt) {
return new BN(0);
}
console.error(`Unable to determine default type for ${JSON.stringify(def)}`);
return void 0;
}
}
}