Check instanceof to determine param (numbers only) (#764)
This commit is contained in:
parent
9294dc895a
commit
bf8e2b15ba
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user