move manaToUSD to format.ts (#172)

This commit is contained in:
Sinclair Chen 2022-05-10 11:14:24 -07:00 committed by GitHub
parent b97301c6fa
commit a297f6492d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 5 deletions

View File

@ -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

View File

@ -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 }) {

View File

@ -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 }) {

View File

@ -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()