Skip to content

Commit

Permalink
fixed kernal redux state
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen-Gordon committed Jan 31, 2024
1 parent 5aa7b40 commit b4414f5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 18 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/GlobalRedux/Features/kernalClient/kernalClientSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
14 changes: 5 additions & 9 deletions src/GlobalRedux/provider.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Provider store={store}>
{children}
</Provider>
)
}
return <Provider store={store}>{children}</Provider>;
}
4 changes: 3 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 18 additions & 6 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -48,7 +53,7 @@ web3auth.configureAdapter(openloginAdapter);
export default function HomePage() {
const [provider, setProvider] = useState<IProvider | null>(null);
const [loggedIn, setLoggedIn] = useState(false);
const [kernalClient, setKernalClient] = useState<any>(null);
const [kernalClient, setKernal] = useState<any>(null);
// set the kernal client in redux
const dispatch = useDispatch();

Expand Down Expand Up @@ -83,7 +88,6 @@ export default function HomePage() {
loginProvider: 'google',
}
);
// IMP END - Login
setProvider(web3authProvider);

if (web3auth.connected) {
Expand All @@ -107,17 +111,25 @@ 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) {
console.log(error);
}
};

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({
Expand Down

0 comments on commit b4414f5

Please sign in to comment.