Show democracy dispatch queue (#1997)

* Show democracy dispatch queue

* Bump API
This commit is contained in:
Jaco Greeff 2019-12-04 16:07:13 +01:00 committed by GitHub
parent e00a39a36b
commit a9baa96e87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 233 additions and 58 deletions

View File

@ -10,10 +10,10 @@
"packages/*"
],
"resolutions": {
"@polkadot/api": "^0.98.0-beta.3",
"@polkadot/api-contract": "^0.98.0-beta.3",
"@polkadot/api": "^0.99.0-beta.0",
"@polkadot/api-contract": "^0.99.0-beta.0",
"@polkadot/keyring": "^1.7.1",
"@polkadot/types": "^0.98.0-beta.3",
"@polkadot/types": "^0.99.0-beta.0",
"@polkadot/util": "^1.7.1",
"@polkadot/util-crypto": "^1.7.1",
"babel-core": "^7.0.0-bridge.0",

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.7.4",
"@polkadot/api-contract": "^0.98.0-beta.3",
"@polkadot/api-contract": "^0.99.0-beta.0",
"@polkadot/react-components": "^0.38.0-beta.29"
}
}

View File

@ -52,7 +52,7 @@ function Motion ({ className, hash, proposal, t, votes }: Props): React.ReactEle
{nays.map((address, index): React.ReactNode => (
<AddressMini
key={`${index}:${address}`}
label={t('Nay')}
label={index === 0 ? t('Nay') : undefined}
value={address}
withBalance={false}
/>

View File

@ -0,0 +1,69 @@
// Copyright 2017-2019 @polkadot/app-democracy authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { BlockNumber, Hash, ReferendumIndex } from '@polkadot/types/interfaces';
import { ITuple } from '@polkadot/types/types';
import React, { useEffect, useState } from 'react';
import { registry } from '@polkadot/react-api';
import { Option, StorageKey, Vec, createType } from '@polkadot/types';
import { hexToU8a } from '@polkadot/util';
import DispatchEntry from './DispatchEntry';
interface Props {
entries: Option<Vec<Option<ITuple<[Hash, ReferendumIndex]>>>>;
keyPrefix: string;
storageKey: StorageKey;
}
interface Entry {
blockNumber?: BlockNumber;
hash: Hash;
referendumIndex: ReferendumIndex;
}
export default function DispatchBlock ({ entries, keyPrefix, storageKey }: Props): React.ReactElement<Props> | null {
const [blockNumber, setBlockNumber] = useState<BlockNumber | undefined>();
const [expanded, setExpanded] = useState<Entry[]>([]);
useEffect((): void => {
if (keyPrefix && storageKey) {
setBlockNumber(createType(registry, 'BlockNumber', hexToU8a(
`0x${storageKey.toHex().replace(keyPrefix, '').substr(16)}`)
));
}
}, [keyPrefix, storageKey]);
useEffect((): void => {
setExpanded(
entries?.isSome
? entries
.unwrap()
.map((entry): [Hash, ReferendumIndex] | null => entry.unwrapOr(null))
.filter((entry): boolean => !!entry)
.map(([hash, referendumIndex]: any): Entry => ({
blockNumber, hash, referendumIndex
}))
: []
);
}, [blockNumber, entries]);
if (!expanded.length) {
return null;
}
return (
<>
{expanded.map(({ blockNumber, hash, referendumIndex }): React.ReactNode => (
<DispatchEntry
blockNumber={blockNumber}
hash={hash}
key={referendumIndex.toString()}
referendumIndex={referendumIndex}
/>
))}
</>
);
}

View File

@ -0,0 +1,51 @@
// Copyright 2017-2019 @polkadot/app-democracy authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { I18nProps } from '@polkadot/react-components/types';
import { AccountId, Balance, BlockNumber, Hash, Proposal, ReferendumIndex } from '@polkadot/types/interfaces';
import { ITuple } from '@polkadot/types/types';
import React, { useEffect, useState } from 'react';
import { useApi, trackStream } from '@polkadot/react-hooks';
import { Bytes, Option } from '@polkadot/types';
import { formatNumber } from '@polkadot/util';
import translate from '../translate';
import ProposalCell from './ProposalCell';
interface Props extends I18nProps {
blockNumber?: BlockNumber;
hash: Hash;
referendumIndex: ReferendumIndex;
}
function DispatchEntry ({ blockNumber, hash, referendumIndex, t }: Props): React.ReactElement<Props> {
const { api } = useApi();
const preimage = trackStream<Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>
>(api.query.democracy.preimages, [hash]);
const [proposal, setProposal] = useState<Proposal | undefined>();
useEffect((): void => {
if (preimage?.isSome) {
setProposal(api.createType('Proposal', preimage.unwrap()[0].toU8a(true)));
}
}, [preimage]);
return (
<tr>
<td className='number top'><h1>{formatNumber(referendumIndex)}</h1></td>
<td className='number top'>
{blockNumber && (
<>
<label>{t('enact at')}</label>
{formatNumber(blockNumber)}
</>
)}
</td>
<ProposalCell proposalHash={hash} proposal={proposal} />
</tr>
);
}
export default translate(DispatchEntry);

View File

@ -0,0 +1,52 @@
// Copyright 2017-2019 @polkadot/app-democracy authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { I18nProps as Props } from '@polkadot/react-components/types';
import { Hash, ReferendumIndex } from '@polkadot/types/interfaces';
import { ITuple } from '@polkadot/types/types';
import React, { useState } from 'react';
import { Table } from '@polkadot/react-components';
import { useApi, trackStream } from '@polkadot/react-hooks';
import { Option, StorageKey, Vec } from '@polkadot/types';
import { u8aToHex } from '@polkadot/util';
import translate from '../translate';
import DispatchBlock from './DispatchBlock';
function DispatchQueue ({ className, t }: Props): React.ReactElement<Props> | null {
const { api } = useApi();
const [keyPrefix] = useState(u8aToHex(api.query.democracy.dispatchQueue.creator.iterKey));
const queued = trackStream<[StorageKey, Option<Vec<Option<ITuple<[Hash, ReferendumIndex]>>>>
][]>(api.query.democracy.dispatchQueue.entries as any, []);
if (!queued?.length) {
return null;
}
return (
<div className={className}>
<h1>{t('dispatch queue')}</h1>
{queued?.length
? (
<Table>
<Table.Body>
{queued.map(([storageKey, entries]): React.ReactNode => (
<DispatchBlock
entries={entries}
key={storageKey.toString()}
keyPrefix={keyPrefix}
storageKey={storageKey}
/>
))}
</Table.Body>
</Table>
)
: t('nothing queued to be executed')
}
</div>
);
}
export default translate(DispatchQueue);

View File

@ -9,6 +9,7 @@ import styled from 'styled-components';
import { Button } from '@polkadot/react-components';
import translate from '../translate';
import DispatchQueue from './DispatchQueue';
import Externals from './Externals';
import Proposals from './Proposals';
import Referendums from './Referendums';
@ -50,6 +51,7 @@ function Overview ({ className, t }: Props): React.ReactElement {
<Referendums />
<Proposals />
<Externals />
<DispatchQueue />
</div>
);
}

View File

@ -31,7 +31,7 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
"dependencies": {
"@babel/runtime": "^7.7.4",
"@polkadot/api": "^0.98.0-beta.3",
"@polkadot/api": "^0.99.0-beta.0",
"@polkadot/extension-dapp": "^0.14.0-beta.6",
"edgeware-node-types": "^1.0.10",
"rxjs-compat": "^6.5.3"

View File

@ -43,6 +43,11 @@ function Call ({ children, className, labelHash, style, mortality, tip, value, w
className={classes('ui--Extrinsic', className)}
style={style}
>
<Params
isDisabled
params={params}
values={values}
/>
{children}
{hash && (
<Static
@ -68,11 +73,6 @@ function Call ({ children, className, labelHash, style, mortality, tip, value, w
<FormatBalance value={tip} />
</Static>
)}
<Params
isDisabled
params={params}
values={values}
/>
</div>
);
}

View File

@ -30,7 +30,7 @@ export default styled(Card)`
justify-content: space-around;
label {
opacity: 0.25;
opacity: 0.42;
}
&:hover {

View File

@ -72,7 +72,7 @@ export default styled(Table)`
}
label {
opacity: 0.25;
opacity: 0.42;
}
&:hover {

View File

@ -2029,35 +2029,35 @@
dependencies:
"@types/node" ">= 8"
"@polkadot/api-contract@^0.98.0-beta.3":
version "0.98.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.98.0-beta.3.tgz#ca0bea26158de417447bb76b21c6d1a403117502"
integrity sha512-FQ/EuLkaR6UBcZulJNXOjk3lT4df+BUY8pJ5maaLJukc35QTHPqcys30VidGVwmYw50u/30bVynE5Wtf2yY4Gw==
"@polkadot/api-contract@^0.99.0-beta.0":
version "0.99.0-beta.0"
resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.99.0-beta.0.tgz#4a8d65e3e21e7e2f2bc3369d9f01ba479909023a"
integrity sha512-JmLiOYo9kwdk4ILDJenMFwguH2394h61pNnRXWqbWazFYR0iWcA1vyaH5bSMqBc64hGMDknTqnem/h5ifsK8Tg==
dependencies:
"@babel/runtime" "^7.7.4"
"@polkadot/types" "^0.98.0-beta.3"
"@polkadot/types" "^0.99.0-beta.0"
"@polkadot/api-derive@^0.98.0-beta.3":
version "0.98.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.98.0-beta.3.tgz#b3239c80692e7f40329c0bc89e06eb98c00dcb05"
integrity sha512-ccPv0gKdEIX0XXjzvJJ++Hnl+k9x/ZldZq3BXxJE6yR4WVmoUUTTbwH8t4zihpovdZKd8AKaIliSJIvHvrT3RA==
"@polkadot/api-derive@^0.99.0-beta.0":
version "0.99.0-beta.0"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.99.0-beta.0.tgz#ca0c9cc4216798cb2e7f623e86a49d076b6eea7e"
integrity sha512-J9eaFEA8reDvI7LY6m98XM48IfmsKVsj7VFIdo66/aABBzYeLHciCoi37sBm2AV0k+eeB3+/90F3+h3HOu5jYQ==
dependencies:
"@babel/runtime" "^7.7.4"
"@polkadot/api" "^0.98.0-beta.3"
"@polkadot/types" "^0.98.0-beta.3"
"@polkadot/api" "^0.99.0-beta.0"
"@polkadot/types" "^0.99.0-beta.0"
"@polkadot/api@^0.98.0-beta.3":
version "0.98.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.98.0-beta.3.tgz#0eba15688c7bfd1e18cee5a5c2bf22b3150e7183"
integrity sha512-Vi0DhsZBNp36ECEdrIMktqvi+/W+CegcrLgZ5JqqOjxwFuzFOSS1Xr9saYeD7v1TA4D7IFdrnikOVCs/cCKw2Q==
"@polkadot/api@^0.99.0-beta.0":
version "0.99.0-beta.0"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.99.0-beta.0.tgz#dcc9d4a00de7534c71b969ba4ab148c0c5ea0592"
integrity sha512-Q+hSAtwtV3C70+r9EjJlbXdADGlczn5PubhVjQd030hvTDC2HHvfNvYDLiKQnTvoV9jrdFyyYnibsqVL7lI0zA==
dependencies:
"@babel/runtime" "^7.7.4"
"@polkadot/api-derive" "^0.98.0-beta.3"
"@polkadot/api-derive" "^0.99.0-beta.0"
"@polkadot/keyring" "^1.7.1"
"@polkadot/metadata" "^0.98.0-beta.3"
"@polkadot/rpc-core" "^0.98.0-beta.3"
"@polkadot/rpc-provider" "^0.98.0-beta.3"
"@polkadot/types" "^0.98.0-beta.3"
"@polkadot/metadata" "^0.99.0-beta.0"
"@polkadot/rpc-core" "^0.99.0-beta.0"
"@polkadot/rpc-provider" "^0.99.0-beta.0"
"@polkadot/types" "^0.99.0-beta.0"
"@polkadot/util-crypto" "^1.7.1"
"@polkadot/dev-react@^0.32.0-beta.15":
@ -2161,10 +2161,10 @@
dependencies:
"@babel/runtime" "^7.7.4"
"@polkadot/jsonrpc@^0.98.0-beta.3":
version "0.98.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.98.0-beta.3.tgz#bed2307791472e836dca9347830da287a73a738d"
integrity sha512-B2c8zcJ7OtAJHCoMa+j/3I5fkDUN7BrhZen7EGhY0YTxlHdg+i2Tgrg36cMoIjEJEnL+IPgQ+sKI5JGB2WV3vg==
"@polkadot/jsonrpc@^0.99.0-beta.0":
version "0.99.0-beta.0"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.99.0-beta.0.tgz#de844ffd57e5aa6b8776022c55d7bebca2b3627e"
integrity sha512-YvHLBdXfQVlpCmwo8bQQm6hmCRpY/DWKK/ptqCalEaOpIsl9yyZ8ts4yXRYz2rUpYFqdun7gS+8FlsTwJt6W6A==
dependencies:
"@babel/runtime" "^7.7.4"
@ -2177,13 +2177,13 @@
"@polkadot/util" "^1.7.1"
"@polkadot/util-crypto" "^1.7.1"
"@polkadot/metadata@^0.98.0-beta.3":
version "0.98.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/metadata/-/metadata-0.98.0-beta.3.tgz#303de74416a8af6de9f8c89904433ed65531b017"
integrity sha512-XtHCh9pVy4AgwmI9vevr798a3xFnBhZQVsEUaJHm7DZ3L/AqpfRrXrcfMZBRvEFGDp5dTzTE3B064DO93/DKzQ==
"@polkadot/metadata@^0.99.0-beta.0":
version "0.99.0-beta.0"
resolved "https://registry.yarnpkg.com/@polkadot/metadata/-/metadata-0.99.0-beta.0.tgz#de7e5622e8a2d26d1c33a2c02b62668dcbf251af"
integrity sha512-MPA3ZG1rGzfyp9TDyT6bmFhh5fCNcR51cHkeTUaabaJUOpNwH2FOFjJlNJ4R2IDYfIIs6hZFwrbdJzLgCvKvgg==
dependencies:
"@babel/runtime" "^7.7.4"
"@polkadot/types" "^0.98.0-beta.3"
"@polkadot/types" "^0.99.0-beta.0"
"@polkadot/util" "^1.7.1"
"@polkadot/util-crypto" "^1.7.1"
@ -2212,25 +2212,25 @@
qrcode-generator "^1.4.4"
react-qr-reader "^2.2.1"
"@polkadot/rpc-core@^0.98.0-beta.3":
version "0.98.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.98.0-beta.3.tgz#860ac5f27faa9798f0cb0c87c24d6558c8a1baf1"
integrity sha512-t5cLI7qfkWsG6wxasqoRhWvRSMI1fH5i6UY+joChydMpN6vINQDIw9yaw0cHMyWes5SY5aN/MHAqSqAjsVFxRA==
"@polkadot/rpc-core@^0.99.0-beta.0":
version "0.99.0-beta.0"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.99.0-beta.0.tgz#c6c57ad7fb0e8cb9e1ff756d45f857e0ca411b6b"
integrity sha512-4uCa9+E6U/Hvb63y5p8RCSeJIbdVjXVDWX0WZJ4zXquQ1ktBvwjkrkpcQr7z6mlJrtibqfEJdytP3YEGZRuDKw==
dependencies:
"@babel/runtime" "^7.7.4"
"@polkadot/jsonrpc" "^0.98.0-beta.3"
"@polkadot/rpc-provider" "^0.98.0-beta.3"
"@polkadot/types" "^0.98.0-beta.3"
"@polkadot/jsonrpc" "^0.99.0-beta.0"
"@polkadot/rpc-provider" "^0.99.0-beta.0"
"@polkadot/types" "^0.99.0-beta.0"
"@polkadot/util" "^1.7.1"
rxjs "^6.5.3"
"@polkadot/rpc-provider@^0.98.0-beta.3":
version "0.98.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.98.0-beta.3.tgz#5a5cb16baca9f67c2919b8b5430b5328327dcd36"
integrity sha512-acEwTkmPMHkvG59QqCmESO+pdClmk3eDJ3cb0/9CwfKnNByqp4rbM6USEAXgoT4N+5nGtZ13SIaUl5O6kGi2jA==
"@polkadot/rpc-provider@^0.99.0-beta.0":
version "0.99.0-beta.0"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.99.0-beta.0.tgz#b162da5d3a941bf850a360d3169264f11023081f"
integrity sha512-WNkuAhLcRo1X3t8H2ox+9DpZgz1PepY+FyhxIej74M7E1heOQX1JvcOq+74nTQF1KE9JMR21YJb1cdQuvIrFtg==
dependencies:
"@babel/runtime" "^7.7.4"
"@polkadot/metadata" "^0.98.0-beta.3"
"@polkadot/metadata" "^0.99.0-beta.0"
"@polkadot/util" "^1.7.1"
"@polkadot/util-crypto" "^1.7.1"
eventemitter3 "^4.0.0"
@ -2244,12 +2244,13 @@
dependencies:
"@types/chrome" "^0.0.91"
"@polkadot/types@^0.98.0-beta.3":
version "0.98.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.98.0-beta.3.tgz#82c9c2184e1cbea5083a901c559d5b563047e7f8"
integrity sha512-ZxUj4eevwVVIHieyrHB94io/vI0KEtFkrmi/xgljInD23byP4uYx5b4XE0r8I/yfpqihj+FXVUQ5n2xNIQE+lA==
"@polkadot/types@^0.99.0-beta.0":
version "0.99.0-beta.0"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.99.0-beta.0.tgz#93833493c067f55b1129ffaca716a216e5f53af6"
integrity sha512-Ax5mQWoyzH0YWUCb8yKqCvEWlLI67rFZstbIKMKm/ksxL+wsLmEN0fvwim8zoqpFKdS3i7BAsQ0prVrQb4i1CA==
dependencies:
"@babel/runtime" "^7.7.4"
"@polkadot/metadata" "^0.99.0-beta.0"
"@polkadot/util" "^1.7.1"
"@polkadot/util-crypto" "^1.7.1"
"@types/memoizee" "^0.4.3"