First of all, window.cardano
can be undefined if the user doesn't have a Cardano wallet installed on their browser.
Secondly, you don't need to use await
with window.cardano
as it's not an async function. Also, you should avoid nested hell and instead try something like this:-
const isCardano = window && window.cardano
const isNamiInstalled = isCardano && window.cardano.nami
const isNamiEnabled = isNamiInstalled ? await window.cardano.nami.isEnabled() : false
Edit: sometimes window.cardano
or window.cardano.nami
can be undefined even if you have nami installed. That happens mostly when you try to access these parameters before the extension is even injected to the site. To prevent such scenarios, you can try wrapping your code with a setTimeout delay.
setTimeout(()=> {
const isCardano = window && window.cardano
const isNamiInstalled = isCardano && window.cardano.nami
const isNamiEnabled = isNamiInstalled ? await window.cardano.nami.isEnabled() : false
}, 1500)