generated from theodorusclarence/ts-nextjs-tailwind-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b54faa7
commit f4bc92f
Showing
20 changed files
with
626 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use client'; | ||
|
||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
export const contactsSlice = createSlice({ | ||
name: 'contacts', | ||
initialState: { | ||
value: [], | ||
}, | ||
reducers: { | ||
setContacts: (state, action) => { | ||
state.value = action.payload; | ||
}, | ||
}, | ||
}); | ||
export const { setContacts } = contactsSlice.actions; | ||
export default contactsSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function AddToContactsPage() { | ||
return ( | ||
<div> | ||
<h1>Add To Contacts</h1> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// wagmi | ||
'use client'; | ||
import { useBalance } from 'wagmi'; | ||
|
||
// Redux | ||
import { RootState } from '../../../GlobalRedux/store'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { setBalance } from '@/GlobalRedux/Features/balance/balanceSlice'; | ||
|
||
// React | ||
import { useEffect } from 'react'; | ||
|
||
// next | ||
import { usePathname } from 'next/navigation'; | ||
|
||
export default function Balance() { | ||
// Redux | ||
const dispatch = useDispatch(); | ||
// next | ||
const pathname = usePathname(); | ||
// hooks | ||
const address = useSelector((state: RootState) => state.address.value); | ||
|
||
|
||
|
||
const checkBalance = async () => { | ||
try { | ||
console.log('balance', result?.data?.formatted); | ||
|
||
const result = useBalance({ | ||
// @ts-ignore | ||
address: address, | ||
token: '0x94a9D9AC8a22534E3FaCa9F4e7F2E2cf85d5E4C8', | ||
}); | ||
// @ts-ignore | ||
dispatch(setBalance(result?.data?.formatted)); | ||
} catch (error) { | ||
console.log('error', error); | ||
} | ||
}; | ||
|
||
// pathname use effect | ||
useEffect(() => { | ||
console.log(`Route changed to: ${pathname}`); | ||
checkBalance(); | ||
}, [pathname]); | ||
|
||
// Get the balance from Redux | ||
const balanceState = useSelector((state: RootState) => state.balance.value); | ||
console.log('balanceState', balanceState); | ||
|
||
// Render the balance | ||
return <div className='text-white'>${balanceState}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.