@@ -57,28 +57,23 @@ export const usePoolsWithFallback = () => {
5757 userActiveRequests : [ ] ,
5858 } ) ;
5959
60- // Determine which account to use and which service to use
60+ // Determine which account to use - always use RPC service for read operations
6161 const effectiveAccount = metamaskAccount || manualSignatureWalletAddress ;
62- // Use read-only service when MetaMask account is not available but manual signature wallet is
63- const useReadOnlyService = ! metamaskAccount && ! ! manualSignatureWalletAddress ;
6462
6563 console . log ( 'usePoolsWithFallback state:' , {
6664 hasHydrated,
6765 metamaskAccount,
6866 manualSignatureWalletAddress,
6967 connected,
7068 effectiveAccount,
71- useReadOnlyService,
7269 } ) ;
7370
7471 /**
75- * Check user membership using either contractService or poolReadService
72+ * Check user membership using direct RPC calls via poolReadService
7673 */
7774 const checkUserMembership = useCallback ( async ( ) => {
7875 console . log ( 'checkUserMembership' , {
79- useReadOnlyService,
8076 effectiveAccount,
81- contractService : ! ! contractService ,
8277 } ) ;
8378
8479 if ( ! effectiveAccount ) {
@@ -90,37 +85,17 @@ export const usePoolsWithFallback = () => {
9085 }
9186
9287 try {
93- if ( useReadOnlyService ) {
94- // Use read-only service when MetaMask is not connected
95- const poolReadService = getPoolReadService ( selectedChain ) ;
96- const userPoolInfo = await poolReadService . getUserPoolInfo (
97- effectiveAccount ,
98- currentBloxPeerId
99- ) ;
100-
101- return {
102- isMemberOfAnyPool : userPoolInfo . poolId !== '0' && userPoolInfo . poolId !== '' ,
103- memberPools : userPoolInfo . poolId !== '0' && userPoolInfo . poolId !== '' ? [ userPoolInfo . poolId ] : [ ] ,
104- activeRequests : userPoolInfo . requestPoolId !== '0' && userPoolInfo . requestPoolId !== '' ? [ userPoolInfo . requestPoolId ] : [ ] ,
105- } ;
106- } else if ( isReady && contractService && connected ) {
107- // Use contract service when MetaMask is connected
108- const { poolId, requestPoolId } = await contractService . getUserPool (
109- effectiveAccount ,
110- currentBloxPeerId
111- ) ;
112-
113- return {
114- isMemberOfAnyPool : poolId !== '0' && poolId !== '' ,
115- memberPools : poolId !== '0' && poolId !== '' ? [ poolId ] : [ ] ,
116- activeRequests : requestPoolId !== '0' && requestPoolId !== '' ? [ requestPoolId ] : [ ] ,
117- } ;
118- }
88+ // Always use read-only service for reliable direct RPC calls
89+ const poolReadService = getPoolReadService ( selectedChain ) ;
90+ const userPoolInfo = await poolReadService . getUserPoolInfo (
91+ effectiveAccount ,
92+ currentBloxPeerId
93+ ) ;
11994
12095 return {
121- isMemberOfAnyPool : false ,
122- memberPools : [ ] ,
123- activeRequests : [ ] ,
96+ isMemberOfAnyPool : userPoolInfo . poolId !== '0' && userPoolInfo . poolId !== '' ,
97+ memberPools : userPoolInfo . poolId !== '0' && userPoolInfo . poolId !== '' ? [ userPoolInfo . poolId ] : [ ] ,
98+ activeRequests : userPoolInfo . requestPoolId !== '0' && userPoolInfo . requestPoolId !== '' ? [ userPoolInfo . requestPoolId ] : [ ] ,
12499 } ;
125100 } catch ( error ) {
126101 console . error ( 'Error checking user membership:' , error ) ;
@@ -130,43 +105,25 @@ export const usePoolsWithFallback = () => {
130105 activeRequests : [ ] ,
131106 } ;
132107 }
133- } , [ useReadOnlyService , effectiveAccount , contractService , isReady , connected , selectedChain , currentBloxPeerId ] ) ;
108+ } , [ effectiveAccount , selectedChain , currentBloxPeerId ] ) ;
134109
135110 /**
136- * Load pools using either contractService or poolReadService
111+ * Load pools using direct RPC calls via poolReadService
137112 */
138113 const loadPools = useCallback ( async ( ) => {
139114 console . log ( 'loadPools called' , {
140- useReadOnlyService,
141115 effectiveAccount,
142- isReady,
143- contractService : ! ! contractService ,
144- isOnCorrectNetwork,
145116 } ) ;
146117
147- // If using read-only service, we don't need to check network or contract readiness
148- if ( ! useReadOnlyService ) {
149- // For MetaMask-connected flow, require all prerequisites
150- if ( ! isReady || ! contractService || ! effectiveAccount || ! isOnCorrectNetwork ) {
151- console . log ( 'loadPools: Prerequisites not met for contract service' ) ;
152- setState ( ( prev ) => ( {
153- ...prev ,
154- enableInteraction : false ,
155- loading : false ,
156- } ) ) ;
157- return ;
158- }
159- } else {
160- // For read-only service, only need effective account
161- if ( ! effectiveAccount ) {
162- console . log ( 'loadPools: No effective account available' ) ;
163- setState ( ( prev ) => ( {
164- ...prev ,
165- enableInteraction : false ,
166- loading : false ,
167- } ) ) ;
168- return ;
169- }
118+ // For read-only RPC service, only need effective account
119+ if ( ! effectiveAccount ) {
120+ console . log ( 'loadPools: No effective account available' ) ;
121+ setState ( ( prev ) => ( {
122+ ...prev ,
123+ enableInteraction : false ,
124+ loading : false ,
125+ } ) ) ;
126+ return ;
170127 }
171128
172129 setState ( ( prev ) => ( { ...prev , loading : true , error : null } ) ) ;
@@ -175,18 +132,10 @@ export const usePoolsWithFallback = () => {
175132 console . log ( '🔍 loadPools: Starting...' ) ;
176133 console . log ( '🔍 effectiveAccount:' , effectiveAccount ) ;
177134 console . log ( '🔍 currentBloxPeerId:' , currentBloxPeerId ) ;
178- console . log ( '🔍 useReadOnlyService:' , useReadOnlyService ) ;
179-
180- let poolList : PoolInfo [ ] ;
181135
182- if ( useReadOnlyService ) {
183- // Use read-only service
184- const poolReadService = getPoolReadService ( selectedChain ) ;
185- poolList = await poolReadService . listPools ( 0 , 25 ) ;
186- } else {
187- // Use contract service
188- poolList = await contractService ! . listPools ( 0 , 25 ) ;
189- }
136+ // Always use read-only service for reliable direct RPC calls
137+ const poolReadService = getPoolReadService ( selectedChain ) ;
138+ const poolList : PoolInfo [ ] = await poolReadService . listPools ( 0 , 25 ) ;
190139
191140 console . log ( '🔍 Pools received:' , poolList ?. length ) ;
192141
@@ -213,18 +162,12 @@ export const usePoolsWithFallback = () => {
213162
214163 try {
215164 console . log ( '🔍 Getting user pool info...' ) ;
216- if ( useReadOnlyService ) {
217- const poolReadService = getPoolReadService ( selectedChain ) ;
218- userPool = await poolReadService . getUserPoolInfo (
219- effectiveAccount ,
220- currentBloxPeerId
221- ) ;
222- } else {
223- userPool = await contractService ! . getUserPool (
224- effectiveAccount ,
225- currentBloxPeerId
226- ) ;
227- }
165+ // Always use read-only service for reliable direct RPC calls
166+ const poolReadService = getPoolReadService ( selectedChain ) ;
167+ userPool = await poolReadService . getUserPoolInfo (
168+ effectiveAccount ,
169+ currentBloxPeerId
170+ ) ;
228171
229172 console . log ( '🔍 User pool result:' , userPool ) ;
230173
@@ -235,19 +178,12 @@ export const usePoolsWithFallback = () => {
235178 } else if ( userPool && userPool . requestPoolId !== '0' ) {
236179 poolIdOfInterest = userPool . requestPoolId ;
237180 try {
238- let joinRequestInfo ;
239- if ( useReadOnlyService ) {
240- const poolReadService = getPoolReadService ( selectedChain ) ;
241- joinRequestInfo = await poolReadService . getJoinRequest (
242- userPool . requestPoolId ,
243- effectiveAccount
244- ) ;
245- } else {
246- joinRequestInfo = await contractService ! . getJoinRequest (
247- userPool . requestPoolId ,
248- effectiveAccount
249- ) ;
250- }
181+ // Always use read-only service for reliable direct RPC calls
182+ const poolReadService = getPoolReadService ( selectedChain ) ;
183+ const joinRequestInfo = await poolReadService . getJoinRequest (
184+ userPool . requestPoolId ,
185+ effectiveAccount
186+ ) ;
251187 console . log ( 'Join request info:' , joinRequestInfo ) ;
252188 numVotes = joinRequestInfo . positive_votes + joinRequestInfo . negative_votes ;
253189 requested = true ;
@@ -314,7 +250,7 @@ export const usePoolsWithFallback = () => {
314250 enableInteraction : false ,
315251 } ) ) ;
316252 }
317- } , [ useReadOnlyService , effectiveAccount , isReady , contractService , isOnCorrectNetwork , selectedChain , currentBloxPeerId , checkUserMembership ] ) ;
253+ } , [ effectiveAccount , selectedChain , currentBloxPeerId , checkUserMembership ] ) ;
318254
319255 /**
320256 * Join pool via API - works with both MetaMask and manual signature
@@ -460,29 +396,12 @@ export const usePoolsWithFallback = () => {
460396 [ effectiveAccount , currentBloxPeerId , selectedChain , loadPools ]
461397 ) ;
462398
463- // Load pools when conditions are met
464- useEffect ( ( ) => {
465- if ( useReadOnlyService ) {
466- // For read-only service, load when we have effective account
467- if ( effectiveAccount ) {
468- loadPools ( ) ;
469- }
470- } else {
471- // For contract service, load when contract is ready and on correct network
472- if ( isReady && isOnCorrectNetwork ) {
473- loadPools ( ) ;
474- }
475- }
476- } , [ useReadOnlyService , effectiveAccount , isReady , isOnCorrectNetwork , loadPools ] ) ;
477-
478- // Refresh pools when account changes
399+ // Load pools when we have an effective account
479400 useEffect ( ( ) => {
480401 if ( effectiveAccount ) {
481- if ( useReadOnlyService || ( isReady && isOnCorrectNetwork ) ) {
482- loadPools ( ) ;
483- }
402+ loadPools ( ) ;
484403 }
485- } , [ effectiveAccount , useReadOnlyService , isReady , isOnCorrectNetwork , loadPools ] ) ;
404+ } , [ effectiveAccount , loadPools ] ) ;
486405
487406 return {
488407 ...state ,
0 commit comments