Created
January 5, 2022 13:09
-
-
Save irzhywau/5ece1ba6eec5863ef353e82471d31050 to your computer and use it in GitHub Desktop.
dapps browser connect attempts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// we are in an create-react-app context | |
export default () => { | |
const [mm, setSupport] = React.useState<MetamaskSupport | null>(null); | |
React.useEffect(() => { | |
let alreadyHandled = false; | |
// as the provider may be not available all the time on mobile, we need this side-effect implementation | |
// see https://docs.metamask.io/guide/mobile-best-practices.html#the-provider-window-ethereum | |
// also see https://github.com/MetaMask/detect-provider | |
const handleEthereum = () => { | |
if (alreadyHandled) { | |
return; | |
} | |
const { ethereum, elastos } = window; | |
setSupport({ | |
supported: Boolean(ethereum), | |
elastos: Boolean(elastos), | |
chainId: parseInt(ethereum?.chainId || '0x0', 16), | |
}); | |
// eslint-disable-next-line no-alert | |
alert(JSON.stringify({ | |
supported: Boolean(ethereum), | |
elastos: Boolean(elastos), | |
chainId: parseInt(ethereum?.chainId || '0x0', 16), | |
})); | |
alreadyHandled = true; | |
}; | |
window.addEventListener('ethereum#initialized', handleEthereum); | |
setTimeout(handleEthereum, 3000); | |
return () => { | |
window.removeEventListener('ethereum#initialized', handleEthereum); | |
}; | |
}, []); | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the result is not the same when I browse https://staging.ela.city and directly to the IP of the same server with the application port