Merge pull request #2324 from ethereum/waitForTx

wait to get tx receipt
pull/5370/head
yann300 3 years ago committed by GitHub
commit bdb4588ecb
  1. 29
      apps/remix-ide/src/app/tabs/web3-provider.js

@ -28,13 +28,36 @@ export class Web3ProviderModule extends Plugin {
if (error) return reject(error)
if (payload.method === 'eth_sendTransaction') {
if (payload.params.length && !payload.params[0].to && message.result) {
const receipt = await this.call('blockchain', 'getTransactionReceipt', message.result)
const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', receipt.contractAddress)
if (contractData) this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name)
setTimeout(async () => {
const receipt = await this.tryTillReceiptAvailable(message.result)
if (!receipt.contractAddress) {
console.log('receipt available but contract address not present', receipt)
return
}
const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', receipt.contractAddress)
if (contractData) this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name)
}, 50)
}
}
resolve(message)
})
})
}
async tryTillReceiptAvailable (txhash) {
try {
const receipt = await this.call('blockchain', 'getTransactionReceipt', txhash)
if (receipt) return receipt
} catch (e) {
// do nothing
}
await this.pause()
return await this.tryTillReceiptAvailable(txhash)
}
async pause () {
return new Promise((resolve, reject) => {
setTimeout(resolve, 500)
})
}
}

Loading…
Cancel
Save