diff --git a/src/app/providers.tsx b/src/app/providers.tsx index 498a9c71..944abce3 100644 --- a/src/app/providers.tsx +++ b/src/app/providers.tsx @@ -16,7 +16,6 @@ import { CartProvider } from '#/contexts/cart-context' import { SoundsProvider } from '#/contexts/sounds-context' import { ActionsProvider } from '#/contexts/actions-context' import { EFPProfileProvider } from '#/contexts/efp-profile-context' -import { TransactionsProvider } from '#/contexts/transactions-context' import { RecommendedProfilesProvider } from '#/contexts/recommended-profiles-context' type ProviderProps = { @@ -43,7 +42,6 @@ const Providers: React.FC = ({ children, initialState }) => { - {/* */} = ({ children, initialState }) => { > - - - - - - {children} - - - - + + + + + {children} + + + - {/* */} diff --git a/src/contexts/actions-context.tsx b/src/contexts/actions-context.tsx index aecdf902..ece3253d 100644 --- a/src/contexts/actions-context.tsx +++ b/src/contexts/actions-context.tsx @@ -1,16 +1,16 @@ 'use client' -import type { WriteContractReturnType } from 'viem' -import { useWaitForTransactionReceipt } from 'wagmi' import { - createContext, - useContext, + useMemo, useState, - type ReactNode, + useEffect, + useContext, useCallback, - useMemo, - useEffect + createContext, + type ReactNode } from 'react' +import type { WriteContractReturnType } from 'viem' +import { useWaitForTransactionReceipt } from 'wagmi' import useChain from '#/hooks/use-chain' @@ -123,22 +123,6 @@ export const ActionsProvider = ({ children }: { children: ReactNode }) => { return nextIndex }, [currentActionIndex, actions.length]) - // const getRequiredChain = useCallback( - // async (index: number, list?: number | string) => - // actions[index || 0]?.label === 'create list' - // ? DEFAULT_CHAIN.id - // : list - // ? fromHex( - // `0x${(await listRegistryContract.read.getListStorageLocation([BigInt(list)])).slice( - // 64, - // 70 - // )}`, - // 'number' - // ) - // : currentChainId, - // [actions, listRegistryContract, currentChainId] - // ) - // Executes the action based on the index to be able to handle async execution with synchronous state updates const executeActionByIndex = useCallback( async (index: number) => { diff --git a/src/contexts/efp-profile-context.tsx b/src/contexts/efp-profile-context.tsx index 03584e9e..646d37ff 100644 --- a/src/contexts/efp-profile-context.tsx +++ b/src/contexts/efp-profile-context.tsx @@ -36,6 +36,7 @@ import type { import { useCart } from './cart-context' import { DEFAULT_CHAIN } from '#/lib/constants/chains' import type { ProfileTableTitleType } from '#/types/common' +import { coreEfpContracts } from '#/lib/constants/contracts' import { fetchProfileRoles } from '#/api/profile/fetch-profile-roles' import { fetchProfileLists } from '#/api/profile/fetch-profile-lists' import { fetchProfileStats } from '#/api/profile/fetch-profile-stats' @@ -46,7 +47,6 @@ import { fetchProfileAllFollowings } from '#/api/following/fetch-profile-all-fol import { fetchFollowerTags, nullFollowerTags } from '#/api/followers/fetch-follower-tags' import { fetchFollowingTags, nullFollowingTags } from '#/api/following/fetch-following-tags' import { BLOCKED_MUTED_TAGS, DEFAULT_TAGS_TO_ADD, FETCH_LIMIT_PARAM } from '#/lib/constants' -import { coreEfpContracts } from '#/lib/constants/contracts' // Define the type for the profile context type EFPProfileContextType = { diff --git a/src/contexts/transactions-context.tsx b/src/contexts/transactions-context.tsx index 656bbff0..01395cd3 100644 --- a/src/contexts/transactions-context.tsx +++ b/src/contexts/transactions-context.tsx @@ -1,85 +1,85 @@ -'use client' - -import { useAddRecentTransaction } from '@rainbow-me/rainbowkit' -import { createContext, useCallback, useContext, useState } from 'react' - -type Transaction = { - hash: `0x${string}` - chainId: number - description: string -} - -type TransactionsContextType = { - transactions: Transaction[] - addTransaction: (transaction: Transaction) => void -} - -// const TransactionsLocalStorageKey = 'efp-transactions' -const MAX_TRANSACTIONS_STORED = 100 - -const TransactionsContext = createContext(undefined) - -export const TransactionsProvider = ({ - children -}: { - children: React.ReactNode -}) => { - const addRecentTransaction = useAddRecentTransaction() - - const [transactions, setTransactions] = useState([]) - - // Populate transactions from localStorage when component mounts - // useEffect(() => { - // if (window === undefined) return - - // const storedTransactions = window.localStorage.getItem(TransactionsLocalStorageKey) - // if (storedTransactions) { - // setTransactions(JSON.parse(storedTransactions) as Transaction[]) - // } - // }, []) - - const addTransaction = useCallback( - (transaction: Transaction) => { - setTransactions(prevTransactions => { - const exists = prevTransactions.some(tx => tx.hash === transaction.hash) - if (exists) return prevTransactions - - // Add the new transaction and ensure the list does not exceed `MAX_TRANSACTIONS_STORED` - const updatedTransactions = [...prevTransactions, transaction].slice( - -MAX_TRANSACTIONS_STORED - ) - - // Add the transaction to Rainbow - addRecentTransaction({ - hash: transaction.hash, - description: transaction.description - }) - - return updatedTransactions - }) - }, - [addRecentTransaction] - ) - - // Synchronize the transactions state with local storage on changes, - // ensuring that only the most recent transactions are stored. - // useEffect(() => { - // if (window === undefined) return - // const recentTransactions = transactions.slice(-MAX_TRANSACTIONS_STORED) - // window.localStorage.setItem(TransactionsLocalStorageKey, JSON.stringify(recentTransactions)) - // }, [transactions]) - - return ( - - {children} - - ) -} - -export const useTransactions = (): TransactionsContextType => { - const context = useContext(TransactionsContext) - if (!context) { - throw new Error('useTransactions must be used within a TransactionsProvider') - } - return context -} +// 'use client' + +// import { useAddRecentTransaction } from '@rainbow-me/rainbowkit' +// import { createContext, useCallback, useContext, useState } from 'react' + +// type Transaction = { +// hash: `0x${string}` +// chainId: number +// description: string +// } + +// type TransactionsContextType = { +// transactions: Transaction[] +// addTransaction: (transaction: Transaction) => void +// } + +// // const TransactionsLocalStorageKey = 'efp-transactions' +// const MAX_TRANSACTIONS_STORED = 100 + +// const TransactionsContext = createContext(undefined) + +// export const TransactionsProvider = ({ +// children +// }: { +// children: React.ReactNode +// }) => { +// const addRecentTransaction = useAddRecentTransaction() + +// const [transactions, setTransactions] = useState([]) + +// // Populate transactions from localStorage when component mounts +// // useEffect(() => { +// // if (window === undefined) return + +// // const storedTransactions = window.localStorage.getItem(TransactionsLocalStorageKey) +// // if (storedTransactions) { +// // setTransactions(JSON.parse(storedTransactions) as Transaction[]) +// // } +// // }, []) + +// const addTransaction = useCallback( +// (transaction: Transaction) => { +// setTransactions(prevTransactions => { +// const exists = prevTransactions.some(tx => tx.hash === transaction.hash) +// if (exists) return prevTransactions + +// // Add the new transaction and ensure the list does not exceed `MAX_TRANSACTIONS_STORED` +// const updatedTransactions = [...prevTransactions, transaction].slice( +// -MAX_TRANSACTIONS_STORED +// ) + +// // Add the transaction to Rainbow +// addRecentTransaction({ +// hash: transaction.hash, +// description: transaction.description +// }) + +// return updatedTransactions +// }) +// }, +// [addRecentTransaction] +// ) + +// // Synchronize the transactions state with local storage on changes, +// // ensuring that only the most recent transactions are stored. +// // useEffect(() => { +// // if (window === undefined) return +// // const recentTransactions = transactions.slice(-MAX_TRANSACTIONS_STORED) +// // window.localStorage.setItem(TransactionsLocalStorageKey, JSON.stringify(recentTransactions)) +// // }, [transactions]) + +// return ( +// +// {children} +// +// ) +// } + +// export const useTransactions = (): TransactionsContextType => { +// const context = useContext(TransactionsContext) +// if (!context) { +// throw new Error('useTransactions must be used within a TransactionsProvider') +// } +// return context +// }