Skip to content

Commit

Permalink
feat(home): display currency in latest sales (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
remiroyc authored Oct 10, 2024
1 parent ef02269 commit 7d2f1fa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 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
27 changes: 23 additions & 4 deletions packages/ui/src/price-tag.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
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 +39,12 @@ export function PriceTag({
className,
)}
>
<Ethereum className="size-5" />
<CurrencyIcon symbol={currency?.symbol ?? "ETH"} />
<p className={ellipsableStyles}>
{isNaN(parsedPrice) ? formatUnits(price, 18) : parsedPrice.toFixed(5)}
<span className="text-muted-foreground"> ETH</span>
{isNaN(parsedPrice)
? formatUnits(price, currency?.decimals ?? 18)
: parsedPrice.toFixed(5)}
<span className="text-muted-foreground">{` ${currency?.symbol ?? "ETH"}`}</span>
</p>
</div>
);
Expand Down

0 comments on commit 7d2f1fa

Please sign in to comment.