Skip to content

Commit 5ffa452

Browse files
committed
delegation changes
1 parent 9b46b15 commit 5ffa452

3 files changed

Lines changed: 31 additions & 31 deletions

File tree

src/components/CreatePositionModal.tsx

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
} from "@helium/helium-react-hooks";
1010
import { HNT_MINT, toBN, toNumber } from "@helium/spl-utils";
1111
import {
12-
Position,
1312
PositionWithMeta,
1413
calcLockupMultiplier,
1514
useCreatePosition,
@@ -19,7 +18,7 @@ import { useWallet } from "@/hooks/useWallet";
1918
import { PublicKey } from "@solana/web3.js";
2019
import BN from "bn.js";
2120
import { Loader2 } from "lucide-react";
22-
import React, { FC, useCallback, useMemo, useState } from "react";
21+
import React, { FC, useCallback, useEffect, useMemo, useState } from "react";
2322
import { toast } from "sonner";
2423
import {
2524
LockTokensForm,
@@ -31,6 +30,7 @@ import { SubDaoSelection } from "./SubDaoSelection";
3130
import { Button } from "./ui/button";
3231
import { Dialog, DialogContent, DialogTrigger } from "./ui/dialog";
3332
import { PositionPreview } from "./PositionPreview";
33+
import { MOBILE_SUB_DAO_KEY } from "@/lib/constants";
3434

3535
export const CreatePositionModal: FC<React.PropsWithChildren<{}>> = ({
3636
children,
@@ -42,29 +42,25 @@ export const CreatePositionModal: FC<React.PropsWithChildren<{}>> = ({
4242
const [formValues, setFormValues] = useState<LockTokensFormValues>();
4343
const [selectedSubDaoPk, setSelectedSubDaoPk] = useState<PublicKey>();
4444
const { publicKey: wallet } = useWallet();
45-
const {
46-
network,
47-
mint,
48-
subDaos,
49-
registrar,
50-
refetch: refetchState,
51-
} = useGovernance();
45+
const { mint, subDaos, registrar, refetch: refetchState } = useGovernance();
5246
const { amount: ownedAmount, decimals } = useOwnedAmount(wallet, mint);
5347
const { error: createPositionError, createPosition } = useCreatePosition();
5448
const steps = useMemo(() => (mint.equals(HNT_MINT) ? 3 : 2), [mint]);
5549

50+
useEffect(() => {
51+
if (subDaos && !selectedSubDaoPk) {
52+
setSelectedSubDaoPk(
53+
subDaos.find((subDao) => subDao.pubkey.equals(MOBILE_SUB_DAO_KEY))
54+
?.pubkey || undefined
55+
);
56+
}
57+
}, [subDaos, selectedSubDaoPk, setSelectedSubDaoPk]);
58+
5659
const maxLockupAmount =
5760
ownedAmount && decimals
5861
? toNumber(new BN(ownedAmount.toString()), decimals)
5962
: 0;
6063

61-
const selectedSubDao = useMemo(
62-
() =>
63-
selectedSubDaoPk &&
64-
subDaos?.find((subDao) => subDao.pubkey.equals(selectedSubDaoPk!))!,
65-
[selectedSubDaoPk, subDaos]
66-
);
67-
6864
const handleCalcLockupMultiplier = useCallback(
6965
(lockupPeriodInDays: number) =>
7066
(registrar &&
@@ -165,9 +161,7 @@ export const CreatePositionModal: FC<React.PropsWithChildren<{}>> = ({
165161
const subheading =
166162
(step === 1 &&
167163
"Boost your voting power by strategically locking your tokens for a specified period, opting for either a constant or decaying lockup") ||
168-
(steps > 2 &&
169-
step === 2 &&
170-
"Choose whether to delegate your tokens to a subnetwork for rewards") ||
164+
(steps > 2 && step === 2 && "Choose a subnetwork to delegate to") ||
171165
(step === steps && "Review your position before creating it");
172166

173167
return (
@@ -196,21 +190,18 @@ export const CreatePositionModal: FC<React.PropsWithChildren<{}>> = ({
196190
{steps > 2 && step === 2 && (
197191
<>
198192
<div className="flex flex-col gap-2">
193+
<div className="flex flex-col gap-4 p-4 text-sm bg-slate-600 rounded">
194+
Delegating your position to a subnetwork and voting regularly
195+
earns you HNT rewards. Select the subnetwork you believe offers
196+
the greatest potential for growth and impact. This choice does
197+
not affect the rewarded amount.
198+
</div>
199199
<SubDaoSelection
200+
hideNoneOption
200201
selectedSubDaoPk={selectedSubDaoPk}
201202
onSelect={setSelectedSubDaoPk}
202203
/>
203204
<div className="flex flex-col gap-4 p-4 text-sm bg-slate-600 rounded">
204-
<div>
205-
<span className="font-medium">
206-
By selecting a subnetwork, you indicate that:
207-
</span>
208-
<ul className="flex flex-col px-6 list-disc font-light">
209-
<li>You believe in that subnetwork</li>
210-
<li>You want to help increase the subnetworks Protocol Score</li>
211-
<li>You are willing to be an active participant in governance in order to receive HNT rewards (which can be claimed on a daily basis)</li>
212-
</ul>
213-
</div>
214205
<div>
215206
<span className="font-medium">
216207
Remember the following before you delegate:

src/components/SubDaoSelection.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import classNames from "classnames";
66
import Image from "next/image";
77
import React, { FC } from "react";
88
import { Skeleton } from "./ui/skeleton";
9+
import { truthy } from "@helium/spl-utils";
10+
import { MOBILE_SUB_DAO_KEY } from "@/lib/constants";
911

1012
export const SubDaoSelection: FC<{
1113
hideNoneOption?: boolean;
@@ -64,15 +66,17 @@ export const SubDaoSelection: FC<{
6466
)}
6567
onClick={() => onSelect(subDao.pubkey)}
6668
>
67-
<div className="flex flex-col gap-1 justify-center items-center">
69+
<div className="flex flex-col justify-center items-center">
6870
<div className="size-12 rounded-full relative">
6971
<Image
7072
alt={subDao.dntMetadata.json?.name}
7173
src={subDao.dntMetadata.json?.image}
7274
fill
7375
/>
7476
</div>
75-
{subDao.dntMetadata.symbol}
77+
{subDao.dntMetadata.symbol
78+
? subDao.dntMetadata.symbol.replace(/\u0000/g, "")
79+
: ""}
7680
</div>
7781
</div>
7882
))}

src/lib/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { subDaoKey } from "@helium/helium-sub-daos-sdk";
12
import { HNT_MINT, IOT_MINT, MOBILE_MINT } from "@helium/spl-utils";
23
import { PublicKey } from "@solana/web3.js";
34

@@ -9,3 +10,7 @@ export const networksToMint: { [key: string]: PublicKey } = {
910
mobile: MOBILE_MINT,
1011
iot: IOT_MINT,
1112
};
13+
14+
export const IOT_SUB_DAO_KEY = subDaoKey(IOT_MINT)[0];
15+
16+
export const MOBILE_SUB_DAO_KEY = subDaoKey(MOBILE_MINT)[0];

0 commit comments

Comments
 (0)