This commit is contained in:
2025-04-22 13:00:10 +04:00
parent 6573a01d75
commit 3e49f48f60
12 changed files with 1416 additions and 188 deletions

View File

@@ -141,12 +141,14 @@ let selectedKeypair = null;
let hasEthereumWallet = false;
// Update UI based on login state
function updateLoginUI() {
async function updateLoginUI() {
const loginStatus = document.getElementById('login-status');
try {
console.log('Ethereum: Checking login status...');
// Try to list keypairs to check if logged in
const keypairs = list_keypairs();
console.log('Ethereum: Keypairs found:', keypairs);
if (keypairs && keypairs.length > 0) {
loginStatus.textContent = 'Status: Logged in';
@@ -163,6 +165,7 @@ function updateLoginUI() {
hasEthereumWallet = false;
}
} catch (e) {
console.error('Ethereum: Error checking login status:', e);
loginStatus.textContent = 'Status: Not logged in. Please login in the Main Crypto Demo page first.';
loginStatus.className = 'status logged-out';
@@ -449,35 +452,39 @@ const GNOSIS_RPC_URL = "https://rpc.gnosis.gateway.fm";
const GNOSIS_EXPLORER = "https://gnosisscan.io";
async function run() {
// Initialize the WebAssembly module
await init();
console.log('WebAssembly crypto module initialized!');
// Set up the keypair selection
document.getElementById('select-keypair').addEventListener('change', performSelectKeypair);
// Set up the Ethereum wallet management
document.getElementById('create-ethereum-wallet-button').addEventListener('click', performCreateEthereumWallet);
document.getElementById('create-from-name-button').addEventListener('click', performCreateEthereumWalletFromName);
document.getElementById('import-private-key-button').addEventListener('click', performCreateEthereumWalletFromPrivateKey);
// Set up the copy buttons
document.getElementById('copy-address-button').addEventListener('click', () => {
const address = document.getElementById('ethereum-address-value').textContent;
copyToClipboard(address, 'Ethereum address copied to clipboard!');
});
document.getElementById('copy-private-key-button').addEventListener('click', () => {
const privateKey = document.getElementById('ethereum-private-key-value').textContent;
copyToClipboard(privateKey, 'Private key copied to clipboard!');
});
// Set up the balance check
document.getElementById('check-balance-button').addEventListener('click', checkBalance);
// Initialize UI
updateLoginUI();
try {
// Initialize the WebAssembly module
await init();
console.log('WebAssembly crypto module initialized!');
// Set up the keypair selection
document.getElementById('select-keypair').addEventListener('change', performSelectKeypair);
// Set up the Ethereum wallet management
document.getElementById('create-ethereum-wallet-button').addEventListener('click', performCreateEthereumWallet);
document.getElementById('create-from-name-button').addEventListener('click', performCreateEthereumWalletFromName);
document.getElementById('import-private-key-button').addEventListener('click', performCreateEthereumWalletFromPrivateKey);
// Set up the copy buttons
document.getElementById('copy-address-button').addEventListener('click', () => {
const address = document.getElementById('ethereum-address-value').textContent;
copyToClipboard(address, 'Ethereum address copied to clipboard!');
});
document.getElementById('copy-private-key-button').addEventListener('click', () => {
const privateKey = document.getElementById('ethereum-private-key-value').textContent;
copyToClipboard(privateKey, 'Private key copied to clipboard!');
});
// Set up the balance check
document.getElementById('check-balance-button').addEventListener('click', checkBalance);
// Initialize UI - call async function and await it
await updateLoginUI();
} catch (error) {
console.error('Error initializing Ethereum page:', error);
}
}
run().catch(console.error);