Commit 5e3cb489 authored by Stefy Spora's avatar Stefy Spora

Add direct MetaMask detection in popup

- Added direct injection method to check for MetaMask availability
- Improved Web3 provider detection with multiple fallback approaches
- Enhanced error handling with clearer user feedback
parent 1f5d875b
......@@ -233,6 +233,25 @@ document.addEventListener('DOMContentLoaded', function() {
}, 5000);
}
// Function to check if MetaMask is available via direct injection
async function checkMetaMaskDirect(tabId) {
try {
const results = await chrome.scripting.executeScript({
target: { tabId: tabId },
func: () => {
// This function runs in the context of the web page
return typeof window.ethereum !== 'undefined' ||
(typeof window.web3 !== 'undefined' && typeof window.web3.currentProvider !== 'undefined');
}
});
return results[0].result === true;
} catch (error) {
console.error('Direct MetaMask check failed:', error);
return false;
}
}
web3DonateBtn.addEventListener('click', async function() {
try {
web3DonateBtn.disabled = true;
......@@ -247,7 +266,14 @@ document.addEventListener('DOMContentLoaded', function() {
return;
}
// First, check if content script is loaded by sending a test message
// First, check if MetaMask is available via direct injection
const isMetaMaskAvailable = await checkMetaMaskDirect(tab.id);
if (!isMetaMaskAvailable) {
showWeb3Status('MetaMask not detected. Please ensure MetaMask is installed and unlocked.', true);
return;
}
// Then check if content script is loaded by sending a test message
try {
await chrome.tabs.sendMessage(tab.id, { action: 'ping' });
} catch (pingError) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment