Skip to content

Commit fd41657

Browse files
committed
feat: rerenders error fixed
1 parent 6658da7 commit fd41657

File tree

6 files changed

+126
-40
lines changed

6 files changed

+126
-40
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@rainbow-me/rainbowkit": "^1.0.8",
2121
"@rainbow-me/rainbowkit-siwe-next-auth": "^0.3.0",
2222
"@tanstack/react-query": "^4.29.19",
23+
"@tanstack/react-query-devtools": "^4.32.5",
2324
"@trpc/client": "^10.33.0",
2425
"@trpc/next": "^10.33.0",
2526
"@trpc/react-query": "^10.33.0",
@@ -61,7 +62,7 @@
6162
"lint-staged": "^13.2.3",
6263
"postcss": "^8.4.24",
6364
"prettier": "^2.8.8",
64-
"prettier-plugin-tailwindcss": "^0.3.0",
65+
"prettier-plugin-tailwindcss": "0.2.1",
6566
"prisma": "^5.0.0",
6667
"react-syntax-highlighter": "^15.5.0",
6768
"remark-frontmatter": "^4.0.1",

src/components/Topbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export default function Topbar() {
120120
spacing={6}
121121
minW={"10rem"}
122122
>
123-
<ConnectButton />
123+
<ConnectButton accountStatus="address" />
124124
</Stack>
125125
</Flex>
126126

src/pages/_app.tsx

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ import "@/styles/globals.css";
1212
import "@rainbow-me/rainbowkit/styles.css";
1313

1414
import { RainbowKitSiweNextAuthProvider } from "@rainbow-me/rainbowkit-siwe-next-auth";
15-
import { getDefaultWallets, RainbowKitProvider } from "@rainbow-me/rainbowkit";
15+
import {
16+
connectorsForWallets,
17+
getDefaultWallets,
18+
RainbowKitProvider,
19+
} from "@rainbow-me/rainbowkit";
20+
import {
21+
ledgerWallet,
22+
trustWallet,
23+
zerionWallet,
24+
} from "@rainbow-me/rainbowkit/wallets";
1625

1726
// SIWE Integration
1827
import { WagmiConfig, createConfig, configureChains } from "wagmi";
@@ -24,6 +33,7 @@ import { MDXProvider } from "@mdx-js/react";
2433
import Components from "@/components/mdx/Components";
2534
import Layout from "@/components/Layout";
2635
import { env } from "@/env.mjs";
36+
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
2737

2838
// Config
2939
// ========================================================
@@ -35,12 +45,26 @@ const { chains, publicClient } = configureChains(
3545
[publicProvider()],
3646
);
3747

38-
const { connectors } = getDefaultWallets({
48+
const projectId = env.NEXT_PUBLIC_WALLET_CONNECT_ID;
49+
50+
const { wallets } = getDefaultWallets({
3951
appName: "D_D Academy",
40-
projectId: env.NEXT_PUBLIC_WALLET_CONNECT_ID,
52+
projectId,
4153
chains,
4254
});
4355

56+
const connectors = connectorsForWallets([
57+
...wallets,
58+
{
59+
groupName: "Other",
60+
wallets: [
61+
zerionWallet({ projectId, chains }),
62+
trustWallet({ projectId, chains }),
63+
ledgerWallet({ projectId, chains }),
64+
],
65+
},
66+
]);
67+
4468
const wagmiConfig = createConfig({
4569
autoConnect: true,
4670
connectors,
@@ -51,21 +75,22 @@ const wagmiConfig = createConfig({
5175
// ========================================================
5276
const MyApp: AppType<{ session: Session | null }> = ({
5377
Component,
54-
pageProps: { session, ...pageProps },
78+
pageProps,
5579
}) => {
5680
return (
5781
<ChakraProvider theme={theme}>
5882
<WagmiConfig config={wagmiConfig}>
59-
<SessionProvider refetchInterval={0} session={session}>
83+
<SessionProvider refetchInterval={0} session={pageProps.session}>
6084
<RainbowKitSiweNextAuthProvider>
61-
<RainbowKitProvider chains={chains}>
62-
<React.StrictMode>
63-
<MDXProvider components={Components}>
64-
<Layout>
85+
<RainbowKitProvider chains={chains} initialChain={polygonMumbai}>
86+
<MDXProvider components={Components}>
87+
<Layout>
88+
<>
6589
<Component {...pageProps} />
66-
</Layout>
67-
</MDXProvider>
68-
</React.StrictMode>
90+
<ReactQueryDevtools />
91+
</>
92+
</Layout>
93+
</MDXProvider>
6994
</RainbowKitProvider>
7095
</RainbowKitSiweNextAuthProvider>
7196
</SessionProvider>

src/pages/getting-started.tsx

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import fs from "fs";
2222
import path from "path";
2323
import matter from "gray-matter";
2424
import { CONTENT_PATH } from "@/lib/constants";
25-
import { useMemo, useState } from "react";
25+
import { useEffect, useState } from "react";
2626
import { api } from "@/utils/api";
2727
import { useSession } from "next-auth/react";
28+
import { useAccount } from "wagmi";
2829

2930
export interface Lesson {
3031
frontMatter: any;
@@ -81,52 +82,83 @@ export interface ProjectFrontMatter {
8182
const GettingStarted: React.FC<Lessons> = ({ lessons }) => {
8283
const [formattedLessons, setFormattedLessons] = useState<LessonProps>();
8384

84-
const [fetchNow, setFetchNow] = useState<boolean>(true);
85+
const [fetchNow, setFetchNow] = useState(true);
8586
const { data: sessionData } = useSession();
8687

88+
const { address } = useAccount();
89+
8790
// Requests
8891
// - All
8992
const {
9093
data: completedQuizzesAllData,
91-
// isLoading: completedQuizzesAllIsLoading,
94+
isLoading: completedQuizzesAllIsLoading,
95+
refetch: refetchCompletedQuizzesAll,
9296
} = api.completedQuizzes.all.useQuery(
9397
undefined, // no input
9498
{
9599
// Disable request if no session data
96100
enabled: sessionData?.user !== undefined && fetchNow,
97-
onSuccess: () => {
98-
// setNewTodo(""); // reset input form
99-
},
100101
},
101102
);
102103

103-
useMemo(() => {
104-
if (completedQuizzesAllData?.length && fetchNow) {
105-
const result: LessonProps = lessons.reduce((acc: any, curr: any) => {
106-
if (!acc[curr.path]) acc[curr.path] = [];
104+
useEffect(() => {
105+
const result: LessonProps = lessons.reduce((acc: any, curr: any) => {
106+
if (!acc[curr.path]) acc[curr.path] = [];
107+
108+
acc[curr.path].push(curr);
109+
return acc;
110+
}, {});
107111

108-
acc[curr.path].push(curr);
109-
return acc;
110-
}, {});
112+
if (sessionData?.user !== undefined && !!completedQuizzesAllData) {
113+
console.log(
114+
"1 ",
115+
{ completedQuizzesAllData },
116+
{
117+
a: !completedQuizzesAllIsLoading,
118+
b: !!completedQuizzesAllData,
119+
},
120+
);
111121

112-
let completedQuizzes: Project[] = [];
113122
const completedSlugs: string[] = completedQuizzesAllData?.map(
114123
(quiz: any) =>
115124
quiz.lesson
116125
.replace("quiz-lesson-", "")
117126
.replace("lesson-", "")
118127
.replace("-quiz", "") || [],
119128
);
120-
completedQuizzes = result?.projects?.map((project: Project) => {
121-
if (completedSlugs.includes(project.slug)) project.completed = true;
122-
else project.completed = false;
123-
return project;
124-
});
129+
130+
const completedQuizzes: Project[] = result?.projects?.map(
131+
(project: Project) => {
132+
if (completedSlugs.includes(project.slug)) project.completed = true;
133+
else project.completed = false;
134+
return project;
135+
},
136+
);
125137

126138
setFormattedLessons({ ...result, projects: completedQuizzes });
127139
setFetchNow(false);
140+
console.log("1");
141+
} else {
142+
setFormattedLessons(result);
143+
// setFetchNow(false);
144+
console.log("2");
128145
}
129-
}, [completedQuizzesAllData, fetchNow, lessons]);
146+
}, [
147+
completedQuizzesAllData,
148+
completedQuizzesAllIsLoading,
149+
lessons,
150+
sessionData,
151+
]);
152+
153+
console.log({ address });
154+
155+
// useEffect(() => {
156+
// if (address) {
157+
// console.log("Refetch");
158+
// refetchCompletedQuizzesAll();
159+
// }
160+
// // eslint-disable-next-line react-hooks/exhaustive-deps
161+
// }, [address]);
130162

131163
return (
132164
<Flex

src/server/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import CredentialsProvider from "next-auth/providers/credentials";
1313
import { SiweMessage } from "siwe";
1414
import { getCsrfToken } from "next-auth/react";
1515
import type { Session } from "next-auth";
16-
import { PrismaAdapter } from "@next-auth/prisma-adapter";
16+
// import { PrismaAdapter } from "@next-auth/prisma-adapter";
1717
// import { env } from "@/env.mjs";
1818

1919
// Types
@@ -106,7 +106,7 @@ export const authOptions: (ctxReq: CtxOrReq) => NextAuthOptions = ({
106106
// OTHER OPTIONS (not needed)
107107
session: { strategy: "jwt" },
108108
secret: process.env.NEXTAUTH_SECRET, // in case you want pass this along for other functionality
109-
adapter: PrismaAdapter(prisma), // Not meant for type 'credentials' (used for db sessions)
109+
// adapter: PrismaAdapter(prisma), // Not meant for type 'credentials' (used for db sessions)
110110
// jwt: { // Custom functionlaity for jwt encoding/decoding
111111
// encode: async ({ token, secret, maxAge }: JWTEncodeParams) => {
112112
// return encode({

yarn.lock

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,6 +1863,13 @@
18631863
dependencies:
18641864
tslib "^2.4.0"
18651865

1866+
"@tanstack/match-sorter-utils@^8.7.0":
1867+
version "8.8.4"
1868+
resolved "https://registry.yarnpkg.com/@tanstack/match-sorter-utils/-/match-sorter-utils-8.8.4.tgz#0b2864d8b7bac06a9f84cb903d405852cc40a457"
1869+
integrity sha512-rKH8LjZiszWEvmi01NR72QWZ8m4xmXre0OOwlRGnjU01Eqz/QnN+cqpty2PJ0efHblq09+KilvyR7lsbzmXVEw==
1870+
dependencies:
1871+
remove-accents "0.4.2"
1872+
18661873
"@tanstack/[email protected]":
18671874
version "4.29.15"
18681875
resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-4.29.15.tgz#6f8721341dbece517326a8e402d29ea3365538a8"
@@ -1887,6 +1894,15 @@
18871894
dependencies:
18881895
"@tanstack/query-persist-client-core" "4.29.15"
18891896

1897+
"@tanstack/react-query-devtools@^4.32.5":
1898+
version "4.32.5"
1899+
resolved "https://registry.yarnpkg.com/@tanstack/react-query-devtools/-/react-query-devtools-4.32.5.tgz#c859c3a812f52f32b6750fcaf921919746083de4"
1900+
integrity sha512-4JJjf8M2Q3X0fs5GTzq3DvVemeyEw1ASiFdAyVxuMCh8D4m45aqNMuYGsRTNVN2JMNnuLaBKctSB8t0iTNIEZQ==
1901+
dependencies:
1902+
"@tanstack/match-sorter-utils" "^8.7.0"
1903+
superjson "^1.10.0"
1904+
use-sync-external-store "^1.2.0"
1905+
18901906
"@tanstack/react-query-persist-client@^4.28.0":
18911907
version "4.29.15"
18921908
resolved "https://registry.yarnpkg.com/@tanstack/react-query-persist-client/-/react-query-persist-client-4.29.15.tgz#3c9ce05b187eb27fc47684f00d331481c2fd03c8"
@@ -6634,10 +6650,10 @@ prelude-ls@^1.2.1:
66346650
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
66356651
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==
66366652

6637-
prettier-plugin-tailwindcss@^0.3.0:
6638-
version "0.3.0"
6639-
resolved "https://registry.yarnpkg.com/prettier-plugin-tailwindcss/-/prettier-plugin-tailwindcss-0.3.0.tgz#8299b307c7f6467f52732265579ed9375be6c818"
6640-
integrity sha512-009/Xqdy7UmkcTBpwlq7jsViDqXAYSOMLDrHAdTMlVZOrKfM2o9Ci7EMWTMZ7SkKBFTG04UM9F9iM2+4i6boDA==
6653+
prettier-plugin-tailwindcss@0.2.1:
6654+
version "0.2.1"
6655+
resolved "https://registry.yarnpkg.com/prettier-plugin-tailwindcss/-/prettier-plugin-tailwindcss-0.2.1.tgz#989b35afd86c550cb671da69891aba4f4a051159"
6656+
integrity sha512-aIO8IguumORyRsmT+E7JfJ3A9FEoyhqZR7Au7TBOege3VZkgMvHJMkufeYp4zjnDK2iq4ktkvGMNOQR9T8lisQ==
66416657

66426658
prettier@^2.8.8:
66436659
version "2.8.8"
@@ -6995,6 +7011,11 @@ remark-rehype@^10.0.0:
69957011
mdast-util-to-hast "^12.1.0"
69967012
unified "^10.0.0"
69977013

7014+
7015+
version "0.4.2"
7016+
resolved "https://registry.yarnpkg.com/remove-accents/-/remove-accents-0.4.2.tgz#0a43d3aaae1e80db919e07ae254b285d9e1c7bb5"
7017+
integrity sha512-7pXIJqJOq5tFgG1A2Zxti3Ht8jJF337m4sowbuHsW30ZnkQFnDzy9qBNhgzX8ZLW4+UBcXiiR7SwR6pokHsxiA==
7018+
69987019
require-directory@^2.1.1:
69997020
version "2.1.1"
70007021
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
@@ -7538,6 +7559,13 @@ [email protected]:
75387559
dependencies:
75397560
copy-anything "^3.0.2"
75407561

7562+
superjson@^1.10.0:
7563+
version "1.13.1"
7564+
resolved "https://registry.yarnpkg.com/superjson/-/superjson-1.13.1.tgz#a0b6ab5d22876f6207fcb9d08b0cb2acad8ee5cd"
7565+
integrity sha512-AVH2eknm9DEd3qvxM4Sq+LTCkSXE2ssfh1t11MHMXyYXFQyQ1HLgVvV+guLTsaQnJU3gnaVo34TohHPulY/wLg==
7566+
dependencies:
7567+
copy-anything "^3.0.2"
7568+
75417569
superstruct@^0.14.2:
75427570
version "0.14.2"
75437571
resolved "https://registry.yarnpkg.com/superstruct/-/superstruct-0.14.2.tgz#0dbcdf3d83676588828f1cf5ed35cda02f59025b"

0 commit comments

Comments
 (0)