Skip to content

Commit

Permalink
feat(home): display currency in latest sales
Browse files Browse the repository at this point in the history
  • Loading branch information
remiroyc committed Oct 10, 2024
1 parent ef02269 commit aa2ddbe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/arkmarket/src/app/components/latest-sales.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default function LatestSales() {
</div>
</TableCell>
<TableCell className="text-foreground">
<PriceTag price={sale.price} />
<PriceTag price={sale.price} currency={sale.currency} />
</TableCell>
<TableCell className="text-primary">
<Link href={`/wallet/${sale.from}`}>
Expand Down
5 changes: 5 additions & 0 deletions apps/arkmarket/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ export interface LatestSales {
timestamp: number;
to: string;
transaction_hash: string | null;
currency: {
contract: string;
decimals: number;
symbol: string;
} | null;
}

export interface TrendingNow {
Expand Down
26 changes: 23 additions & 3 deletions packages/ui/src/price-tag.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import { Star } from "lucide-react";

Check failure on line 1 in packages/ui/src/price-tag.tsx

View workflow job for this annotation

GitHub Actions / lint

'Star' is defined but never used. Allowed unused vars must match /^_/u

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

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

function CurrencyIcon({ symbol }: { symbol: string }) {
switch (symbol) {
case "STRK":
return <Starknet className="size-5" />;
default:
case "ETH":
return <Ethereum className="size-5" />;
}
}

export function PriceTag({
className,
price,
currency,
}: PropsWithClassName<PriceTagProps>) {
if (!price) {
return null;
Expand All @@ -22,10 +41,11 @@ export function PriceTag({
className,
)}
>
<Ethereum className="size-5" />
<CurrencyIcon symbol={currency?.symbol || "ETH"} />

Check failure on line 44 in packages/ui/src/price-tag.tsx

View workflow job for this annotation

GitHub Actions / lint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator

<p className={ellipsableStyles}>
{isNaN(parsedPrice) ? formatUnits(price, 18) : parsedPrice.toFixed(5)}
<span className="text-muted-foreground"> ETH</span>
<span className="text-muted-foreground">{` ${currency?.symbol || "ETH"}`}</span>

Check failure on line 48 in packages/ui/src/price-tag.tsx

View workflow job for this annotation

GitHub Actions / lint

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
</p>
</div>
);
Expand Down

0 comments on commit aa2ddbe

Please sign in to comment.