From a297f6492d89a137ca68154a5a110156579311d1 Mon Sep 17 00:00:00 2001 From: Sinclair Chen Date: Tue, 10 May 2022 11:14:24 -0700 Subject: [PATCH] move manaToUSD to format.ts (#172) --- common/util/format.ts | 7 +++++++ web/components/charity/charity-card.tsx | 2 +- web/components/charity/feed-items.tsx | 2 +- web/pages/charity/[charitySlug].tsx | 4 +--- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/common/util/format.ts b/common/util/format.ts index 3310d902..20dc0100 100644 --- a/common/util/format.ts +++ b/common/util/format.ts @@ -16,6 +16,13 @@ export function formatWithCommas(amount: number) { return formatter.format(Math.floor(amount)).replace('$', '') } +export function manaToUSD(mana: number) { + return (mana / 100).toLocaleString('en-US', { + style: 'currency', + currency: 'USD', + }) +} + export function formatPercent(zeroToOne: number) { // Show 1 decimal place if <2% or >98%, giving more resolution on the tails const decimalPlaces = zeroToOne < 0.02 || zeroToOne > 0.98 ? 1 : 0 diff --git a/web/components/charity/charity-card.tsx b/web/components/charity/charity-card.tsx index 92fa56d2..cf87aff1 100644 --- a/web/components/charity/charity-card.tsx +++ b/web/components/charity/charity-card.tsx @@ -4,7 +4,7 @@ import Link from 'next/link' import Image from 'next/image' import { Charity } from 'common/charity' import { useCharityTxns } from 'web/hooks/use-charity-txns' -import { manaToUSD } from '../../pages/charity/[charitySlug]' +import { manaToUSD } from '../../../common/util/format' import { Row } from '../layout/row' export function CharityCard(props: { charity: Charity }) { diff --git a/web/components/charity/feed-items.tsx b/web/components/charity/feed-items.tsx index 368854c9..b12c7274 100644 --- a/web/components/charity/feed-items.tsx +++ b/web/components/charity/feed-items.tsx @@ -2,7 +2,7 @@ import { Txn } from 'common/txn' import { Avatar } from '../avatar' import { useUserById } from 'web/hooks/use-users' import { UserLink } from '../user-page' -import { manaToUSD } from '../../pages/charity/[charitySlug]' +import { manaToUSD } from '../../../common/util/format' import { RelativeTimestamp } from '../relative-timestamp' export function Donation(props: { txn: Txn }) { diff --git a/web/pages/charity/[charitySlug].tsx b/web/pages/charity/[charitySlug].tsx index 53e9fecd..c943df9d 100644 --- a/web/pages/charity/[charitySlug].tsx +++ b/web/pages/charity/[charitySlug].tsx @@ -19,9 +19,7 @@ import { useWindowSize } from 'web/hooks/use-window-size' import Confetti from 'react-confetti' import { Donation } from 'web/components/charity/feed-items' import Image from 'next/image' - -export const manaToUSD = (mana: number) => - (mana / 100).toLocaleString('en-US', { style: 'currency', currency: 'USD' }) +import { manaToUSD } from '../../../common/util/format' export default function CharityPageWrapper() { const router = useRouter()