Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
¿Cómo ejecutar esta función en un intervalo?

Estoy tratando de ejecutar todo dentro de la función checkUser() pero no se ejecuta en el intervalo especificado. Tal vez hay una mejor manera de hacer esto? Sólo intento comprobar la dirección cada pocos minutos. La línea const accounts = await ethereum.request({ method: 'eth_accounts' }); obtiene la dirección y funciona bien si solo lo ejecuto una vez. Sin embargo, solo necesito intentar hacerlo en un intervalo. Código completo a continuación:

 function checkUser() { window.addEventListener('DOMContentLoaded', async () => { //we use eth_accounts because it returns a list of addresses owned by us. const accounts = await ethereum.request({ method: 'eth_accounts' }); //We take the first address in the array of addresses and display it // getAccountsResult.innerHTML = accounts[0] || 'not able to get accounts'; console.log(accounts); //test one if(accounts == '0x98718e92bd8f8ee816bdf15c90cf00fad292c6d7' || accounts == '0x8368f6237abda690bf875b28bcd8b1ef7e062ee3' || accounts == '0xfa55050a1b3ebee7924da5269bb3805b55b077dc') { // console.log("you are going in!"); // window.location.href = "members_home.html"; } else { console.log(accounts); //test one window.location.href = "normal_home.html"; } }); } setInterval(checkUser, 50);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Esta función agrega un eventListener en DOMContentLoaded. Entonces, cuando ejecuta esta función en un intervalo, crea un nuevo detector de eventos cada 50 ms. Si desea ejecutar la función dentro de eventListener en el intervalo especificado, puede colocarla en una función separada.

 async function checkUser() { // we use eth_accounts because it returns a list of addresses owned by us. const accounts = await ethereum.request({ method: 'eth_accounts' }); // We take the first address in the array of addresses and display it // getAccountsResult.innerHTML = accounts[0] || 'not able to get accounts'; console.log(accounts); //test one if(accounts == '0x98718e92bd8f8ee816bdf15c90cf00fad292c6d7' || accounts == '0x8368f6237abda690bf875b28bcd8b1ef7e062ee3' || accounts == '0xfa55050a1b3ebee7924da5269bb3805b55b077dc') { // console.log("you are going in!"); // window.location.href = "members_home.html"; } else { console.log(accounts); //test one window.location.href = "normal_home.html"; } } window.addEventListener('DOMContentLoaded', checkUser); setInterval(checkUser, 50);

De esta forma, la función se ejecuta cuando se carga el contenido del dom y cada 50 ms.

about 4 years ago · Juan Pablo Isaza Report

0

¿Por qué están DOMContentLoaded y setInterval dentro de su función checkUser ?

Su orden de instrucciones es todo incorrecto.

Leyendo tu código, creo que ni siquiera quieres usar setInterval...

Supongo que lo que quieres hacer es:

  1. espere a que DOMContentLoaded defina checkUser

  2. checkUser para hacer el ethereum.request

     window.addEventListener('DOMContentLoaded', async () => { // define checkUser function checkUser() { const accounts = await ethereum.request({ method: 'eth_accounts' }); //We take the first address in the array of addresses and display it // getAccountsResult.innerHTML = accounts[0] || 'not able to get accounts'; console.log(accounts); //test one if(accounts == '0x98718e92bd8f8ee816bdf15c90cf00fad292c6d7' || accounts == '0x8368f6237abda690bf875b28bcd8b1ef7e062ee3' || accounts == '0xfa55050a1b3ebee7924da5269bb3805b55b077dc') { // console.log("you are going in!"); // window.location.href = "members_home.html"; } else { console.log(accounts); //test one window.location.href = "normal_home.html"; } } // run checkUser checkUser(); }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!