Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
encryptedDegen committed Nov 26, 2024
1 parent 2f5413c commit 3b36794
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 122 deletions.
21 changes: 8 additions & 13 deletions src/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -43,7 +42,6 @@ const Providers: React.FC<ProviderProps> = ({ children, initialState }) => {
<QueryClientProvider client={queryClient}>
<ReactQueryStreamedHydration>
<WagmiProvider config={wagmiConfig} initialState={initialState}>
{/* <PersistQueryClientProvider client={queryClient} persistOptions={{ persister }}> */}
<RainbowKitProvider
coolMode={true}
theme={
Expand All @@ -52,20 +50,17 @@ const Providers: React.FC<ProviderProps> = ({ children, initialState }) => {
>
<CartProvider>
<EFPProfileProvider>
<TransactionsProvider>
<ActionsProvider>
<SoundsProvider>
<RecommendedProfilesProvider>
<Navigation />
{children}
</RecommendedProfilesProvider>
</SoundsProvider>
</ActionsProvider>
</TransactionsProvider>
<ActionsProvider>
<SoundsProvider>
<RecommendedProfilesProvider>
<Navigation />
{children}
</RecommendedProfilesProvider>
</SoundsProvider>
</ActionsProvider>
</EFPProfileProvider>
</CartProvider>
</RainbowKitProvider>
{/* </PersistQueryClientProvider> */}
</WagmiProvider>
</ReactQueryStreamedHydration>
<ReactQueryDevtools initialIsOpen={false} />
Expand Down
30 changes: 7 additions & 23 deletions src/contexts/actions-context.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/efp-profile-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 = {
Expand Down
170 changes: 85 additions & 85 deletions src/contexts/transactions-context.tsx
Original file line number Diff line number Diff line change
@@ -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<TransactionsContextType | undefined>(undefined)

export const TransactionsProvider = ({
children
}: {
children: React.ReactNode
}) => {
const addRecentTransaction = useAddRecentTransaction()

const [transactions, setTransactions] = useState<Transaction[]>([])

// 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 (
<TransactionsContext.Provider value={{ transactions, addTransaction }}>
{children}
</TransactionsContext.Provider>
)
}

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<TransactionsContextType | undefined>(undefined)

// export const TransactionsProvider = ({
// children
// }: {
// children: React.ReactNode
// }) => {
// const addRecentTransaction = useAddRecentTransaction()

// const [transactions, setTransactions] = useState<Transaction[]>([])

// // 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 (
// <TransactionsContext.Provider value={{ transactions, addTransaction }}>
// {children}
// </TransactionsContext.Provider>
// )
// }

// export const useTransactions = (): TransactionsContextType => {
// const context = useContext(TransactionsContext)
// if (!context) {
// throw new Error('useTransactions must be used within a TransactionsProvider')
// }
// return context
// }

0 comments on commit 3b36794

Please sign in to comment.