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

Fix new created entity outlined #448

Merged
merged 25 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 21 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { PoolMetrics, Proposals } from "@/components";
import { LoadingSpinner } from "@/components/LoadingSpinner";
import PoolHeader from "@/components/PoolHeader";
import { QUERY_PARAMS } from "@/constants/query-params";
import { useCollectQueryParams } from "@/hooks/useCollectQueryParams";
import { useCollectQueryParams } from "@/contexts/collectQueryParams.context";
import { useMetadataIpfsFetch } from "@/hooks/useIpfsFetch";
import { useSubgraphQuery } from "@/hooks/useSubgraphQuery";
import { PoolTypes } from "@/types";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import MarkdownWrapper from "@/components/MarkdownWrapper";
import { TokenGardenFaucet } from "@/components/TokenGardenFaucet";
import { isProd } from "@/configs/isProd";
import { QUERY_PARAMS } from "@/constants/query-params";
import { useCollectQueryParams } from "@/hooks/useCollectQueryParams";
import { useCollectQueryParams } from "@/contexts/collectQueryParams.context";
import { useDisableButtons } from "@/hooks/useDisableButtons";
import { useSubgraphQuery } from "@/hooks/useSubgraphQuery";
import { PoolTypes } from "@/types";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/(app)/gardens/[chain]/[garden]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { LoadingSpinner } from "@/components/LoadingSpinner";
import { TokenGardenFaucet } from "@/components/TokenGardenFaucet";
import { isProd } from "@/configs/isProd";
import { QUERY_PARAMS } from "@/constants/query-params";
import { useCollectQueryParams } from "@/hooks/useCollectQueryParams";
import { useCollectQueryParams } from "@/contexts/collectQueryParams.context";
import { useDisableButtons } from "@/hooks/useDisableButtons";
import { useSubgraphQuery } from "@/hooks/useSubgraphQuery";

Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/CommunityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Card } from "./Card";
import { Statistic } from "./Statistic";
import { commImg } from "@/assets";
import { QUERY_PARAMS } from "@/constants/query-params";
import { useCollectQueryParams } from "@/hooks/useCollectQueryParams";
import { useCollectQueryParams } from "@/contexts/collectQueryParams.context";

type CommunityCardProps = {
name: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/PoolCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { blueLand, grass } from "@/assets";
import { Badge, Card, DisplayNumber, Statistic } from "@/components";
import { QUERY_PARAMS } from "@/constants/query-params";
import { useCollectQueryParams } from "@/hooks/useCollectQueryParams";
import { useCollectQueryParams } from "@/contexts/collectQueryParams.context";
import { PointSystems, PoolTypes } from "@/types";
import { capitalize } from "@/utils/text";

Expand Down
4 changes: 2 additions & 2 deletions apps/web/components/ProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getProposals } from "@/actions/getProposals";
import { Badge, Card } from "@/components";
import { ConvictionBarChart } from "@/components/Charts/ConvictionBarChart";
import { QUERY_PARAMS } from "@/constants/query-params";
import { useCollectQueryParams } from "@/hooks/useCollectQueryParams";
import { useCollectQueryParams } from "@/contexts/collectQueryParams.context";
import { useConvictionRead } from "@/hooks/useConvictionRead";
import { PoolTypes } from "@/types";
import { calculatePercentage } from "@/utils/numbers";
Expand Down Expand Up @@ -233,7 +233,7 @@ export function ProposalCard({
proposalCardContent
: <Card
href={`${pathname}/${id}`}
className={`py-4 ${isNewProposal ? "shadow-xl" : ""}`}
className={`py-4 ${isNewProposal ? "shadow-2xl" : ""}`}
>
{proposalCardContent}
</Card>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/configs/subgraph.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"VERSION_TESTNET": "0.0.2",
"VERSION_PROD": "0.0.3"
"VERSION_PROD": "0.0.4"
}
61 changes: 61 additions & 0 deletions apps/web/contexts/collectQueryParams.context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {
createContext,
useContext,
ReactNode,
useState,
useEffect,
useRef,
} from "react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { logOnce } from "@/utils/log";

// Define the context
interface QueryParamsContextType {
[key: string]: string;
}
const QueryParamsContext = createContext<QueryParamsContextType | undefined>(
undefined,
);

// Create a provider component
export const QueryParamsProvider = ({ children }: { children: ReactNode }) => {
const searchParams = useSearchParams();
const router = useRouter();
const path = usePathname();
const [queryParams, setQueryParams] = useState<{ [k: string]: string }>({});
const pathRef = useRef(path);

useEffect(() => {
const params = Object.fromEntries(searchParams.entries());
setQueryParams((old) => {
if (!Object.keys(queryParams).length) {
logOnce("debug", "QueryParamsProvider: collected query params", params);
return params;
}
return old;
});
}, [searchParams]);

useEffect(() => {
router.push(path); // Navigate to the path without query params
if (pathRef.current !== path) {
setQueryParams({}); // Reset query params when changing page
}
pathRef.current = path;
}, [router, path]);

return (
<QueryParamsContext.Provider value={queryParams}>
{children}
</QueryParamsContext.Provider>
);
};

// Custom hook to use the query parameters
export const useCollectQueryParams = () => {
const context = useContext(QueryParamsContext);
if (context === undefined) {
throw new Error("useQueryParams must be used within a QueryParamsProvider");
}
return context;
};
27 changes: 0 additions & 27 deletions apps/web/hooks/useCollectQueryParams.ts

This file was deleted.

25 changes: 14 additions & 11 deletions apps/web/hooks/useSubgraphQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function useSubgraphQuery<
}
setFetching(true);
fetchingRef.current = true;
const res = await refetch();
const res = await refetch(undefined, false);
setResponse(res);
setFetching(false);
fetchingRef.current = false;
Expand All @@ -151,19 +151,22 @@ export function useSubgraphQuery<

const refetch = async (
retryCount?: number,
withToast: boolean = true,
): Promise<Awaited<ReturnType<typeof fetch>>> => {
const result = await fetch();
if (!retryCount) {
retryCount = 0;
toast.loading("Pulling new data", {
toastId: pendingRefreshToastId,
autoClose: false,
closeOnClick: true,
style: {
width: "fit-content",
marginLeft: "auto",
},
});
if (withToast) {
toast.loading("Pulling new data", {
toastId: pendingRefreshToastId,
autoClose: false,
closeOnClick: true,
style: {
width: "fit-content",
marginLeft: "auto",
},
});
}
}

if (result.error) {
Expand Down Expand Up @@ -246,7 +249,7 @@ export function useSubgraphQuery<
return {
...response,
refetch: () => {
return refetchFromOutside();
return refetch();
},
fetching,
};
Expand Down
13 changes: 12 additions & 1 deletion apps/web/hooks/useSubgraphQueryMultiChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@ import { initUrqlClient } from "@/providers/urql";
import { ChainId } from "@/types";
import { delayAsync } from "@/utils/delayAsync";

let isQueryAllChains = false;
try {
isQueryAllChains = localStorage.getItem("queryAllChains") === "true";
} catch (error) {
// ignore when not browser side
}

const allChains: ChainId[] = Object.values(chains)
.filter((x) => (isProd ? !x.testnet : !!x.testnet || x.id === localhost.id))
.filter(
(x) =>
isQueryAllChains ||
(isProd ? !x.testnet : !!x.testnet || x.id === localhost.id),
)
.map((x) => x.id);

const pendingRefreshToastId = "pending-refresh";
Expand Down
5 changes: 4 additions & 1 deletion apps/web/providers/Providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { alchemyProvider } from "wagmi/providers/alchemy";
import { publicProvider } from "wagmi/providers/public";
import ThemeProvider from "./ThemeProvider";
import { UrqlProvider } from "./UrqlProvider";
import { QueryParamsProvider } from "@/contexts/collectQueryParams.context";
import { PubSubProvider } from "@/contexts/pubsub.context";
import { useChainFromPath } from "@/hooks/useChainFromPath";

Expand Down Expand Up @@ -94,7 +95,9 @@ const Providers = ({ children }: Props) => {
})}
>
<ThemeProvider>
<PubSubProvider>{mounted && children}</PubSubProvider>
<QueryParamsProvider>
<PubSubProvider>{mounted && children}</PubSubProvider>
</QueryParamsProvider>
</ThemeProvider>
</RainbowKitProvider>
</AddrethConfig>
Expand Down
2 changes: 1 addition & 1 deletion pkg/contracts/out/CollateralVault.sol/CollateralVault.json

Large diffs are not rendered by default.

Loading
Loading