Detect periods as secs or miliseconds (#1580)

* Detect periods as secs or miliseconds

* Cleanup timer unmount

* Additional NodeInfo cleanups
This commit is contained in:
Jaco Greeff 2019-09-03 14:43:00 +02:00 committed by GitHub
parent fce8dc44ee
commit fbcb0f3001
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 86 additions and 72 deletions

View File

@ -10,10 +10,10 @@
"packages/*"
],
"resolutions": {
"@polkadot/api": "^0.91.0-beta.15",
"@polkadot/api-contract": "^0.91.0-beta.15",
"@polkadot/api": "^0.91.0-beta.16",
"@polkadot/api-contract": "^0.91.0-beta.16",
"@polkadot/keyring": "^1.2.0-beta.6",
"@polkadot/types": "^0.91.0-beta.15",
"@polkadot/types": "^0.91.0-beta.16",
"@polkadot/util": "^1.2.0-beta.6",
"@polkadot/util-crypto": "^1.2.0-beta.6",
"@types/styled-components": "4.1.8",

View File

@ -11,7 +11,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.5.5",
"@polkadot/api-contract": "^0.91.0-beta.15",
"@polkadot/api-contract": "^0.91.0-beta.16",
"@polkadot/react-components": "^0.35.0-beta.27"
}
}

View File

@ -2,13 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Health, PeerInfo, Extrinsic } from '@polkadot/types/interfaces';
import { I18nProps } from '@polkadot/react-components/types';
import { Info } from './types';
import React, { useContext, useEffect, useState } from 'react';
import { ApiPromise } from '@polkadot/api';
import { ApiContext } from '@polkadot/react-api';
import { Vec } from '@polkadot/types';
import './index.css';
@ -21,39 +20,45 @@ const POLL_TIMEOUT = 9900;
type Props = I18nProps;
async function retrieveInfo (api: ApiPromise): Promise<Partial<Info>> {
try {
const [blockNumber, health, peers, extrinsics] = await Promise.all([
api.derive.chain.bestNumber(),
api.rpc.system.health(),
api.rpc.system.peers(),
api.rpc.author.pendingExtrinsics()
]);
return { blockNumber, extrinsics, health, peers };
} catch (error) {
return {};
}
}
function NodeInfo ({ t }: Props): React.ReactElement<Props> {
const { api } = useContext(ApiContext);
const [info, setInfo] = useState<Partial<Info>>({});
const [nextRefresh, setNextRefresh] = useState(Date.now());
const [timerId, setTimerId] = useState(0);
const executeStatus = (): void => {
const executeStatus = (isFirstRun = false): void => {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
getStatus().catch((): void => {});
getStatus(isFirstRun).catch((): void => {});
};
const getStatus = async (): Promise<void> => {
try {
const [blockNumber, health, peers, extrinsics] = await Promise.all([
api.derive.chain.bestNumber(),
api.rpc.system.health<Health>(),
api.rpc.system.peers<Vec<PeerInfo>>(),
api.rpc.author.pendingExtrinsics<Vec<Extrinsic>>()
]);
setInfo({ blockNumber, extrinsics, health, peers });
} catch (error) {
setInfo({});
const getStatus = async (isFirstRun: boolean): Promise<void> => {
if (isFirstRun || timerId) {
setInfo(await retrieveInfo(api));
setNextRefresh(Date.now() + POLL_TIMEOUT);
setTimerId(window.setTimeout(executeStatus, POLL_TIMEOUT));
}
setNextRefresh(Date.now() + POLL_TIMEOUT);
setTimerId(window.setTimeout(executeStatus, POLL_TIMEOUT));
};
useEffect((): () => void => {
executeStatus();
executeStatus(true);
return (): void => {
window.clearTimeout(timerId);
setTimerId(0);
};
}, []);

View File

@ -31,7 +31,7 @@
"homepage": "https://github.com/polkadot-js/ui/tree/master/packages/ui-reactive#readme",
"dependencies": {
"@babel/runtime": "^7.5.5",
"@polkadot/api": "^0.91.0-beta.15",
"@polkadot/api": "^0.91.0-beta.16",
"@polkadot/extension-dapp": "^0.10.0-beta.1",
"edgeware-node-types": "^1.0.9",
"rxjs-compat": "^6.4.0"

View File

@ -28,6 +28,9 @@ const NOOP = (): void => {
// ignore
};
// a mapping of actual error messages that has already been shown
const errorred: Record<string, boolean> = {};
export default function withCall<P extends ApiProps> (
endpoint: string,
{
@ -212,7 +215,13 @@ export default function withCall<P extends ApiProps> (
info = this.getApiMethod(newParams);
} catch (error) {
console.error(endpoint, '::', error);
// don't flood the console with the same errors each time, just do it once, then
// ignore it going forward
if (!errorred[error.message]) {
console.error(endpoint, '::', error);
errorred[error.message] = true;
}
}
if (!info) {

View File

@ -27,7 +27,7 @@ export function TimePeriod ({ babe_expectedBlockTime, children, className, label
babe_expectedBlockTime
? `${formatNumber(babe_expectedBlockTime.toNumber() / 1000)}s`
: timestamp_minimumPeriod
? `${formatNumber(timestamp_minimumPeriod.toNumber() * 2)}s`
? `${formatNumber(timestamp_minimumPeriod.gtn(1000) ? (timestamp_minimumPeriod.toNumber() / 500) : (timestamp_minimumPeriod.toNumber() * 2))}s`
: '-'
}{children}
</div>

View File

@ -1930,44 +1930,44 @@
universal-user-agent "^3.0.0"
url-template "^2.0.8"
"@polkadot/api-contract@^0.91.0-beta.15":
version "0.91.0-beta.15"
resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.91.0-beta.15.tgz#c01fdaba14acc27f4175c74581a53b3253282c09"
integrity sha512-MInJlrNK2Z61iPgfU4o7g7cmHEZyAhNR6uBMzBXqm/zI7inne5U8/FvfpkIkHyokcsXV8iyRNEirBqijPcEPAw==
"@polkadot/api-contract@^0.91.0-beta.16":
version "0.91.0-beta.16"
resolved "https://registry.yarnpkg.com/@polkadot/api-contract/-/api-contract-0.91.0-beta.16.tgz#d6079eb1e67fc659dc6699817cd84c7dc037ca39"
integrity sha512-wktjEIErNy4NRjIXJ8uONTeunfZsohKAGOuhLT3OuOTTfn0DQ/iP+YD8+lcgdPGR6rxSziS8G1EUavtTJbrmSQ==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/types" "^0.91.0-beta.15"
"@polkadot/types" "^0.91.0-beta.16"
"@polkadot/api-derive@^0.91.0-beta.15":
version "0.91.0-beta.15"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.91.0-beta.15.tgz#8e5efdb4e476480bc6e85f355878e41b0c5458d1"
integrity sha512-tC/iH/+G234lODxOmoFAt9NL8Gdsfmhvi6yOGYbTROzmUIX6FvXQ9U32GV0JkZdE6bJCGLlmS0gB5EjwTIyb8A==
"@polkadot/api-derive@^0.91.0-beta.16":
version "0.91.0-beta.16"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-0.91.0-beta.16.tgz#abb4967c08b0cc7de879ec4e3b40f9044d8ea681"
integrity sha512-RGJB/4XbpK8VkvuP5ogbaqJfq55e2zKBZT5zRJ6Jcq6eYwbO5m7xA4UF9J7YPg0urB66jgTEMzvX8V8w/Wzi/w==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/api" "^0.91.0-beta.15"
"@polkadot/types" "^0.91.0-beta.15"
"@polkadot/api" "^0.91.0-beta.16"
"@polkadot/types" "^0.91.0-beta.16"
"@polkadot/api-metadata@^0.91.0-beta.15":
version "0.91.0-beta.15"
resolved "https://registry.yarnpkg.com/@polkadot/api-metadata/-/api-metadata-0.91.0-beta.15.tgz#5c6550003e4ef747f18739b2d1dbb662b0028827"
integrity sha512-UXoq3On5ZDs/BFa04juZFdCyvqtX27a/IFcg+243SNBInMfhrN5wkZd5fchvtalUnIT+t6G64fNYQiqB3UIrfQ==
"@polkadot/api-metadata@^0.91.0-beta.16":
version "0.91.0-beta.16"
resolved "https://registry.yarnpkg.com/@polkadot/api-metadata/-/api-metadata-0.91.0-beta.16.tgz#545248d3cd1ef9d85db431217ac8ea7053851913"
integrity sha512-qutfqHbazahtjLu86zrl2HOyoSrYKPQl8pB5RC8Ov7iAS79yzbYNg7qljWNxt4GiiECJpyBOXCnRH3kK89mImA==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/types" "^0.91.0-beta.15"
"@polkadot/types" "^0.91.0-beta.16"
"@polkadot/util" "^1.2.0-beta.6"
"@polkadot/util-crypto" "^1.2.0-beta.6"
"@polkadot/api@^0.91.0-beta.15":
version "0.91.0-beta.15"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.91.0-beta.15.tgz#397a2dd9cfd94df1bc3c186bff05952f625c9171"
integrity sha512-6MPpy3Eu9+qdjgvDCbsCns7zVw151bUY+HERBi7yMcNnhy36fns/ZzEch06BUSiZ73TVVzIjB04eq0PhqA5dZw==
"@polkadot/api@^0.91.0-beta.16":
version "0.91.0-beta.16"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-0.91.0-beta.16.tgz#22f5b703b9c2b8c147748df50aae2b890da0c622"
integrity sha512-VeO+utFrjNIjNS3U7PG/4nPLiBk4L1cWFVKuAXJYeIiXcZHEd+smzRNYbNo1KKhxjllnJT4ouO8zm+WlxfZ9IQ==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/api-derive" "^0.91.0-beta.15"
"@polkadot/api-metadata" "^0.91.0-beta.15"
"@polkadot/rpc-core" "^0.91.0-beta.15"
"@polkadot/rpc-provider" "^0.91.0-beta.15"
"@polkadot/types" "^0.91.0-beta.15"
"@polkadot/api-derive" "^0.91.0-beta.16"
"@polkadot/api-metadata" "^0.91.0-beta.16"
"@polkadot/rpc-core" "^0.91.0-beta.16"
"@polkadot/rpc-provider" "^0.91.0-beta.16"
"@polkadot/types" "^0.91.0-beta.16"
"@polkadot/util-crypto" "^1.2.0-beta.6"
"@polkadot/dev-react@^0.31.0-beta.6":
@ -2066,10 +2066,10 @@
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/jsonrpc@^0.91.0-beta.15":
version "0.91.0-beta.15"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.91.0-beta.15.tgz#b910c3f9e98afacfa2b54d30d8a6a8225e036a47"
integrity sha512-1A2oX5FIKbGW49wE8p0zOWToARBwJLzu4aPi15OMR3/5Pa3kGTCpG2hGmnvXvLbEdbMr+W5tamot2tvedNzvlA==
"@polkadot/jsonrpc@^0.91.0-beta.16":
version "0.91.0-beta.16"
resolved "https://registry.yarnpkg.com/@polkadot/jsonrpc/-/jsonrpc-0.91.0-beta.16.tgz#abca58376ebb9da7977773ccb8c137ed19663a61"
integrity sha512-bi/cSqEzW2Fho/zBUNK5YpzYmWiHnQ5mK9mIAqlp8j8XgYn3J86tfTvDo5DmRflNLFQmZO0hVi346oP5ebTNnA==
dependencies:
"@babel/runtime" "^7.5.5"
@ -2097,25 +2097,25 @@
react-copy-to-clipboard "^5.0.1"
styled-components "^4.3.1"
"@polkadot/rpc-core@^0.91.0-beta.15":
version "0.91.0-beta.15"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.91.0-beta.15.tgz#c9a9c472fe6acde73e66d01b822ee980f8c1a40e"
integrity sha512-TMEmHXlib0TrBpF4V5JM3Y79x3LEndkypWGUjzAAwxmnrGuP1Fs3LEj+g5JKSafU6OQ0gJYpMHGEci2AZ9MvHA==
"@polkadot/rpc-core@^0.91.0-beta.16":
version "0.91.0-beta.16"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-0.91.0-beta.16.tgz#aca26e8cc611aa723c5886460cd68200617111cc"
integrity sha512-zW756psFCUZ6t8jdTFixBX8CEZg5mUvJCuS+lxTXQzvfjeeNd1FglqHk2wSq8+n15lGJ2N4S9UQ9PE69lMVIZw==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/jsonrpc" "^0.91.0-beta.15"
"@polkadot/rpc-provider" "^0.91.0-beta.15"
"@polkadot/types" "^0.91.0-beta.15"
"@polkadot/jsonrpc" "^0.91.0-beta.16"
"@polkadot/rpc-provider" "^0.91.0-beta.16"
"@polkadot/types" "^0.91.0-beta.16"
"@polkadot/util" "^1.2.0-beta.6"
rxjs "^6.5.2"
"@polkadot/rpc-provider@^0.91.0-beta.15":
version "0.91.0-beta.15"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.91.0-beta.15.tgz#d41e6e24128a9a00f85ea2b2692151e186a762b4"
integrity sha512-f1uprAxM+goXVDQnvz4VzM6oKphunz2Smej5CmsDbbNwyAzBmtdzhLlgMFIlY5nVHIrD/BemYDyWdn5V1Mgg5A==
"@polkadot/rpc-provider@^0.91.0-beta.16":
version "0.91.0-beta.16"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-0.91.0-beta.16.tgz#7a4c652dd566eacf50ff79d7dacd8aba8a2d8324"
integrity sha512-oBgcPz/wmxCU+3fZFHdscP1MtQhhwjGjmy7rXim/twJwIRuWgvgJ2hMAyGiww2ovZngi1o5El/La+7EWsxOBMg==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/api-metadata" "^0.91.0-beta.15"
"@polkadot/api-metadata" "^0.91.0-beta.16"
"@polkadot/util" "^1.2.0-beta.6"
"@polkadot/util-crypto" "^1.2.0-beta.6"
"@types/nock" "^10.0.3"
@ -2130,10 +2130,10 @@
dependencies:
"@types/chrome" "^0.0.88"
"@polkadot/types@^0.91.0-beta.15":
version "0.91.0-beta.15"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.91.0-beta.15.tgz#4ca731b34a62a0e109adc1941aee9b3ad7cc9e68"
integrity sha512-s85EknDqK6A7W98t8zfh0u/hBpY0gEFtahNjj5bS1bxjnkbuYGapDxvGIf27yODZiG/7Yf8kldYHWRzMfAqBMQ==
"@polkadot/types@^0.91.0-beta.16":
version "0.91.0-beta.16"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.91.0-beta.16.tgz#98ca2e2fa713a9b6021549144aeca9e91e3560d4"
integrity sha512-JK73wdMwECc6lNxaShxLEd5JDY75QyWS+fk2jjGsv76BEw8KC/k0MQjtMbOZrtSFDkAk1BSzD/YIoz4C8LUsQA==
dependencies:
"@babel/runtime" "^7.5.5"
"@polkadot/util" "^1.2.0-beta.6"