UNPKG

@polkadot/react-query

Version:

A collection of RxJs React components the Polkadot JS API

69 lines (55 loc) 2.52 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _styledComponents = _interopRequireDefault(require("styled-components")); 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. // for million, 2 * 3-grouping + comma const M_LENGTH = 6 + 1; function format(value, currency) { const [prefix, postfix] = (0, _util.formatBalance)(value, { forceUnit: '-', withSi: false }).split('.'); if (prefix.length > M_LENGTH) { // TODO Format with balance-postfix return (0, _util.formatBalance)(value); } return _react.default.createElement(_react.default.Fragment, null, prefix, ".", _react.default.createElement("span", { className: "balance-postfix" }, "000".concat(postfix || '').slice(-3)), " ", currency); } function formatSi(value) { const strValue = (value.toBn ? value.toBn() : value).toString(); const [prefix, postfix] = strValue === '0' ? ['0', '0'] : (0, _util.formatBalance)(value, { withSi: false }).split('.'); const unit = strValue === '0' ? '' : _util.formatBalance.calcSi(strValue).value; return _react.default.createElement(_react.default.Fragment, null, prefix, ".", _react.default.createElement("span", { className: "balance-postfix" }, "000".concat(postfix || '').slice(-3)), unit === '-' ? '' : unit); } function FormatBalance({ children, className, label, value, withSi }) { const [currency] = (0, _react.useState)(_util.formatBalance.getDefaults().unit); return _react.default.createElement("div", { className: "ui--FormatBalance ".concat(className) }, label || '', value ? withSi ? formatSi(value) : format(value, currency) : '-', children); } var _default = (0, _styledComponents.default)(FormatBalance).withConfig({ displayName: "FormatBalance", componentId: "agqvod-0" })(["display:inline-block;vertical-align:baseline;*{vertical-align:baseline !important;}> label,> .label{display:inline-block;margin-right:0.25rem;vertical-align:baseline;}> .balance-postfix{font-weight:100;opacity:0.75;vertical-align:baseline;}"]); exports.default = _default;