From b4414f57a90179b4f6f6e82d086660b14ce3ca24 Mon Sep 17 00:00:00 2001 From: Stephen Gordon Date: Wed, 31 Jan 2024 12:17:13 +0000 Subject: [PATCH] fixed kernal redux state --- package-lock.json | 10 ++++++++ package.json | 2 ++ .../kernalClient/kernalClientSlice.tsx | 4 ++-- src/GlobalRedux/provider.tsx | 14 ++++------- src/app/layout.tsx | 4 +++- src/app/page.tsx | 24 ++++++++++++++----- 6 files changed, 40 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 33d31b3..a64c4b6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,8 @@ "react-icons": "^4.12.0", "react-redux": "^9.1.0", "redux": "^5.0.1", + "redux-persist": "^6.0.0", + "redux-thunk": "^3.1.0", "reverse-mirage": "^1.0.3", "tailwind-merge": "^2.1.0", "truncate-eth-address": "^1.0.2", @@ -22172,6 +22174,14 @@ "resolved": "https://registry.npmjs.org/redux/-/redux-5.0.1.tgz", "integrity": "sha512-M9/ELqF6fy8FwmkpnF0S3YKOqMyoWJ4+CS5Efg2ct3oY9daQvd/Pc71FpGZsVsbl3Cpb+IIcjBDUnnyBdQbq4w==" }, + "node_modules/redux-persist": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/redux-persist/-/redux-persist-6.0.0.tgz", + "integrity": "sha512-71LLMbUq2r02ng2We9S215LtPu3fY0KgaGE0k8WRgl6RkqxtGfl7HUozz1Dftwsb0D/5mZ8dwAaPbtnzfvbEwQ==", + "peerDependencies": { + "redux": ">4.0.0" + } + }, "node_modules/redux-thunk": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/redux-thunk/-/redux-thunk-3.1.0.tgz", diff --git a/package.json b/package.json index 21691f7..b2fd458 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,8 @@ "react-icons": "^4.12.0", "react-redux": "^9.1.0", "redux": "^5.0.1", + "redux-persist": "^6.0.0", + "redux-thunk": "^3.1.0", "reverse-mirage": "^1.0.3", "tailwind-merge": "^2.1.0", "truncate-eth-address": "^1.0.2", diff --git a/src/GlobalRedux/Features/kernalClient/kernalClientSlice.tsx b/src/GlobalRedux/Features/kernalClient/kernalClientSlice.tsx index 541ef66..18da45e 100644 --- a/src/GlobalRedux/Features/kernalClient/kernalClientSlice.tsx +++ b/src/GlobalRedux/Features/kernalClient/kernalClientSlice.tsx @@ -8,10 +8,10 @@ export const kernalClientSlice = createSlice({ value: {}, }, reducers: { - kernalClient: (state, action) => { + setKernalClient: (state, action) => { state.value = action.payload; }, }, }); -export const { kernalClient } = kernalClientSlice.actions; +export const { setKernalClient } = kernalClientSlice.actions; export default kernalClientSlice.reducer; diff --git a/src/GlobalRedux/provider.tsx b/src/GlobalRedux/provider.tsx index ea780cc..b76af71 100644 --- a/src/GlobalRedux/provider.tsx +++ b/src/GlobalRedux/provider.tsx @@ -1,12 +1,8 @@ 'use client'; -import { Provider } from "react-redux" -import { store } from "./store"; - +import { Provider } from 'react-redux'; +import { store } from './store'; +import { Children } from 'react'; export function Providers({ children }) { - return ( - - {children} - - ) -} \ No newline at end of file + return {children}; +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index dafa338..8f93242 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -20,7 +20,9 @@ import { siteConfig } from '@/constant/config'; // Redux import { useSelector } from 'react-redux'; -import { RootState } from '@/GlobalRedux/store'; +import { RootState, persistor } from '@/GlobalRedux/store'; + +import { PersistGate } from 'redux-persist/integration/react'; // !STARTERCONF Change these default meta // !STARTERCONF Look at @/constant/config to change them diff --git a/src/app/page.tsx b/src/app/page.tsx index 1901912..73c087c 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -19,6 +19,11 @@ import Balance from '@/app/components/Balance/Balance'; import useCreateKernal from '@/app/utils/useCreateKernal'; import Link from 'next/link'; +// +import { setKernalClient } from '@/GlobalRedux/Features/kernalClient/kernalClientSlice'; + +import { parseEther } from 'viem'; + const chainConfig = { chainNamespace: CHAIN_NAMESPACES.EIP155, chainId: '0x13881', @@ -48,7 +53,7 @@ web3auth.configureAdapter(openloginAdapter); export default function HomePage() { const [provider, setProvider] = useState(null); const [loggedIn, setLoggedIn] = useState(false); - const [kernalClient, setKernalClient] = useState(null); + const [kernalClient, setKernal] = useState(null); // set the kernal client in redux const dispatch = useDispatch(); @@ -83,7 +88,6 @@ export default function HomePage() { loginProvider: 'google', } ); - // IMP END - Login setProvider(web3authProvider); if (web3auth.connected) { @@ -107,10 +111,7 @@ export default function HomePage() { try { if (web3auth) { const kernal = await useCreateKernal(web3auth); - - setKernalClient(kernal); - dispatch(kernal); - console.log('REDUX KERNAL', kernal); + setKernal(kernal); console.log('My account:', kernal.account.address); } } catch (error) { @@ -118,6 +119,17 @@ export default function HomePage() { } }; + useEffect(() => { + const setReduxKernal = async () => { + try { + console.log('setting kernal'); + dispatch(setKernalClient(kernalClient)); + console.log('kernal set'); + } catch (error) {} + }; + setReduxKernal(); + }, [kernalClient]); + const sendTx = async () => { try { const txnHash = await kernalClient.sendTransaction({