Type rendering updates (#643)

* Type rendering updates

* Moment renders via Amount

* Remove errant console.log
This commit is contained in:
Jaco Greeff 2019-01-24 22:38:17 +01:00 committed by GitHub
parent a3526127c6
commit 0663483a2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 95 additions and 80 deletions

View File

@ -31,8 +31,8 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
"dependencies": {
"@babel/runtime": "^7.2.0",
"@polkadot/api": "^0.40.24",
"@polkadot/types": "^0.40.24",
"@polkadot/api": "^0.40.25",
"@polkadot/types": "^0.40.25",
"rxjs-compat": "^6.3.2"
}
}

View File

@ -11,10 +11,10 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.2.0",
"@polkadot/extrinsics": "^0.40.24",
"@polkadot/extrinsics": "^0.40.25",
"@polkadot/keyring": "^0.33.36",
"@polkadot/storage": "^0.40.24",
"@polkadot/types": "^0.40.24",
"@polkadot/storage": "^0.40.25",
"@polkadot/types": "^0.40.25",
"@polkadot/ui-api": "^0.22.44",
"@polkadot/ui-identicon": "^0.25.8",
"@polkadot/ui-keyring": "^0.25.8",

View File

@ -8,6 +8,7 @@ import BN from 'bn.js';
import React from 'react';
import { Input } from '@polkadot/ui-app/index';
import numberFormat from '@polkadot/ui-reactive/util/numberFormat';
import { bnToBn } from '@polkadot/util';
import Bare from './Bare';
@ -16,11 +17,9 @@ export default class Amount extends React.PureComponent<Props> {
const { className, defaultValue: { value }, isDisabled, isError, label, style, withLabel } = this.props;
const defaultValue = isDisabled
? numberFormat(value)
: (
value instanceof BN
? value.toNumber()
: new BN((value as number) || 0).toNumber()
);
: bnToBn((value as number) || 0).toString();
console.error('vlue', value, defaultValue);
return (
<Bare

View File

@ -7,7 +7,7 @@ import { Props as BaseProps, Size } from '../types';
import React from 'react';
import { Compact } from '@polkadot/types/codec';
import { Input } from '@polkadot/ui-app/index';
import { hexToU8a, u8aToHex } from '@polkadot/util';
import { hexToU8a, isHex, u8aToHex } from '@polkadot/util';
import Bare from './Bare';
@ -26,7 +26,11 @@ export default class BaseBytes extends React.PureComponent<Props> {
render () {
const { children, className, defaultValue: { value }, isDisabled, isError, label, size = 'full', style, withLabel } = this.props;
const defaultValue = value
? u8aToHex(value as Uint8Array, isDisabled ? 256 : -1)
? (
isHex(value)
? value
: u8aToHex(value as Uint8Array, isDisabled ? 256 : -1)
)
: undefined;
return (
@ -56,16 +60,20 @@ export default class BaseBytes extends React.PureComponent<Props> {
const { length = -1, onChange, validate = defaultValidate, withLength } = this.props;
let value: Uint8Array;
let isValid: boolean = true;
try {
value = hexToU8a(hex);
} catch (error) {
value = new Uint8Array([]);
isValid = false;
}
let isValid = validate(value) && length !== -1
? value.length === length
: value.length !== 0;
isValid = isValid && validate(value) && (
length !== -1
? value.length === length
: value.length !== 0
);
if (withLength && isValid) {
value = Compact.addLengthPrefix(value);

View File

@ -9,7 +9,7 @@ import { Input } from '@polkadot/ui-app/index';
import Bare from './Bare';
export default class StringParam extends React.PureComponent<Props> {
export default class Text extends React.PureComponent<Props> {
render () {
const { className, defaultValue: { value }, isDisabled, isError, label, style, withLabel } = this.props;
const defaultValue = (value || '').toString();

View File

@ -12,11 +12,11 @@ import Bool from './Bool';
import Bytes from './Bytes';
import Code from './Code';
import Hash from './Hash';
import Moment from './Moment';
import Proposal from './Proposal';
import KeyValue from './KeyValue';
import KeyValueArray from './KeyValueArray';
import StringParam from './String';
import Timestamp from './Timestamp';
import Text from './Text';
import Tuple from './Tuple';
import Unknown from './Unknown';
import Vector from './Vector';
@ -32,22 +32,22 @@ const components: ComponentMap = {
'bool': Bool,
'Bytes': Bytes,
'Code': Code,
'Call': Unknown,
'Digest': Unknown,
'CodeHash': Hash,
'Gas': Amount,
'Hash': Hash,
'Index': Amount,
'KeyValue': KeyValue,
'Vec<KeyValue>': KeyValueArray,
'MisbehaviorReport': Unknown,
'ParaId': Amount,
'Moment': Moment,
'ProposalIndex': Amount,
'PropIndex': Amount,
'Proposal': Proposal,
'ReferendumIndex': Amount,
'SessionKey': Amount,
'Signature': Hash,
'String': StringParam,
'Timestamp': Timestamp,
'String': Text,
'Text': Text,
'Tuple': Tuple,
'u32': Amount,
'u64': Amount,

View File

@ -6,6 +6,7 @@ import { TypeDef, TypeDefInfo } from '@polkadot/types/codec';
import { RawParam$Value } from './types';
import BN from 'bn.js';
import { Bytes, Hash } from '@polkadot/types';
export default function getInitValue (def: TypeDef): RawParam$Value | Array<RawParam$Value> {
if (def.info === TypeDefInfo.Vector) {
@ -32,6 +33,7 @@ export default function getInitValue (def: TypeDef): RawParam$Value | Array<RawP
case 'Index':
case 'ParaId':
case 'PropIndex':
case 'ProposalIndex':
case 'ReferendumIndex':
case 'SessionKey':
case 'u32':
@ -46,8 +48,8 @@ export default function getInitValue (def: TypeDef): RawParam$Value | Array<RawP
case 'String':
return '';
case 'Timestamp':
return new Date(0);
case 'Moment':
return new BN(0);
case 'Vote':
return -1;
@ -55,13 +57,19 @@ export default function getInitValue (def: TypeDef): RawParam$Value | Array<RawP
case 'VoteThreshold':
return 0;
case 'Bytes':
return new Bytes();
case 'CodeHash':
case 'Hash':
return new Hash();
case 'AccountId':
case 'Address':
case 'Bytes':
case 'Call':
case 'CandidateReceipt':
case 'Digest':
case 'Hash':
case 'Header':
case 'KeyValue':
case 'MisbehaviorReport':

View File

@ -31,8 +31,8 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
"dependencies": {
"@babel/runtime": "^7.2.0",
"@polkadot/api": "^0.40.24",
"@polkadot/types": "^0.40.24",
"@polkadot/api": "^0.40.25",
"@polkadot/types": "^0.40.25",
"rxjs-compat": "^6.3.2"
}
}

104
yarn.lock
View File

@ -1385,31 +1385,31 @@
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b"
integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==
"@polkadot/api-derive@^0.40.24":
version "0.40.24"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.40.24.tgz#7e0721b224693ee3edd6389e65aef4b82937592a"
integrity sha512-nN+RqvuFavYK484vFBagnvM3zOQ6aEZ6XUeiOcu9EmJOnltz1tlrKXWDaO7kYdHGtuVaPUddQ9hVQ1+HyWfKOA==
"@polkadot/api-derive@^0.40.25":
version "0.40.25"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.40.25.tgz#7ad0d4b372531e979554c66bbefe354487f6cbb1"
integrity sha512-A6WiggdMT3r06T2AJR1j0VuwTAhF9ve6nVBNrfDylBN/MD6HFTkTocuMactIdgYeMu9QpAwiGdGqma4FmWpGoA==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/api" "^0.40.24"
"@polkadot/types" "^0.40.24"
"@polkadot/api" "^0.40.25"
"@polkadot/types" "^0.40.25"
"@types/memoizee" "^0.4.2"
"@types/rx" "^4.1.1"
memoizee "^0.4.14"
rxjs "^6.3.3"
"@polkadot/api@^0.40.24":
version "0.40.24"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.40.24.tgz#27866cd0cf389a33b3c8df188a5e86ddd34c1897"
integrity sha512-r7737BVM9Tz82F6AxHJBuvpWRvA+FTq3fesJrUNGsVycnOz2QOmC/TPNCAneEeuSRINrPI15nyUE6pj0nRCPIA==
"@polkadot/api@^0.40.25":
version "0.40.25"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.40.25.tgz#fb788ffc67dcb0cc66988709f7b8e0f2be9ea86b"
integrity sha512-BLvESJwzvErUsX7onDTgwvQWsgsV02y5drc+CFUFnijgg9VPirXRw1DapAlvdJan4YBmhTzPnZAjWFiJLn84qw==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/api-derive" "^0.40.24"
"@polkadot/extrinsics" "^0.40.24"
"@polkadot/rpc-provider" "^0.40.24"
"@polkadot/rpc-rx" "^0.40.24"
"@polkadot/storage" "^0.40.24"
"@polkadot/types" "^0.40.24"
"@polkadot/api-derive" "^0.40.25"
"@polkadot/extrinsics" "^0.40.25"
"@polkadot/rpc-provider" "^0.40.25"
"@polkadot/rpc-rx" "^0.40.25"
"@polkadot/storage" "^0.40.25"
"@polkadot/types" "^0.40.25"
"@types/rx" "^4.1.1"
rxjs "^6.3.3"
@ -1489,19 +1489,19 @@
typedoc-plugin-no-inherit "^1.1.2"
typescript "^3.2.2"
"@polkadot/extrinsics@^0.40.24":
version "0.40.24"
resolved "https://registry.yarnpkg.com/@polkadot/extrinsics/-/extrinsics-0.40.24.tgz#0540e4fbf1be5ca59f417cfb564d4e82ac36c257"
integrity sha512-bWbMt7iOVsXr7Kie5hQdF86B8MtMekPiVYfBEgJTIfXteYjk0qdXwWR1VV6oZPZiow1rAfVA8PLWCMK/URrIPA==
"@polkadot/extrinsics@^0.40.25":
version "0.40.25"
resolved "https://registry.yarnpkg.com/@polkadot/extrinsics/-/extrinsics-0.40.25.tgz#2f2370591201e258f3085fce1687423d76f895cb"
integrity sha512-VkFjZkoowd2JxNBqQsZ7oY+YIq0f4Ngy0JjOHClo61QJMYQc5IU3LBf3+gBaHH72s73901Ui6lI6n0NKzqohKg==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/types" "^0.40.24"
"@polkadot/types" "^0.40.25"
"@polkadot/util" "^0.33.36"
"@polkadot/jsonrpc@^0.40.24":
version "0.40.24"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.40.24.tgz#4ea631a2dc9ff073a11c6f7f062c5392e0f75d61"
integrity sha512-d3HNdIX3XiKS3lD+aspDoWtqUucDjRG6bxxwnOfKm6JNsaMfjoyJ/RZsqJFAUFI1ZnSWzgCGmrYkPvcahAX+9w==
"@polkadot/jsonrpc@^0.40.25":
version "0.40.25"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.40.25.tgz#01d92e8d3934353505ac65ddd9969a8e3a86cf5a"
integrity sha512-psCR8uFCh67VIOY1J2QEkKkLMH4m2reK4rmCmcL26FJEGrPB1Eo5Of+qO6e1bU5s/bzAraXZrX+MfsyXpoSqZg==
dependencies:
"@babel/runtime" "^7.2.0"
@ -1516,25 +1516,25 @@
"@types/bs58" "^4.0.0"
bs58 "^4.0.1"
"@polkadot/rpc-core@^0.40.24":
version "0.40.24"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.40.24.tgz#f713720d36b8537e132bbf65bdaaea3b12ad4d32"
integrity sha512-Vj1k5h3J7Bnyss1JwN3VtSLszLeURDBgwOITdpCG+QpVxbluCZ0ZRCICYyVhuXXONrTj4vDSvLvhSQJFYkiuFQ==
"@polkadot/rpc-core@^0.40.25":
version "0.40.25"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.40.25.tgz#f7d9c70c3be02a7ee5e23dd0d5e0dc7dc4b721eb"
integrity sha512-RE2ADJWL3dGr93/dUg8tVPaXzcKvH2Oc7kONf7NI8mSn9sqJZsEQ1G27ImnI+lfLZmikiCATyTYxGrxOIPNhTQ==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/jsonrpc" "^0.40.24"
"@polkadot/rpc-provider" "^0.40.24"
"@polkadot/types" "^0.40.24"
"@polkadot/jsonrpc" "^0.40.25"
"@polkadot/rpc-provider" "^0.40.25"
"@polkadot/types" "^0.40.25"
"@polkadot/util" "^0.33.36"
"@polkadot/rpc-provider@^0.40.24":
version "0.40.24"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.40.24.tgz#5d150dddef67b738a02c3475d29680af90d3530e"
integrity sha512-Z/dSNHvDvdoTTTOEYB6JtWO6VASXg0HNL3jr5Vg4bv+NVF/6XK37GbORtDcKBVjh8pwhxTi9RJJ+5gCbedfcQg==
"@polkadot/rpc-provider@^0.40.25":
version "0.40.25"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.40.25.tgz#31cd8d06ef76760fb6f9597a06f18bf8ea8c125f"
integrity sha512-+RuHIvZJj9MtXLVHvZJDxmpHdIjgdNFE4XgMMMKA/bOOxGWMu4bVLwEM51xnkZBjY2pb4S0eXFGKTRVCnf6DYg==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/keyring" "^0.33.36"
"@polkadot/storage" "^0.40.24"
"@polkadot/storage" "^0.40.25"
"@polkadot/util" "^0.33.36"
"@polkadot/util-crypto" "^0.33.36"
"@types/nock" "^9.3.0"
@ -1542,25 +1542,25 @@
isomorphic-fetch "^2.2.1"
websocket "^1.0.28"
"@polkadot/rpc-rx@^0.40.24":
version "0.40.24"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-rx/-/rpc-rx-0.40.24.tgz#a6f209004042457e04933f21793764b1e217bf4c"
integrity sha512-gwGUyqxMFbbt4zy8ZNdE0zai9O3Qd+WGkmUNpPeUZrp5G4ZE6fPwNxlvyXoAZVVORLlv4M7zFQn/x5m2ira92w==
"@polkadot/rpc-rx@^0.40.25":
version "0.40.25"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-rx/-/rpc-rx-0.40.25.tgz#801ee1aebd8548ea5013e91b50665b4d8647f58f"
integrity sha512-avIXaoOD843s4fz4pB1ky+x9f+RiI4ySvZc7JDfB8GXXELPf3XX9bXR+ltB89kfVYnxrJKAxSqGmocg05Nx+7g==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/rpc-core" "^0.40.24"
"@polkadot/rpc-provider" "^0.40.24"
"@polkadot/rpc-core" "^0.40.25"
"@polkadot/rpc-provider" "^0.40.25"
"@types/rx" "^4.1.1"
rxjs "^6.3.3"
"@polkadot/storage@^0.40.24":
version "0.40.24"
resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.40.24.tgz#ced8c25244110fae7171ce7b4c84544805c6b8ab"
integrity sha512-x8R+3VNYqK9AI2Hp6kcxiYwCd4UKs5D9zTJJpbVa66J079JYo5900unUCD+Wd990wgEAQiTv0fWjBM1AaIGDzw==
"@polkadot/storage@^0.40.25":
version "0.40.25"
resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.40.25.tgz#118bc7ab5e86e42265f4ca815779ac4a457b8514"
integrity sha512-5igB+g/OBA9FMgWiWD6aAbnk/26t7CYSsZd/eAQ2NsbwIU11SCc12tofmgb13Ia56HNCdL7xpMWdrOU2pZyWpQ==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/keyring" "^0.33.36"
"@polkadot/types" "^0.40.24"
"@polkadot/types" "^0.40.25"
"@polkadot/util" "^0.33.36"
"@polkadot/util-crypto" "^0.33.36"
@ -1569,10 +1569,10 @@
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.52.tgz#6fb09e494d244dad4b3a9ca581bfe13beec66565"
integrity sha512-sij1O0x4CY51A394RYD4/aQwDPwIxIeTOpYI4AZgdF/vq5nvF14b4XFq9vAcSnblaIosf0sYKoz1f3dkN3QqLw==
"@polkadot/types@^0.40.24":
version "0.40.24"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.40.24.tgz#00a780861328a19999c7b2308bcb7de5d90df957"
integrity sha512-FdCS9GFZJexItAA/OYVB8kunkjt7GwP4ULmESPcPhYW+wVC+QSPYiIYHZJrcTxszpCyc78gIsHAjgyG93YSWww==
"@polkadot/types@^0.40.25":
version "0.40.25"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.40.25.tgz#2a161d7f71c2f4241e889056d8040f01d63e82d8"
integrity sha512-gv4m0DdETF+MVEIDWUJuzBB0AGsx8HIKGazfmfssep8u/IwCPdq4bK3dQidlUnil6/5b4vqq+HEfMZSXfU7hJA==
dependencies:
"@babel/runtime" "^7.2.0"
"@polkadot/keyring" "^0.33.36"