Skip to content

Commit

Permalink
remove position managment for subdaos
Browse files Browse the repository at this point in the history
  • Loading branch information
bryzettler committed Jan 31, 2025
1 parent ebd46b6 commit 5ef71e2
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 59 deletions.
42 changes: 25 additions & 17 deletions src/components/CreatePositionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import { daysToSecs, onInstructions } from "@/lib/utils";
import { useGovernance } from "@/providers/GovernanceProvider";
import { useAnchorProvider, useMint, useOwnedAmount } from "@helium/helium-react-hooks";
import {
useAnchorProvider,
useMint,
useOwnedAmount,
} from "@helium/helium-react-hooks";
import { HNT_MINT, toBN, toNumber } from "@helium/spl-utils";
import {
Position,
PositionWithMeta,
calcLockupMultiplier,
useCreatePosition
useCreatePosition,
} from "@helium/voter-stake-registry-hooks";
import { WalletSignTransactionError } from "@solana/wallet-adapter-base";
import { useWallet } from "@solana/wallet-adapter-react";
Expand Down Expand Up @@ -79,21 +83,25 @@ export const CreatePositionModal: FC<React.PropsWithChildren<{}>> = ({
const { info: mintAcc } = useMint(mint);

const draftPosition: Partial<PositionWithMeta> | undefined = useMemo(
() => formValues && ({
lockup: {
startTs: new BN(new Date().getTime() / 1000),
endTs: new BN(
new Date().setDate(
new Date().getDate() + formValues.lockupPeriodInDays
) / 1000
),
kind: formValues!.lockupKind == LockupKind.cliff ? { cliff: {} } as any : { decay: {} } as any,
() =>
formValues && {
lockup: {
startTs: new BN(new Date().getTime() / 1000),
endTs: new BN(
new Date().setDate(
new Date().getDate() + formValues.lockupPeriodInDays
) / 1000
),
kind:
formValues!.lockupKind == LockupKind.cliff
? ({ cliff: {} } as any)
: ({ decay: {} } as any),
},
amountDepositedNative: toBN(formValues!.amount, mintAcc?.decimals || 6),
delegatedSubDao: selectedSubDaoPk,
// @ts-ignore
registrar: registrar?.pubkey,
},
amountDepositedNative: toBN(formValues!.amount, mintAcc?.decimals || 6),
delegatedSubDao: selectedSubDaoPk,
// @ts-ignore
registrar: registrar?.pubkey,
}),
[formValues, mintAcc, selectedSubDaoPk, registrar]
);

Expand Down Expand Up @@ -244,7 +252,7 @@ export const CreatePositionModal: FC<React.PropsWithChildren<{}>> = ({
)}
{step === steps && (
<>
{ draftPosition && <PositionPreview position={draftPosition} /> }
{draftPosition && <PositionPreview position={draftPosition} />}
<div className="flex flex-col flex-grow justify-end">
<div className="flex flex-row gap-2">
<Button
Expand Down
1 change: 0 additions & 1 deletion src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Image from "next/image";
import Link from "next/link";
import { FC } from "react";
import { ContentSection } from "./ContentSection";
import { CreatePositionButton } from "./CreatePositionButton";
import { NetworkTabs } from "./NetworkTabs";
import { SubNav } from "./SubNav";
import { VeTokensCallout } from "./VeTokensCallout";
Expand Down
8 changes: 4 additions & 4 deletions src/components/NetworkBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { WalletConnectButton } from "./WalletConnectButton";
export const NetworkBanner: FC = () => {
const { connected } = useWallet();
const { network } = useGovernance();
const isHNT = network === "hnt";

return (
<ContentSection className="flex-1">
Expand All @@ -37,10 +38,9 @@ export const NetworkBanner: FC = () => {
</div>
<div className="flex flex-col flex-grow gap-1">
<p>How proposals work:</p>
<h5>Voting is enabled by locking tokens within this network</h5>
<h5>Voting is enabled by locking tokens</h5>
<p className="text-sm text-slate-100">
Create a vote escrow position using either HNT, MOBILE, or IOT
tokens
Create a vote escrow position using HNT
</p>
</div>
<div className="flex flex-row gap-4 max-md:w-full max-md:gap-12">
Expand All @@ -49,7 +49,7 @@ export const NetworkBanner: FC = () => {
<WalletConnectButton />
</div>
)}
{connected && (
{connected && isHNT && (
<>
<div className="flex flex-col flex-1 gap-2 max-md:flex-none">
<Button
Expand Down
61 changes: 33 additions & 28 deletions src/components/PositionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const PositionCard: FC<{
const path = usePathname();
const { lockup, hasGenesisMultiplier } = position;
const { loading: loadingGov, network, mintAcc, subDaos } = useGovernance();
const isHNT = network === "hnt";
const unixNow = useSolanaUnixNow() || Date.now() / 1000;
const lockupKind = Object.keys(lockup.kind)[0] as string;
const isConstant = lockupKind === "constant";
Expand Down Expand Up @@ -240,35 +241,39 @@ export const PositionCard: FC<{
</div>
</div>
<hr className="hidden max-md:flex h-0.5 w-full bg-slate-600" />
<div
className={classNames(
"flex flex-col w-3/12 lg:w-2/12 max-md:p-4 max-md:w-full max-md:flex-row max-md:items-center max-md:justify-between",
!position.proxy ? "gap-1" : "gap-1.5"
)}
>
<p className="text-muted-foreground text-xs">PROXIED TO</p>
{position.proxy &&
!position.proxy.nextVoter.equals(PublicKey.default) ? (
<Link
href={`/${network}/proxies/${position.proxy.nextVoter.toBase58()}`}
>
<Pill variant="pink" className="hover:bg-pink/70">
{knownProxy?.name ||
ellipsisMiddle(position.proxy.nextVoter.toBase58())}
</Pill>
</Link>
) : (
<Link href={`${path}/${position.pubkey.toBase58()}?action=proxy`}>
<Button
variant="secondary"
size="xxs"
className="text-foreground"
{isHNT && (
<div
className={classNames(
"flex flex-col w-3/12 lg:w-2/12 max-md:p-4 max-md:w-full max-md:flex-row max-md:items-center max-md:justify-between",
!position.proxy ? "gap-1" : "gap-1.5"
)}
>
<p className="text-muted-foreground text-xs">PROXIED TO</p>
{position.proxy &&
!position.proxy.nextVoter.equals(PublicKey.default) ? (
<Link
href={`/${network}/proxies/${position.proxy.nextVoter.toBase58()}`}
>
Proxy Now
</Button>
</Link>
)}
</div>
<Pill variant="pink" className="hover:bg-pink/70">
{knownProxy?.name ||
ellipsisMiddle(position.proxy.nextVoter.toBase58())}
</Pill>
</Link>
) : (
<Link
href={`${path}/${position.pubkey.toBase58()}?action=proxy`}
>
<Button
variant="secondary"
size="xxs"
className="text-foreground"
>
Proxy Now
</Button>
</Link>
)}
</div>
)}
{canDelegate && (
<div
className={classNames(
Expand Down
3 changes: 2 additions & 1 deletion src/components/PositionManager/PositionManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const PositionManager: FC<PositionManagerProps> = ({
organization,
refetch: refetchState,
} = useGovernance();
const isHNT = network === "hnt";
const router = useRouter();
const { lockup, isDelegated } = position;
const isConstant = Object.keys(lockup.kind)[0] === "constant";
Expand Down Expand Up @@ -388,7 +389,7 @@ export const PositionManager: FC<PositionManagerProps> = ({
handleClaimRewards={handleClaimPositionRewards}
/>
</div>
{!position.isProxiedToMe && (
{!position.isProxiedToMe && isHNT && (
<div className="flex flex-col py-10 px-4 gap-12 min-w-[465px] max-md:min-w-full max-md:py-4 max-md:gap-4">
<div className="flex flex-row justify-center items-center">
<span className="flex flex-grow h-[1px] bg-foreground/30 mx-2" />
Expand Down
34 changes: 26 additions & 8 deletions src/components/Positions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import { toast } from "sonner";
import { Skeleton } from "./ui/skeleton";
import { CreatePositionButton } from "./CreatePositionButton";
import { onInstructions } from "@/lib/utils";
import { useAnchorProvider, useSolanaUnixNow } from "@helium/helium-react-hooks";
import {
useAnchorProvider,
useSolanaUnixNow,
} from "@helium/helium-react-hooks";
import { ContentSection } from "./ContentSection";
import { WalletSignTransactionError } from "@solana/wallet-adapter-base";

Expand All @@ -27,6 +30,7 @@ export const Positions: FC = () => {
refetch: refetchState,
network,
} = useGovernance();
const isHNT = network === "hnt";

const sortedPositions = useMemo(
() =>
Expand Down Expand Up @@ -141,7 +145,7 @@ export const Positions: FC = () => {
<div className="flex flex-col gap-2 md:gap-0 md:flex-row md:justify-between md:items-center">
<h4>All Positions</h4>
<div className="flex max-md:flex-col gap-2">
<CreatePositionButton showText />
{isHNT && <CreatePositionButton showText />}
{network === "hnt" && (
<Button
variant="default"
Expand All @@ -163,13 +167,27 @@ export const Positions: FC = () => {
<Card className="flex flex-col flex-1 p-8">
<div className="flex flex-col flex-grow items-center justify-center gap-4">
<div className="flex flex-col items-center">
<h4 className="text-xl text-muted-foreground">No positions</h4>
<p className="text-sm text-center text-muted-foreground">
You have no active positions, create one to participate in
voting
</p>
{isHNT && (
<>
<h4 className="text-xl text-muted-foreground">
No positions
</h4>
<p className="text-sm text-center text-muted-foreground">
You have no active positions, create one to participate in
voting
</p>
</>
)}
{!isHNT && (
<>
<p className="text-sm text-center text-muted-foreground">
As of January 30th 2025, only new HNT positions can be
created
</p>
</>
)}
</div>
<CreatePositionButton className="m-0" />
{isHNT && <CreatePositionButton className="m-0" />}
</div>
</Card>
)}
Expand Down

0 comments on commit 5ef71e2

Please sign in to comment.