Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: renaming #53

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 0 additions & 71 deletions src/components/element/participate/Participate.client.tsx

This file was deleted.

135 changes: 135 additions & 0 deletions src/components/element/participate/Participate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import type { Opportunity } from "@merkl/api";
import { Button, Group, Icon, Input, PrimitiveTag, Text, Value } from "dappkit";
import { Fmt } from "packages/dappkit/src/utils/formatter.service";
import { Suspense, useState } from "react";
import useOpportunity from "src/hooks/resources/useOpportunity";
import useParticipate from "src/hooks/useParticipate";
import OpportunityShortCard from "../opportunity/OpportunityShortCard";
import TokenSelect from "../token/TokenSelect";
import Interact from "./Interact.client";

export type ParticipateProps = {
opportunity: Opportunity;
displayOpportunity?: boolean;
displayMode?: boolean | "withdraw" | "deposit";
displayLinks?: boolean;
};

export default function Participate({
opportunity,
displayOpportunity,
displayMode,
displayLinks,
}: ParticipateProps) {
const [tokenAddress, setTokenAddress] = useState();
const [amount, setAmount] = useState<bigint>(0n);
const [mode] = useState<"deposit" | "withdraw">(
typeof displayMode === "string" ? displayMode : "deposit"
);

const {
target,
balance,
token: inputToken,
loading,
} = useParticipate(
opportunity.chainId,
opportunity.protocol?.id,
opportunity.identifier,
tokenAddress
);
const { link } = useOpportunity(opportunity);

// const switchModeButton = useMemo(() => {
// if (typeof displayMode === "boolean" && !displayMode) return;
// switch (mode) {
// case "deposit":
// return (
// <Button onClick={() => setMode("withdraw")} size="sm">
// Withdraw
// </Button>
// );
// case "withdraw":
// return (
// <Button onClick={() => setMode("deposit")} size="sm">
// Supply
// </Button>
// );
// }
// }, [mode]);

return (
<>
{displayOpportunity && <OpportunityShortCard opportunity={opportunity} />}
{displayLinks && (
<Group className="w-full justify-between">
<Group>
{opportunity.protocol && (
<Button
external
to={opportunity.protocol?.url}
disabled={!opportunity.protocol?.url}
size="md"
look="base"
>
Visit {opportunity.protocol.name}
<Icon remix="RiArrowRightUpLine" />
</Button>
)}
</Group>
<Group className="flex-col justify-center">
<Button to={link} size="md" look="soft">
More info <Icon remix="RiArrowRightLine" />
</Button>
</Group>
</Group>
)}
<Group>
<Input.BigInt
className="w-full"
state={[amount, (a) => setAmount(a)]}
base={inputToken?.decimals ?? 18}
header={
<Group className="justify-between w-full">
<Text>{mode === "deposit" ? "Supply" : "Withdraw"}</Text>
<Group>
<Text>Balance</Text>
{inputToken && (
<Value format="$0,0.#">
{Fmt.toPrice(inputToken.balance, inputToken)}
</Value>
)}
<PrimitiveTag
onClick={() => {
setAmount(BigInt(inputToken?.balance ?? "0"));
}}
size="xs"
>
Max
</PrimitiveTag>
</Group>
</Group>
}
suffix={
<TokenSelect
balances
state={[tokenAddress, setTokenAddress]}
tokens={balance}
/>
}
placeholder="0.0"
/>
{/* biome-ignore lint/complexity/noUselessFragments: <explanation> */}
<Suspense fallback={<></>}>
<Interact
disabled={!loading && !target}
target={target}
inputToken={inputToken}
amount={amount}
opportunity={opportunity}
/>
</Suspense>
</Group>
</>
);
}
Loading