dabit3 / nextjs-gitcoin-passport

Next.js + Gitcoin passport example application

Home Page:https://nextjs-gitcoin-passport.vercel.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

checkConnection()

0xZakk opened this issue · comments

checkConnection()
async function checkConnection() {
try {
const provider = new ethers.providers.Web3Provider(window.ethereum)
const accounts = await provider.listAccounts()
if (accounts && accounts[0]) {
setConnected(true)
setAddress(accounts[0])
checkPassport(accounts[0])
}
} catch (err) {
console.log('not connected...')
}
}

Do we need to invoke and then define the function on the next line like this?

hey, I'm not sure I follow the question here

this function just checks their connection and automatically fetches their score if they've already connected.

My question is just about the formatting (defining and then invoking a function, all inside of a function). Could we make the parent function async and move everything from checkConnection out into the parent function? Or is there a technical reason it has to be inside a separate function?

AH! yes, great question, you cannot (or are not supposed to do this) due to how useEffect works, there's some discussion about those details here

Ahh okay - good to know