From a9baa96e87098a272d6a775aa32d46ceeed9e655 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 4 Dec 2019 16:07:13 +0100 Subject: [PATCH] Show democracy dispatch queue (#1997) * Show democracy dispatch queue * Bump API --- package.json | 6 +- packages/app-contracts/package.json | 2 +- packages/app-council/src/Motions/Motion.tsx | 2 +- .../src/Overview/DispatchBlock.tsx | 69 ++++++++++++++ .../src/Overview/DispatchEntry.tsx | 51 +++++++++++ .../src/Overview/DispatchQueue.tsx | 52 +++++++++++ packages/app-democracy/src/Overview/index.tsx | 2 + packages/react-api/package.json | 2 +- packages/react-components/src/Call.tsx | 10 +- packages/react-components/src/Card.tsx | 2 +- packages/react-components/src/Table.tsx | 2 +- yarn.lock | 91 ++++++++++--------- 12 files changed, 233 insertions(+), 58 deletions(-) create mode 100644 packages/app-democracy/src/Overview/DispatchBlock.tsx create mode 100644 packages/app-democracy/src/Overview/DispatchEntry.tsx create mode 100644 packages/app-democracy/src/Overview/DispatchQueue.tsx diff --git a/package.json b/package.json index e85a97ef88..dffa4531f1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/app-contracts/package.json b/packages/app-contracts/package.json index 00c37bae6c..91d895e5bf 100644 --- a/packages/app-contracts/package.json +++ b/packages/app-contracts/package.json @@ -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" } } diff --git a/packages/app-council/src/Motions/Motion.tsx b/packages/app-council/src/Motions/Motion.tsx index 7a76101939..d4694b14e6 100644 --- a/packages/app-council/src/Motions/Motion.tsx +++ b/packages/app-council/src/Motions/Motion.tsx @@ -52,7 +52,7 @@ function Motion ({ className, hash, proposal, t, votes }: Props): React.ReactEle {nays.map((address, index): React.ReactNode => ( diff --git a/packages/app-democracy/src/Overview/DispatchBlock.tsx b/packages/app-democracy/src/Overview/DispatchBlock.tsx new file mode 100644 index 0000000000..758875487a --- /dev/null +++ b/packages/app-democracy/src/Overview/DispatchBlock.tsx @@ -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>>>; + keyPrefix: string; + storageKey: StorageKey; +} + +interface Entry { + blockNumber?: BlockNumber; + hash: Hash; + referendumIndex: ReferendumIndex; +} + +export default function DispatchBlock ({ entries, keyPrefix, storageKey }: Props): React.ReactElement | null { + const [blockNumber, setBlockNumber] = useState(); + const [expanded, setExpanded] = useState([]); + + 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 => ( + + ))} + + ); +} diff --git a/packages/app-democracy/src/Overview/DispatchEntry.tsx b/packages/app-democracy/src/Overview/DispatchEntry.tsx new file mode 100644 index 0000000000..502353c388 --- /dev/null +++ b/packages/app-democracy/src/Overview/DispatchEntry.tsx @@ -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 { + const { api } = useApi(); + const preimage = trackStream> + >(api.query.democracy.preimages, [hash]); + const [proposal, setProposal] = useState(); + + useEffect((): void => { + if (preimage?.isSome) { + setProposal(api.createType('Proposal', preimage.unwrap()[0].toU8a(true))); + } + }, [preimage]); + + return ( + +

{formatNumber(referendumIndex)}

+ + {blockNumber && ( + <> + + {formatNumber(blockNumber)} + + )} + + + + ); +} + +export default translate(DispatchEntry); diff --git a/packages/app-democracy/src/Overview/DispatchQueue.tsx b/packages/app-democracy/src/Overview/DispatchQueue.tsx new file mode 100644 index 0000000000..789c7fc0df --- /dev/null +++ b/packages/app-democracy/src/Overview/DispatchQueue.tsx @@ -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 | null { + const { api } = useApi(); + const [keyPrefix] = useState(u8aToHex(api.query.democracy.dispatchQueue.creator.iterKey)); + const queued = trackStream<[StorageKey, Option>>> + ][]>(api.query.democracy.dispatchQueue.entries as any, []); + + if (!queued?.length) { + return null; + } + + return ( +
+

{t('dispatch queue')}

+ {queued?.length + ? ( + + + {queued.map(([storageKey, entries]): React.ReactNode => ( + + ))} + +
+ ) + : t('nothing queued to be executed') + } +
+ ); +} + +export default translate(DispatchQueue); diff --git a/packages/app-democracy/src/Overview/index.tsx b/packages/app-democracy/src/Overview/index.tsx index 0d6ce9ab05..4de359ab84 100644 --- a/packages/app-democracy/src/Overview/index.tsx +++ b/packages/app-democracy/src/Overview/index.tsx @@ -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 { + ); } diff --git a/packages/react-api/package.json b/packages/react-api/package.json index 60ba728694..2f3b9a68bc 100644 --- a/packages/react-api/package.json +++ b/packages/react-api/package.json @@ -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" diff --git a/packages/react-components/src/Call.tsx b/packages/react-components/src/Call.tsx index 99c76b2fe0..721a7480c9 100644 --- a/packages/react-components/src/Call.tsx +++ b/packages/react-components/src/Call.tsx @@ -43,6 +43,11 @@ function Call ({ children, className, labelHash, style, mortality, tip, value, w className={classes('ui--Extrinsic', className)} style={style} > + {children} {hash && ( )} - ); } diff --git a/packages/react-components/src/Card.tsx b/packages/react-components/src/Card.tsx index cc5ad9e09c..9bc431e126 100644 --- a/packages/react-components/src/Card.tsx +++ b/packages/react-components/src/Card.tsx @@ -30,7 +30,7 @@ export default styled(Card)` justify-content: space-around; label { - opacity: 0.25; + opacity: 0.42; } &:hover { diff --git a/packages/react-components/src/Table.tsx b/packages/react-components/src/Table.tsx index a127279c7d..3550e98a3c 100644 --- a/packages/react-components/src/Table.tsx +++ b/packages/react-components/src/Table.tsx @@ -72,7 +72,7 @@ export default styled(Table)` } label { - opacity: 0.25; + opacity: 0.42; } &:hover { diff --git a/yarn.lock b/yarn.lock index 10a0c784fe..518f5ff9ed 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"