| … | … | @@ -603,22 +603,32 @@ async function exportIdentity() { |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | try { |
| 606 | console.log('[Export] Requesting identity mnemonic...') |
| 606 | 607 | const res = await authFetch(`/api/export-identity`, { |
| 607 | 608 | method: 'POST', |
| 608 | 609 | headers: { 'Content-Type': 'application/json' }, |
| 609 | 610 | body: JSON.stringify({ password }) |
| 610 | 611 | }) |
| 612 | |
| 613 | console.log('[Export] Response status:', res.status) |
| 611 | 614 | const data = await res.json() |
| 615 | console.log('[Export] Response data:', data.error ? `Error: ${data.error}` : 'Success') |
| 612 | 616 | |
| 613 | 617 | if (data.error) { |
| 614 | 618 | showError(data.error) |
| 615 | 619 | return |
| 616 | 620 | } |
| 617 | 621 | |
| 618 | | // Show mnemonic in alert (not ideal, but simple) |
| 619 | | alert(`Your Identity Mnemonic (24 words):\n\n${data.mnemonic}\n\n⚠️ KEEP THIS SAFE!`) |
| 622 | // Show mnemonic in modal (better than alert) |
| 623 | if (data.mnemonic) { |
| 624 | showMnemonicDisplay(data.mnemonic, 'Identity Mnemonic (24 words)') |
| 625 | } else { |
| 626 | showError('No mnemonic returned from server') |
| 627 | console.error('[Export] No mnemonic in response:', data) |
| 628 | } |
| 620 | 629 | } catch (err) { |
| 621 | | showError('Failed to export identity mnemonic') |
| 630 | console.error('[Export] Error:', err) |
| 631 | showError('Failed to export identity mnemonic: ' + err.message) |
| 622 | 632 | } |
| 623 | 633 | } |
| 624 | 634 | |
| … | … | @@ -635,22 +645,32 @@ async function exportWalletMnemonic() { |
| 635 | 645 | } |
| 636 | 646 | |
| 637 | 647 | try { |
| 648 | console.log('[Export] Requesting wallet mnemonic...') |
| 638 | 649 | const res = await authFetch(`/api/export-wallet`, { |
| 639 | 650 | method: 'POST', |
| 640 | 651 | headers: { 'Content-Type': 'application/json' }, |
| 641 | 652 | body: JSON.stringify({ password }) |
| 642 | 653 | }) |
| 654 | |
| 655 | console.log('[Export] Response status:', res.status) |
| 643 | 656 | const data = await res.json() |
| 657 | console.log('[Export] Response data:', data.error ? `Error: ${data.error}` : 'Success') |
| 644 | 658 | |
| 645 | 659 | if (data.error) { |
| 646 | 660 | showError(data.error) |
| 647 | 661 | return |
| 648 | 662 | } |
| 649 | 663 | |
| 650 | | // Show mnemonic in alert (not ideal, but simple) |
| 651 | | alert(`Your Wallet Mnemonic (12 words):\n\n${data.mnemonic}\n\n⚠️ KEEP THIS SAFE!`) |
| 664 | // Show mnemonic in modal (better than alert) |
| 665 | if (data.mnemonic) { |
| 666 | showMnemonicDisplay(data.mnemonic, 'Wallet Mnemonic (12 words)') |
| 667 | } else { |
| 668 | showError('No mnemonic returned from server') |
| 669 | console.error('[Export] No mnemonic in response:', data) |
| 670 | } |
| 652 | 671 | } catch (err) { |
| 653 | | showError('Failed to export wallet mnemonic') |
| 672 | console.error('[Export] Error:', err) |
| 673 | showError('Failed to export wallet mnemonic: ' + err.message) |
| 654 | 674 | } |
| 655 | 675 | } |
| 656 | 676 | |
| … | … | @@ -3633,6 +3653,40 @@ window.setWalletAddressCurrent = setWalletAddressCurrent |
| 3633 | 3653 | window.showAddWallet = showAddWallet |
| 3634 | 3654 | window.showTxDetails = showTxDetails |
| 3635 | 3655 | |
| 3656 | // Mnemonic display modal functions |
| 3657 | let currentMnemonic = '' |
| 3658 | |
| 3659 | function showMnemonicDisplay(mnemonic, title = 'Mnemonic') { |
| 3660 | const modal = document.getElementById('mnemonic-display-modal') |
| 3661 | const textEl = document.getElementById('mnemonic-display-text') |
| 3662 | const titleEl = modal.querySelector('h3') |
| 3663 | |
| 3664 | currentMnemonic = mnemonic |
| 3665 | textEl.textContent = mnemonic |
| 3666 | titleEl.textContent = `🔐 ${title}` |
| 3667 | |
| 3668 | modal.showModal() |
| 3669 | } |
| 3670 | |
| 3671 | function closeMnemonicDisplay() { |
| 3672 | const modal = document.getElementById('mnemonic-display-modal') |
| 3673 | currentMnemonic = '' |
| 3674 | modal.close() |
| 3675 | } |
| 3676 | |
| 3677 | async function copyMnemonicToClipboard() { |
| 3678 | try { |
| 3679 | await navigator.clipboard.writeText(currentMnemonic) |
| 3680 | showSuccess('Mnemonic copied to clipboard!') |
| 3681 | } catch (err) { |
| 3682 | showError('Failed to copy to clipboard') |
| 3683 | } |
| 3684 | } |
| 3685 | |
| 3686 | window.showMnemonicDisplay = showMnemonicDisplay |
| 3687 | window.closeMnemonicDisplay = closeMnemonicDisplay |
| 3688 | window.copyMnemonicToClipboard = copyMnemonicToClipboard |
| 3689 | |
| 3636 | 3690 | // Start when DOM is ready |
| 3637 | 3691 | if (document.readyState === 'loading') { |
| 3638 | 3692 | document.addEventListener('DOMContentLoaded', init) |