Skip to content

Commit

Permalink
use block fetch to detect network issue, + both conditions need to be…
Browse files Browse the repository at this point in the history
… true
  • Loading branch information
paulo-ocean committed Jul 24, 2024
1 parent 61895f7 commit af4619f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class Blockchain {
}

public async isNetworkReady(): Promise<ConnectionStatus> {
if (this.networkAvailable || this.provider.ready) {
if (this.networkAvailable && this.provider.ready) {
return { ready: true }
}
return await this.detectNetwork()
Expand All @@ -73,11 +73,12 @@ export class Blockchain {
CORE_LOGGER.error(`Unable to detect provider network: (TIMEOUT)`)
resolve({ ready: false, error: 'TIMEOUT' })
}, 3000)

this.provider
._detectNetwork()
.then((network) => {
.getBlock('latest')
.then((block) => {
clearTimeout(timeout)
resolve({ ready: network instanceof Network })
resolve({ ready: block.hash !== null })
})
.catch((err) => {
CORE_LOGGER.error(`Unable to detect provider network: ${err.message}`)
Expand Down

0 comments on commit af4619f

Please sign in to comment.