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

fix(market): format price tag using currency #207

Merged
merged 1 commit into from
Nov 20, 2024
Merged
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
5 changes: 2 additions & 3 deletions apps/arkmarket/src/app/components/latest-sales.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ export default function LatestSales() {
</TableRow>
</TableHeader>
<TableBody className="text-sm font-semibold">
{data.data.map((sale, index) => {
// TOOD @YohanTz: Proper key when real data
{data.data.map((sale) => {
return (
<TableRow
key={index}
key={`ls-${sale.transaction_hash}`}
className="group h-[5.75rem] text-muted-foreground"
>
<TableCell className="text-foreground transition-colors group-hover:text-muted-foreground">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export default function TokenOffersListItem({
<div className="mb-4">
<div className="flex items-center justify-between">
<div className="flex items-center gap-4 overflow-hidden">
<PriceTag price={offer.price} className="h-7 text-xs" />
<PriceTag
price={offer.price}
currency={offer.currency}
className="h-7 text-xs"
/>
{offer.floor_difference ? (
<p
className={cn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ export default function MobilePortfolioOffers({
</div>
<div className="flex items-center justify-between">
<div className="flex items-center gap-4">
<PriceTag price={offer.price} className="h-7 text-xs" />{" "}
<PriceTag
price={offer.price}
currency={offer.currency}
className="h-7 text-xs"
/>{" "}
<p
className={cn(
"text-sm font-medium",
Expand Down
6 changes: 5 additions & 1 deletion apps/arkmarket/src/components/cells/offer-price-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ interface OfferProps {
export default function OfferPriceCell({ offer }: OfferProps) {
return (
<TableCell>
<PriceTag price={offer.price} className="max-w-full" />
<PriceTag
price={offer.price}
currency={offer.currency}
className="max-w-full"
/>
</TableCell>
);
}
2 changes: 1 addition & 1 deletion apps/arkmarket/src/components/cells/token-price-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function TokenPriceCell({ token }: PriceCellProps) {
<LoaderCircle className="ml-4 size-4 animate-spin" />
</div>
) : token.price ? (
<PriceTag price={token.price} />
<PriceTag price={token.price} currency={token.listing.currency} />
) : (
"_"
)}
Expand Down
27 changes: 6 additions & 21 deletions apps/arkmarket/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,7 @@ export interface PortfolioActivity {
to: string;
token_id: string;
transaction_hash: string | null;
currency?: {
contract: string;
decimals: number;
symbol: string;
} | null;
currency: Currency;
}

export interface PortfolioOffers {
Expand Down Expand Up @@ -214,7 +210,7 @@ export interface PortfolioOffers {
start_amount: string;
start_date: number | null;
};
currency?: Currency | null;
currency: Currency;
}

export interface CollectionActivity {
Expand All @@ -229,11 +225,7 @@ export interface CollectionActivity {
token_id: string;
token_metadata: TokenMetadata | null;
transaction_hash: string | null;
currency?: {
contract: string;
decimals: number;
symbol: string;
} | null;
currency: Currency;
}

export interface TokenOffer {
Expand All @@ -243,6 +235,7 @@ export interface TokenOffer {
offer_id: number;
price: string;
source: string;
currency: Currency;
}

export interface TokenApiResponse {
Expand Down Expand Up @@ -320,11 +313,7 @@ export interface TokenActivity {
time_stamp: number;
to: string | null;
transaction_hash: string | null;
currency?: {
contract: string;
decimals: number;
symbol: string;
} | null;
currency: Currency;
}

export interface Filters {
Expand All @@ -341,11 +330,7 @@ export interface LatestSales {
timestamp: number;
to: string;
transaction_hash: string | null;
currency: {
contract: string;
decimals: number;
symbol: string;
} | null;
currency: Currency;
}

export interface TrendingNow {
Expand Down
26 changes: 11 additions & 15 deletions packages/ui/src/price-tag.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { formatUnits } from "viem";

import type { PropsWithClassName } from ".";
import { cn, ellipsableStyles, formatUnits } from ".";
import { cn, ellipsableStyles } from ".";
import { Ethereum, Starknet } from "./icons";

interface PriceTagProps {
price: number | bigint | string;
currency?: {
price: string;
currency: {
contract: string;
decimals: number;
symbol: string;
} | null;
decimals: number;
};
}

function CurrencyIcon({ symbol }: { symbol: string }) {
Expand All @@ -27,11 +29,7 @@ export function PriceTag({
price,
currency,
}: PropsWithClassName<PriceTagProps>) {
if (!price) {
return null;
}

const parsedPrice = parseFloat(formatUnits(price, 18));
const formattedPrice = formatUnits(BigInt(price), currency.decimals);

return (
<div
Expand All @@ -40,12 +38,10 @@ export function PriceTag({
className,
)}
>
<CurrencyIcon symbol={currency?.symbol ?? "ETH"} />
<CurrencyIcon symbol={currency.symbol} />
<p className={ellipsableStyles}>
{isNaN(parsedPrice)
? formatUnits(price, currency?.decimals ?? 18)
: parsedPrice.toFixed(5)}
<span className="text-muted-foreground">{` ${currency?.symbol ?? "ETH"}`}</span>
{formattedPrice}{" "}
<span className="text-muted-foreground">{currency.symbol}</span>
</p>
</div>
);
Expand Down
Loading