Skip to content

Commit

Permalink
contract MethodFactory updated for production build
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Furter committed Mar 29, 2019
1 parent 45b0992 commit 507d2b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,6 @@ export default class EthSendTransactionMethod extends SendTransactionMethod {
* @returns {Boolean}
*/
hasCustomSigner() {
return this.moduleInstance.transactionSigner.constructor.name !== 'TransactionSigner';
return this.moduleInstance.transactionSigner.type !== 'TransactionSigner';
}
}
58 changes: 33 additions & 25 deletions packages/web3-eth-contract/src/factories/MethodFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,7 @@ export default class MethodFactory {
* @returns {SendContractMethod}
*/
createSendContractMethod(contract) {
const transactionObserver = new TransactionObserver(
contract.currentProvider,
this.getTransactionObserverTimeout(contract),
contract.transactionConfirmationBlocks,
new GetTransactionReceiptMethod(this.utils, this.formatters, contract),
new GetBlockByNumberMethod(this.utils, this.formatters, contract),
new NewHeadsSubscription(this.utils, this.formatters, contract)
);
const transactionObserver = this.createTransactionObserver(contract);

return new SendContractMethod(
this.utils,
Expand All @@ -186,21 +179,16 @@ export default class MethodFactory {
* @returns {ContractDeployMethod}
*/
createContractDeployMethod(contract) {
const transactionObserver = this.createTransactionObserver(contract);

return new ContractDeployMethod(
this.utils,
this.formatters,
contract,
new TransactionObserver(
contract.currentProvider,
this.getTransactionObserverTimeout(contract),
contract.transactionConfirmationBlocks,
new GetTransactionReceiptMethod(this.utils, this.formatters, contract),
new GetBlockByNumberMethod(this.utils, this.formatters, contract),
new NewHeadsSubscription(this.utils, this.formatters, contract)
),
transactionObserver,
new ChainIdMethod(this.utils, this.formatters, contract),
new GetTransactionCountMethod(this.utils, this.formatters, contract),
new SendRawTransactionMethod(this.utils, this.formatters, contract)
new SendRawTransactionMethod(this.utils, this.formatters, contract, transactionObserver)
);
}

Expand All @@ -217,23 +205,43 @@ export default class MethodFactory {
return new EstimateGasMethod(this.utils, this.formatters, contract);
}


/**
* Returns the correct timeout value based on the provider type
* Returns the correct timeout value
*
* @method getTransactionObserverTimeout
* @method getTimeout
*
* @param {AbstractContract} contract
* @param {AbstractWeb3Module} moduleInstance
*
* @returns {Number}
*/
getTransactionObserverTimeout(contract) {
let timeout = contract.transactionBlockTimeout;
const providerName = contract.currentProvider.constructor.name;
getTimeout(moduleInstance) {
let timeout = moduleInstance.transactionBlockTimeout;

if (providerName === 'HttpProvider' || providerName === 'CustomProvider') {
timeout = contract.transactionPollingTimeout;
if (!moduleInstance.currentProvider.SOCKET_MESSAGE) {
timeout = moduleInstance.transactionPollingTimeout;
}

return timeout;
}

/**
* Returns a object of type TransactionObserver
*
* @method createTransactionObserver
*
* @param {AbstractContract} contract
*
* @returns {TransactionObserver}
*/
createTransactionObserver(contract) {
return new TransactionObserver(
contract.currentProvider,
this.getTimeout(contract),
contract.transactionConfirmationBlocks,
new GetTransactionReceiptMethod(this.utils, this.formatters, contract),
new GetBlockByNumberMethod(this.utils, this.formatters, contract),
new NewHeadsSubscription(this.utils, this.formatters, contract)
);
}
}

0 comments on commit 507d2b0

Please sign in to comment.