this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

works

alice 6e5d591a c6a63687

+31 -21
+31 -21
popup.js
··· 29 29 return; // Exit if no relevant data 30 30 } 31 31 32 - let ds = window.WormholeTransform.buildDestinations(info); 33 - render(ds); 32 + let ds = window.WormholeTransform.buildDestinations(info); // Initial build (might be without handle) 33 + render(ds); // Initial render 34 34 35 35 if (info.did && !info.handle) { 36 + let handleToUse = null; 37 + let errorStatusWasSet = false; // Flag to track if an error message was shown 36 38 const { didHandleCache = {} } = await chrome.storage.local.get('didHandleCache'); 37 39 const cachedHandleValue = didHandleCache[info.did]; 38 40 39 41 if (typeof cachedHandleValue === 'string') { 40 - // Cached handle is a string, use it 41 - info.handle = cachedHandleValue; 42 - ds = window.WormholeTransform.buildDestinations(info); // Re-build ds with the handle 43 - render(ds); // Re-render 42 + handleToUse = cachedHandleValue; 44 43 } else { 45 - // Handle is not in cache as a string (either undefined or a non-string type) 44 + // Not a string in cache (or not present) 46 45 if (cachedHandleValue !== undefined) { 47 - // It existed but was not a string, log it. 48 46 console.warn('Cached handle for DID', info.did, 'was not a string, re-fetching. Value:', cachedHandleValue); 49 47 } 50 48 51 - // Show "Resolving..." if list is empty OR if we are about to overwrite a bad/missing cache entry 52 - // The condition `!ds.length` comes from the original code structure. 53 - // The condition `cachedHandleValue !== undefined` ensures "Resolving..." is shown if we just invalidated a non-string cache entry. 49 + // Show "Resolving..." status only if necessary. 50 + // (`!ds.length` implies nothing was renderable initially, `cachedHandleValue !== undefined` implies we are re-fetching a bad cache entry) 54 51 if (!ds.length || cachedHandleValue !== undefined) { 55 52 showStatus('Resolving...'); 56 53 } ··· 58 55 try { 59 56 if (typeof window.WormholeTransform.resolveDidToHandle !== 'function') { 60 57 showStatus('Error: resolve fn missing'); 58 + errorStatusWasSet = true; // Set flag 59 + // handleToUse remains null 61 60 } else { 62 - const freshHandle = await window.WormholeTransform.resolveDidToHandle(info.did); // freshHandle is a string 61 + const freshHandle = await window.WormholeTransform.resolveDidToHandle(info.did); 63 62 if (freshHandle) { 64 - info.handle = freshHandle; 65 - ds = window.WormholeTransform.buildDestinations(info); // Re-build ds 66 - render(ds); // Re-render 67 - // Store the correct string format in cache, potentially overwriting a bad entry 63 + handleToUse = freshHandle; 64 + // Update cache with the correct string format 68 65 await chrome.storage.local.set({ didHandleCache: { ...didHandleCache, [info.did]: freshHandle } }); 69 - } else if (!ds.length) { 70 - // Only show "No actions" if list is still empty after failed fetch 71 - showStatus('No actions available'); 72 66 } 67 + // If freshHandle is null, handleToUse remains null (no specific error, just no handle found for DID) 73 68 } 74 69 } catch (err) { 75 70 console.error('Error resolving DID to handle:', err); 76 - showStatus('Error resolving'); // Show error status 71 + showStatus('Error resolving'); 72 + errorStatusWasSet = true; // Set flag 73 + // handleToUse remains null due to error 74 + } 75 + } 76 + 77 + // After attempting to get handle from cache or by fetching: 78 + if (handleToUse) { 79 + info.handle = handleToUse; 80 + ds = window.WormholeTransform.buildDestinations(info); // Re-build destinations with the handle 81 + render(ds); // Re-render the list 82 + } else { 83 + // Handle was not obtained. An error status might have already been set. 84 + // If the list is still empty and no explicit error status was set, show "No actions available". 85 + if (!ds.length && !errorStatusWasSet) { 86 + showStatus('No actions available'); 77 87 } 78 88 } 79 89 } ··· 88 98 emptyBtn.disabled = true; 89 99 90 100 try { 91 - await chrome.storage.local.remove('didHandleCache'); // Old key 101 + await chrome.storage.local.remove('didHandleCache'); 92 102 93 103 await new Promise((resolve, reject) => { 94 104 chrome.runtime.sendMessage({ type: 'CLEAR_CACHE' }, (msgResponse) => {
refactor-plan.md OLD-refactor-plan.md