Skip to content

Commit

Permalink
fix: server side supabase loading
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinmarnold committed Sep 8, 2024
1 parent 3fadef7 commit 76d9e2d
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 45 deletions.
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@aarc-xyz/deposit-widget": "^0.2.1",
"@clerk/nextjs": "^5.2.8",
"@clerk/nextjs": "^5.4.1",
"@clerk/themes": "^2.1.1",
"@headlessui/react": "^1.7.19",
"@popperjs/core": "^2.11.8",
Expand Down
10 changes: 6 additions & 4 deletions src/app/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { Suspense } from "react";

import Loader from "@/components/Loader";
import LockerNav from "@/components/LockerNav";
import { LockerPortfolioProvider } from "@/components/LockerPortfolioContext";
import { LockerProvider } from "@/providers/LockerProvider";
import { LockerDb, PolicyDb } from "@/types";
import { TABLE_LOCKERS } from "@/utils/supabase/tables";

import { supabaseServerClient } from "../utils/server";
import { createClerkSupabaseClientSsr } from "../utils/server";

async function HomePage() {
const supabaseServerClient = createClerkSupabaseClientSsr();

const { data: lockersData, error: lockersError } =
await supabaseServerClient
.from(TABLE_LOCKERS)
Expand Down Expand Up @@ -46,13 +48,13 @@ async function HomePage() {
return (
<div className="flex w-full flex-1 flex-col items-center py-12">
<Suspense fallback={<Loader />}>
<LockerPortfolioProvider
<LockerProvider
initialLockers={lockers}
initialPolicies={policies}
initialOfframpAddresses={[]}
>
<LockerNav />
</LockerPortfolioProvider>
</LockerProvider>
</Suspense>
</div>
);
Expand Down
2 changes: 0 additions & 2 deletions src/app/utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,3 @@ export function createClerkSupabaseClientSsr() {
}
);
}

export const supabaseServerClient = createClerkSupabaseClientSsr();
4 changes: 2 additions & 2 deletions src/components/LockerNav.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use client";

import { useLocker } from "../providers/LockerProvider";
import LockerCreate from "./LockerCreate";
import LockerPortfolio from "./LockerPortfolio";
import { useLockerPortfolio } from "./LockerPortfolioContext";
import LockerSetup from "./LockerSetup";

function LockerNav() {
const { lockers, policies } = useLockerPortfolio();
const { lockers, policies } = useLocker();

const shouldCreateLocker = lockers && lockers.length === 0;
if (shouldCreateLocker) return <LockerCreate lockerIndex={0} />;
Expand Down
4 changes: 2 additions & 2 deletions src/components/LockerPortfolio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import { getFundedChainIds } from "@/utils/getFundedChainIds";
import { isChainSupported } from "@/utils/isChainSupported";
import { isTestnet } from "@/utils/isTestnet";

import { useLockerPortfolio } from "./LockerPortfolioContext";
import { useLocker } from "../providers/LockerProvider";

function LockerPortfolio() {
const { lockers, policies, txs, offrampAddresses } = useLockerPortfolio();
const { lockers, policies, txs, offrampAddresses } = useLocker();
const [errorMessage, setErrorMessage] = useState<string>("");
const [tokenList, setTokenList] = useState<Token[]>([]);
const [fundedChainIds, setFundedChainIds] = useState<number[]>([]);
Expand Down
6 changes: 3 additions & 3 deletions src/components/LockerSetup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { useAccount } from "wagmi";
import ChannelPieChart from "@/components/ChannelPieChart";
import ChannelSelection from "@/components/ChannelSelection";
import DistributionBox from "@/components/DistributionBox";
import Steps from "@/components/Steps";
import TxTable from "@/components/TxTable";
import { disclosures } from "@/data/constants/disclosures";
import { errors } from "@/data/constants/errorMessages";
import { useConnectModal } from "@/hooks/useConnectModal";
import { usePolicyReviewModal } from "@/hooks/usePolicyReviewModal";
import useSmartAccount from "@/hooks/useSmartAccount";
import { useLocker } from "@/providers/LockerProvider";
import { createPolicy } from "@/services/lockers";
import {
Automation,
Expand All @@ -26,10 +26,10 @@ import {
} from "@/types";
import { isChainSupported } from "@/utils/isChainSupported";

import { useLockerPortfolio } from "./LockerPortfolioContext";
import Steps from "./Steps";

function LockerSetup() {
const { lockers } = useLockerPortfolio();
const { lockers } = useLocker();
const [sendToAddress, setSendToAddress] = useState<string>(
lockers[0].ownerAddress
);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
} from "@supabase/supabase-js";
import { useCallback, useEffect, useState } from "react";

import { convertKeysToCamelCase } from "../../utils/strings";
import { supabaseJwtClient } from "../../utils/supabase/jwt";
import { convertKeysToCamelCase } from "@/utils/strings";
import { supabaseJwtClient } from "@/utils/supabase/jwt";

import { useJwt } from "./useJwt";

export const useRealtimeTable = <T extends { id: number }>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { createContext, ReactNode, useContext, useMemo, useState } from "react";

import { useRealtimeTable } from "@/app/utils/useRealtimeTable";
import { useRealtimeTable } from "@/hooks/useRealtimeTable";
import { LockerDb, PolicyDb, Tx } from "@/types";
import {
TABLE_LOCKERS,
Expand All @@ -29,7 +29,7 @@ const LockerPortfolioContext = createContext<
>(undefined);

// Provider component
export function LockerPortfolioProvider({
export function LockerProvider({
initialLockers,
initialPolicies,
initialOfframpAddresses,
Expand Down Expand Up @@ -73,7 +73,7 @@ export function LockerPortfolioProvider({
}

// Custom hook for accessing the context
export const useLockerPortfolio = (): LockerPortfolioContextProps => {
export const useLocker = (): LockerPortfolioContextProps => {
const context = useContext(LockerPortfolioContext);
if (!context) {
throw new Error(
Expand Down

0 comments on commit 76d9e2d

Please sign in to comment.