Skip to content

Commit

Permalink
feat: new stats component, added stats / action box to mobile layout
Browse files Browse the repository at this point in the history
  • Loading branch information
chambaz committed Dec 1, 2023
1 parent b4104a4 commit 2a23653
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const ActionBox = () => {
}}
/>
</div>
<p>Supply. Earn interest. Borrow. Repeat.</p>
<p className="text-muted-foreground">Supply. Earn interest. Borrow. Repeat.</p>
</div>
<div className="p-6 bg-background-gray text-white w-full max-w-[480px] rounded-xl">
<p className="text-lg mb-3">You {lendingMode === LendingModes.LEND ? "supply" : "borrow"}</p>
Expand Down
41 changes: 41 additions & 0 deletions apps/marginfi-v2-ui/src/components/common/Stats/Stats.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react";

import { useMrgnlendStore } from "~/store";

import { cn } from "~/utils";

import { numeralFormatter, usdFormatter } from "@mrgnlabs/mrgn-common";

export const Stats = () => {
const [protocolStats] = useMrgnlendStore((state) => [state.protocolStats]);

const statsList = React.useMemo(() => {
return [
{
label: "Total deposits",
value: usdFormatter.format(protocolStats.deposits),
},
{
label: "Total borrows",
value: usdFormatter.format(protocolStats.borrows),
},
{
label: "Total points",
value: numeralFormatter(protocolStats.pointsTotal),
},
];
}, [protocolStats]);

return (
<ul className="flex text-muted-foreground gap-4 justify-center mt-10 mb-6 text-sm md:gap-8 md:text-base">
{statsList.map((stat, index) => (
<li key={index} className={cn(index !== statsList.length - 1 && "border-r-2 border-white/20 pr-8")}>
<dl className="space-y-1 md:space-y-2">
<dt>{stat.label}</dt>
<dd className="font-bold md:text-2xl text-white">{stat.value}</dd>
</dl>
</li>
))}
</ul>
);
};
1 change: 1 addition & 0 deletions apps/marginfi-v2-ui/src/components/common/Stats/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Stats";
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import {
STABLECOINS,
LSTS,
} from "~/components/common/AssetList";
import { ActionBox, ActionBoxDialog } from "~/components/common/ActionBox";
import { Portfolio } from "~/components/common/Portfolio";
import { MrgnTooltip } from "~/components/common";

import { LendingModes } from "~/types";
import { Button } from "~/components/ui/button";

const UserPositions = dynamic(async () => (await import("~/components/desktop/UserPositions")).UserPositions, {
ssr: false,
Expand Down Expand Up @@ -174,13 +172,6 @@ const AssetsList = () => {

return (
<>
<div className="flex flex-col justify-center items-center gap-8 mb-16">
<ActionBox />
<ActionBoxDialog>
<Button>Open Action Box Dialog</Button>
</ActionBoxDialog>
</div>

<AssetListFilters />

<div className="col-span-full">
Expand Down
13 changes: 9 additions & 4 deletions apps/marginfi-v2-ui/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ import { shortenAddress } from "@mrgnlabs/mrgn-common";
import config from "~/config/marginfi";
import { Desktop, Mobile } from "~/mediaQueries";
import { useMrgnlendStore } from "~/store";
import { showErrorToast } from "~/utils/toastUtils";
import { useConnection } from "~/hooks/useConnection";
import { useWalletContext } from "~/hooks/useWalletContext";

import { Banner } from "~/components/desktop/Banner";
import { OverlaySpinner } from "~/components/desktop/OverlaySpinner";
import { PageHeader } from "~/components/common/PageHeader";
import { ActionBox } from "~/components/common/ActionBox";
import { Stats } from "~/components/common/Stats";

import { IconAlertTriangle } from "~/components/ui/icons";
import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger } from "~/components/ui/select";
import { showErrorToast } from "~/utils/toastUtils";

const DesktopAccountSummary = dynamic(
async () => (await import("~/components/desktop/DesktopAccountSummary")).DesktopAccountSummary,
Expand Down Expand Up @@ -114,9 +116,10 @@ const Home = () => {
setIsRefreshing={setIsRefreshingStore}
/>
)}
<DesktopAccountSummary />
<Stats />
<ActionBox />
</div>
<div className="pt-[16px] pb-[64px] px-4 w-full xl:w-4/5 xl:max-w-7xl gap-4">
<div className="pt-[16px] pb-[64px] px-4 w-full xl:w-4/5 xl:max-w-7xl mt-8 gap-4">
<AssetsList />
</div>
<OverlaySpinner fetching={!isStoreInitialized || isRefreshingStore} />
Expand All @@ -133,7 +136,9 @@ const Home = () => {
setIsRefreshing={setIsRefreshingStore}
/>
)}
<div className="flex flex-col w-full h-full justify-start content-start pt-4 px-4 gap-4 mb-20">
<Stats />
<ActionBox />
<div className="flex flex-col w-full h-full justify-start content-start pt-4 px-4 gap-4 mt-8 mb-20">
<MobileAssetsList />
</div>
</Mobile>
Expand Down

0 comments on commit 2a23653

Please sign in to comment.