···2929 return; // Exit if no relevant data
3030 }
31313232- let ds = window.WormholeTransform.buildDestinations(info);
3333- render(ds);
3232+ let ds = window.WormholeTransform.buildDestinations(info); // Initial build (might be without handle)
3333+ render(ds); // Initial render
34343535 if (info.did && !info.handle) {
3636+ let handleToUse = null;
3737+ let errorStatusWasSet = false; // Flag to track if an error message was shown
3638 const { didHandleCache = {} } = await chrome.storage.local.get('didHandleCache');
3739 const cachedHandleValue = didHandleCache[info.did];
38403941 if (typeof cachedHandleValue === 'string') {
4040- // Cached handle is a string, use it
4141- info.handle = cachedHandleValue;
4242- ds = window.WormholeTransform.buildDestinations(info); // Re-build ds with the handle
4343- render(ds); // Re-render
4242+ handleToUse = cachedHandleValue;
4443 } else {
4545- // Handle is not in cache as a string (either undefined or a non-string type)
4444+ // Not a string in cache (or not present)
4645 if (cachedHandleValue !== undefined) {
4747- // It existed but was not a string, log it.
4846 console.warn('Cached handle for DID', info.did, 'was not a string, re-fetching. Value:', cachedHandleValue);
4947 }
50485151- // Show "Resolving..." if list is empty OR if we are about to overwrite a bad/missing cache entry
5252- // The condition `!ds.length` comes from the original code structure.
5353- // The condition `cachedHandleValue !== undefined` ensures "Resolving..." is shown if we just invalidated a non-string cache entry.
4949+ // Show "Resolving..." status only if necessary.
5050+ // (`!ds.length` implies nothing was renderable initially, `cachedHandleValue !== undefined` implies we are re-fetching a bad cache entry)
5451 if (!ds.length || cachedHandleValue !== undefined) {
5552 showStatus('Resolving...');
5653 }
···5855 try {
5956 if (typeof window.WormholeTransform.resolveDidToHandle !== 'function') {
6057 showStatus('Error: resolve fn missing');
5858+ errorStatusWasSet = true; // Set flag
5959+ // handleToUse remains null
6160 } else {
6262- const freshHandle = await window.WormholeTransform.resolveDidToHandle(info.did); // freshHandle is a string
6161+ const freshHandle = await window.WormholeTransform.resolveDidToHandle(info.did);
6362 if (freshHandle) {
6464- info.handle = freshHandle;
6565- ds = window.WormholeTransform.buildDestinations(info); // Re-build ds
6666- render(ds); // Re-render
6767- // Store the correct string format in cache, potentially overwriting a bad entry
6363+ handleToUse = freshHandle;
6464+ // Update cache with the correct string format
6865 await chrome.storage.local.set({ didHandleCache: { ...didHandleCache, [info.did]: freshHandle } });
6969- } else if (!ds.length) {
7070- // Only show "No actions" if list is still empty after failed fetch
7171- showStatus('No actions available');
7266 }
6767+ // If freshHandle is null, handleToUse remains null (no specific error, just no handle found for DID)
7368 }
7469 } catch (err) {
7570 console.error('Error resolving DID to handle:', err);
7676- showStatus('Error resolving'); // Show error status
7171+ showStatus('Error resolving');
7272+ errorStatusWasSet = true; // Set flag
7373+ // handleToUse remains null due to error
7474+ }
7575+ }
7676+7777+ // After attempting to get handle from cache or by fetching:
7878+ if (handleToUse) {
7979+ info.handle = handleToUse;
8080+ ds = window.WormholeTransform.buildDestinations(info); // Re-build destinations with the handle
8181+ render(ds); // Re-render the list
8282+ } else {
8383+ // Handle was not obtained. An error status might have already been set.
8484+ // If the list is still empty and no explicit error status was set, show "No actions available".
8585+ if (!ds.length && !errorStatusWasSet) {
8686+ showStatus('No actions available');
7787 }
7888 }
7989 }
···8898 emptyBtn.disabled = true;
899990100 try {
9191- await chrome.storage.local.remove('didHandleCache'); // Old key
101101+ await chrome.storage.local.remove('didHandleCache');
9210293103 await new Promise((resolve, reject) => {
94104 chrome.runtime.sendMessage({ type: 'CLEAR_CACHE' }, (msgResponse) => {