| … | … | @@ -1712,17 +1712,17 @@ async function checkStatus() { |
| 1712 | 1712 | if (!data.initialized) { |
| 1713 | 1713 | // Show setup wizard instead of error |
| 1714 | 1714 | showSetupWizard() |
| 1715 | | return false |
| 1715 | return { initialized: false } |
| 1716 | 1716 | } |
| 1717 | 1717 | |
| 1718 | 1718 | document.getElementById('wallet-status').innerHTML = '✅ Ready' |
| 1719 | 1719 | // Network name is set by updateNetworkLabels() based on selectedNetwork |
| 1720 | | return true |
| 1720 | return data |
| 1721 | 1721 | } catch (err) { |
| 1722 | 1722 | console.error('Status check failed:', err) |
| 1723 | 1723 | document.getElementById('wallet-status').innerHTML = '❌ Server Error' |
| 1724 | 1724 | showError('Cannot connect to wallet server') |
| 1725 | | return false |
| 1725 | return { initialized: false } |
| 1726 | 1726 | } |
| 1727 | 1727 | } |
| 1728 | 1728 | |
| … | … | @@ -2769,15 +2769,26 @@ async function init() { |
| 2769 | 2769 | // Update network labels |
| 2770 | 2770 | updateNetworkLabels() |
| 2771 | 2771 | |
| 2772 | | const initialized = await checkStatus() |
| 2772 | const status = await checkStatus() |
| 2773 | 2773 | |
| 2774 | | // If initialized but no API token, prompt for password |
| 2775 | | if (initialized && !getToken()) { |
| 2776 | | console.log('🔐 Wallet initialized but password needed') |
| 2777 | | const success = await promptForPassword() |
| 2778 | | if (!success) { |
| 2779 | | showError('Failed to unlock wallet. Please refresh and try again.') |
| 2780 | | return |
| 2774 | // If initialized, check if we need to prompt for password |
| 2775 | if (status.initialized) { |
| 2776 | const token = getToken() |
| 2777 | |
| 2778 | // If password not cached on server but we have a token, it's stale |
| 2779 | if (status.passwordCached === false && token) { |
| 2780 | console.log('🔐 Stale token detected - clearing and prompting for password') |
| 2781 | clearToken() |
| 2782 | } |
| 2783 | |
| 2784 | // If no token (or cleared stale token), prompt for password |
| 2785 | if (!getToken()) { |
| 2786 | console.log('🔐 Wallet initialized but password needed') |
| 2787 | const success = await promptForPassword() |
| 2788 | if (!success) { |
| 2789 | showError('Failed to unlock wallet. Please refresh and try again.') |
| 2790 | return |
| 2791 | } |
| 2781 | 2792 | } |
| 2782 | 2793 | } |
| 2783 | 2794 | |