@@ -79,20 +79,25 @@ const UserProfile = ({ wallet: walletProp, network, initialTab = 'overview', onT
7979 // Process real blockchain data when available
8080 useEffect ( ( ) => {
8181 if ( reputation && history && ! reputationLoading && ! historyLoading ) {
82- // Convert real blockchain data to profile format
82+ // Convert real blockchain data to profile format with null safety
83+ const safeReputation = reputation || { } ;
84+ const safeHistory = history || [ ] ;
85+
8386 const realProfileData = {
8487 reputation : {
85- successfulTrades : reputation . successfulTrades ,
86- disputedTrades : reputation . disputedTrades ,
87- disputesWon : reputation . disputesWon ,
88- totalTrades : reputation . totalTrades ,
89- completionRate : reputation . successRate ,
90- averageRating : reputation . rating / 100 , // Convert from 0-500 to 0-5 scale
88+ successfulTrades : safeReputation . successfulTrades || 0 ,
89+ disputedTrades : safeReputation . disputedTrades || 0 ,
90+ disputesWon : safeReputation . disputesWon || 0 ,
91+ totalTrades : safeReputation . totalTrades || 0 ,
92+ completionRate : safeReputation . successRate || 0 ,
93+ averageRating : ( safeReputation . rating || 0 ) / 100 , // Convert from 0-500 to 0-5 scale
9194 averageResponseTime : 'N/A' , // Would need additional tracking
92- disputeRate : reputation . disputedTrades / reputation . totalTrades * 100 ,
93- lastUpdated : new Date ( reputation . lastUpdated ) . toLocaleDateString ( )
95+ disputeRate : ( safeReputation . totalTrades || 0 ) > 0 ?
96+ ( ( safeReputation . disputedTrades || 0 ) / safeReputation . totalTrades * 100 ) : 0 ,
97+ lastUpdated : safeReputation . lastUpdated ?
98+ new Date ( safeReputation . lastUpdated ) . toLocaleDateString ( ) : 'Never'
9499 } ,
95- transactions : history . slice ( 0 , 10 ) . map ( trade => ( {
100+ transactions : safeHistory . slice ( 0 , 10 ) . map ( trade => ( {
96101 id : trade . id ,
97102 type : trade . type === 'sell' ? 'Sell' : 'Buy' ,
98103 solAmount : trade . solAmount ,
@@ -113,23 +118,23 @@ const UserProfile = ({ wallet: walletProp, network, initialTab = 'overview', onT
113118 hideWalletAddress : false
114119 } ,
115120 tradingStats : {
116- totalTrades : reputation . totalTrades ,
117- successfulTrades : reputation . successfulTrades ,
118- completionRate : reputation . successRate ,
119- totalVolume : history . reduce ( ( sum , trade ) => sum + trade . fiatAmount , 0 ) ,
120- buyOrders : history . filter ( trade => trade . type === 'buy' ) . length ,
121- sellOrders : history . filter ( trade => trade . type === 'sell' ) . length ,
122- disputedTrades : reputation . disputedTrades ,
123- cancelledTrades : history . filter ( trade => trade . status === 'Cancelled' ) . length ,
121+ totalTrades : safeReputation . totalTrades || 0 ,
122+ successfulTrades : safeReputation . successfulTrades || 0 ,
123+ completionRate : safeReputation . successRate || 0 ,
124+ totalVolume : safeHistory . reduce ( ( sum , trade ) => sum + ( trade . fiatAmount || 0 ) , 0 ) ,
125+ buyOrders : safeHistory . filter ( trade => trade . type === 'buy' ) . length ,
126+ sellOrders : safeHistory . filter ( trade => trade . type === 'sell' ) . length ,
127+ disputedTrades : safeReputation . disputedTrades || 0 ,
128+ cancelledTrades : safeHistory . filter ( trade => trade . status === 'Cancelled' ) . length ,
124129 averageResponseTime : 'N/A' ,
125130 responseTimeRating : 'average' ,
126131 periodStart : 'All time' ,
127132 periodEnd : 'Today'
128133 } ,
129- activities : history . slice ( 0 , 5 ) . map ( ( trade , i ) => ( {
134+ activities : safeHistory . slice ( 0 , 5 ) . map ( ( trade , i ) => ( {
130135 id : `activity-${ trade . id } ` ,
131136 type : 'trade' ,
132- message : `You ${ trade . type === 'sell' ? 'sold' : 'bought' } ${ trade . solAmount . toFixed ( 4 ) } SOL` ,
137+ message : `You ${ trade . type === 'sell' ? 'sold' : 'bought' } ${ ( trade . solAmount || 0 ) . toFixed ( 4 ) } SOL` ,
133138 timestamp : new Date ( trade . createdAt ) . toISOString ( ) ,
134139 relatedId : trade . id ,
135140 actionable : true ,
0 commit comments