Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (
!apiResponse.fast ||
!apiResponse.standard ||
!apiResponse.safeLow ||
isNaN(apiResponse.fast) ||
isNaN(apiResponse.standard) ||
isNaN(apiResponse.safeLow)
) {
throw new Error(`Etherchain API response doesn't contain the correct format`);
}
// Retrieve the gas price from the provided gas price type and the format of the API response
const apiGasPrice = new bigNumber(
parseFloat(
{
[StorageTypes.GasPriceType.FAST as StorageTypes.GasPriceType]: apiResponse.fast,
[StorageTypes.GasPriceType.STANDARD as StorageTypes.GasPriceType]: apiResponse.standard,
[StorageTypes.GasPriceType.SAFELOW as StorageTypes.GasPriceType]: apiResponse.safeLow,
}[type],
) * API_MULTIPLIER,
);
if (!EthereumUtils.isGasPriceSafe(apiGasPrice)) {
throw Error('Etherchain provided gas price not safe to use');
}
return apiGasPrice;
}
}
!apiResponse.fast ||
!apiResponse.standard ||
!apiResponse.safeLow ||
isNaN(apiResponse.fast) ||
isNaN(apiResponse.standard) ||
isNaN(apiResponse.safeLow)
) {
throw new Error(`Etherchain API response doesn't contain the correct format`);
}
// Retrieve the gas price from the provided gas price type and the format of the API response
const apiGasPrice = new bigNumber(
parseFloat(
{
[StorageTypes.GasPriceType.FAST as StorageTypes.GasPriceType]: apiResponse.fast,
[StorageTypes.GasPriceType.STANDARD as StorageTypes.GasPriceType]: apiResponse.standard,
[StorageTypes.GasPriceType.SAFELOW as StorageTypes.GasPriceType]: apiResponse.safeLow,
}[type],
) * API_MULTIPLIER,
);
if (!EthereumUtils.isGasPriceSafe(apiGasPrice)) {
throw Error('Etherchain provided gas price not safe to use');
}
return apiGasPrice;
}
}
!apiResponse.fast ||
!apiResponse.average ||
!apiResponse.safeLow ||
isNaN(apiResponse.fast) ||
isNaN(apiResponse.average) ||
isNaN(apiResponse.safeLow)
) {
throw new Error(`EthGasStation API response doesn't contain the correct format`);
}
// Retrieve the gas price from the provided gas price type and the format of the API response
const apiGasPrice = new bigNumber(
parseFloat(
{
[StorageTypes.GasPriceType.FAST as StorageTypes.GasPriceType]: apiResponse.fast,
[StorageTypes.GasPriceType.STANDARD as StorageTypes.GasPriceType]: apiResponse.average,
[StorageTypes.GasPriceType.SAFELOW as StorageTypes.GasPriceType]: apiResponse.safeLow,
}[type],
) * API_MULTIPLIER,
);
if (!EthereumUtils.isGasPriceSafe(apiGasPrice)) {
throw Error('EthGasStation provided gas price not safe to use');
}
return apiGasPrice;
}
}
// Get the fee from the size of the content
// Throws an error if timeout is reached
const fee = await Promise.race([
Utils.timeoutPromise(this.timeout, 'Web3 getFeesAmount connection timeout'),
this.requestHashSubmitter.methods.getFeesAmount(feesParameters.contentSize).call(),
]);
// Determines the gas price to use
// If the gas price is provided as a parameter, we use this value
// If the gas price is not provided and we use mainnet, we determine it from gas price api providers
// We use the fast value provided by the api providers
// Otherwise, we use default value from config
const gasPriceToUse =
gasPrice ||
(await gasPriceDefiner.getGasPrice(StorageTypes.GasPriceType.FAST, this.networkName));
// parse the fees parameters to hex bytes
const feesParametersAsBytes = web3Utils.padLeft(
web3Utils.toHex(feesParameters.contentSize),
LENGTH_BYTES32_STRING,
);
// Send transaction to contract
// TODO(PROT-181): Implement a log manager for the library
// use it for the different events (error, transactionHash, receipt and confirmation)
return new Promise(
(resolve, reject): any => {
// This boolean is set to true once the ethereum metadata has been created and the promise has been resolved
// When set to true, we use it to ignore next confirmation event function call
let ethereumMetadataCreated: boolean = false;
if (
!apiResponse.fast ||
!apiResponse.average ||
!apiResponse.safeLow ||
isNaN(apiResponse.fast) ||
isNaN(apiResponse.average) ||
isNaN(apiResponse.safeLow)
) {
throw new Error(`EthGasStation API response doesn't contain the correct format`);
}
// Retrieve the gas price from the provided gas price type and the format of the API response
const apiGasPrice = new bigNumber(
parseFloat(
{
[StorageTypes.GasPriceType.FAST as StorageTypes.GasPriceType]: apiResponse.fast,
[StorageTypes.GasPriceType.STANDARD as StorageTypes.GasPriceType]: apiResponse.average,
[StorageTypes.GasPriceType.SAFELOW as StorageTypes.GasPriceType]: apiResponse.safeLow,
}[type],
) * API_MULTIPLIER,
);
if (!EthereumUtils.isGasPriceSafe(apiGasPrice)) {
throw Error('EthGasStation provided gas price not safe to use');
}
return apiGasPrice;
}
}