@polkadot/react-query
Version:
A collection of RxJs React components the Polkadot JS API
35 lines (28 loc) • 1.55 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = TimePeriod;
var _react = _interopRequireDefault(require("react"));
var _reactHooks = require("@polkadot/react-hooks");
var _util = require("@polkadot/util");
// Copyright 2017-2020 @polkadot/react-query authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
function TimePeriod({
children,
className,
label,
style
}) {
var _api$consts, _api$consts$timestamp, _api$consts2, _api$consts2$babe;
const {
api
} = (0, _reactHooks.useApi)();
const minimumPeriod = (_api$consts = api.consts) === null || _api$consts === void 0 ? void 0 : (_api$consts$timestamp = _api$consts.timestamp) === null || _api$consts$timestamp === void 0 ? void 0 : _api$consts$timestamp.minimumPeriod;
return _react.default.createElement("div", {
className: className,
style: style
}, label || '', ((_api$consts2 = api.consts) === null || _api$consts2 === void 0 ? void 0 : (_api$consts2$babe = _api$consts2.babe) === null || _api$consts2$babe === void 0 ? void 0 : _api$consts2$babe.expectedBlockTime) ? "".concat((0, _util.formatNumber)(api.consts.babe.expectedBlockTime.toNumber() / 1000), "s") : minimumPeriod ? "".concat((0, _util.formatNumber)(minimumPeriod.gtn(1000) ? minimumPeriod.toNumber() / 500 : minimumPeriod.toNumber() * 2), "s") : '-', children);
}