Skip to content

Commit

Permalink
Namadillo: new overview panel (#1356)
Browse files Browse the repository at this point in the history
* feat: new overview panel

* refactor: removing deprecated component

* feat: updating tests

* feat: handling empty amounts
  • Loading branch information
pedrorezende authored Dec 2, 2024
1 parent 78f243f commit ec92436
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 229 deletions.
59 changes: 24 additions & 35 deletions apps/namadillo/src/App/AccountOverview/AccountOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Panel, Stack } from "@namada/components";
import { Panel } from "@namada/components";
import { ConnectPanel } from "App/Common/ConnectPanel";
import { PageWithSidebar } from "App/Common/PageWithSidebar";
import { EpochInformation } from "App/Sidebars/EpochInformation";
Expand All @@ -9,18 +9,15 @@ import { applicationFeaturesAtom } from "atoms/settings";
import { useUserHasAccount } from "hooks/useIsAuthenticated";
import { useAtomValue } from "jotai";
import { twMerge } from "tailwind-merge";
import { AccountBalanceContainer } from "./AccountBalanceContainer";
import { BalanceContainer } from "./BalanceContainer";
import { BalanceOverviewChart } from "./BalanceOverviewChart";
import { MaspBanner } from "./MaspBanner";
import { NamBalanceContainer } from "./NamBalanceContainer";
import { NavigationFooter } from "./NavigationFooter";
import { TransparentOverviewPanel } from "./TransparentOverviewPanel";

export const AccountOverview = (): JSX.Element => {
const userHasAccount = useUserHasAccount();
const { claimRewardsEnabled, maspEnabled } = useAtomValue(
applicationFeaturesAtom
);
const { maspEnabled } = useAtomValue(applicationFeaturesAtom);

if (!userHasAccount) {
return (
Expand All @@ -33,37 +30,29 @@ export const AccountOverview = (): JSX.Element => {
return (
<PageWithSidebar>
<div className={twMerge("flex w-full")}>
{claimRewardsEnabled ?
<section className="flex flex-col w-full rounded-sm min-h-full gap-2">
<div className="grid sm:grid-cols-[1.25fr_1fr] gap-2">
<Panel>
{maspEnabled ?
<BalanceContainer />
: <NamBalanceContainer />}
</Panel>
<Panel>
<StakingRewardsPanel />
</Panel>
</div>
{maspEnabled && (
<>
<MaspBanner />
<TransparentOverviewPanel />
</>
)}
<Panel className="flex items-center flex-1 justify-center">
<NavigationFooter />
<section className="flex flex-col w-full rounded-sm min-h-full gap-2">
<div className="grid sm:grid-cols-[0.8fr_1.25fr_0.66fr] gap-2">
<Panel className="flex items-center justify-center">
<BalanceOverviewChart />
</Panel>
<Panel>
<NamBalanceContainer />
</Panel>
</section>
: <section className="flex items-center bg-black rounded-sm w-full">
<Stack gap={5} className="my-auto min-w-[365px] mx-auto py-12">
<AccountBalanceContainer />
<NavigationFooter />
</Stack>
</section>
}
<Panel>
<StakingRewardsPanel />
</Panel>
</div>
{maspEnabled && (
<>
<MaspBanner />
<TransparentOverviewPanel />
</>
)}
<Panel className="flex items-center flex-1 justify-center">
<NavigationFooter />
</Panel>
</section>
</div>

<aside className="flex flex-col gap-2">
<EpochInformation />
<ShieldAllBanner />
Expand Down
143 changes: 0 additions & 143 deletions apps/namadillo/src/App/AccountOverview/BalanceContainer.tsx

This file was deleted.

131 changes: 131 additions & 0 deletions apps/namadillo/src/App/AccountOverview/BalanceOverviewChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import {
Heading,
PieChart,
PieChartData,
SkeletonLoading,
} from "@namada/components";
import { FiatCurrency } from "App/Common/FiatCurrency";
import { NamCurrency } from "App/Common/NamCurrency";
import { shieldedTokensAtom, transparentTokensAtom } from "atoms/balance";
import { getTotalDollar } from "atoms/balance/functions";
import { applicationFeaturesAtom } from "atoms/settings";
import BigNumber from "bignumber.js";
import { useBalances } from "hooks/useBalances";
import { useAtomValue } from "jotai";
import { colors } from "theme";

const BalanceOverviewCaptionItem = ({
color,
children,
}: { color: string } & React.PropsWithChildren): JSX.Element => {
return (
<li className="flex gap-2 items-center text-base">
<i
className="w-3 h-3 aspect-square rounded-full"
style={{ background: color }}
/>
{children}
</li>
);
};

export const BalanceOverviewChart = (): JSX.Element => {
const { maspEnabled } = useAtomValue(applicationFeaturesAtom);
const shieldedTokensQuery = useAtomValue(shieldedTokensAtom);
const transparentTokensQuery = useAtomValue(transparentTokensAtom);
const { totalTransparentAmount, isLoading: isLoadingTransparent } =
useBalances();
const shieldedDollars =
getTotalDollar(shieldedTokensQuery.data) || new BigNumber(0);
const transparentDollars =
getTotalDollar(transparentTokensQuery.data) || new BigNumber(0);
const totalAmountInDollars = shieldedDollars.plus(transparentDollars);

const isLoading =
maspEnabled ?
isLoadingTransparent ||
shieldedTokensQuery.isLoading ||
transparentTokensQuery.isLoading
: isLoadingTransparent;

const getPiechartData = (): Array<PieChartData> => {
if (isLoading) {
return [];
}

if (!maspEnabled) {
return [
{
value: 1,
color: totalTransparentAmount.gt(0) ? colors.shielded : colors.empty,
},
];
}

if (totalAmountInDollars.eq(0)) {
return [{ value: 1, color: colors.empty }];
}

return [
{
value: transparentDollars || new BigNumber(0),
color: colors.balance,
},
{ value: shieldedDollars || new BigNumber(0), color: colors.shielded },
];
};

return (
<div>
<div className="h-[230px] w-[230px]">
{isLoading ?
<SkeletonLoading
height="100%"
width="100%"
className="rounded-full border-neutral-800 border-[24px] bg-transparent"
/>
: <PieChart
id="balance-chart"
data={getPiechartData()}
strokeWidth={24}
radius={125}
segmentMargin={0}
>
<div className="flex flex-col gap-1 leading-tight">
<Heading className="text-sm" level="h3">
{maspEnabled ? "Total Balance" : "NAM Balance"}
</Heading>
<div className="text-2xl">
{maspEnabled ?
<span>
<FiatCurrency amount={totalAmountInDollars} />*
</span>
: <NamCurrency
amount={totalTransparentAmount}
currencySymbolClassName="hidden"
decimalPlaces={2}
/>
}
</div>
</div>
</PieChart>
}
</div>
{maspEnabled && (
<>
<ul className="mx-auto px-5 mt-3">
<BalanceOverviewCaptionItem color={colors.shielded}>
Shielded Assets
</BalanceOverviewCaptionItem>
<BalanceOverviewCaptionItem color={colors.balance}>
Transparent Assets
</BalanceOverviewCaptionItem>
</ul>
<small className="text-xxs -mb-3 mt-3 block">
* Balances exclude NAM until phase 5
</small>
</>
)}
</div>
);
};
Loading

1 comment on commit ec92436

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.