Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async getGasPrice(type: StorageTypes.GasPriceType, networkName: string): Promise {
if (networkName === EthereumUtils.getEthereumNetworkNameFromId(StorageTypes.EthereumNetwork.MAINNET)) {
const gasPriceArray: Array = await this.pollProviders(type);
if (gasPriceArray.length > 0) {
// Divide the sum of gas prices to get the mean
const gasPriceSum = gasPriceArray.reduce(
(currentGasPriceSum, gasPrice) => currentGasPriceSum.add(gasPrice),
new bigNumber(0),
);
return gasPriceSum.div(new bigNumber(this.gasPriceProviderList.length)).toString();
} else {
this.logger.warn('Cannot determine gas price: There is no available gas price provider', [
'ethereum',
]);
}
}
getEthereumNetworkNameFromId(networkId: StorageTypes.EthereumNetwork): string {
return {
[StorageTypes.EthereumNetwork.PRIVATE as StorageTypes.EthereumNetwork]: 'private',
[StorageTypes.EthereumNetwork.MAINNET as StorageTypes.EthereumNetwork]: 'mainnet',
[StorageTypes.EthereumNetwork.KOVAN as StorageTypes.EthereumNetwork]: 'kovan',
[StorageTypes.EthereumNetwork.RINKEBY as StorageTypes.EthereumNetwork]: 'rinkeby',
}[networkId];
},
getEthereumNetworkNameFromId(networkId: StorageTypes.EthereumNetwork): string {
return {
[StorageTypes.EthereumNetwork.PRIVATE as StorageTypes.EthereumNetwork]: 'private',
[StorageTypes.EthereumNetwork.MAINNET as StorageTypes.EthereumNetwork]: 'mainnet',
[StorageTypes.EthereumNetwork.KOVAN as StorageTypes.EthereumNetwork]: 'kovan',
[StorageTypes.EthereumNetwork.RINKEBY as StorageTypes.EthereumNetwork]: 'rinkeby',
}[networkId];
},