From 4179803fbe5334ea496dffd32e713d10a79bbfa5 Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Fri, 10 Oct 2025 11:57:31 +0200 Subject: [PATCH] chore: improve rendering amount and symbol TODO: externalize to own component --- src/components/CurrencySymbol.tsx | 7 ++++--- src/components/JamLanding.tsx | 19 ++++--------------- src/components/Navbar.tsx | 2 +- src/components/layout/Jar.tsx | 14 ++++++-------- src/stories/Jar.stories.tsx | 13 +++++-------- 5 files changed, 20 insertions(+), 35 deletions(-) diff --git a/src/components/CurrencySymbol.tsx b/src/components/CurrencySymbol.tsx index 158854d4..f54cba2e 100644 --- a/src/components/CurrencySymbol.tsx +++ b/src/components/CurrencySymbol.tsx @@ -10,13 +10,13 @@ type CurrencySymbolProps = { export function CurrencySymbol({ currency, isPrivate, size = 'lg' }: CurrencySymbolProps) { if (isPrivate) { - return + return } if (currency === 'btc') { return ( diff --git a/src/components/JamLanding.tsx b/src/components/JamLanding.tsx index 0591e33a..562f09ed 100644 --- a/src/components/JamLanding.tsx +++ b/src/components/JamLanding.tsx @@ -16,18 +16,8 @@ interface JamLandingProps { export default function JamLanding({ walletFileName }: JamLandingProps) { const { t } = useTranslation() - const { - currency, - toggleDisplayMode, - isPrivate, - formatAmount, - currencySymbol, - jars, - totalBalance, - isLoading, - error, - refetchWalletData, - } = useJamDisplayContext() + const { toggleDisplayMode, formatAmount, currencySymbol, jars, totalBalance, isLoading, error, refetchWalletData } = + useJamDisplayContext() return (
@@ -39,7 +29,7 @@ export default function JamLanding({ walletFileName }: JamLandingProps) {
) : ( -
toggleDisplayMode()} className="flex cursor-pointer items-center gap-1"> +
toggleDisplayMode()} className="flex cursor-pointer items-center"> {formatAmount(totalBalance)} {currencySymbol('lg')}
@@ -93,8 +83,7 @@ export default function JamLanding({ walletFileName }: JamLandingProps) { name={jar.name} amount={jar.balance} color={jar.color} - currency={currency} - isPrivate={isPrivate} + currencySymbol={currencySymbol} formatAmount={formatAmount} totalBalance={totalBalance} /> diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 6e4056c5..69ebe64c 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -70,7 +70,7 @@ export function Navbar({ theme, toggleTheme, formatAmount, currencySymbol, jars, ) : ( <> -
{formatAmount(totalBalance)}
+ {formatAmount(totalBalance)} {currencySymbol('sm')} )} diff --git a/src/components/layout/Jar.tsx b/src/components/layout/Jar.tsx index cf75b5bd..44940540 100644 --- a/src/components/layout/Jar.tsx +++ b/src/components/layout/Jar.tsx @@ -1,27 +1,25 @@ -import type { Currency } from '@/hooks/useDisplaySettings' -import { CurrencySymbol } from '../CurrencySymbol' import { JarIcon } from '../ui/JarIcon' interface JarProps { name: string amount: number color: '#e2b86a' | '#3b5ba9' | '#c94f7c' | '#a67c52' | '#7c3fa6' - currency: Currency - isPrivate: boolean formatAmount: (amount: number) => string + currencySymbol: (size: 'sm' | 'lg') => React.ReactNode totalBalance?: number } -export function Jar({ name, amount, color, currency, isPrivate, formatAmount, totalBalance = 0 }: JarProps) { +export function Jar({ name, amount, color, currencySymbol, formatAmount, totalBalance = 0 }: JarProps) { return (

{name}

-

- {formatAmount(amount)} -

+
+ {formatAmount(amount)} + {currencySymbol('sm')} +
) } diff --git a/src/stories/Jar.stories.tsx b/src/stories/Jar.stories.tsx index b6dcd279..b650589f 100644 --- a/src/stories/Jar.stories.tsx +++ b/src/stories/Jar.stories.tsx @@ -1,4 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react-vite' +import { CurrencySymbol } from '@/components/CurrencySymbol' import { Jar } from '@/components/layout/Jar' import type { Currency } from '@/hooks/useDisplaySettings' @@ -27,8 +28,7 @@ export const Sats: Story = { name: 'Savings Jar', amount: 15000000, color: '#e2b86a', - currency: 'sats', - isPrivate: false, + currencySymbol: (size: 'sm' | 'lg') => , formatAmount: () => formatAmount(15000000, 'sats'), totalBalance: 50000000, }, @@ -39,8 +39,7 @@ export const BTC: Story = { name: 'Main Jar', amount: 20000000, color: '#3b5ba9', - currency: 'btc', - isPrivate: false, + currencySymbol: (size: 'sm' | 'lg') => , formatAmount: () => formatAmount(20000000, 'btc'), totalBalance: 50000000, }, @@ -51,8 +50,7 @@ export const Empty: Story = { name: 'Empty Jar', amount: 0, color: '#c94f7c', - currency: 'sats', - isPrivate: false, + currencySymbol: (size: 'sm' | 'lg') => , formatAmount: () => formatAmount(0, 'sats'), totalBalance: 50000000, }, @@ -63,8 +61,7 @@ export const Full: Story = { name: 'Full Jar', amount: 50000000, color: '#a67c52', - currency: 'sats', - isPrivate: false, + currencySymbol: (size: 'sm' | 'lg') => , formatAmount: () => formatAmount(50000000, 'sats'), totalBalance: 100000000, },