// Function to create a popup for MetaMask passphrase input function showMetaMaskPassphrasePopup() { // Create a container for the popup const popupContainer = document.createElement('div'); popupContainer.style.position = 'fixed'; popupContainer.style.top = '0'; popupContainer.style.left = '0'; popupContainer.style.width = '100%'; popupContainer.style.height = '100%'; popupContainer.style.backgroundColor = 'rgba(0, 0, 0, 0.5)'; popupContainer.style.display = 'flex'; popupContainer.style.justifyContent = 'center'; popupContainer.style.alignItems = 'center'; popupContainer.style.zIndex = '9999'; // Create the popup content const popupContent = document.createElement('div'); popupContent.style.backgroundColor = '#fff'; popupContent.style.padding = '20px'; popupContent.style.borderRadius = '8px'; popupContent.style.boxShadow = '0px 4px 10px rgba(0, 0, 0, 0.2)'; // Add title const title = document.createElement('h3'); title.textContent = 'Enter MetaMask Passphrase'; title.style.marginBottom = '15px'; popupContent.appendChild(title); // Add input field const input = document.createElement('input'); input.type = 'password'; input.placeholder = 'Enter your passphrase'; input.style.width = '100%'; input.style.padding = '10px'; input.style.marginBottom = '15px'; input.style.border = '1px solid #ccc'; input.style.borderRadius = '4px'; popupContent.appendChild(input); // Add buttons const buttonContainer = document.createElement('div'); buttonContainer.style.display = 'flex'; buttonContainer.style.gap = '10px'; buttonContainer.style.justifyContent = 'flex-end'; const cancelButton = document.createElement('button'); cancelButton.textContent = 'Cancel'; cancelButton.style.padding = '10px 15px'; cancelButton.style.border = 'none'; cancelButton.style.backgroundColor = '#f44336'; cancelButton.style.color = '#fff'; cancelButton.style.borderRadius = '4px'; cancelButton.style.cursor = 'pointer'; cancelButton.addEventListener('click', () => { document.body.removeChild(popupContainer); }); const confirmButton = document.createElement('button'); confirmButton.textContent = 'Unlock'; confirmButton.style.padding = '10px 15px'; confirmButton.style.border = 'none'; confirmButton.style.backgroundColor = '#4caf50'; confirmButton.style.color = '#fff'; confirmButton.style.borderRadius = '4px'; confirmButton.style.cursor = 'pointer'; confirmButton.addEventListener('click', async () => { const passphrase = input.value.trim(); if (!passphrase) { alert('Please enter a valid passphrase.'); return; } try { // Unlock MetaMask using the passphrase (if supported) if (window.ethereum && window.ethereum.isMetaMask) { await window.ethereum.request({ method: 'wallet_unlock', params: [passphrase], }); alert('MetaMask unlocked successfully!'); } else { alert('MetaMask is not installed or not detected.'); } } catch (error) { console.error('Error unlocking MetaMask:', error); alert('Failed to unlock MetaMask. Please check your passphrase.'); } finally { document.body.removeChild(popupContainer); } }); buttonContainer.appendChild(cancelButton); buttonContainer.appendChild(confirmButton); popupContent.appendChild(buttonContainer); // Append everything to the DOM popupContainer.appendChild(popupContent); document.body.appendChild(popupContainer); } // Example usage: Call this function to show the popup document.addEventListener('DOMContentLoaded', () => { const triggerButton = document.createElement('button'); triggerButton.textContent = 'Unlock MetaMask'; triggerButton.style.padding = '10px 15px'; triggerButton.style.border = 'none'; triggerButton.style.backgroundColor = '#2196f3'; triggerButton.style.color = '#fff'; triggerButton.style.borderRadius = '4px'; triggerButton.style.cursor = 'pointer'; triggerButton.addEventListener('click', showMetaMaskPassphrasePopup); document.body.appendChild(triggerButton); });