Skip to content

Commit a5e7099

Browse files
authored
Merge pull request #2324 from ethereum/waitForTx
wait to get tx receipt
2 parents b444717 + 32a6c0e commit a5e7099

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

apps/remix-ide/src/app/tabs/web3-provider.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,36 @@ export class Web3ProviderModule extends Plugin {
2828
if (error) return reject(error)
2929
if (payload.method === 'eth_sendTransaction') {
3030
if (payload.params.length && !payload.params[0].to && message.result) {
31-
const receipt = await this.call('blockchain', 'getTransactionReceipt', message.result)
32-
const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', receipt.contractAddress)
33-
if (contractData) this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name)
31+
setTimeout(async () => {
32+
const receipt = await this.tryTillReceiptAvailable(message.result)
33+
if (!receipt.contractAddress) {
34+
console.log('receipt available but contract address not present', receipt)
35+
return
36+
}
37+
const contractData = await this.call('compilerArtefacts', 'getContractDataFromAddress', receipt.contractAddress)
38+
if (contractData) this.call('udapp', 'addInstance', receipt.contractAddress, contractData.contract.abi, contractData.name)
39+
}, 50)
3440
}
3541
}
3642
resolve(message)
3743
})
3844
})
3945
}
46+
47+
async tryTillReceiptAvailable (txhash) {
48+
try {
49+
const receipt = await this.call('blockchain', 'getTransactionReceipt', txhash)
50+
if (receipt) return receipt
51+
} catch (e) {
52+
// do nothing
53+
}
54+
await this.pause()
55+
return await this.tryTillReceiptAvailable(txhash)
56+
}
57+
58+
async pause () {
59+
return new Promise((resolve, reject) => {
60+
setTimeout(resolve, 500)
61+
})
62+
}
4063
}

0 commit comments

Comments
 (0)