Skip to content

Commit 9e36741

Browse files
committed
fix: remove redundant pie chart and fix token allocation data discrepancy
🔧 Removed Redundant UI Elements: - Removed token allocation overview pie chart from spend tokens page - Chart was redundant since monthly token allocation card already shows composition chart - Cleaned up unused TokenPieChart import 🔧 Fixed Token Allocation Data Discrepancy: - Updated spend tokens page to use same API as header and composition bars (/api/tokens/balance) - Previously used /api/tokens/allocations which had stale data - Now ensures consistent token allocation display across all components: * Header token pie chart ✅ * Recent edits composition bars ✅ * Spend tokens page allocations ✅ 🎯 Data Consistency Improvements: - All token displays now use TokenBalanceContext data source - Eliminates discrepancy between header/composition bars (A) and spend tokens page (B) - Ensures most up-to-date token allocation data across entire app All changes tested with successful build ✅
1 parent a0aec43 commit 9e36741

File tree

1 file changed

+20
-67
lines changed

1 file changed

+20
-67
lines changed

app/settings/spend-tokens/page.tsx

Lines changed: 20 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Button } from '../../components/ui/button';
77
import { SettingsPageHeader } from '../../components/settings/SettingsPageHeader';
88
import TokenAllocationDisplay from '../../components/subscription/TokenAllocationDisplay';
99
import TokenAllocationBreakdown from '../../components/subscription/TokenAllocationBreakdown';
10-
import { TokenPieChart } from '../../components/ui/TokenPieChart';
10+
1111

1212
import { useWeWriteAnalytics } from '../../hooks/useWeWriteAnalytics';
1313
import { 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

Comments
 (0)