Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/components/Home/HomeHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ const HomeHistory = ({ isPublic = false, username }: { isPublic?: boolean; usern
// fetch the latest 5 transaction history entries
const mode = isPublic ? 'public' : 'latest'
const limit = isPublic ? 20 : 5
const { data: historyData, isLoading, isError, error } = useTransactionHistory({ mode, limit, username })
// Only filter when user is requesting for some different user's history
const filterMutualTxs = !isPublic && username !== user?.user.username
const {
data: historyData,
isLoading,
isError,
error,
} = useTransactionHistory({ mode, limit, username, filterMutualTxs, enabled: isLoggedIn })
const kycStatus: KYCStatus = user?.user?.kycStatus || 'not_started'

// WebSocket for real-time updates
Expand Down
11 changes: 6 additions & 5 deletions src/components/Profile/components/PublicProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useRouter } from 'next/navigation'
import { formatExtendedNumber } from '@/utils'
import Card from '@/components/Global/Card'
import { useAuth } from '@/context/authContext'
import chillPeanutAnim from '@/animations/GIF_ALPHA_BACKGORUND/512X512_ALPHA_GIF_konradurban_01.gif'

interface PublicProfileProps {
username: string
Expand Down Expand Up @@ -124,9 +125,8 @@ const PublicProfile: React.FC<PublicProfileProps> = ({
</div>
</div>
)}

{/*
{!hasTransactions && (
{/* Show create account box to guest users */}
{!isLoggedIn && (
<div className="relative flex flex-col items-center">
<Card position="single" className="z-10 mt-28 space-y-2 p-4 text-center">
{isLoggedIn ? (
Expand Down Expand Up @@ -170,8 +170,9 @@ const PublicProfile: React.FC<PublicProfileProps> = ({
</div>
</div>
)}
*/}
<HomeHistory isPublic={true} username={username} />

{/* Show history to logged in users */}
{isLoggedIn && <HomeHistory isPublic={false} username={username} />}
</div>
</div>
)
Expand Down
9 changes: 8 additions & 1 deletion src/hooks/useTransactionHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ type UseTransactionHistoryOptions = {
limit?: number
enabled?: boolean
username?: string
filterMutualTxs?: boolean
}

export function useTransactionHistory(options: {
mode: 'latest' | 'public'
limit?: number
enabled?: boolean
username?: string
filterMutualTxs?: boolean
}): LatestHistoryResult

export function useTransactionHistory(options: {
Expand All @@ -106,6 +108,7 @@ export function useTransactionHistory({
limit = 50,
enabled = true,
username,
filterMutualTxs,
}: UseTransactionHistoryOptions): LatestHistoryResult | InfiniteHistoryResult {
const fetchHistory = async ({
cursor,
Expand All @@ -119,6 +122,8 @@ export function useTransactionHistory({
const queryParams = new URLSearchParams()
if (cursor) queryParams.append('cursor', cursor)
if (limit) queryParams.append('limit', limit.toString())
// append targetUsername to the query params if filterMutualTxs is true and username is provided
if (filterMutualTxs && username) queryParams.append('targetUsername', username)

let url: string
if (isPublic) {
Expand Down Expand Up @@ -222,8 +227,10 @@ export function useTransactionHistory({

// Latest transactions mode (for home page)
if (mode === 'latest') {
// if filterMutualTxs is true, we need to add the username to the query key to invalidate the query when the username changes
const queryKeyTxn = TRANSACTIONS + (filterMutualTxs ? username : '')
return useQuery({
queryKey: [TRANSACTIONS, 'latest', { limit }],
queryKey: [queryKeyTxn, 'latest', { limit }],
queryFn: () => fetchHistory({ limit }),
enabled,
staleTime: 5 * 60 * 1000, // 5 minutes
Expand Down
Loading