Monorepo for Aesthetic.Computer aesthetic.computer
4
fork

Configure Feed

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

keeps: instrument startMintFlow, connectWallet, syncWalletToProfile

Temporary ๐Ÿ”‘ KEEP-FLOW console logs to surface why validate-ownership fails
on first modal open. Logs capture:
- Initial acAuth0Client / acToken / mintWalletAddress state on entry.
- initAuth0 + getTokenSilently success/failure (empty catches were hiding this).
- connectWallet beacon session lookup + new perms result.
- syncWalletToProfile skip reason (missing address vs missing token) and
its response status when it does fire.
- keep-prepare request body, auth header presence, and full response payload.

Remove once the first-open failure is diagnosed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

+51 -10
+51 -10
system/public/kidlisp.com/keeps.html
··· 5781 5781 // initTezosWallet should already be resolved (pre-loaded at page init). 5782 5782 // If not, this await is the fallback โ€” but may cause popup blocking. 5783 5783 await initTezosWallet(); 5784 + console.log('๐Ÿ”‘ KEEP-FLOW connectWallet()', { cachedMintWalletAddress: mintWalletAddress }); 5784 5785 // Verify the session is still active (Kukai/WalletConnect sessions can expire) 5785 5786 if (mintWalletAddress) { 5786 5787 const active = await beaconClient.getActiveAccount(); 5788 + console.log('๐Ÿ”‘ KEEP-FLOW connectWallet: beacon active account', { active: active?.address }); 5787 5789 if (active?.address === mintWalletAddress) return mintWalletAddress; 5788 5790 // Session expired โ€” clear stale address and re-request 5789 5791 mintWalletAddress = null; ··· 5791 5793 } 5792 5794 const perms = await beaconClient.requestPermissions(); 5793 5795 mintWalletAddress = perms.address; 5796 + console.log('๐Ÿ”‘ KEEP-FLOW connectWallet: new perms', { address: mintWalletAddress }); 5794 5797 updateWalletBtn(); 5795 5798 // Sync wallet address to user profile so keep-prepare can validate it 5796 5799 await syncWalletToProfile(mintWalletAddress); ··· 5799 5802 5800 5803 // Save connected wallet address to user's AC profile (MongoDB) 5801 5804 async function syncWalletToProfile(address) { 5802 - if (!address || !acToken) return; 5805 + console.log('๐Ÿ”‘ KEEP-FLOW syncWalletToProfile entry', { address, hasAcToken: !!acToken, acTokenLen: acToken ? acToken.length : 0 }); 5806 + if (!address || !acToken) { 5807 + console.warn('๐Ÿ”‘ KEEP-FLOW syncWalletToProfile SKIPPED', { reason: !address ? 'no address' : 'no acToken' }); 5808 + return; 5809 + } 5803 5810 try { 5804 5811 const net = getTezosNetwork(); 5805 5812 const res = await fetch(`${API_BASE}/api/update-tezos-address`, { ··· 5810 5817 }, 5811 5818 body: JSON.stringify({ address, network: net }), 5812 5819 }); 5820 + console.log('๐Ÿ”‘ KEEP-FLOW syncWalletToProfile response', { status: res.status, ok: res.ok }); 5813 5821 if (res.ok) linkedWalletAddress = address; 5814 5822 } catch (e) { 5815 - console.warn('Could not sync wallet to profile:', e); 5823 + console.warn('๐Ÿ”‘ KEEP-FLOW syncWalletToProfile failed:', e); 5816 5824 } 5817 5825 } 5818 5826 ··· 6025 6033 const autoSync = options.autoSync === true && rebake; 6026 6034 mintAbortController = new AbortController(); 6027 6035 6036 + // TEMP instrumentation to debug first-open "validate ownership fails" โ€” 6037 + // remove once the root cause is nailed down. 6038 + const logFlow = (...args) => console.log('๐Ÿ”‘ KEEP-FLOW', ...args); 6039 + logFlow('startMintFlow entry', { 6040 + piece, 6041 + rebake, regenerate, autoSync, 6042 + hasAcAuth0Client: !!acAuth0Client, 6043 + hasAcUser: !!acUser, 6044 + acTokenLen: acToken ? acToken.length : 0, 6045 + mintWalletAddress, 6046 + linkedWalletAddress, 6047 + acHandle, 6048 + }); 6049 + 6028 6050 try { 6029 6051 // Ensure Auth0 + acToken are ready BEFORE connectWallet runs, because 6030 6052 // connectWallet โ†’ syncWalletToProfile early-returns if acToken is null, ··· 6032 6054 // then rejects with "No wallet linked" on first open; second open 6033 6055 // works because the first getTokenSilently populated acToken. 6034 6056 if (!acAuth0Client) { 6035 - try { await initAuth0(); } catch {} 6057 + logFlow('initAuth0 needed โ€” client not yet ready'); 6058 + try { await initAuth0(); logFlow('initAuth0 resolved', { hasClient: !!acAuth0Client }); } 6059 + catch (e) { logFlow('initAuth0 threw', e?.message || e); } 6036 6060 } 6037 6061 if (acAuth0Client) { 6038 - try { acToken = await acAuth0Client.getTokenSilently(); } catch {} 6062 + try { 6063 + const t = await acAuth0Client.getTokenSilently(); 6064 + acToken = t; 6065 + logFlow('getTokenSilently OK', { tokenLen: t ? t.length : 0 }); 6066 + } catch (e) { 6067 + logFlow('getTokenSilently threw', e?.error || e?.message || e); 6068 + } 6069 + } else { 6070 + logFlow('skipping getTokenSilently โ€” no acAuth0Client'); 6039 6071 } 6040 6072 6041 6073 // Step 1: Connect wallet 6042 6074 addTrackEntry(rebake ? 'Starting regeneration...' : (regenerate ? 'Starting regeneration...' : 'Starting keep flow...'), 'active'); 6043 6075 setMintStep('wallet', 'active', 'Connecting...'); 6076 + logFlow('connectWallet() before', { acTokenReady: !!acToken }); 6044 6077 const address = await connectWallet(); 6078 + logFlow('connectWallet() after', { address, linkedWalletAddress }); 6045 6079 if (!address) { 6046 6080 setMintStep('wallet', 'error', 'Connection cancelled'); 6047 6081 addTrackEntry('Wallet connection cancelled', 'error'); ··· 6053 6087 // Step 2: Create job via keep-prepare 6054 6088 setMintStep('validate', 'active', rebake ? 'Validating ownership...' : (regenerate ? 'Regenerating...' : 'Validating...')); 6055 6089 6090 + const prepBody = { 6091 + piece: '$' + piece, 6092 + walletAddress: address, 6093 + network: getTezosNetwork(), 6094 + ...(regenerate || rebake ? { regenerate: true, force: true } : {}), 6095 + }; 6096 + logFlow('keep-prepare POST', { 6097 + url: `${API_BASE}/api/keep-prepare`, 6098 + hasAuthHeader: !!acToken, 6099 + body: prepBody, 6100 + }); 6056 6101 const prepRes = await fetch(`${API_BASE}/api/keep-prepare`, { 6057 6102 method: 'POST', 6058 6103 headers: { 6059 6104 'Content-Type': 'application/json', 6060 6105 ...(acToken ? { Authorization: `Bearer ${acToken}` } : {}), 6061 6106 }, 6062 - body: JSON.stringify({ 6063 - piece: '$' + piece, 6064 - walletAddress: address, 6065 - network: getTezosNetwork(), 6066 - ...(regenerate || rebake ? { regenerate: true, force: true } : {}), 6067 - }), 6107 + body: JSON.stringify(prepBody), 6068 6108 signal: mintAbortController.signal, 6069 6109 }); 6070 6110 6071 6111 const prepData = await prepRes.json(); 6112 + logFlow('keep-prepare response', { status: prepRes.status, ok: prepRes.ok, data: prepData }); 6072 6113 6073 6114 if (!prepRes.ok) { 6074 6115 setMintStep('validate', 'error', prepData.error || 'Validation failed');