2
0
mirror of synced 2025-02-24 20:18:07 +00:00

Fix waitForTransaction delay (#424).

This commit is contained in:
Richard Moore 2019-02-15 13:32:08 -05:00
parent 94b0abc240
commit c15a89832b
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295

View File

@ -777,17 +777,19 @@ export class BaseProvider extends Provider {
waitForTransaction(transactionHash: string, confirmations?: number): Promise<TransactionReceipt> {
if (confirmations == null) { confirmations = 1; }
if (confirmations === 0) {
return this.getTransactionReceipt(transactionHash);
}
return new Promise((resolve) => {
let handler = (receipt: TransactionReceipt) => {
if (receipt.confirmations < confirmations) { return; }
this.removeListener(transactionHash, handler);
resolve(receipt);
return this.getTransactionReceipt(transactionHash).then((receipt) => {
if (confirmations === 0 || (receipt && receipt.confirmations >= confirmations)) {
return receipt;
}
this.on(transactionHash, handler);
return <Promise<TransactionReceipt>>(new Promise((resolve) => {
let handler = (receipt: TransactionReceipt) => {
if (receipt.confirmations < confirmations) { return; }
this.removeListener(transactionHash, handler);
resolve(receipt);
}
this.on(transactionHash, handler);
}));
});
}