Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate numeral to numbro #242

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions components/DelegatingView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { useBondingManagerAddress } from "hooks/useContracts";
import Link from "next/link";
import { useRouter } from "next/router";
import numeral from "numeral";
import numbro from "numbro";
import { useMemo } from "react";
import Masonry from "react-masonry-css";
import { Address, useContractWrite, usePrepareContractWrite } from "wagmi";
Expand Down Expand Up @@ -187,7 +187,7 @@ const Index = ({ delegator, transcoders, protocol, currentRound }: Props) => {
fontSize: 26,
}}
>
{`${numeral(pendingStake).format("0.00a")} LPT`}
{`${numbro(pendingStake).format("0.00a")} LPT`}
</Box>
) : null
}
Expand Down Expand Up @@ -222,7 +222,7 @@ const Index = ({ delegator, transcoders, protocol, currentRound }: Props) => {
<Box>
{unbonded > 0 ? (
<Text size="2" css={{ fontWeight: 600, color: "$red11" }}>
{numeral(-unbonded).format("+0.00a")} LPT
{numbro(-unbonded).format("+0.00a")} LPT
</Text>
) : (
<Text size="2" css={{ fontWeight: 600 }}>
Expand Down Expand Up @@ -251,7 +251,7 @@ const Index = ({ delegator, transcoders, protocol, currentRound }: Props) => {
</ExplorerTooltip>
</Flex>
<Text size="2" css={{ fontWeight: 600, color: "$green11" }}>
{numeral(Math.abs(rewards)).format("+0.00a")} LPT
{numbro(Math.abs(rewards)).format("+0.00a")} LPT
</Text>
</Flex>
</Box>
Expand All @@ -268,7 +268,7 @@ const Index = ({ delegator, transcoders, protocol, currentRound }: Props) => {
fontSize: 26,
}}
>
{numeral(pendingFees).format("0.000")} ETH
{numbro(pendingFees).format("0.000")} ETH
</Box>
) : null
}
Expand Down Expand Up @@ -301,7 +301,7 @@ const Index = ({ delegator, transcoders, protocol, currentRound }: Props) => {
</ExplorerTooltip>
</Flex>
<Text size="2" css={{ fontWeight: 600 }}>
{numeral(lifetimeEarnings || 0).format("0.000a")} ETH
{numbro(lifetimeEarnings || 0).format("0.000a")} ETH
</Text>
</Flex>
<Flex
Expand Down Expand Up @@ -330,7 +330,7 @@ const Index = ({ delegator, transcoders, protocol, currentRound }: Props) => {
</ExplorerTooltip>
</Flex>
<Text size="2" css={{ fontWeight: 600 }}>
{numeral(delegator?.withdrawnFees || 0).format("0.000a")} ETH
{numbro(delegator?.withdrawnFees || 0).format("0.000a")} ETH
</Text>
</Flex>
{isMyAccount && !withdrawButtonDisabled && delegator?.id && (
Expand Down Expand Up @@ -374,7 +374,7 @@ const Index = ({ delegator, transcoders, protocol, currentRound }: Props) => {
}
value={
<Box>
{numeral(
{numbro(
totalActiveStake === 0
? 0
: delegator.delegate.id === delegator.id
Expand All @@ -396,15 +396,15 @@ const Index = ({ delegator, transcoders, protocol, currentRound }: Props) => {
>
<Box>
Account (
{numeral(
{numbro(
totalActiveStake === 0
? 0
: pendingStake / totalActiveStake
).format("0.00%")}
)
</Box>
<Text size="2" css={{ fontWeight: 600 }}>
{numeral(pendingStake).format("0.00a")} LPT
{numbro(pendingStake).format("0.00a")} LPT
</Text>
</Flex>
<Flex
Expand All @@ -416,7 +416,7 @@ const Index = ({ delegator, transcoders, protocol, currentRound }: Props) => {
>
<Box>
Orchestrator (
{numeral(
{numbro(
totalActiveStake === 0
? 0
: Math.abs(+delegator.delegate.totalStake) /
Expand All @@ -425,7 +425,7 @@ const Index = ({ delegator, transcoders, protocol, currentRound }: Props) => {
)
</Box>
<Text size="2" css={{ fontWeight: 600 }}>
{numeral(Math.abs(+delegator.delegate.totalStake)).format(
{numbro(Math.abs(+delegator.delegate.totalStake)).format(
"0.00a"
)}{" "}
LPT
Expand Down
10 changes: 5 additions & 5 deletions components/DelegatingWidget/ProjectionBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { ExplorerTooltip } from "@components/ExplorerTooltip";
import { Box, Card, Flex, Text } from "@livepeer/design-system";
import { QuestionMarkCircledIcon } from "@modulz/radix-icons";
import { useExplorerStore } from "hooks";
import numeral from "numeral";
import numbro from "numbro";
import { useMemo } from "react";

const ProjectionBox = ({ action }) => {
const { yieldResults } = useExplorerStore();

const formattedPrinciple = useMemo(
() => numeral(Number(yieldResults?.principle) || 0).format("0a"),
() => numbro(Number(yieldResults?.principle) || 0).format("0a"),
[yieldResults]
);

Expand Down Expand Up @@ -65,7 +65,7 @@ const ProjectionBox = ({ action }) => {
</Box>
{action === "delegate" && (
<Box css={{ fontFamily: "$monospace", color: "$neutral11" }}>
{numeral(
{numbro(
yieldResults.principle
? (yieldResults.roiFeesLpt + yieldResults.roiRewards) /
+yieldResults.principle
Expand Down Expand Up @@ -96,7 +96,7 @@ const ProjectionBox = ({ action }) => {
</ExplorerTooltip>
</Flex>
<Text css={{ fontSize: "$2", fontFamily: "$monospace" }}>
{numeral(yieldResults.roiRewards).format("0.0")} LPT
{numbro(yieldResults.roiRewards).format("0.0")} LPT
</Text>
</Flex>
<Flex css={{ justifyContent: "space-between", alignItems: "center" }}>
Expand All @@ -120,7 +120,7 @@ const ProjectionBox = ({ action }) => {
</ExplorerTooltip>
</Flex>
<Text css={{ fontSize: "$2", fontFamily: "$monospace" }}>
{numeral(yieldResults.roiFees).format("0.000")} ETH
{numbro(yieldResults.roiFees).format("0.000")} ETH
</Text>
</Flex>
</Box>
Expand Down
4 changes: 2 additions & 2 deletions components/DelegatingWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EnsIdentity } from "@lib/api/types/get-ens";
import { Box, Card, Flex, Text } from "@livepeer/design-system";
import { AccountQueryResult, OrchestratorsSortedQueryResult } from "apollo";
import { useEnsData, useExplorerStore } from "hooks";
import numeral from "numeral";
import numbro from "numbro";
import { useMemo, useState } from "react";
import ArrowDown from "../../public/img/arrow-down.svg";
import Footer from "./Footer";
Expand Down Expand Up @@ -106,7 +106,7 @@ const Index = ({
<Text variant="neutral" css={{ textAlign: "center" }}>
{`This transaction will move your current delegated stake of `}
<Box as="span" css={{ fontWeight: 700 }}>
{numeral(delegator?.bondedAmount || 0).format("0,0.0")}
{numbro(delegator?.bondedAmount || 0).format("0,0.0")}
{` LPT`}
</Box>
{` from `}
Expand Down
10 changes: 5 additions & 5 deletions components/ExplorerChart/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ExplorerTooltip } from "@components/ExplorerTooltip";
import { Box, Button, Flex, Skeleton, Text } from "@livepeer/design-system";
import { QuestionMarkCircledIcon } from "@modulz/radix-icons";
import dayjs from "dayjs";
import numeral from "numeral";
import numbro from "numbro";
import React, {
useCallback,
useEffect,
Expand Down Expand Up @@ -87,7 +87,7 @@ const ExplorerChart = ({
);
const formatSubtitle = useCallback(
(value: number) =>
`${numeral(value).format(
`${numbro(value).format(
unit === "usd"
? "$0,0"
: unit === "eth"
Expand All @@ -107,7 +107,7 @@ const ExplorerChart = ({
const defaultPercentChange = useMemo<string>(
() =>
basePercentChange !== 0
? numeral(basePercentChange / 100).format("+0.00%")
? numbro(basePercentChange / 100).format("+0.00%")
: "",
[basePercentChange]
);
Expand Down Expand Up @@ -147,7 +147,7 @@ const ExplorerChart = ({
fontWeight={400}
fontSize="13px"
>
{numeral(payload.value).format(
{numbro(payload.value).format(
unit === "usd"
? "$0a"
: unit === "eth"
Expand Down Expand Up @@ -255,7 +255,7 @@ const ExplorerChart = ({
ml: "$2",
fontSize: "$3",
color:
(numeral(barSelected.percentChange).value() ?? 0) < 0
(numbro(barSelected.percentChange).value() ?? 0) < 0
? "#ff0022"
: "#00EB88",
}}
Expand Down
20 changes: 10 additions & 10 deletions components/HistoryView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useTransactionsQuery } from "apollo";
import dayjs from "dayjs";
import { CHAIN_INFO, DEFAULT_CHAIN_ID } from "lib/chains";
import { useRouter } from "next/router";
import numeral from "numeral";
import numbro from "numbro";
import { useMemo } from "react";
import InfiniteScroll from "react-infinite-scroll-component";

Expand Down Expand Up @@ -213,7 +213,7 @@ function renderSwitch(event: any, i: number) {
<Box css={{ fontSize: "$3", ml: "$4" }}>
{" "}
<Box as="span" css={{ fontWeight: 600 }}>
+{numeral(event.additionalAmount).format("0.0a")}
+{numbro(event.additionalAmount).format("0.0a")}
</Box>{" "}
LPT
</Box>
Expand Down Expand Up @@ -329,7 +329,7 @@ function renderSwitch(event: any, i: number) {
<Box css={{ fontSize: "$3", ml: "$4" }}>
{" "}
<Box as="span" css={{ fontWeight: 600 }}>
+{numeral(event.amount).format("0.0a")}
+{numbro(event.amount).format("0.0a")}
</Box>{" "}
LPT
</Box>
Expand Down Expand Up @@ -389,7 +389,7 @@ function renderSwitch(event: any, i: number) {
<Box css={{ fontSize: "$3", ml: "$4" }}>
{" "}
<Box as="span" css={{ fontWeight: 600 }}>
-{numeral(event.amount).format("0.0a")}
-{numbro(event.amount).format("0.0a")}
</Box>{" "}
LPT
</Box>
Expand Down Expand Up @@ -448,7 +448,7 @@ function renderSwitch(event: any, i: number) {
<Box css={{ fontSize: "$3", ml: "$4" }}>
{" "}
<Box as="span" css={{ fontWeight: 600 }}>
+{numeral(event.rewardTokens).format("0.00a")}
+{numbro(event.rewardTokens).format("0.00a")}
</Box>{" "}
LPT
</Box>
Expand Down Expand Up @@ -570,7 +570,7 @@ function renderSwitch(event: any, i: number) {
<Box css={{ fontSize: "$3", ml: "$4" }}>
{" "}
<Box as="span" css={{ fontWeight: 600 }}>
{numeral(event.amount).format("0.00a")}
{numbro(event.amount).format("0.00a")}
</Box>{" "}
LPT
</Box>
Expand Down Expand Up @@ -627,7 +627,7 @@ function renderSwitch(event: any, i: number) {
<Box css={{ fontSize: "$3", ml: "$4" }}>
{" "}
<Box as="span" css={{ fontWeight: 600 }}>
{numeral(event.amount).format("0.000a")}
{numbro(event.amount).format("0.000a")}
</Box>{" "}
ETH
</Box>
Expand Down Expand Up @@ -684,7 +684,7 @@ function renderSwitch(event: any, i: number) {
<Box css={{ fontSize: "$3", ml: "$4" }}>
{" "}
<Box as="span" css={{ fontWeight: 600 }}>
+{numeral(event.faceValue).format("0.000a")}
+{numbro(event.faceValue).format("0.000a")}
</Box>{" "}
ETH
</Box>
Expand Down Expand Up @@ -741,7 +741,7 @@ function renderSwitch(event: any, i: number) {
<Box css={{ fontSize: "$3", ml: "$4" }}>
{" "}
<Box as="span" css={{ fontWeight: 600 }}>
+{numeral(event.amount).format("0.00a")}
+{numbro(event.amount).format("0.00a")}
</Box>{" "}
ETH
</Box>
Expand Down Expand Up @@ -803,7 +803,7 @@ function renderSwitch(event: any, i: number) {
<Box css={{ fontSize: "$3", ml: "$4" }}>
{" "}
<Box as="span" css={{ fontWeight: 600 }}>
+{numeral(event.amount).format("0.00a")}
+{numbro(event.amount).format("0.00a")}
</Box>{" "}
ETH
</Box>
Expand Down
18 changes: 9 additions & 9 deletions components/OrchestratingView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Stat from "@components/Stat";
import { Box, Flex } from "@livepeer/design-system";
import { CheckIcon, Cross1Icon } from "@modulz/radix-icons";
import dayjs from "dayjs";
import numeral from "numeral";
import numbro from "numbro";
import Masonry from "react-masonry-css";

import { AccountQueryResult } from "apollo";
Expand Down Expand Up @@ -84,7 +84,7 @@ const Index = ({ currentRound, transcoder, isActive }: Props) => {
}
value={
transcoder
? `${numeral(transcoder?.totalStake || 0).format("0.00a")} LPT`
? `${numbro(transcoder?.totalStake || 0).format("0.00a")} LPT`
: null
}
/>
Expand All @@ -100,7 +100,7 @@ const Index = ({ currentRound, transcoder, isActive }: Props) => {
tooltip={`The transcoding score for the orchestrator's best operational region, ${maxScore.region}, in the past 24 hours. Note: this may be inaccurate, depending on the reliability of the testing infrastructure.`}
value={
scores
? `${numeral(maxScore.score).divide(100).format("0.0%")} (${
? `${numbro(maxScore.score).divide(100).format("0.0%")} (${
maxScore.region
})`
: null
Expand All @@ -122,7 +122,7 @@ const Index = ({ currentRound, transcoder, isActive }: Props) => {
tooltip={
"The total amount of fees this orchestrator has earned (since the migration to Arbitrum One)."
}
value={`${numeral(transcoder?.totalVolumeETH || 0).format(
value={`${numbro(transcoder?.totalVolumeETH || 0).format(
"0.00a"
)} ETH`}
/>
Expand All @@ -132,7 +132,7 @@ const Index = ({ currentRound, transcoder, isActive }: Props) => {
tooltip="The most recent price for transcoding which the orchestrator is currently advertising off-chain to broadcasters. This may be different from on-chain pricing."
value={
scores
? `${numeral(
? `${numbro(
(scores?.pricePerPixel || 0) <= 0 ? 0 : scores.pricePerPixel
).format("0,0")} WEI`
: null
Expand All @@ -144,7 +144,7 @@ const Index = ({ currentRound, transcoder, isActive }: Props) => {
tooltip={
"The number of delegators which have delegated stake to this orchestrator."
}
value={`${numeral(transcoder?.delegators?.length || 0).format(
value={`${numbro(transcoder?.delegators?.length || 0).format(
"0,0"
)}`}
/> */}
Expand All @@ -154,7 +154,7 @@ const Index = ({ currentRound, transcoder, isActive }: Props) => {
tooltip={
"The percent of the transcoding fees which are kept by the orchestrator, with the remainder distributed to its delegators by percent stake."
}
value={numeral(1 - (+(transcoder?.feeShare || 0)) / 1000000).format(
value={numbro(1 - (+(transcoder?.feeShare || 0)) / 1000000).format(
"0%"
)}
/>
Expand All @@ -164,9 +164,9 @@ const Index = ({ currentRound, transcoder, isActive }: Props) => {
tooltip={
"The percent of the inflationary reward fees which are kept by the orchestrator, with the remainder distributed to its delegators by percent stake."
}
value={numeral(transcoder?.rewardCut || 0)
value={numbro(transcoder?.rewardCut || 0)
.divide(1000000)
.format("0%")}
.format({mantissa: 0, output: "percent"})}
/>
<Stat
className="masonry-grid_item"
Expand Down
Loading