Skip to content

Commit

Permalink
MRKT-93: format stream token NEWM values (#694)
Browse files Browse the repository at this point in the history
* transforms sale cost amount to correct value

* updates NEWM precision to 2 and drops extra zeroes

* reverts dropping extra NEWM price zeroes

* updates song card price alignment

* formats song card USD amount to three decimal places

* reverts marketplace port number

* updates formatUsdAmount args
  • Loading branch information
scandycuz authored Jul 3, 2024
1 parent 983de2d commit 7bf5ad2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/marketplace/src/modules/sale/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const transformApiSale = (apiSale: ApiSale): Sale => {

return {
...sale,
// TODO: look into back-end returning value with correct decimal places
costAmount: sale.costAmount / 1000000,
song: {
...song,
isExplicit: parentalAdvisory === "Explicit",
Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/lib/SongCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PlayArrow, Stop } from "@mui/icons-material";
import { bgImage } from "@newm-web/assets";
import {
formatNewmAmount,
formatUsdAmount,
getImageSrc,
resizeCloudinaryImage,
} from "@newm-web/utils";
Expand Down Expand Up @@ -232,6 +233,7 @@ const SongCard = ({

{ priceVariant === "text" && (
<Stack
alignItems="flex-end"
display="flex"
flexDirection={ title ? "column" : "row" }
whiteSpace="nowrap"
Expand All @@ -251,7 +253,7 @@ const SongCard = ({
fontSize={ title ? "12px" : "15px" }
variant="subtitle1"
>
&nbsp;(≈ { currency(priceInUsd).format() })
&nbsp;(≈ { formatUsdAmount(priceInUsd) })
</Typography>
) }
</Stack>
Expand Down
13 changes: 12 additions & 1 deletion packages/utils/src/lib/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ export const formatNewmAmount = (amount?: number, includeSymbol = true) => {

return currency(amount, {
pattern: "# !",
precision: 1,
precision: 2,
symbol: includeSymbol ? "Ɲ" : "",
}).format();
};

/**
* Formats a numerical USD amount to three decimal places
* rather than the standard two, based on the exchange rate
* for NEWM to USD.
*/
export const formatUsdAmount = (amount?: number, precision = 3) => {
if (!amount) return "";

return currency(amount, { precision }).format();
};

0 comments on commit 7bf5ad2

Please sign in to comment.