-
Notifications
You must be signed in to change notification settings - Fork 20
Show network and admin fees (values) in Donation flow, collective and wallet screens #243 #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
21f7c69
5edf7cf
c6d2c83
3761f52
44c0baf
9866d72
8161c30
284039e
2beb4c5
21020dd
d3dac2b
1a6fc6e
6f788ca
7219dbb
5392e9b
35359bc
180f640
7326e53
69f99f1
743ab6d
4d4a756
089cab0
6cbee29
b007d93
c45fc2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import { ActiveStreamCard } from '../ActiveStreamCard'; | |
| import { WalletDonatedCard } from './WalletDonatedCard'; | ||
| import { useState } from 'react'; | ||
| import { useCollectiveFees } from '../../hooks/useCollectiveFees'; | ||
| import { useRealtimeStats } from '../../hooks/useRealtimeStats'; | ||
| import { calculateFeeAmounts, formatFlowRateToDaily } from '../../lib/calculateFeeAmounts'; | ||
|
|
||
| interface DonorCollectiveCardProps { | ||
|
|
@@ -78,6 +79,7 @@ function DonorCollectiveCard({ ipfsCollective, donorCollective, ensName, tokenPr | |
| }; | ||
|
|
||
| const { fees, loading: feesLoading, error: feesError } = useCollectiveFees(donorCollective.collective); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inefficient Fee Data Fetching
Tell me moreWhat is the issue?The fees data is fetched individually for each DonorCollectiveCard instance, potentially causing multiple unnecessary network requests if multiple cards are rendered. Why this mattersThis can lead to increased network traffic and slower page load times, especially when displaying multiple collective cards simultaneously. Suggested change ∙ Feature PreviewMove the fee fetching logic to a parent component and pass the fees data down as props, or implement a caching mechanism in useCollectiveFees hook using React Query or similar state management solution: const queryClient = useQueryClient();
const { data: fees } = useQuery(['collectiveFees', collective],
() => fetchFees(collective),
{
staleTime: 5 * 60 * 1000, // Cache for 5 minutes
cacheTime: 30 * 60 * 1000 // Keep unused data for 30 minutes
}
);Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. |
||
| const { stats: realtimeStats } = useRealtimeStats(donorCollective.collective); | ||
|
|
||
| const feeAmounts = | ||
| fees && donorCollective.flowRate && Number(donorCollective.flowRate) > 0 | ||
|
|
@@ -107,7 +109,8 @@ function DonorCollectiveCard({ ipfsCollective, donorCollective, ensName, tokenPr | |
| : 'Unknown'; | ||
|
|
||
| // Debug: Show if we're using actual fees or fallback values | ||
| const isUsingActualFees = fees && fees.protocolFeeBps !== 500 && fees.managerFeeBps !== 300; | ||
| const isUsingActualFees = | ||
| Boolean(realtimeStats) || (fees && fees.protocolFeeBps !== 500 && fees.managerFeeBps !== 300); | ||
|
||
|
|
||
| return ( | ||
| <TouchableOpacity | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { useCallback, useEffect, useMemo, useState } from 'react'; | ||
| import { useAccount } from 'wagmi'; | ||
| import { useEthersSigner } from './useEthers'; | ||
| import { GoodCollectiveSDK } from '@gooddollar/goodcollective-sdk'; | ||
|
|
||
| export type RealtimeStats = { | ||
| netIncome: string; | ||
| totalFees: string; | ||
| protocolFees: string; | ||
| managerFees: string; | ||
| incomeFlowRate: string; | ||
| feeRate: string; | ||
| managerFeeRate: string; | ||
| }; | ||
|
|
||
| export function useRealtimeStats(poolAddress: string) { | ||
| const { chain } = useAccount(); | ||
| const maybeSigner = useEthersSigner({ chainId: chain?.id }); | ||
|
|
||
| const [stats, setStats] = useState<RealtimeStats | null>(null); | ||
| const [loading, setLoading] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| const networkName = useMemo(() => { | ||
L03TJ3 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (!chain?.id) return undefined; | ||
| const chainIdString = chain.id.toString(); | ||
| if (chainIdString === '44787') return 'alfajores'; | ||
| if (chainIdString === '122') return 'fuse'; | ||
| if (chainIdString === '42220') { | ||
| const isProduction = | ||
| typeof window !== 'undefined' && | ||
| (window.location.hostname === 'goodcollective.org' || | ||
| window.location.hostname === 'app.goodcollective.org' || | ||
| process.env.NODE_ENV === 'production'); | ||
| return isProduction ? 'production-celo' : 'development-celo'; | ||
| } | ||
| return undefined; | ||
| }, [chain?.id]); | ||
|
|
||
| const fetchStats = useCallback(async () => { | ||
| if (!poolAddress || !chain?.id || !maybeSigner?.provider || !networkName) { | ||
| return; | ||
| } | ||
| setLoading(true); | ||
| setError(null); | ||
| try { | ||
| const sdk = new GoodCollectiveSDK(chain.id.toString() as any, maybeSigner.provider, { network: networkName }); | ||
| const result = await sdk.getRealtimeStats(poolAddress); | ||
| setStats(result as RealtimeStats); | ||
| } catch (e) { | ||
| const msg = e instanceof Error ? e.message : 'Failed to fetch realtime stats'; | ||
| setError(msg); | ||
| setStats(null); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }, [poolAddress, chain?.id, maybeSigner?.provider, networkName]); | ||
|
|
||
| useEffect(() => { | ||
| fetchStats(); | ||
| }, [fetchStats]); | ||
|
|
||
| return { stats, loading, error, refetch: fetchStats }; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.