@@ -7,7 +7,7 @@ import { Button } from '../../components/ui/button';
77import { SettingsPageHeader } from '../../components/settings/SettingsPageHeader' ;
88import TokenAllocationDisplay from '../../components/subscription/TokenAllocationDisplay' ;
99import TokenAllocationBreakdown from '../../components/subscription/TokenAllocationBreakdown' ;
10- import { TokenPieChart } from '../../components/ui/TokenPieChart' ;
10+
1111
1212import { useWeWriteAnalytics } from '../../hooks/useWeWriteAnalytics' ;
1313import { NAVIGATION_EVENTS } from '../../constants/analytics-events' ;
@@ -119,14 +119,26 @@ export default function SpendTokensPage() {
119119 console . log ( '🎯 Spend Tokens: Token balance response not ok' , tokenResponse . status ) ;
120120 }
121121
122- // Fetch token allocations for accurate calculations
123- const allocationsResponse = await fetch ( '/api/tokens/allocations' ) ;
124- if ( allocationsResponse . ok ) {
125- const allocationsData = await allocationsResponse . json ( ) ;
126- console . log ( '🎯 Spend Tokens: Loaded allocations data' , allocationsData ) ;
122+ // FIXED: Use the same token balance API as header and composition bars for consistency
123+ // This ensures we get the most up-to-date token allocation data
124+ const balanceResponse = await fetch ( '/api/tokens/balance' ) ;
125+ if ( balanceResponse . ok ) {
126+ const balanceData = await balanceResponse . json ( ) ;
127+ console . log ( '🎯 Spend Tokens: Loaded balance data (same as header)' , balanceData ) ;
128+
129+ // Convert balance API response to allocations format for compatibility
130+ const allocationsData = {
131+ success : true ,
132+ allocations : balanceData . allocations || [ ] ,
133+ summary : {
134+ totalAllocations : balanceData . allocations ?. length || 0 ,
135+ totalTokensAllocated : balanceData . summary ?. allocatedTokens || 0 ,
136+ balance : balanceData . balance || balanceData . summary
137+ }
138+ } ;
127139 setAllocationData ( allocationsData ) ;
128140 } else {
129- console . log ( '🎯 Spend Tokens: Allocations response not ok' , allocationsResponse . status ) ;
141+ console . log ( '🎯 Spend Tokens: Balance response not ok' , balanceResponse . status ) ;
130142 }
131143 } catch ( error ) {
132144 console . error ( 'Error fetching data:' , error ) ;
@@ -344,66 +356,7 @@ export default function SpendTokensPage() {
344356 ) ;
345357 } ) ( ) }
346358
347- { /* Token Allocation Pie Chart Visualization */ }
348- { ( ( ) => {
349- // Use live allocation data if available, otherwise fall back to initial data
350- const currentAllocationData = liveAllocationData || allocationData ;
351- const actualAllocatedTokens = currentAllocationData ?. summary ?. totalTokensAllocated || 0 ;
352-
353- // Create enhanced token balance with real-time allocation data
354- const enhancedTokenBalance = tokenBalance ? {
355- ...tokenBalance ,
356- allocatedTokens : actualAllocatedTokens ,
357- availableTokens : tokenBalance . totalTokens - actualAllocatedTokens
358- } : null ;
359-
360- // Determine which token balance to use for the pie chart
361- let pieChartTokenBalance = null ;
362-
363- if ( ! currentSubscription && simulatedTokenBalance ) {
364- // For users without subscription, show simulated data
365- pieChartTokenBalance = {
366- totalTokens : 0 , // No subscription = 0 tokens per month
367- allocatedTokens : simulatedTokenBalance . allocatedTokens ,
368- availableTokens : 0 - simulatedTokenBalance . allocatedTokens , // Always negative
369- } ;
370- } else if ( currentSubscription && enhancedTokenBalance ) {
371- // For users with subscription
372- pieChartTokenBalance = enhancedTokenBalance ;
373- } else if ( enhancedTokenBalance ) {
374- // Default case with token balance
375- pieChartTokenBalance = enhancedTokenBalance ;
376- }
377-
378- // Only show pie chart if we have token data to display
379- if ( pieChartTokenBalance && ( pieChartTokenBalance . totalTokens > 0 || pieChartTokenBalance . allocatedTokens > 0 ) ) {
380- return (
381- < div className = "flex justify-center mb-6" >
382- < div className = "flex flex-col items-center space-y-3" >
383- < h3 className = "text-lg font-semibold text-center" > Token Allocation Overview</ h3 >
384- < TokenPieChart
385- allocatedTokens = { pieChartTokenBalance . allocatedTokens }
386- totalTokens = { Math . max ( pieChartTokenBalance . totalTokens , pieChartTokenBalance . allocatedTokens ) }
387- size = { 120 }
388- strokeWidth = { 8 }
389- className = "hover:opacity-80 transition-opacity"
390- showFraction = { true }
391- />
392- < p className = "text-sm text-muted-foreground text-center max-w-md" >
393- { pieChartTokenBalance . totalTokens === 0
394- ? "You've allocated tokens but don't have an active subscription. Consider upgrading to fund your allocations."
395- : pieChartTokenBalance . allocatedTokens > pieChartTokenBalance . totalTokens
396- ? "You've allocated more tokens than your subscription provides. Consider upgrading your plan."
397- : "Visual representation of your monthly token allocation to creators."
398- }
399- </ p >
400- </ div >
401- </ div >
402- ) ;
403- }
404-
405- return null ;
406- } ) ( ) }
359+ { /* Removed redundant Token Allocation Pie Chart - composition chart in monthly token allocation card above provides the same information */ }
407360
408361 { /* Token Allocation Breakdown - Always show so users can see their allocations */ }
409362 < TokenAllocationBreakdown
0 commit comments