···
179
179
180
180
const checkVerificationsValidity = useCallback(async (verificationsList) => {
181
181
if (!agent || verificationsList.length === 0) return;
182
182
+
if (verificationsList.length === 0) return;
183
183
+
182
184
setIsCheckingValidity(true);
183
185
const updatedVerifications = [...verificationsList];
184
186
try {
···
186
188
for (let i = 0; i < updatedVerifications.length; i += batchSize) {
187
189
const batch = updatedVerifications.slice(i, i + batchSize);
188
190
await Promise.all(batch.map(async (verification, index) => {
191
191
+
const batchIndex = i + index;
189
192
try {
190
190
-
const profileRes = await agent.api.app.bsky.actor.getProfile({ actor: verification.handle });
191
191
-
const currentHandle = profileRes.data.handle;
192
192
-
const currentDisplayName = profileRes.data.displayName || profileRes.data.handle;
193
193
-
const batchIndex = i + index;
193
193
+
// *** Get the specific PDS for the verified user ***
194
194
+
const targetDid = verification.subject;
195
195
+
const pdsEndpoint = await getPdsEndpoint(targetDid);
196
196
+
197
197
+
if (!pdsEndpoint) {
198
198
+
throw new Error(`Could not find PDS for ${verification.handle || targetDid}`);
199
199
+
}
200
200
+
201
201
+
// *** Use direct fetch to get the profile from the correct PDS ***
202
202
+
const profileUrl = `${pdsEndpoint}/xrpc/app.bsky.actor.getProfile?actor=${encodeURIComponent(targetDid)}`;
203
203
+
const profileResponse = await fetch(profileUrl);
204
204
+
205
205
+
if (!profileResponse.ok) {
206
206
+
// If profile fetch fails (e.g., 404), mark validity check failed
207
207
+
throw new Error(`Failed to fetch profile from ${pdsEndpoint}: ${profileResponse.status}`);
208
208
+
}
209
209
+
const profileData = await profileResponse.json();
210
210
+
211
211
+
// Check if handle and displayName still match
212
212
+
const currentHandle = profileData.handle;
213
213
+
const currentDisplayName = profileData.displayName || profileData.handle;
214
214
+
194
215
updatedVerifications[batchIndex].validityChecked = true;
195
216
updatedVerifications[batchIndex].isValid =
196
217
currentHandle === verification.handle &&
197
218
currentDisplayName === verification.displayName;
219
219
+
198
220
if (!updatedVerifications[batchIndex].isValid) {
199
221
updatedVerifications[batchIndex].currentHandle = currentHandle;
200
222
updatedVerifications[batchIndex].currentDisplayName = currentDisplayName;
201
223
}
202
202
-
setVerifications([...updatedVerifications]);
203
224
} catch (err) {
204
204
-
console.error(`Failed to check validity for ${verification.handle}:`, err);
205
205
-
const batchIndex = i + index;
225
225
+
console.error(`Failed to check validity for ${verification.handle || verification.subject}:`, err);
206
226
updatedVerifications[batchIndex].validityChecked = true;
207
227
updatedVerifications[batchIndex].isValid = false;
208
228
updatedVerifications[batchIndex].validityError = true;
209
209
-
setVerifications([...updatedVerifications]);
210
229
}
211
230
}));
231
231
+
// Update state after each batch completes
232
232
+
setVerifications([...updatedVerifications]);
212
233
}
213
234
console.log('Verified all records validity:', updatedVerifications);
214
235
} catch (error) {
215
215
-
console.error('Failed to check verifications validity:', error);
236
236
+
console.error('Error during batch processing for validity check:', error);
216
237
} finally {
217
238
setIsCheckingValidity(false);
218
239
}
219
219
-
}, [agent]);
240
240
+
}, []); // Removed agent dependency as it's no longer used directly here
220
241
221
242
const checkNetworkVerifications = useCallback(async () => {
222
243
if (!agent || !session || !userInfo) return;