Display justifications for block click-through (#230)

* Display justifications for block click-through

* >25/25 display
This commit is contained in:
Jaco Greeff 2018-08-16 22:52:01 +02:00 committed by GitHub
parent 41608a139b
commit 682331e793
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 182 additions and 82 deletions

View File

@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0-rc.1",
"@polkadot/storage": "^0.28.16",
"@polkadot/storage": "^0.28.17",
"@polkadot/ui-react": "^0.19.36",
"@polkadot/ui-react-rx": "^0.19.36",
"@polkadot/util-keyring": "^0.28.3"

View File

@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0-rc.1",
"@polkadot/storage": "^0.28.16",
"@polkadot/storage": "^0.28.17",
"@polkadot/ui-react": "^0.19.36",
"@polkadot/ui-react-rx": "^0.19.36",
"@polkadot/util-keyring": "^0.28.3"

View File

@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0-rc.1",
"@polkadot/primitives": "^0.28.16",
"@polkadot/primitives": "^0.28.17",
"@polkadot/ui-app": "^0.19.36",
"@polkadot/util-crypto": "^0.28.3"
}

View File

@ -2,37 +2,53 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { BareProps } from '@polkadot/ui-app/types';
import { BlockDecoded } from '@polkadot/params/types';
import { I18nProps } from '@polkadot/ui-app/types';
import { ApiProps } from '@polkadot/ui-react-rx/types';
import React from 'react';
import withMulti from '@polkadot/ui-react-rx/with/multi';
import withObservable from '@polkadot/ui-react-rx/with/observable';
import AddressMini from '@polkadot/ui-app/AddressMini';
import Card from '@polkadot/ui-app/Card';
import Extrinsic from '@polkadot/ui-app/Extrinsic';
import numberFormat from '@polkadot/ui-react-rx/util/numberFormat';
import isBn from '@polkadot/util/is/bn';
import isHex from '@polkadot/util/is/hex';
import isU8a from '@polkadot/util/is/u8a';
import u8aToHex from '@polkadot/util/u8a/toHex';
import BlockHeader from '../BlockHeader';
import isHex from '@polkadot/util/is/hex';
import translate from '../translate';
type Props = ApiProps & BareProps & {
chainGetBlock: any,
type Props = ApiProps & I18nProps & {
chainGetBlock: BlockDecoded,
value: string
};
function debugJSON (key: string, value: any) {
return isU8a(value)
? u8aToHex(value)
: (
isBn(value)
? value.toString()
: value
);
}
// FIXME Duplicated layout here and in democracy, clean up with extrinsics
class BlockByHash extends React.PureComponent<Props> {
render () {
const { chainGetBlock, value } = this.props;
const { chainGetBlock } = this.props;
if (!chainGetBlock) {
return null;
}
const { extrinsics, header } = chainGetBlock;
const { header } = chainGetBlock;
// TODO Remove, debug info for reverse-engineering
console.log('hash=', value);
console.log('block=', chainGetBlock);
console.log(JSON.stringify(chainGetBlock, debugJSON));
return (
<div className='explorer--BlockByHash'>
@ -40,7 +56,22 @@ class BlockByHash extends React.PureComponent<Props> {
value={header}
withExtrinsics
/>
<div className='explorer--BlockByHash-extrinsics'>
{this.renderExtrinsics()}
{this.renderJustification()}
</div>
);
}
private renderExtrinsics () {
const { chainGetBlock, t, value } = this.props;
const { extrinsics } = chainGetBlock;
return (
<div className='explorer--BlockByHash-extrinsics'>
<h1>{t('block.extrinsics', {
defaultValue: 'extrinsics'
})}</h1>
<div className='explorer--BlockByHash-flexable'>
{extrinsics.map((extrinsic: any, index: number) => (
<div
className='explorer--BlockByHash-extrinsic'
@ -55,10 +86,13 @@ class BlockByHash extends React.PureComponent<Props> {
{extrinsic.extrinsic.description}
</div>
<div className='explorer--BlockByHash-header-right'>
{isHex(extrinsic.address)
<div>{isHex(extrinsic.address)
? extrinsic.address
: <AddressMini value={extrinsic.address} />
}
}</div>
<div className='explorer--BlockByHash-accountIndex'>{t('block.nonce', {
defaultValue: 'index'
})} {numberFormat(extrinsic.nonce)}</div>
</div>
</div>
<Extrinsic value={extrinsic} />
@ -69,6 +103,37 @@ class BlockByHash extends React.PureComponent<Props> {
</div>
);
}
private renderJustification () {
const { chainGetBlock, t, value } = this.props;
const { justification } = chainGetBlock;
return (
<div className='explorer--BlockByHash-justification'>
<h1>{t('block.justifications', {
defaultValue: 'justifications'
})}</h1>
<div className='explorer--BlockByHash-flexable'>
{justification.signatures.map(({ address, signature }) => (
<div
className='explorer--BlockByHash-justification-signature'
key={`${value}:justification:${address}`}
>
<AddressMini value={address}>
<span>
{u8aToHex(signature, 64)}
</span>
</AddressMini>
</div>
))}
</div>
</div>
);
}
}
export default withObservable('chainGetBlock', { paramProp: 'value' })(BlockByHash);
export default withMulti(
BlockByHash,
translate,
withObservable('chainGetBlock', { paramProp: 'value' })
);

View File

@ -25,7 +25,10 @@ export default class Entry extends React.PureComponent<Props> {
}
return (
<BlockByHash value={hash} />
<BlockByHash
key={hash}
value={hash}
/>
);
}
}

View File

@ -38,6 +38,7 @@ class BlockHeader extends React.PureComponent<Props> {
// tslint:disable-next-line:variable-name
const { extrinsicsRoot, number, parentHash, stateRoot } = value;
const hashHex = u8aToHex(hash);
const parentHex = u8aToHex(parentHash);
const linkable = withLink
? <Link to={`/explorer/hash/${hashHex}`}>{hashHex}</Link>
: hashHex;
@ -59,7 +60,9 @@ class BlockHeader extends React.PureComponent<Props> {
<tr>
<td className='type'>parentHash</td>
<td className='hash'>
{u8aToHex(parentHash)}
<Link to={`/explorer/hash/${parentHex}`}>
{parentHex}
</Link>
</td>
</tr>
<tr>

View File

@ -30,10 +30,14 @@
text-align: right;
}
.explorer--BlockByHash-extrinsics {
.explorer--BlockByHash-extrinsics,
.explorer--BlockByHash-justification {
margin-top: 2em;
}
.explorer--BlockByHash-flexable {
display: flex;
flex-wrap: wrap;
margin-top: 2em;
}
.explorer--BlockByHash-extrinsic {
@ -55,10 +59,23 @@
line-height: 1.2rem;
}
.explorer--BlockByHash-accountIndex {
font-size: .75rem;
margin-top: -0.5rem;
opacity: 0.45;
text-align: right;
}
.explorer--BlockByHash-justification-signature span {
color: rgba(0, 0, 0, 0.6);
font-style: italic;
padding-left: 0.5rem;
}
.explorer--BlockByHash-header-right {
position: absolute;
top: 0em;
right: 1em;
top: -0.5rem;
right: 0rem;
}
.explorer--Summary {

View File

@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0-rc.1",
"@polkadot/extrinsics": "^0.28.16",
"@polkadot/extrinsics": "^0.28.17",
"@polkadot/ui-app": "^0.19.36",
"@polkadot/ui-signer": "^0.19.36",
"react-dropzone": "^4.3.0"

View File

@ -12,7 +12,7 @@
"dependencies": {
"@babel/runtime": "^7.0.0-rc.1",
"@polkadot/app-extrinsics": "^0.19.36",
"@polkadot/storage": "^0.28.16",
"@polkadot/storage": "^0.28.17",
"@polkadot/ui-app": "^0.19.36",
"@polkadot/ui-keyring": "^0.19.36",
"@polkadot/ui-react": "^0.19.36",

View File

@ -5,7 +5,7 @@
.apps--SideBar {
background: #f9f9f9;
flex-shrink: 0;
min-width: 12em;
min-width: 10em;
padding: 0.75em 0 0 0.75em;
position: relative;
text-align: left;
@ -13,6 +13,7 @@
.apps--SideBar .ui.vertical.menu {
margin: 0;
width: 13em;
}
.apps--SideBar-github {

View File

@ -11,8 +11,8 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0-rc.1",
"@polkadot/extrinsics": "^0.28.16",
"@polkadot/storage": "^0.28.16",
"@polkadot/extrinsics": "^0.28.17",
"@polkadot/storage": "^0.28.17",
"@polkadot/ui-keyring": "^0.19.36",
"@polkadot/ui-react": "^0.19.36",
"@polkadot/ui-react-rx": "^0.19.36",

View File

@ -14,6 +14,7 @@ import Balance from './Balance';
type Props = BareProps & {
balance?: BN | Array<BN>,
children?: React.ReactNode,
isPadded?: boolean,
isShort?: boolean,
value?: string,
@ -22,7 +23,7 @@ type Props = BareProps & {
export default class AddressMini extends React.PureComponent<Props> {
render () {
const { className, isPadded = true, isShort = true, style, value } = this.props;
const { children, className, isPadded = true, isShort = true, style, value } = this.props;
if (!value) {
return null;
@ -39,6 +40,7 @@ export default class AddressMini extends React.PureComponent<Props> {
value={value}
/>
<div>{isShort ? toShortAddress(value) : value}</div>
{children}
</div>
{this.renderBalance()}
</div>

View File

@ -28,6 +28,13 @@ type Props = BareProps & {
export default class CardSummary extends React.PureComponent<Props> {
render () {
const { children, className, progress, label, style } = this.props;
const left = progress && !isUndefined(progress.value) && !isUndefined(progress.total) && progress.value.gten(0) && progress.total.gtn(0)
? (
progress.value.gt(progress.total)
? `>${progress.total.toString()}`
: progress.value.toString()
)
: undefined;
return (
<Card
@ -38,9 +45,9 @@ export default class CardSummary extends React.PureComponent<Props> {
<div className='ui--CardSummary-large'>
{children}{
progress && (
(isUndefined(progress.value) || isUndefined(progress.total) || progress.value.ltn(0)) || progress.value.gt(progress.total) || progress.total.eqn(0)
!left || isUndefined(progress.total)
? '-'
: `${progress.value.toString()}/${progress.total.toString()}`
: `${left}/${progress.total.toString()}`
)
}
</div>

View File

@ -31,9 +31,9 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-react-rx#readme",
"dependencies": {
"@babel/runtime": "^7.0.0-rc.1",
"@polkadot/api-rx": "^0.28.16",
"@polkadot/extrinsics": "^0.28.16",
"@polkadot/storage": "^0.28.16",
"@polkadot/api-rx": "^0.28.17",
"@polkadot/extrinsics": "^0.28.17",
"@polkadot/storage": "^0.28.17",
"rxjs-compat": "^6.2.2"
},
"devDependencies": {

View File

@ -5,7 +5,7 @@
import { Header } from '@polkadot/primitives/header';
import { RxApiInterface, RxApiInterface$Method } from '@polkadot/api-rx/types';
import { Interfaces } from '@polkadot/jsonrpc/types';
import { ExtrinsicDecoded, SectionItem } from '@polkadot/params/types';
import { BlockDecoded, ExtrinsicDecoded, SectionItem } from '@polkadot/params/types';
import { Storages } from '@polkadot/storage/types';
import { RxBalance, RxBalanceMap, RxProposal, RxProposalDeposits, RxReferendum, ObservableApiInterface, KeyWithParams, RxReferendumVote } from './types';
@ -88,7 +88,7 @@ export default class ObservableApi implements ObservableApiInterface {
);
}
chainGetBlock = (hash: Uint8Array): Observable<any> => {
chainGetBlock = (hash: Uint8Array): Observable<BlockDecoded | undefined> => {
return this.api.chain.getBlock(hash);
}

View File

@ -5,7 +5,7 @@
import BN from 'bn.js';
import { Observable } from 'rxjs';
import { Interfaces } from '@polkadot/jsonrpc/types';
import { ExtrinsicDecoded, SectionItem } from '@polkadot/params/types';
import { BlockDecoded, ExtrinsicDecoded, SectionItem } from '@polkadot/params/types';
import { Header } from '@polkadot/primitives/header';
import { Storages } from '@polkadot/storage/types';
@ -54,7 +54,7 @@ export interface ObservableApiInterface {
rawStorage: <T> (key: SectionItem<Storages>, ...params: Array<any>) => Observable<T>,
rawStorageMulti: <T> (...keys: Array<[SectionItem<Storages>, any]>) => Observable<T>,
bestNumber: () => Observable<BN | undefined>,
chainGetBlock: (hash: Uint8Array) => Observable<any>,
chainGetBlock: (hash: Uint8Array) => Observable<BlockDecoded | undefined>,
chainNewHead: () => Observable<Header | undefined>,
democracyLaunchPeriod: () => Observable<BN | undefined>,
democracyNextTally: () => Observable<BN | undefined>,

View File

@ -70,8 +70,10 @@ export default class Elapsed extends React.PureComponent<Props, State> {
display = `${elapsed.toFixed(1)}s`;
} else if (elapsed < 60) {
display = `${elapsed | 0}s`;
} else if (elapsed < 3600) {
display = `${elapsed / 60 | 0}m`;
} else {
display = `${ elapsed / 60 | 0}m`;
display = `${elapsed / 3600 | 0}h`;
}
}

View File

@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.0.0-rc.1",
"@polkadot/extrinsics": "^0.28.16",
"@polkadot/extrinsics": "^0.28.17",
"@polkadot/ui-app": "^0.19.36",
"@polkadot/ui-keyring": "^0.19.36"
},

View File

@ -1291,22 +1291,22 @@
version "1.1.0"
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.0.tgz#50c1e2260ac0ed9439a181de3725a0168d59c48a"
"@polkadot/api-format@^0.28.16":
version "0.28.16"
resolved "https://registry.yarnpkg.com/@polkadot/api-format/-/api-format-0.28.16.tgz#3642cac8f22b8af25715b2d6c27eee5c89982efa"
"@polkadot/api-format@^0.28.17":
version "0.28.17"
resolved "https://registry.yarnpkg.com/@polkadot/api-format/-/api-format-0.28.17.tgz#b7fe73bf6e984842a1c419e93b30745108138b84"
dependencies:
"@babel/runtime" "^7.0.0-rc.1"
"@polkadot/jsonrpc" "^0.28.16"
"@polkadot/primitives" "^0.28.16"
"@polkadot/jsonrpc" "^0.28.17"
"@polkadot/primitives" "^0.28.17"
"@polkadot/util" "^0.28.3"
"@polkadot/util-keyring" "^0.28.3"
"@polkadot/api-provider@^0.28.16":
version "0.28.16"
resolved "https://registry.yarnpkg.com/@polkadot/api-provider/-/api-provider-0.28.16.tgz#2c4073dfa86bb426371da5e2e29614785db373e5"
"@polkadot/api-provider@^0.28.17":
version "0.28.17"
resolved "https://registry.yarnpkg.com/@polkadot/api-provider/-/api-provider-0.28.17.tgz#8b178db819588e6a49568d1904b4cf1de309415b"
dependencies:
"@babel/runtime" "^7.0.0-rc.1"
"@polkadot/storage" "^0.28.16"
"@polkadot/storage" "^0.28.17"
"@polkadot/util" "^0.28.3"
"@polkadot/util-crypto" "^0.28.3"
"@polkadot/util-keyring" "^0.28.3"
@ -1315,25 +1315,25 @@
isomorphic-fetch "^2.2.1"
websocket "^1.0.25"
"@polkadot/api-rx@^0.28.16":
version "0.28.16"
resolved "https://registry.yarnpkg.com/@polkadot/api-rx/-/api-rx-0.28.16.tgz#fc8ff96815a57f5224490bcda3e4d0b80c98a579"
"@polkadot/api-rx@^0.28.17":
version "0.28.17"
resolved "https://registry.yarnpkg.com/@polkadot/api-rx/-/api-rx-0.28.17.tgz#6a42cca37df8bda5fdf8268a1cc3134b24f22eee"
dependencies:
"@babel/runtime" "^7.0.0-rc.1"
"@polkadot/api" "^0.28.16"
"@polkadot/api-provider" "^0.28.16"
"@polkadot/api" "^0.28.17"
"@polkadot/api-provider" "^0.28.17"
"@types/rx" "^4.1.1"
rxjs "^6.2.2"
"@polkadot/api@^0.28.16":
version "0.28.16"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.28.16.tgz#44ff0f39925bf9d0d31b1914691eb25a0052770f"
"@polkadot/api@^0.28.17":
version "0.28.17"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.28.17.tgz#44184dfb62ab82463effac777968cbbbda0270f3"
dependencies:
"@babel/runtime" "^7.0.0-rc.1"
"@polkadot/api-format" "^0.28.16"
"@polkadot/api-provider" "^0.28.16"
"@polkadot/jsonrpc" "^0.28.16"
"@polkadot/params" "^0.28.16"
"@polkadot/api-format" "^0.28.17"
"@polkadot/api-provider" "^0.28.17"
"@polkadot/jsonrpc" "^0.28.17"
"@polkadot/params" "^0.28.17"
"@polkadot/util" "^0.28.3"
"@polkadot/dev-react@^0.20.16":
@ -1401,48 +1401,48 @@
typedoc "^0.11.1"
typescript "^3.0.1"
"@polkadot/extrinsics@^0.28.16":
version "0.28.16"
resolved "https://registry.yarnpkg.com/@polkadot/extrinsics/-/extrinsics-0.28.16.tgz#d94a49de59ec7686db6c2e1dd80a0e10c4cbb199"
"@polkadot/extrinsics@^0.28.17":
version "0.28.17"
resolved "https://registry.yarnpkg.com/@polkadot/extrinsics/-/extrinsics-0.28.17.tgz#d66777e6dbeb38dcad204aa29f2d75d0b6fa5682"
dependencies:
"@babel/runtime" "^7.0.0-rc.1"
"@polkadot/params" "^0.28.16"
"@polkadot/primitives" "^0.28.16"
"@polkadot/params" "^0.28.17"
"@polkadot/primitives" "^0.28.17"
"@polkadot/util" "^0.28.3"
"@polkadot/jsonrpc@^0.28.16":
version "0.28.16"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.28.16.tgz#cf60e160e53aec10eb5cc605e16d8af3182ff344"
"@polkadot/jsonrpc@^0.28.17":
version "0.28.17"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.28.17.tgz#5f653e0de344c60ad6cac0a7f1420e900b265adc"
dependencies:
"@polkadot/params" "^0.28.16"
"@polkadot/params" "^0.28.17"
babel-runtime "^6.26.0"
"@polkadot/params@^0.28.16":
version "0.28.16"
resolved "https://registry.yarnpkg.com/@polkadot/params/-/params-0.28.16.tgz#79422f73266fb317e0327f5ce2c5d1303d883e93"
"@polkadot/params@^0.28.17":
version "0.28.17"
resolved "https://registry.yarnpkg.com/@polkadot/params/-/params-0.28.17.tgz#9eb493a8cff8961f977e1767edfb9a773fbc2221"
dependencies:
"@babel/runtime" "^7.0.0-rc.1"
"@polkadot/extrinsics" "^0.28.16"
"@polkadot/params" "^0.28.16"
"@polkadot/primitives" "^0.28.16"
"@polkadot/extrinsics" "^0.28.17"
"@polkadot/params" "^0.28.17"
"@polkadot/primitives" "^0.28.17"
"@polkadot/util" "^0.28.3"
"@polkadot/util-keyring" "^0.28.3"
"@polkadot/primitives@^0.28.16":
version "0.28.16"
resolved "https://registry.yarnpkg.com/@polkadot/primitives/-/primitives-0.28.16.tgz#e44774c077ee3446bd26ac72e09f455ec6d34375"
"@polkadot/primitives@^0.28.17":
version "0.28.17"
resolved "https://registry.yarnpkg.com/@polkadot/primitives/-/primitives-0.28.17.tgz#4cd35c3a68990156dbb0490fa55c271aa44dfc79"
dependencies:
"@babel/runtime" "^7.0.0-rc.1"
"@polkadot/trie-hash" "^0.28.3"
"@polkadot/util" "^0.28.3"
"@polkadot/storage@^0.28.16":
version "0.28.16"
resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.28.16.tgz#7207d8a5aa4b21ecd31183ab734a8087458b7a85"
"@polkadot/storage@^0.28.17":
version "0.28.17"
resolved "https://registry.yarnpkg.com/@polkadot/storage/-/storage-0.28.17.tgz#3e00d7a22a0fdd8f117144c3dcaf115d6c4407f2"
dependencies:
"@babel/runtime" "^7.0.0-rc.1"
"@polkadot/params" "^0.28.16"
"@polkadot/primitives" "^0.28.16"
"@polkadot/params" "^0.28.17"
"@polkadot/primitives" "^0.28.17"
"@polkadot/util" "^0.28.3"
"@polkadot/util-crypto" "^0.28.3"
"@polkadot/util-keyring" "^0.28.3"