Skip to content

Commit

Permalink
New tabs for Longs, Shorts, LP (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyDelott authored Jul 6, 2023
1 parent 22c83c2 commit b7ca514
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 88 deletions.
15 changes: 2 additions & 13 deletions apps/hyperdrive-trading/src/ui/base/components/Well/Well.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,11 @@ export function Well({
const isInteractive = !disabled && (interactive || onClick);
const className = classNames("rounded-lg p-4", {
"w-full": block,
"hover:cursor-pointer hover:ring-opacity-50": isInteractive,

"bg-base-300/50": !variant,
"hover:ring-neutral-content hover:ring-1": isInteractive && !variant,

"hover:cursor-pointer hover:glass": isInteractive,
"bg-base-300/50 ring-neutral-content/20 ring-1": !variant,
"bg-primary/5 ring-primary/20 ring-1": variant === "primary",
"hover:bg-primary/10 hover:ring-primary/50":
isInteractive && variant === "primary",

"bg-secondary/5 ring-secondary/20 ring-1": variant === "secondary",
"hover:bg-secondary/10 hover:ring-secondary/50":
isInteractive && variant === "secondary",

"bg-accent/5 ring-accent/20 ring-1": variant === "accent",
"hover:bg-accent/10 hover:ring-accent/50":
isInteractive && variant === "accent",
});

if (onClick || interactive) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ChevronRightIcon, CircleStackIcon } from "@heroicons/react/24/outline";
import { ReactElement } from "react";
import { Well } from "src/ui/base/components/Well/Well";

export function AddLiquidityModalButton(): ReactElement {
return (
<Well interactive variant="primary">
<div className="flex w-52 flex-col gap-2 py-4 text-center">
<CircleStackIcon className="mb-2 h-16 text-primary" />
<p className="font-lato text-h5 font-light text-primary">
Add liquidity
</p>
<p className="font-light">
Earn trading fees when users open longs or shorts
</p>
<div className="daisy-btn-primary daisy-btn-sm daisy-btn mt-2 justify-between gap-0 normal-case">
<span className="ml-4 flex-1 text-center">Add LP</span>
<ChevronRightIcon className="h-3 text-right" />
</div>
</div>
</Well>
);
}
3 changes: 3 additions & 0 deletions apps/hyperdrive-trading/src/ui/hyperdrive/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { BigNumber } from "ethers";

/**
* @deprecated
*/
export function getAssetTimestampFromTokenId(id: bigint): number {
const idBN = BigNumber.from(id);
return idBN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function ClosedLongsTable({
return (
<SortableGridTable
headingRowClassName="grid-cols-5 text-neutral-content"
bodyRowClassName="grid-cols-5 text-base-content items-center text-h6 even:bg-base-300/50 h-16"
bodyRowClassName="grid-cols-5 text-base-content items-center text-h6 even:bg-secondary/5 h-16"
cols={["Position", "Balance", "Value", "Matures on", "Closed on"]}
rows={closedLongRows}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function OpenLongsTable({
return (
<SortableGridTable
headingRowClassName="grid-cols-4 text-neutral-content"
bodyRowClassName="grid-cols-4 text-base-content items-center text-h6 even:bg-base-300/50 h-16"
bodyRowClassName="grid-cols-4 text-base-content items-center text-h6 even:bg-secondary/5 h-16"
// Blank col added for actions
cols={["Position", "Balance", "Value", "Matures on", ""]}
rows={openLongRows}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function OpenShortsTable({
return (
<SortableGridTable
headingRowClassName="grid-cols-4 text-neutral-content"
bodyRowClassName="grid-cols-4 text-base-content items-center text-h6 even:bg-base-300/50 h-16"
bodyRowClassName="grid-cols-4 text-base-content items-center text-h6 even:bg-accent/5 h-16"
// Blank col added for actions
cols={["Position", "Balance", "Value", "Matures on", ""]}
rows={openShortRows}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,29 @@ export function PositionsSection({
<div>
<div className="mb-2 flex w-full items-center justify-between border-b border-neutral-content/30">
<span className="text-h5 font-thin text-neutral-content">
Your Positions
Your positions
</span>
<div className="daisy-tabs">
<a
onClick={() => setActivePositionTab("Longs")}
className={classNames("daisy-tab-lifted daisy-tab daisy-tab-lg", {
"daisy-tab-active !bg-secondary/30":
activePositionTab === "Longs",
className={classNames("daisy-tab-lifted daisy-tab daisy-tab-lg ", {
"daisy-tab-active glass": activePositionTab === "Longs",
})}
>
Longs
</a>
<a
onClick={() => setActivePositionTab("Shorts")}
className={classNames("daisy-tab-lifted daisy-tab daisy-tab-lg", {
"daisy-tab-active !bg-neutral-content/30":
activePositionTab === "Shorts",
"daisy-tab-active glass": activePositionTab === "Shorts",
})}
>
Shorts
</a>
<a
onClick={() => setActivePositionTab("LP")}
className={classNames("daisy-tab-lifted daisy-tab daisy-tab-lg", {
"daisy-tab-active !bg-neutral-content/30":
activePositionTab === "LP",
"daisy-tab-active glass": activePositionTab === "LP",
})}
>
LP
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ReactElement } from "react";
import { Token } from "src/appconfig/types";
import { Stat } from "src/ui/base/components/Stat";
import { Well } from "src/ui/base/components/Well/Well";
import { formatBalance } from "src/ui/base/formatting/formatBalance";
import { useMintBaseToken } from "src/ui/token/hooks/useMintBaseToken";
import { parseUnits } from "viem";
import { useAccount, useBalance, useChainId } from "wagmi";

export function YourBalanceWell({ token }: { token: Token }): ReactElement {
const { address: account } = useAccount();
const { data: balance } = useBalance({
address: account,
token: token.address,
});
const chainId = useChainId();
const { mint } = useMintBaseToken({
amount: parseUnits("100", token.decimals),
baseToken: token.address,
destination: account,
});

return (
<Well>
<div className="flex items-center gap-4">
<Stat
label="Your available balance"
value={
<div className="-mt-1 flex items-center gap-1 text-h5">
<img className="h-4" src={token.iconUrl} />
{formatBalance(balance?.formatted || 0, 4)} {token.symbol}
{chainId === 31337 ? (
<button
disabled={!mint}
className="daisy-btn-xs daisy-btn ml-1"
onClick={() => mint?.()}
>
Mint Tokens
</button>
) : undefined}
</div>
}
/>
</div>
</Well>
);
}
71 changes: 7 additions & 64 deletions apps/hyperdrive-trading/src/ui/trade/TradeBody/TradeBody.tsx
Original file line number Diff line number Diff line change
@@ -1,107 +1,50 @@
import { ChevronRightIcon, CircleStackIcon } from "@heroicons/react/24/outline";
import { ReactElement } from "react";
import { Hyperdrive } from "src/appconfig/types";
import { useAppConfig } from "src/ui/appconfig/useAppConfig";
import { Stat } from "src/ui/base/components/Stat";
import { Well } from "src/ui/base/components/Well/Well";
import { formatBalance } from "src/ui/base/formatting/formatBalance";
import { OpenLongModalButton } from "src/ui/hyperdrive/longs/OpenLongModalButton/OpenLongModalButton";
import { AddLiquidityModalButton } from "src/ui/hyperdrive/lp/AddLiquidityModalButton/AddLiquidityModalButton";
import { OpenShortModalButton } from "src/ui/hyperdrive/shorts/OpenShortModalButton/OpenShortModalButton";
import { MarketSelect } from "src/ui/markets/MarketSelect/MarketSelect";
import { MarketStats } from "src/ui/markets/MarketStats/MarketStats";
import { YieldSourceLabel } from "src/ui/markets/YieldSourceLabel/YieldSourceLabel";
import { FAQ } from "src/ui/onboarding/FAQ/FAQ";
import { PositionsSection } from "src/ui/portfolio/PositionsSection/PositionsSection";
import { useMintBaseToken } from "src/ui/token/hooks/useMintBaseToken";
import { parseUnits } from "viem";
import { useAccount, useBalance, useChainId } from "wagmi";
import { YourBalanceWell } from "src/ui/portfolio/YourBalanceWell/YourBalanceWell";

interface PositionsTableProps {
hyperdrive: Hyperdrive;
}

export function TradeBody({ hyperdrive }: PositionsTableProps): ReactElement {
const { appConfig } = useAppConfig();
const { address: account } = useAccount();
const { data: balance } = useBalance({
address: account,
token: hyperdrive.baseToken.address,
});
const chainId = useChainId();
const yieldSource = appConfig?.yieldSources[hyperdrive.yieldSource];
const { mint } = useMintBaseToken({
amount: parseUnits("100", hyperdrive.baseToken.decimals),
baseToken: hyperdrive.baseToken.address,
destination: account,
});

return (
<div className="flex max-w-4xl flex-col gap-16 ">
<div className="flex max-w-[840px] flex-col gap-16 ">
{/* Name w/ market select */}
<div className="flex w-full flex-col gap-6">
<div className="flex flex-wrap items-start justify-between">
<div className="flex shrink-0 flex-col">
<div className="flex flex-1 justify-between">
<YieldSourceLabel yieldSource={yieldSource} />{" "}
<YieldSourceLabel yieldSource={yieldSource} />
<MarketSelect markets={[hyperdrive]} />
</div>
<p className="text-h3 font-semibold">{hyperdrive.name}</p>
</div>
<Well>
<div className="flex items-center gap-4">
<Stat
label="Your available balance"
value={
<div className="-mt-1 flex items-center gap-1 text-h5">
<img className="h-4" src={hyperdrive.baseToken.iconUrl} />
{formatBalance(balance?.formatted || 0, 4)}{" "}
{hyperdrive.baseToken.symbol}
{chainId === 31337 ? (
<button
disabled={!mint}
className="daisy-btn-xs daisy-btn ml-1"
onClick={() => mint?.()}
>
Mint Tokens
</button>
) : undefined}
</div>
}
/>
</div>
</Well>
<YourBalanceWell token={hyperdrive.baseToken} />
</div>

{/* Stats row */}
<MarketStats hyperdrive={hyperdrive} />
</div>

<div>
<div className="mb-8 flex w-full items-center border-b border-neutral-content/30">
<span className="pb-2 font-lato text-h5 font-light text-neutral-content">
Hyperdrive Actions
</span>
</div>
<div className="flex flex-wrap gap-10 ">
<div className="flex flex-wrap justify-between gap-10 ">
<OpenLongModalButton hyperdrive={hyperdrive} />

<OpenShortModalButton hyperdrive={hyperdrive} />

<Well interactive variant="primary">
<div className="flex w-52 flex-col gap-2 py-4 text-center">
<CircleStackIcon className="mb-2 h-16 text-primary" />
<p className="font-lato text-h5 font-light text-primary">
Add liquidity
</p>
<p className="font-light">
Earn trading fees when users open longs or shorts
</p>
<div className="daisy-btn-primary daisy-btn-sm daisy-btn mt-2 justify-between gap-0 normal-case">
<span className="ml-4 flex-1 text-center">Add LP</span>
<ChevronRightIcon className="h-3 text-right" />
</div>
</div>
</Well>
<AddLiquidityModalButton />
</div>
</div>

Expand Down

2 comments on commit b7ca514

@vercel
Copy link

@vercel vercel bot commented on b7ca514 Jul 6, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

hyperdrive-monorepo-hyperdrive-trading – ./apps/hyperdrive-trading

hyperdrive-monorepo-hyperdrive-trading-git-main-delvtech.vercel.app
hyperdrive-monorepo-hyperdrive-trading.vercel.app
hyperdrive-monorepo-hyperdrive-trading-delvtech.vercel.app

@vercel
Copy link

@vercel vercel bot commented on b7ca514 Jul 6, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

hyperdrive-fixed-borrow – ./apps/fixed-borrow

hyperdrive-fixed-borrow-git-main-delvtech.vercel.app
hyperdrive-fixed-borrow-delvtech.vercel.app
hyperdrive-fixed-borrow.vercel.app

Please sign in to comment.