diff --git a/src/app/[network]/proxies/[wallet]/page.tsx b/src/app/[network]/proxies/[wallet]/page.tsx index eed5c10..e1b2d30 100644 --- a/src/app/[network]/proxies/[wallet]/page.tsx +++ b/src/app/[network]/proxies/[wallet]/page.tsx @@ -8,6 +8,7 @@ import { VoteService, getRegistrarKey } from "@helium/voter-stake-registry-sdk"; import { PublicKey } from "@solana/web3.js"; import { HydrationBoundary, QueryClient, dehydrate, useQueryClient } from "@tanstack/react-query"; import { useMemo } from "react"; +import { notFound } from "next/navigation"; function getVoteService({ mint }: { mint: PublicKey }) { const registrar = getRegistrarKey(mint); @@ -29,16 +30,22 @@ export default async function ProxyPage({ const wallet = useMemo(() => new PublicKey(walletRaw), [walletRaw]); const queryClient = new QueryClient(); - await queryClient.prefetchQuery( + // Do not use prefetch here, because we want to error when it errors + const result = await queryClient.fetchQuery( proxyQuery({ wallet, voteService, }) ); + + + if (!result) { + return notFound(); + } + const dehydrated = dehydrate( queryClient, ); - console.log(dehydrated); return ( <> diff --git a/src/app/globals.css b/src/app/globals.css index 47482f6..1370407 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -28,8 +28,6 @@ --info-foreground: 217 91% 60%; --purple: 274 87 21%; --purple-foreground: 258 90 66%; - --pink: 336, 84%, 17%; - --pink-foreground: 330 81% 60%; --border: 214.3 31.8% 91.4%; --input: 214.3 31.8% 91.4%; --ring: 221.2 83.2% 53.3%; @@ -48,7 +46,7 @@ --secondary: 213 19% 32%; --secondary-foreground: 210 40% 98%; --muted: 217.2 32.6% 17.5%; - --muted-foreground: 213 19% 56%; + --muted-foreground: 215 20.2% 65.1%; --accent: 217.2 32.6% 17.5%; --accent-foreground: 210 40% 98%; --destructive: 0 62.8% 30.6%; diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 850c77b..a64a92a 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -10,10 +10,8 @@ export const metadata = formMetaTags(); export default function RootLayout({ children, - dehydratedState, }: { children: React.ReactNode; - dehydratedState: any; }) { return ( diff --git a/src/components/PositionCard.tsx b/src/components/PositionCard.tsx index d99837a..db6eba8 100644 --- a/src/components/PositionCard.tsx +++ b/src/components/PositionCard.tsx @@ -8,7 +8,7 @@ import { } from "@/lib/utils"; import { useGovernance } from "@/providers/GovernanceProvider"; import { useSolanaUnixNow } from "@helium/helium-react-hooks"; -import { PositionWithMeta } from "@helium/voter-stake-registry-hooks"; +import { PositionWithMeta, useKnownProxy } from "@helium/voter-stake-registry-hooks"; import BN from "bn.js"; import classNames from "classnames"; import Image from "next/image"; @@ -28,7 +28,6 @@ import { Skeleton } from "./ui/skeleton"; import { PublicKey } from "@solana/web3.js"; import { useAsync } from "react-async-hook"; import { VoteService } from "@helium/voter-stake-registry-sdk"; -import { useKnownProxy } from "@/hooks/useKnownProxy"; export const PositionCardSkeleton: FC<{ compact?: boolean }> = () => { const { network } = useGovernance(); diff --git a/src/components/PositionManager/ProxyPositionPrompt.tsx b/src/components/PositionManager/ProxyPositionPrompt.tsx index fb4ae66..6d4da0f 100644 --- a/src/components/PositionManager/ProxyPositionPrompt.tsx +++ b/src/components/PositionManager/ProxyPositionPrompt.tsx @@ -1,17 +1,15 @@ "use client"; -import { PositionWithMeta } from "@helium/voter-stake-registry-hooks"; -import React, { FC, useMemo, useState } from "react"; -import { Button } from "../ui/button"; -import { Loader2, X } from "lucide-react"; -import { PositionCard } from "../PositionCard"; -import { useKnownProxy } from "@/hooks/useKnownProxy"; -import { ProxySearch } from "../ProxySearch"; -import { ExpirationTimeSlider } from "../ExpirationTimeSlider"; -import { PublicKey } from "@solana/web3.js"; -import { RiUserSharedFill } from "react-icons/ri"; import { useGovernance } from "@/providers/GovernanceProvider"; +import { PositionWithMeta, useKnownProxy } from "@helium/voter-stake-registry-hooks"; +import { PublicKey } from "@solana/web3.js"; +import { Loader2, X } from "lucide-react"; import Link from "next/link"; +import { FC, useMemo, useState } from "react"; +import { RiUserSharedFill } from "react-icons/ri"; +import { ExpirationTimeSlider } from "../ExpirationTimeSlider"; +import { ProxySearch } from "../ProxySearch"; +import { Button } from "../ui/button"; export const ProxyPositionPrompt: FC<{ position: PositionWithMeta; @@ -22,9 +20,13 @@ export const ProxyPositionPrompt: FC<{ const isProxied = position.proxy?.nextVoter && !position.proxy?.nextVoter.equals(PublicKey.default); - const { knownProxy } = useKnownProxy(position.proxy?.nextVoter) - const [proxy, setProxy] = useState(position.proxy?.nextVoter?.toBase58() || "") - const { network } = useGovernance() + const { knownProxy } = useKnownProxy(position.proxy?.nextVoter); + const [proxy, setProxy] = useState( + position.proxy?.nextVoter.equals(PublicKey.default) + ? "" + : position.proxy?.nextVoter.toBase58() || "" + ); + const { network } = useGovernance(); const today = new Date(); const augustFirst = Date.UTC( diff --git a/src/components/Proxies.tsx b/src/components/Proxies.tsx index 050d81a..c2f1430 100644 --- a/src/components/Proxies.tsx +++ b/src/components/Proxies.tsx @@ -144,9 +144,12 @@ export function Proxies() { title="Total Voting Power" value={ proxy.delegatedVeTokens - ? humanReadable( - new BN(proxy.delegatedVeTokens), - decimals + ? // force 2 decimals + humanReadable( + new BN(proxy.delegatedVeTokens).div( + new BN(Math.pow(10, (decimals || 0) - 2)) + ), + 2 )! : "0" } diff --git a/src/components/ProxyProfile.tsx b/src/components/ProxyProfile.tsx index 1d5c39f..363db3d 100644 --- a/src/components/ProxyProfile.tsx +++ b/src/components/ProxyProfile.tsx @@ -10,10 +10,7 @@ import { useProxiedTo, useUnassignProxies, } from "@helium/voter-stake-registry-hooks"; -import { - VoteService, - getRegistrarKey -} from "@helium/voter-stake-registry-sdk"; +import { VoteService, getRegistrarKey } from "@helium/voter-stake-registry-sdk"; import { PublicKey } from "@solana/web3.js"; import { useQuery } from "@tanstack/react-query"; import BN from "bn.js"; @@ -42,7 +39,6 @@ export function ProxyProfile({ wallet: walletRaw }: { wallet: string }) { voteService, }) ); - console.log("raw", error); // Due to hydration, should always be present const proxy = proxyRaw!; const detail = proxy.detail; @@ -93,8 +89,14 @@ export function ProxyProfile({ wallet: walletRaw }: { wallet: string }) { TOTAL POWER
- {proxy.delegatedVeTokens - ? humanReadable(new BN(proxy.delegatedVeTokens), decimals) + {proxy.delegatedVeTokens && decimals + ? // Force 2 decimals + humanReadable( + new BN(proxy.delegatedVeTokens).div( + new BN(Math.pow(10, decimals - 2)) + ), + 2 + ) : "0"}
@@ -144,7 +146,10 @@ export function ProxyProfile({ wallet: walletRaw }: { wallet: string }) { POWER FROM ME
- {humanReadable(votingPower, decimals)} + {humanReadable( + votingPower.div(new BN(Math.pow(10, (decimals || 0) - 2))), + 2 + )}
@@ -177,7 +182,7 @@ export function ProxyProfile({ wallet: walletRaw }: { wallet: string }) {
Profile

{proxy.name}

- {ellipsisMiddle(proxy.wallet)} + + {proxy.wallet && ellipsisMiddle(proxy.wallet)} +
@@ -225,7 +232,7 @@ export function ProxyProfile({ wallet: walletRaw }: { wallet: string }) {
- {detail} + {detail || `${proxy.wallet}`}
{infoCard}
diff --git a/src/components/ProxySearch.tsx b/src/components/ProxySearch.tsx index 6c9726e..8faaf59 100644 --- a/src/components/ProxySearch.tsx +++ b/src/components/ProxySearch.tsx @@ -5,7 +5,10 @@ import React, { useMemo, useState } from "react"; import { AutoComplete } from "./ui/autocomplete"; import { Loader2 } from "lucide-react"; import { useInfiniteQuery } from "@tanstack/react-query"; -import { proxiesQuery } from "@helium/voter-stake-registry-hooks"; +import { + proxiesQuery, + useHeliumVsrState, +} from "@helium/voter-stake-registry-hooks"; export const ProxySearch: React.FC<{ value: string; @@ -13,10 +16,12 @@ export const ProxySearch: React.FC<{ }> = ({ value, onValueChange }) => { const [input, setInput] = useState(value); const debouncedInput = useDebounce(input, 300); - const { data: resultPaged, isLoading, error } = useInfiniteQuery( + const { voteService } = useHeliumVsrState(); + const { data: resultPaged, isLoading } = useInfiniteQuery( proxiesQuery({ search: debouncedInput || "", amountPerPage: 20, + voteService, }) ); @@ -38,7 +43,7 @@ export const ProxySearch: React.FC<{ }, [resultPaged, debouncedInput]); const selectedOption = useMemo(() => { return result?.find((r) => r.value == value); - }, [result, value]) + }, [result, value]); if (value && !selectedOption) { return ; diff --git a/src/components/VoteHistory.tsx b/src/components/VoteHistory.tsx index 4018dff..942615d 100644 --- a/src/components/VoteHistory.tsx +++ b/src/components/VoteHistory.tsx @@ -123,7 +123,7 @@ const ProposalItem: React.FC<{ name="Percent of Vote" value={ // Calc with 4 decimals precision - proposal.votes[0].weight + proposal.votes[0].weight && !votingResults.totalVotes.isZero() ? ( new BN(proposal.votes[0].weight) .mul(new BN(10000)) diff --git a/src/components/VoteOption.tsx b/src/components/VoteOption.tsx index 404b112..f5694d5 100644 --- a/src/components/VoteOption.tsx +++ b/src/components/VoteOption.tsx @@ -7,8 +7,8 @@ import React, { FC } from "react"; import { FaCircle, FaCircleCheck } from "react-icons/fa6"; import { Loader2 } from "lucide-react"; import { PublicKey } from "@solana/web3.js"; -import { useKnownProxy } from "@/hooks/useKnownProxy"; import { Pill } from "./Pill"; +import { useKnownProxy } from "@helium/voter-stake-registry-hooks"; export const VoteOption: FC<{ option: VoteChoiceWithMeta;