Skip to content

Commit

Permalink
refactor(home): walletCard next-ui (#787)
Browse files Browse the repository at this point in the history
* refactor(home): walletCard next-ui

* chore: use as const for type-prop
  • Loading branch information
escapedcat authored Oct 27, 2024
1 parent 0050c1f commit 7de0680
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
18 changes: 14 additions & 4 deletions src/components/Headline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ export interface HeadlineProps {
as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
children: ReactNode;
size?: FontSizes;
align?: Alignment;
}

export const alignment = {
left: "text-left",
center: "text-center",
right: "text-right",
} as const;

export type Alignment = keyof typeof alignment;

export const fontSizes = {
"5xl": "text-5xl",
"4xl": "text-4xl",
Expand All @@ -15,21 +24,22 @@ export const fontSizes = {
xl: "text-xl",
base: "text-base",
sm: "text-sm",
};
} as const;

export type FontSizes = keyof typeof fontSizes;

export const Headline = ({
as = "h1",
as: Component = "h1",
size = "3xl",
align = "center",
children,
}: HeadlineProps) => {
const Component = as;
return (
<Component
className={twMerge(
fontSizes[size],
"semibold whitespace-pre-line text-center",
alignment[align],
"whitespace-pre-line font-semibold",
)}
>
{children}
Expand Down
64 changes: 37 additions & 27 deletions src/pages/Home/WalletCard.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Button } from "@/components/Button";
import { Headline } from "@/components/Headline";
import { AppContext, Unit } from "@/context/app-context";
import { SSEContext } from "@/context/sse-context";
import {
Expand Down Expand Up @@ -79,18 +81,20 @@ export const WalletCard: FC<Props> = ({
<section className="flex flex-col flex-wrap p-2 text-black lg:flex-row">
<div className="relative w-full overflow-hidden rounded-xl bg-yellow-600 bg-gradient-to-b from-yellow-500 p-4 text-white">
<article className="flex w-full flex-col">
<h6 className="text-xl">{t("wallet.balance")}</h6>
<Headline as="h6" align="left">
{t("wallet.balance")}
</Headline>
<p className="text-2xl font-bold">
{convertToString(unit, totalBalance)} {unit}
</p>
</article>
<article className="flex w-full flex-col">
<h6>
<Headline as="h5" align="left">
<LinkIcon className="mr-1 inline h-5 w-5 rotate-45 transform align-bottom" />
<span className="inline align-bottom text-sm">
{t("wallet.on_chain")}
</span>
</h6>
</Headline>
<p className="break-before-auto break-words text-lg font-bold">
<span>
{convertToString(unit, convertedOnchainBalance)} {unit}&nbsp;
Expand All @@ -105,50 +109,56 @@ export const WalletCard: FC<Props> = ({
</p>
</article>
<article className="flex w-full flex-col">
<h6>
<Headline as="h5" align="left">
<BoltIcon className="mr-1 inline h-5 w-5 align-bottom" />
<span className="inline align-bottom text-sm">
{t("home.lightning")}
</span>
</h6>
</Headline>
<p className="text-lg font-bold">
{convertToString(unit, convertedLnBalance)} {unit}
</p>
</article>
<BitcoinCircleIcon className="absolute -bottom-9 -right-9 h-32 w-32 opacity-30" />
</div>
</section>
<section className="flex justify-around gap-2 py-4">
<button
<section className="grid grid-cols-2 justify-around gap-4 p-2">
<Button
onClick={onReceive}
className="flex h-10 w-1/2 items-center justify-center rounded bg-black text-white hover:bg-gray-700 lg:w-5/12"
startContent={<ArrowDownTrayIcon className="h-6 w-6" />}
className="flex-grow"
color="primary"
variant="ghost"
>
<ArrowDownTrayIcon className="mr-1 h-6 w-6" />
<span>{t("wallet.receive")}</span>
</button>
<button
{t("wallet.receive")}
</Button>
<Button
onClick={onSend}
className="flex h-10 w-1/2 items-center justify-center rounded bg-black text-white hover:bg-gray-700 lg:w-5/12"
startContent={<ShareIcon className="h-6 w-6" />}
className="flex-grow"
color="primary"
variant="ghost"
>
<ShareIcon className="mr-1 h-6 w-6" />
<span>{t("wallet.send")}</span>
</button>
</section>
<section className="flex justify-around gap-2 pb-4">
<button
{t("wallet.send")}
</Button>
<Button
onClick={onOpenChannel}
className="flex h-10 w-1/2 items-center justify-center rounded bg-black text-white hover:bg-gray-700 lg:w-5/12"
startContent={<LightningIcon className="inline h-6 w-6" />}
className="flex-grow"
color="primary"
variant="ghost"
>
<LightningIcon className="mr-1 inline h-6 w-6" />
{t("home.open_channel")}
</button>
<button
</Button>
<Button
onClick={onCloseChannel}
className="flex h-10 w-1/2 items-center justify-center rounded bg-black text-white hover:bg-gray-700 lg:w-5/12"
startContent={<ListBulletIcon className="inline h-6 w-6" />}
className="flex-grow"
color="primary"
variant="ghost"
>
<ListBulletIcon className="mr-1 inline h-6 w-6" />
<span>{t("home.list_open_channels")}</span>
</button>
{t("home.list_open_channels")}
</Button>
</section>
</div>
</div>
Expand Down

0 comments on commit 7de0680

Please sign in to comment.