Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/reduce default gas price #128

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/dkg.min.js

Large diffs are not rendered by default.

40 changes: 23 additions & 17 deletions services/blockchain-service/blockchain-service-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ class BlockchainServiceBase {
gasPrice = Math.round(response.data.average * 1e9);
}
} else {
gasPrice = Web3.utils.toWei('100', 'Gwei');
gasPrice = Web3.utils.toWei('2', 'Gwei');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move default value to the constants

}
return gasPrice;
} catch (error) {
// eslint-disable-next-line no-console
console.warn(
`Failed to fetch the gas price from the network: ${error}. Using default value: 100 Gwei.`,
`Failed to fetch the gas price from the network: ${error}. Using default value: 2 Gwei.`,
);
return Web3.utils.toWei('100', 'Gwei');
return Web3.utils.toWei('2', 'Gwei');
}
}

Expand Down Expand Up @@ -531,22 +531,28 @@ class BlockchainServiceBase {

async getGasPrice(blockchain) {
const web3Instance = await this.getWeb3Instance(blockchain);
let gasPrice;

if (blockchain.name.startsWith('otp')) {
gasPrice = await web3Instance.eth.getGasPrice();
} else if (blockchain.name.startsWith('gnosis')) {
const response = await axios.get(blockchain.gasPriceOracleLink);
if (blockchain.name.split(':')[1] === '100') {
gasPrice = Number(response.result, 10);
} else if (blockchain.name.split(':')[1] === '10200') {
gasPrice = Math.round(response.data.average * 1e9);
try {
let gasPrice;
if (blockchain.name.startsWith('otp')) {
gasPrice = await web3Instance.eth.getGasPrice();
} else if (blockchain.name.startsWith('gnosis')) {
const response = await axios.get(blockchain.gasPriceOracleLink);
if (blockchain.name.split(':')[1] === '100') {
gasPrice = Number(response.result, 10);
} else if (blockchain.name.split(':')[1] === '10200') {
gasPrice = Math.round(response.data.average * 1e9);
}
} else {
gasPrice = Web3.utils.toWei('2', 'Gwei');
}
} else {
gasPrice = Web3.utils.toWei('100', 'Gwei');
return gasPrice;
} catch (error) {
// eslint-disable-next-line no-console
console.warn(
`Failed to fetch the gas price from the network: ${error}. Using default value: 2 Gwei.`,
);
return Web3.utils.toWei('2', 'Gwei');
}

return gasPrice;
}

async getWalletBalances(blockchain) {
Expand Down