WAIFU
Language:
Fliza
Basic Info
Age 22
Birthday June 5
Zodiac Gemini
Personality
Loading...
Daily Interests
Loading...
Likes & Dislikes
Likes
Dislikes
Favorites
Food
Music
Movies
Games
Fliza
LOADING
Selected Character
A
Select

Connect wallet

Get started by connecting your preferred wallet below.

👻
Phantom
☀️
Solflare
🔷
Coinbase
🎒
Backpack
// Connect button click const connectButton = document.getElementById('wallet-connect-button'); if (connectButton) { connectButton.addEventListener('click', () => this.showWalletModal()); } // closedmodal const closeBtn = document.getElementById('wallet-close-btn'); if (closeBtn) { closeBtn.addEventListener('click', () => this.hideWalletModal()); } // modal覆盖层clickedclosed const modal = document.getElementById('wallet-modal'); if (modal) { modal.addEventListener('click', (e) => { if (e.target === modal || e.target.closest('.wallet-modal-overlay')) { if (e.target === modal || e.target === e.target.closest('.wallet-modal-overlay')) { this.hideWalletModal(); } } }); } // wallet选项clicked const walletOptions = document.querySelectorAll('.wallet-option'); walletOptions.forEach(option => { option.addEventListener('click', () => { const provider = option.dataset.provider; this.connectWallet(provider); }); }); // wallet菜单button const menuBtn = document.getElementById('wallet-menu-btn'); if (menuBtn) { menuBtn.addEventListener('click', (e) => { e.stopPropagation(); this.toggleDropdown(); }); } // copyaddress const copyBtn = document.getElementById('copy-address-btn'); if (copyBtn) { copyBtn.addEventListener('click', () => this.copyAddress()); } // Disconnect const disconnectBtn = document.getElementById('disconnect-wallet-btn'); if (disconnectBtn) { disconnectBtn.addEventListener('click', () => this.disconnect()); } // clicked其他地方closeddropdown document.addEventListener('click', () => { this.hideDropdown(); }); } showWalletModal() { const modal = document.getElementById('wallet-modal'); if (modal) { modal.style.display = 'flex'; document.body.style.overflow = 'hidden'; } } hideWalletModal() { const modal = document.getElementById('wallet-modal'); if (modal) { modal.style.display = 'none'; document.body.style.overflow = ''; } } async connectWallet(walletName) { try { (window.AppConfig?.debug?.log || console.log)(`Connect wallet: ${walletName}`); // Check if wallet is configured const walletConfig = this.wallets.find(w => w.name.toLowerCase() === walletName.toLowerCase()); if (!walletConfig) { throw new Error(`wallet ${walletName} 未找to或未installed`); } const adapter = walletConfig.adapter(); if (!adapter) { this.showToast(`${walletName} wallet未installed`, 'error'); return; } // Update button status this.updateConnectButton(true); // Connect wallet let response; if (adapter.connect) { response = await adapter.connect(); } else if (adapter.publicKey && adapter.isConnected) { response = { publicKey: adapter.publicKey }; } else { throw new Error('walletadaptive器不supportedconnected'); } const address = response.publicKey.toString(); // savedconnectedstatus this.selectedWallet = { name: walletName, adapter, address, config: walletConfig }; this.isConnected = true; // Save to localStorage localStorage.setItem('wallet_address', address); localStorage.setItem('wallet_type', walletName.toLowerCase()); (window.AppConfig?.debug?.log || console.log)(`Wallet connected: ${walletName}`, address); // Update UI this.updateUI(); this.hideWalletModal(); this.showToast(`${walletName} Connection successful!`, 'success'); // Trigger global event window.dispatchEvent(new CustomEvent('walletConnected', { detail: { address, provider: walletName.toLowerCase() } })); } catch (error) { console.error('❌ Wallet connection failed:', error); this.updateConnectButton(false); this.showToast(`Connection failed: ${error.message}`, 'error'); } } async disconnect() { try { (window.AppConfig?.debug?.log || console.log)('Disconnect wallet...'); if (this.selectedWallet?.adapter?.disconnect) { await this.selectedWallet.adapter.disconnect(); } // clean up status this.selectedWallet = null; this.isConnected = false; // Clear localStorage localStorage.removeItem('wallet_address'); localStorage.removeItem('wallet_type'); localStorage.removeItem('selectedCharacter'); // Update UI this.updateUI(); this.hideDropdown(); this.showToast(i18n.t('wallet.disconnected'), 'success'); // Trigger global event window.dispatchEvent(new CustomEvent('walletDisconnected')); } catch (error) { console.error('❌ Disconnect failed:', error); // Force clean up status this.selectedWallet = null; this.isConnected = false; localStorage.clear(); this.updateUI(); } } checkExistingConnection() { const savedAddress = localStorage.getItem('wallet_address'); const savedType = localStorage.getItem('wallet_type'); if (savedAddress && savedType) { (window.AppConfig?.debug?.log || console.log)('Check saved wallet connection...'); const walletConfig = this.wallets.find(w => w.name.toLowerCase() === savedType.toLowerCase()); if (walletConfig) { const adapter = walletConfig.adapter(); if (adapter && adapter.isConnected && adapter.publicKey) { this.selectedWallet = { name: walletConfig.name, adapter, address: savedAddress, config: walletConfig }; this.isConnected = true; this.updateUI(); (window.AppConfig?.debug?.log || console.log)('Auto reconnected:', savedAddress); } } } } updateUI() { const connectButton = document.getElementById('wallet-connect-button'); const walletInfo = document.getElementById('wallet-info'); const walletAddress = document.getElementById('wallet-address'); const walletAvatar = document.getElementById('wallet-avatar'); if (this.isConnected && this.selectedWallet) { // Connected status if (connectButton) connectButton.style.display = 'none'; if (walletInfo) walletInfo.style.display = 'flex'; if (walletAddress) walletAddress.textContent = this.formatAddress(this.selectedWallet.address); if (walletAvatar) walletAvatar.textContent = this.selectedWallet.config.icon; } else { // display未connectedstatus if (connectButton) connectButton.style.display = 'flex'; if (walletInfo) walletInfo.style.display = 'none'; } } updateConnectButton(loading) { const button = document.getElementById('wallet-connect-button'); if (!button) return; const textSpan = button.querySelector('.wallet-text'); if (loading) { button.disabled = true; if (textSpan) textSpan.textContent = 'Connecting...'; } else { button.disabled = false; if (textSpan) textSpan.textContent = 'Connect'; } } toggleDropdown() { const dropdown = document.getElementById('wallet-dropdown'); if (dropdown) { dropdown.style.display = dropdown.style.display === 'none' ? 'block' : 'none'; } } hideDropdown() { const dropdown = document.getElementById('wallet-dropdown'); if (dropdown) { dropdown.style.display = 'none'; } } copyAddress() { if (this.selectedWallet?.address) { navigator.clipboard.writeText(this.selectedWallet.address).then(() => { this.showToast('address已copyto剪贴板', 'success'); }).catch(() => { this.showToast('copyfailed', 'error'); }); } this.hideDropdown(); } formatAddress(address) { if (!address) return ''; return `${address.slice(0, 6)}...${address.slice(-4)}`; } showToast(message, type = 'info') { const toast = document.createElement('div'); toast.className = `wallet-toast wallet-toast-${type}`; toast.textContent = message; document.body.appendChild(toast); setTimeout(() => { toast.remove(); }, 3000); } // Public API getWalletInfo() { return { isConnected: this.isConnected, wallet: this.selectedWallet }; } getPublicKey() { return this.selectedWallet?.adapter?.publicKey || null; } async signMessage(message) { if (!this.selectedWallet?.adapter?.signMessage) { throw new Error('currentwallet不supportedmessagesigned'); } return await this.selectedWallet.adapter.signMessage(message); } } // userprofilemanagementsystem - 移to这in确保atwalletinitializedbefore定义 (window.AppConfig?.debug?.log || console.log)('Start defining UserProfileManager class...'); class UserProfileManager { constructor() { this.currentUserId = null; } // Check if user needs to fill profile - 纯API驱动,nonelocalStorage async checkUserProfile(userId) { // Extract wallet address from userId const walletAddress = userId.replace('wallet_', ''); try { // Get latest profile from backend API const apiUrl = window.AppConfig ? window.AppConfig.getApiUrl() : 'http://localhost:3000'; const response = await fetch(`${apiUrl}/api/profiles/${walletAddress}`); if (response.ok) { const result = await response.json(); if (result.success && result.profile) { (window.AppConfig?.debug?.log || console.log)('Profile fetched from API'); return result.profile; } } if (response.status === 404) { (window.AppConfig?.debug?.log || console.log)('No profile found by API'); return null; } (window.AppConfig?.debug?.warn || console.warn)('API abnormal response status:', response.status); return null; } catch (error) { console.error('❌ API request failed:', error); return null; } } // displayuserprofile面板 showProfilePanel(userId = null, existingProfile = null) { (window.AppConfig?.debug?.log || console.log)('Show user profile panel'); const overlay = document.getElementById('user-profile-overlay'); if (overlay) { // If in edit mode, fill existing data if (existingProfile) { this.fillFormWithProfile(existingProfile); // Change title to edit mode const title = overlay.querySelector('.profile-panel-title'); if (title) title.textContent = i18n.t('registration.edit.title'); } else { // Reset form this.resetForm(); const title = overlay.querySelector('.profile-panel-title'); if (title) title.textContent = i18n.t('registration.title'); } overlay.style.display = 'flex'; (window.AppConfig?.debug?.log || console.log)('Profile panel shown'); } else { console.error('❌ user-profile-overlay element not found'); } } // Fill form data fillFormWithProfile(profile) { const fields = { 'username': profile.nickname || profile.username, 'displayName': profile.nickname || profile.first_name || '', 'birthYear': profile.birth_year, 'birthMonth': profile.birth_month, 'birthDay': profile.birth_day, 'location': profile.location, 'language': profile.language || 'zh-CN' }; Object.entries(fields).forEach(([fieldId, value]) => { const field = document.getElementById(fieldId); if (field && value) { field.value = value; } }); } // Reset form resetForm() { const form = document.getElementById('profile-form'); if (form) { form.reset(); } } // displayuser欢迎info showUserWelcome(profile) { (window.AppConfig?.debug?.log || console.log)('Show user welcome'); // Here can add welcome info display logic } } // Ensure UserProfileManager class is globally accessible (window.AppConfig?.debug?.log || console.log)('Expose UserProfileManager globally'); window.UserProfileManager = UserProfileManager; // Initialize ProfileManager immediately to ensure availability when wallet connects (window.AppConfig?.debug?.log || console.log)('Create profileManager instance...'); const profileManager = new UserProfileManager(); window.profileManager = profileManager; (window.AppConfig?.debug?.log || console.log)('ProfileManager initialized'); // Initialize wallet manager let walletManager; document.addEventListener('DOMContentLoaded', () => { walletManager = new SolanaWalletManager(); window.walletManager = walletManager; // Expose to global window.modernWalletUI = walletManager; // For backward compatibility }); // compatibleold的globalfunction window.connectWallet = function() { if (walletManager) { walletManager.showWalletModal(); } }; window.disconnectWallet = function() { if (walletManager) { walletManager.disconnect(); } }; // userprofilemanagementsystem class UserProfileManager { constructor() { this.currentUserId = null; } // Check if user needs to fill profile - 纯API驱动,nonelocalStorage async checkUserProfile(userId) { // Extract wallet address from userId const walletAddress = userId.replace('wallet_', ''); try { // Get latest profile from backend API const apiUrl = window.AppConfig ? window.AppConfig.getApiUrl() : 'http://localhost:3000'; const response = await fetch(`${apiUrl}/api/profiles/${walletAddress}`); if (response.ok) { const result = await response.json(); const profile = result.profile; (window.AppConfig?.debug?.log || console.log)('Profile from DB exists'); return profile; } else if (response.status === 404) { (window.AppConfig?.debug?.log || console.log)('Profile not found, need registration'); return null; } else { console.error('❌ Failed to fetch profile:', response.status); return null; } } catch (error) { console.error('❌ API request failed:', error.message); // Production: API failure should prompt user to retry alert('networkConnection failed,请检查networkbackrefreshed页面'); return null; } } // Save user profile - pure API driven, no localStorage fallback async saveUserProfile(userId, profileData) { const walletAddress = userId.replace('wallet_', ''); // Prepare API data const apiData = { walletAddress: walletAddress, nickname: profileData.nickname || profileData.username, age: profileData.age, gender: profileData.gender, birthday: profileData.birthday, location: profileData.location, occupation: profileData.occupation, interests: profileData.interests, bio: profileData.bio }; try { // Send to backend API const apiUrl = window.AppConfig ? window.AppConfig.getApiUrl() : 'http://localhost:3000'; (window.AppConfig?.debug?.log || console.log)('POST API:', `${apiUrl}/api/profiles`); (window.AppConfig?.debug?.log || console.log)('Payload prepared'); const response = await fetch(`${apiUrl}/api/profiles`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(apiData) }); (window.AppConfig?.debug?.log || console.log)('API response status:', response.status); if (response.ok) { const result = await response.json(); const savedProfile = result.profile; (window.AppConfig?.debug?.log || console.log)('Profile saved to DB'); return savedProfile; } else if (response.status === 409) { // user已exists,尝试updated (window.AppConfig?.debug?.log || console.log)('User exists, trying update'); return await this.updateUserProfile(userId, profileData); } else { const errorData = await response.json(); throw new Error(errorData.message || `APISave failed: ${response.status}`); } } catch (error) { console.error('❌ Save profile failed:', error.message); // Production: display user-friendly error prompt alert('Save failed,请检查networkconnectedbackretry'); throw error; // Throw error upward, let caller process } } // getuserprofile getUserProfile(userId) { return this.checkUserProfile(userId); } // Delete user profile - pure API driven async deleteUserProfile(userId) { const walletAddress = userId.replace('wallet_', ''); try { // Delete from API const apiUrl = window.AppConfig ? window.AppConfig.getApiUrl() : 'http://localhost:3000'; const response = await fetch(`${apiUrl}/api/profiles/${walletAddress}`, { method: 'DELETE' }); if (response.ok) { (window.AppConfig?.debug?.log || console.log)('Profile deleted'); return true; } else { console.error('❌ Delete failed:', response.status); return false; } } catch (error) { console.error('❌ API delete failed:', error.message); alert('Delete failed,请检查networkconnectedbackretry'); return false; } } // Update user profile - pure API driven async updateUserProfile(userId, updates) { const walletAddress = userId.replace('wallet_', ''); try { const apiUrl = window.AppConfig ? window.AppConfig.getApiUrl() : 'http://localhost:3000'; const response = await fetch(`${apiUrl}/api/profiles/${walletAddress}`, { method: 'PUT', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(updates) }); if (response.ok) { const result = await response.json(); (window.AppConfig?.debug?.log || console.log)('Profile updated'); return result.profile; } else { console.error('❌ Update failed:', response.status); return null; } } catch (error) { console.error('❌ API update failed:', error.message); alert('Update failed,请检查networkconnectedbackretry'); return null; } } // Get all user profiles - pure API driven async getAllUserProfiles() { try { const apiUrl = window.AppConfig ? window.AppConfig.getApiUrl() : 'http://localhost:3000'; const response = await fetch(`${apiUrl}/api/profiles`); if (response.ok) { const result = await response.json(); return result.profiles || []; } else { console.error('❌ Get all users failed:', response.status); return []; } } catch (error) { console.error('❌ API request failed:', error.message); return []; } } // displayprofileregistered面板 showProfilePanel(userId = null, existingProfile = null) { const overlay = document.getElementById('user-profile-overlay'); if (overlay) { // If in edit mode, fill existing data if (existingProfile) { this.fillFormWithProfile(existingProfile); // Change title to edit mode const title = overlay.querySelector('.profile-panel-title'); if (title) title.textContent = i18n.t('registration.edit.title'); } else { // Reset form this.resetForm(); const title = overlay.querySelector('.profile-panel-title'); if (title) title.textContent = i18n.t('registration.title'); } // Initialize month and date selectors setTimeout(() => { this.initDateSelectors(); }, 100); overlay.style.display = 'flex'; (window.AppConfig?.debug?.log || console.log)('Show user registration panel'); } } // hiddenprofileregistered面板 hideProfilePanel() { const overlay = document.getElementById('user-profile-overlay'); if (overlay) { overlay.style.display = 'none'; } } // Initialize month and date selectors initDateSelectors() { const yearSelect = document.getElementById('birthYear'); const monthSelect = document.getElementById('birthMonth'); const daySelect = document.getElementById('birthDay'); if (!yearSelect || !monthSelect || !daySelect) { console.error('Date selectors not found'); return; } // Clear and fill years (1950-2010, suitable for adult users) yearSelect.innerHTML = ''; const currentYear = new Date().getFullYear(); for (let i = currentYear - 15; i >= 1950; i--) { const option = document.createElement('option'); option.value = i; option.textContent = i; yearSelect.appendChild(option); } // Clear and fill months monthSelect.innerHTML = ''; for (let i = 1; i <= 12; i++) { const option = document.createElement('option'); option.value = i; option.textContent = i; monthSelect.appendChild(option); } // Clear and fill dates (default 31 days) daySelect.innerHTML = ''; for (let i = 1; i <= 31; i++) { const option = document.createElement('option'); option.value = i; option.textContent = i; daySelect.appendChild(option); } // Update dates when month changes monthSelect.addEventListener('change', () => { this.updateDayOptions(monthSelect.value); }); } // Update date options based on month updateDayOptions(month) { const daySelect = document.getElementById('birthDay'); const daysInMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; const maxDays = month ? daysInMonth[month - 1] : 31; daySelect.innerHTML = ''; for (let i = 1; i <= maxDays; i++) { const option = document.createElement('option'); option.value = i; option.textContent = i; daySelect.appendChild(option); } } // Fill form with existing profile fillFormWithProfile(profile) { const form = document.getElementById('profile-form'); if (form && profile) { // Fill basic info const nickname = form.querySelector('[name="nickname"]'); if (nickname) nickname.value = profile.nickname || ''; const age = form.querySelector('[name="age"]'); if (age) age.value = profile.age || ''; const location = form.querySelector('[name="location"]'); if (location) location.value = profile.location || ''; const occupation = form.querySelector('[name="occupation"]'); if (occupation) occupation.value = profile.occupation || ''; const interests = form.querySelector('[name="interests"]'); if (interests) interests.value = profile.interests || ''; const bio = form.querySelector('[name="bio"]'); if (bio) bio.value = profile.bio || ''; // Fill birthday if (profile.birthday) { const [year, month, day] = profile.birthday.split('-'); const birthYear = form.querySelector('#birthYear'); const birthMonth = form.querySelector('#birthMonth'); const birthDay = form.querySelector('#birthDay'); if (birthYear) birthYear.value = year; if (birthMonth) birthMonth.value = parseInt(month); if (birthDay) birthDay.value = parseInt(day); } // Fill gender if (profile.gender) { const genderRadio = form.querySelector(`[name="gender"][value="${profile.gender}"]`); if (genderRadio) genderRadio.checked = true; } } } // Reset form resetForm() { const form = document.getElementById('profile-form'); if (form) { form.reset(); // clear日期select器 const birthYear = form.querySelector('#birthYear'); const birthMonth = form.querySelector('#birthMonth'); const birthDay = form.querySelector('#birthDay'); if (birthYear) birthYear.value = ''; if (birthMonth) birthMonth.value = ''; if (birthDay) birthDay.value = ''; } } // displayuser欢迎info showUserWelcome(profile) { // No UI toast in production; keep debug log only (window.AppConfig?.debug?.log || console.log)('User welcome:', !!profile); } } // Ensure UserProfileManager class is globally accessible window.UserProfileManager = UserProfileManager; // Initialize ProfileManager immediately to ensure availability when wallet connects const profileManager = new UserProfileManager(); window.profileManager = profileManager; (window.AppConfig?.debug?.log || console.log)('ProfileManager initialized'); // submitteduserprofileform async function submitProfile(event) { try { (window.AppConfig?.debug?.log || console.log)('Form submit start'); event.preventDefault(); (window.AppConfig?.debug?.log || console.log)('Default submit prevented'); const formData = { username: document.getElementById('username').value.trim(), displayName: document.getElementById('displayName').value.trim(), birthYear: document.getElementById('birthYear').value, birthMonth: document.getElementById('birthMonth').value, birthDay: document.getElementById('birthDay').value, location: document.getElementById('location').value.trim(), language: document.getElementById('language').value, // Memory system data memory: { favoriteFood: document.getElementById('favoriteFood').value.trim(), favoriteColor: document.getElementById('favoriteColor').value.trim(), hobbies: document.getElementById('hobbies').value.trim() } }; (window.AppConfig?.debug?.log || console.log)('Form data collected'); // Validate required fields const requiredFields = { username: formData.username, displayName: formData.displayName, birthYear: formData.birthYear, birthMonth: formData.birthMonth, birthDay: formData.birthDay, location: formData.location, language: formData.language }; const missingFields = Object.entries(requiredFields).filter(([key, value]) => !value).map(([key]) => key); if (missingFields.length > 0) { console.error('❌ Missing required fields:', missingFields); alert(`请填写所有requiredinfo!缺few: ${missingFields.join(', ')}`); return; } // saveduserprofile const walletAddress = localStorage.getItem('wallet_address'); if (walletAddress) { const userId = `wallet_${walletAddress}`; // Convert data format to match API expectations const month = formData.birthMonth.toString().padStart ? formData.birthMonth.padStart(2, '0') : (formData.birthMonth.length === 1 ? '0' + formData.birthMonth : formData.birthMonth); const day = formData.birthDay.toString().padStart ? formData.birthDay.padStart(2, '0') : (formData.birthDay.length === 1 ? '0' + formData.birthDay : formData.birthDay); const apiFormData = { nickname: formData.displayName, username: formData.username, age: new Date().getFullYear() - parseInt(formData.birthYear), birthday: `${formData.birthYear}-${month}-${day}`, location: formData.location, language: formData.language, interests: formData.memory.hobbies, bio: `喜欢的食物: ${formData.memory.favoriteFood}, 喜欢的color: ${formData.memory.favoriteColor}` }; (window.AppConfig?.debug?.log || console.log)('Prepare to save user profile'); // savedtodata库 try { await profileManager.saveUserProfile(userId, apiFormData); (window.AppConfig?.debug?.log || console.log)('User profile saved; hide panel'); profileManager.hideProfilePanel(); } catch (error) { console.error('❌ Save user profile failed:', error); alert('saveduserprofilefailed,请retry'); return; } (window.AppConfig?.debug?.log || console.log)('User profile submitted; ready to select character'); // displaypromptmessage const successMsg = document.createElement('div'); successMsg.style.cssText = ` position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0, 0, 0, 0.9); color: white; padding: 20px 40px; border-radius: 10px; font-size: 16px; z-index: 10001; `; successMsg.textContent = i18n.t('registration.success'); document.body.appendChild(successMsg); setTimeout(() => { successMsg.remove(); }, 3000); } else { console.error('❌ Wallet address missing; cannot save profile'); } } catch (error) { console.error('❌ Error during form submit:', error); alert(i18n.t('error.save') + ': ' + error.message); } } // handleProfileSubmit会at普通scriptlabelmiddle定义 // Expose functions to global scope window.submitProfile = submitProfile; // Test function - force show profile panel window.testShowProfilePanel = function() { (window.AppConfig?.debug?.log || console.log)('Test: show profile panel'); if (window.profileManager) { (window.AppConfig?.debug?.log || console.log)('profileManager exists; show panel'); window.profileManager.showProfilePanel(); } else { console.error('❌ profileManager does not exist'); } }; // new增:testednewuser流程 window.testNewUserFlow = function() { (window.AppConfig?.debug?.log || console.log)('Test: simulate new user flow'); const testAddress = 'TEST_NEW_USER_' + Date.now(); (window.AppConfig?.debug?.log || console.log)('Use test address:', testAddress); setTimeout(async () => { if (window.profileManager) { const userId = `wallet_${testAddress}`; try { const profile = await window.profileManager.checkUserProfile(userId); (window.AppConfig?.debug?.log || console.log)('Check result:', !!profile); if (!profile) { (window.AppConfig?.debug?.log || console.log)('New user confirmed; show panel'); window.profileManager.showProfilePanel(); } } catch (error) { (window.AppConfig?.debug?.log || console.log)('API error; show panel'); window.profileManager.showProfilePanel(); } } }, 500); }; // =================== // globalusermanagementfunction // =================== // clearcurrentuserprofile(模拟首次logged in) window.clearUserProfile = async function() { const walletAddress = localStorage.getItem('wallet_address'); if (walletAddress) { const userId = `wallet_${walletAddress}`; (window.AppConfig?.debug?.log || console.log)('Clearing user profile from DB:', userId); // Pure API deletion, no longer use localStorage if (window.profileManager) { const success = await window.profileManager.deleteUserProfile(userId); if (success) { (window.AppConfig?.debug?.log || console.log)('User profile deleted; refresh to see effect'); location.reload(); } else { (window.AppConfig?.debug?.warn || console.warn)('Delete failed; user may not exist'); } } else { console.error('❌ profileManager not initialized'); } } else { (window.AppConfig?.debug?.log || console.log)('No wallet connected; skip clear'); } }; // clear所有userprofile window.clearAllProfiles = function() { const profiles = window.profileManager.getAllUserProfiles(); profiles.forEach(({userId}) => { window.profileManager.deleteUserProfile(userId); }); (window.AppConfig?.debug?.log || console.log)(`Cleared ${profiles.length} user profiles`); }; // view所有userprofile window.showAllProfiles = function() { const profiles = window.profileManager.getAllUserProfiles(); (window.AppConfig?.debug?.log || console.log)(`Total profiles: ${profiles.length}`); profiles.forEach(({userId, profile}) => { console.log(`👤 ${userId}:`, profile); }); return profiles; }; // editedcurrentuserprofile window.editCurrentProfile = function() { const walletAddress = localStorage.getItem('wallet_address'); if (walletAddress) { const userId = `wallet_${walletAddress}`; const profile = window.profileManager.getUserProfile(userId); if (profile) { window.profileManager.showProfilePanel(userId, profile); (window.AppConfig?.debug?.log || console.log)('Editing user profile'); } else { (window.AppConfig?.debug?.log || console.log)('Profile not found; show registration'); window.profileManager.showProfilePanel(); } } else { (window.AppConfig?.debug?.warn || console.warn)('Wallet not connected'); } }; // getcurrentuserprofile window.getCurrentProfile = function() { const walletAddress = localStorage.getItem('wallet_address'); if (walletAddress) { const userId = `wallet_${walletAddress}`; const profile = window.profileManager.getUserProfile(userId); (window.AppConfig?.debug?.log || console.log)('Current user profile available'); return profile; } else { (window.AppConfig?.debug?.warn || console.warn)('Wallet not connected'); return null; } };